123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace Ppb\Service;
- use Cube\Db\Expr,
- Ppb\Db\Table\ContentPages as ContentPagesTable;
- class ContentPages extends AbstractService
- {
-
- public function __construct()
- {
- parent::__construct();
- $this->setTable(
- new ContentPagesTable());
- }
-
- public function save($data)
- {
- $row = null;
- $data = $this->_prepareSaveData($data);
- if (array_key_exists('id', $data)) {
- $select = $this->_table->select()
- ->where("id = ?", $data['id']);
- unset($data['id']);
- $row = $this->_table->fetchRow($select);
- }
- if (count($row) > 0) {
- $data['updated_at'] = new Expr('now()');
- $this->_table->update($data, "id='{$row['id']}'");
- }
- else {
- $data['created_at'] = new Expr('now()');
- $this->_table->insert($data);
- }
- return $this;
- }
-
- public function delete($id)
- {
- return $this->_table->delete(
- $this->_table->getAdapter()->quoteInto('id = ?', $id));
- }
- }
|