ContentPages.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ +Qdl7nlwciSgX4WCW7NZ8wiXi4vty+b+rTavWG+E63Y=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.0
  11. */
  12. /**
  13. * content pages table service class
  14. */
  15. namespace Ppb\Service;
  16. use Cube\Db\Expr,
  17. Ppb\Db\Table\ContentPages as ContentPagesTable;
  18. class ContentPages extends AbstractService
  19. {
  20. /**
  21. *
  22. * class constructor
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. $this->setTable(
  28. new ContentPagesTable());
  29. }
  30. /**
  31. *
  32. * create or update a page
  33. *
  34. * @param array $data
  35. * @return $this
  36. */
  37. public function save($data)
  38. {
  39. $row = null;
  40. $data = $this->_prepareSaveData($data);
  41. if (array_key_exists('id', $data)) {
  42. $select = $this->_table->select()
  43. ->where("id = ?", $data['id']);
  44. unset($data['id']);
  45. $row = $this->_table->fetchRow($select);
  46. }
  47. if (count($row) > 0) {
  48. $data['updated_at'] = new Expr('now()');
  49. $this->_table->update($data, "id='{$row['id']}'");
  50. }
  51. else {
  52. $data['created_at'] = new Expr('now()');
  53. $this->_table->insert($data);
  54. }
  55. return $this;
  56. }
  57. /**
  58. *
  59. * delete a content page from the table
  60. *
  61. * @param integer $id the id of the content page
  62. * @return integer returns the number of affected rows
  63. */
  64. public function delete($id)
  65. {
  66. return $this->_table->delete(
  67. $this->_table->getAdapter()->quoteInto('id = ?', $id));
  68. }
  69. }