Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed README.md
Empty file.
130 changes: 74 additions & 56 deletions src/Controller/Admin/AdinfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);

/**
Expand All @@ -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'));

Expand Down Expand Up @@ -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()
{
Expand All @@ -153,42 +166,47 @@ 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(
'module' => $module,
'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');
}

/**
Expand All @@ -199,36 +217,36 @@ 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 {
$message = __('Invalid data, please check and re-submit.');
}
} 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 = '';
Expand All @@ -239,19 +257,19 @@ 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()
{
$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;
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/Admin/ChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
32 changes: 29 additions & 3 deletions src/Form/AdinfoFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AdinfoFilter extends InputFilter
public function __construct()
{
$this->add(array(
'name' => 'name',
'name' => 'adformat',
'required' => true,
'filters' => array(
array(
Expand All @@ -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',
)),
),
));

}
}

33 changes: 18 additions & 15 deletions src/Form/AdinfoForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,53 @@
* @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;
}

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(
Expand All @@ -82,3 +84,4 @@ public function init()
));
}
}

Loading