RecentlyViewedListings.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ WR0lhsX7f8cF4cDCtcwojo1jd+eFo+SfDd48cSkW97iePsPkriFe27vLNLvaIS0hfcJWOFGlmVF6N4FZnp45MA==
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2015 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.4
  11. */
  12. /**
  13. * recently viewed listings table service class
  14. */
  15. namespace Ppb\Service;
  16. use Ppb\Db\Table\RecentlyViewedListings as RecentlyViewedListingsTable,
  17. Cube\Db\Expr;
  18. class RecentlyViewedListings extends AbstractService
  19. {
  20. /**
  21. *
  22. * class constructor
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. $this->setTable(
  28. new RecentlyViewedListingsTable());
  29. }
  30. /**
  31. *
  32. * create or update an recently viewed listings row
  33. *
  34. * @param array $data
  35. * @return \Ppb\Service\Offers
  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. }