diff --git a/README.md b/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/src/Controller/Admin/AdinfoController.php b/src/Controller/Admin/AdinfoController.php index d6cce26..97b2033 100755 --- a/src/Controller/Admin/AdinfoController.php +++ b/src/Controller/Admin/AdinfoController.php @@ -37,14 +37,27 @@ class AdinfoController extends ActionController { protected $channelColumns = array( - 'id', 'name', 'protal_id', 'time_create', 'time_update', 'user_update', + 'id', 'protal_id', 'channel_id', + 'adformat','url','supplier_id','content', + 'ad_date','time_create','time_update', + 'user_update', + ); + + protected $AdinfoColumns = array( + 'id', 'protal_id', 'channel_id','adformat', + 'url','supplier_id','content','ad_date', + 'time_create', 'time_update', 'user_update', ); protected $displayColumns = array( - array('column'=>'protal_id', 'name'=> 'Protal', 'width'=>'15'), - array('column'=>'name', 'name'=> 'Adinfo name', 'width'=>'45'), - array('column'=>'time_create', 'name'=> 'Added Date', 'width'=>'15'), - array('column'=>'time_update', 'name'=> 'Last Modified','width'=>'15'), + array('column'=>'supplier_id', 'name'=>'supplier_id', 'width'=>'8' ), + array('column'=>'protal_id', 'name'=> 'protal_id', 'width'=>'8' ), + array('column'=>'channel_id', 'name'=> 'channel_id', 'width'=>'8' ), + array('column'=>'adformat', 'name'=> 'adformat', 'width'=>'8' ), + array('column'=>'url', 'name'=> 'url', 'width'=>'15'), + array('column'=>'content', 'name'=>'content', 'width'=>'8' ), + array('column'=>'time_create', 'name'=>'Added Date', 'width'=>'20'), + array('column'=>'time_update', 'name'=>'Last Modified', 'width'=>'50'), ); /** @@ -66,16 +79,16 @@ public function indexAction() if (!empty($schName)) { $where['name like ?'] = sprintf('%%%s%%',$schName); } - $modelAdinfo = $this->getModel('channel'); - $channels = $modelAdinfo->getSearchRows($where, $limit, $offset, $this->channelColumns, sprintf('%s %s', $orderby, $order)); + $modelAdinfo = $this->getModel('Adinfo'); + $Adinfos = $modelAdinfo->getSearchRows($where, $limit, $offset, $this->channelColumns, sprintf('%s %s', $orderby, $order)); /* get protals info */ - $protal_ids = array(); - foreach($channels as $channel) { - if (!in_array($channel['protal_id'], $protal_ids)) { - array_push(&$protal_ids, $channel['protal_id']); - } - } + // $protal_ids = array(); + // foreach($channels as $channel) { + // if (!in_array($channel['protal_id'], $protal_ids)) { + // array_push(&$protal_ids, $channel['protal_id']); + // } + // } $modelProtal = $this->getModel('protal'); $protals = $modelProtal->getRows($protal_ids, array('id','name')); @@ -128,21 +141,21 @@ public function indexAction() } /* end table header */ $assign = array( - 'channels' => $channels, + 'Adinfos' => $Adinfos, 'protals' => $protals, - 'paginator' => $paginator, - 'tableHeader' => $tableHeader, + 'paginator' => $paginator, + 'tableHeader' => $tableHeader, 'orderby' => $orderby, 'order' => $order, 'schName' => $schName, 'schUrl' => $schUrl, ); $this->view()->assign($assign); - $this->view()->setTemplate('channel-list'); + $this->view()->setTemplate('Adinfo-list'); } /** - * Add a channel + * Add an ad */ public function addAction() { @@ -153,28 +166,28 @@ public function addAction() $form->setInputFilter(new AdinfoFilter); $form->setData($data); if ($form->isValid()) { - $values = $form->getData(); - foreach (array_keys($values) as $key) { - if (!in_array($key, $this->channelColumns)) { - unset($values[$key]); - } - } - $values['time_create'] = $values['time_update'] = time(); - unset($values['id']); - $row = $this->getModel('channel')->createRow($values); - $row->save(); - if ($row->id) { - $message = __('Adinfo data saved successfully.'); - //$this->view()->setTemplate(false); - $this->redirect()->toRoute('', array('action' => 'index')); - return; - } else { - $message = __('Adinfo data not saved.'); - } + $values = $form->getData(); + foreach (array_keys($values) as $key) { + if (!in_array($key, $this->AdinfoColumns)) { + unset($values[$key]); + } + } + $values['time_create'] = $values['time_update'] = time(); + unset($values['id']); + $row = $this->getModel('Adinfo')->createRow($values); + $row->save(); + if ($row->id) { + $message = __('Adinfo data saved successfully.'); + //$this->view()->setTemplate(false); + $this->redirect()->toRoute('', array('action' => 'index')); + return; + } else { + $message = __('Adinfo data not saved.'); + } } else { - $message = __('Invalid data, please check and re-submit.'); + $message = __('Invalid data, please check and re-submit.'); } - } else { + } else { $form = new AdinfoForm('channel'); $form->setAttribute('action', $this->url('', array('action' => 'add'))); $form->setData(array( @@ -182,13 +195,18 @@ public function addAction() 'section' => 'front', )); $message = ''; - } + } - - $this->view()->assign('form', $form); - $this->view()->assign('title', __('Add a channel')); + $assign=array('form' => $form, + 'data' => $data, + 'values' => $values, + 'row' => $row, + ); + $this->view()->assign($assign); + //$this->view()->assign('form', $form); + $this->view()->assign('title', __('Add a Adinfo')); $this->view()->assign('message', $message); - $this->view()->setTemplate('channel-edit'); + $this->view()->setTemplate('adinfo-edit'); } /** @@ -199,21 +217,21 @@ public function editAction() if ($this->request->isPost()) { $data = $this->request->getPost(); $id = $data['id']; - $row = $this->getModel('channel')->find($id); - $form = new AdinfoForm('channel'); + $row = $this->getModel('Adinfo')->find($id); + $form = new AdinfoForm('supplier'); $form->setInputFilter(new AdinfoFilter); $form->setData($data); if ($form->isValid()) { $values = $form->getData(); - foreach (array_keys($values) as $key) { - if (!in_array($key, $this->channelColumns)) { - unset($values[$key]); - } - } + foreach (array_keys($values) as $key) { + if (!in_array($key, $this->AdinfoColumns)) { + unset($values[$key]); + } + } $values['time_update'] = time(); $row->assign($values); $row->save(); - //$message = __('Adinfo data saved successfully.'); + //$message = __('Supplier data saved successfully.'); $this->redirect()->toRoute('', array('action' => 'index')); return; } else { @@ -221,14 +239,14 @@ public function editAction() } } else { $id = $this->params('id'); - $row = $this->getModel('channel')->find($id); + $row = $this->getModel('Adinfo')->find($id); $data = $row->toArray(); $dateFormat = Pi::config('date_format', 'intl'); $extdata = array( 'time_create'=>date($dateFormat, $data['time_create']), 'time_update'=>date($dateFormat, $data['time_update']) ); - $form = new AdinfoForm('channel'); + $form = new AdinfoForm('supplier'); $form->setData($data); $form->setAttribute('action', $this->url('', array('action' => 'edit'))); $message = ''; @@ -239,11 +257,11 @@ public function editAction() $this->view()->assign('form', $form); $this->view()->assign('title', __('Adinfo edit')); $this->view()->assign('message', $message); - $this->view()->setTemplate('channel-edit'); + $this->view()->setTemplate('Adinfo-edit'); } /** - * deleting a channel + * deleting a ad * */ public function deleteAction() @@ -251,7 +269,7 @@ public function deleteAction() $id = Service::getParam($this, 'id', ''); $id = is_array($id)?$id:(array)$id; if (count($id)) { - $this->getModel('channel')->delete(array('id'=>$id)); + $this->getModel('Adinfo')->delete(array('id'=>$id)); } $this->redirect()->toRoute('', array('action' => 'index')); //return 1; diff --git a/src/Controller/Admin/ChannelController.php b/src/Controller/Admin/ChannelController.php index 0db19c4..bfa3448 100755 --- a/src/Controller/Admin/ChannelController.php +++ b/src/Controller/Admin/ChannelController.php @@ -71,11 +71,11 @@ public function indexAction() /* get protals info */ $protal_ids = array(); - foreach($channels as $channel) { - if (!in_array($channel['protal_id'], $protal_ids)) { - array_push(&$protal_ids, $channel['protal_id']); - } - } + // foreach($channels as $channel) { + // if (!in_array($channel['protal_id'], $protal_ids)) { + // array_push(&$protal_ids, $channel['protal_id']); + // } + // } $modelProtal = $this->getModel('protal'); $protals = $modelProtal->getRows($protal_ids, array('id','name')); diff --git a/src/Form/AdinfoFilter.php b/src/Form/AdinfoFilter.php index 405205e..c57d14e 100755 --- a/src/Form/AdinfoFilter.php +++ b/src/Form/AdinfoFilter.php @@ -29,7 +29,7 @@ class AdinfoFilter extends InputFilter public function __construct() { $this->add(array( - 'name' => 'name', + 'name' => 'adformat', 'required' => true, 'filters' => array( array( @@ -45,12 +45,38 @@ public function __construct() )); $this->add(array( - 'name' => 'protal_id', + 'name' => 'url', 'filters' => array( array( - 'name' => 'Int', + 'name' => 'StringTrim', + ), + ), + 'validators' => array( + array( + 'name' => 'Regex', + 'options' => array( + 'pattern' => '/http:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is', + ), + ), + ), + )); + + $this->add(array( + 'name' => 'content', + 'required' => true, + 'filters' => array( + array( + 'name' => 'StringTrim', ), ), + 'validators' => array( + new StringLength(array( + 'min' => '3', + 'max' => '50', + )), + ), )); + } } + diff --git a/src/Form/AdinfoForm.php b/src/Form/AdinfoForm.php index 0b81083..fac54f5 100755 --- a/src/Form/AdinfoForm.php +++ b/src/Form/AdinfoForm.php @@ -18,18 +18,18 @@ * @version $Id$ */ + namespace Module\Admanager\Form; use Pi; use Pi\Form\Form as BaseForm; -use Module\Admanager\Model\Protal; class AdinfoForm extends BaseForm { public function getInputFilter() { if (!$this->filter) { - $this->filter = new AdinfoFilter; + $this->filter = new ProtalFilter; } return $this->filter; } @@ -37,32 +37,34 @@ public function getInputFilter() public function init() { $this->add(array( - 'name' => 'name', + 'name' => 'adformat', 'options' => array( - 'label' => __('Adinfo name'), + 'label' => __('adformat'), ), 'attributes' => array( 'type' => 'text', ) )); - $protalOptions = array(); - $model = Pi::model('protal', 'admanager'); - $protals = $model->getSearchRows(array(), null, null, array('name')); - foreach($protals as $protal_id=>$protal) { - $protalOptions[$protal_id] = $protal['name']; - } - $this->add(array( - 'name' => 'protal_id', + 'name' => 'url', 'options' => array( - 'label' => __('Protal'), + 'label' => __('Protal url'), ), 'attributes' => array( - 'type' => 'select', - 'options' => $protalOptions, + 'type' => 'text', + 'class' => 'input-xxlarge', ) + )); + $this->add(array( + 'name' => 'content', + 'options' => array( + 'label' => __('content'), + ), + 'attributes' => array( + 'type' => 'text', + ) )); $this->add(array( @@ -82,3 +84,4 @@ public function init() )); } } + diff --git a/src/Model/Adinfo.php b/src/Model/Adinfo.php new file mode 100644 index 0000000..0c1ae72 --- /dev/null +++ b/src/Model/Adinfo.php @@ -0,0 +1,136 @@ + + * @since 1.0 + * @package Module\Admanager + */ + +namespace Module\Admanager\Model; + +use Pi; +use Pi\Application\Model\Model; +use Zend\Db\Sql\Expression; + +class Adinfo extends Model +{ + + public static function getDefaultColumns() + { + return array( + 'id', 'protal_id', 'channel_id', + 'adformat','url','supplier_id','content', + 'ad_date','time_create','time_update', + 'user_update', + ); + } + + /** + * Get channels by ids + * + * @param $ids Channel ids + * @param null $columns Columns, null for default + * @return array + */ + public function getRows($ids, $columns = null) + { + $result = $rows = array(); + + if (null === $columns) { + $columns = self::getDefaultColumns(); + } + + if ($ids) { + $result = array_flip($ids); + + $rows = $this->select(array('id' => $ids)); + + foreach ($rows as $row) { + $result[$row['id']] = $row; + } + + $result = array_filter($result, function($var) { + return is_array($var); + }); + } + + return $result; + } + + public function getSearchRows($where = array(), $limit = null, $offset = null, $columns = null, $order = null) + { + $result = $rows = array(); + + if (null === $columns) { + $columns = self::getDefaultColumns(); + } + + if (!in_array('id', $columns)) { + $columns[] = 'id'; + } + + $order = (null === $order) ? 'time_update DESC' : $order; + + $select = $this->select() + ->columns($columns); + + if ($where) { + $select->where($where); + } + + if ($limit) { + $select->limit(intval($limit)); + } + + if ($offset) { + $select->offset(intval($offset)); + } + + if ($order) { + $select->order($order); + } + + $rows = $this->selectWith($select)->toArray(); + + $dateFormat = Pi::config('date_format', 'intl'); + foreach ($rows as $row) { + if (!empty($row['time_create'])) { + $row['time_create'] = date($dateFormat, $row['time_create']); + } + if (!empty($row['time_update'])) { + $row['time_update'] = date($dateFormat, $row['time_update']); + } + $result[$row['id']] = $row; + } + + return $result; + } + + public function getSearchRowsCount($where = array()) + { + $result = 0; + + $select = $this->select() + ->columns(array('total' => new Expression('count(id)'))); + + if ($where) { + $select->where($where); + } + + $resultset = $this->selectWith($select); + $result = intval($resultset->current()->total); + + return $result; + } + +} diff --git a/template/admin/Adinfo-edit.phtml b/template/admin/Adinfo-edit.phtml new file mode 100644 index 0000000..a2e11a9 --- /dev/null +++ b/template/admin/Adinfo-edit.phtml @@ -0,0 +1,27 @@ + + + +
+ +
+ + + templateComponent('form'); ?> +
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+
\ No newline at end of file diff --git a/template/admin/Adinfo-list.phtml b/template/admin/Adinfo-list.phtml new file mode 100644 index 0000000..c644ab6 --- /dev/null +++ b/template/admin/Adinfo-list.phtml @@ -0,0 +1,94 @@ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+
+paginationControl($paginator, 'Sliding', 'paginator.phtml',array('class' => 'pagination-right')); ?> + + \ No newline at end of file