예제 #1
0
 public function add($review, $parent_id = null, $before_id = null)
 {
     if (empty($review['product_id'])) {
         return false;
     }
     if ($parent_id) {
         $parent = $this->getById($parent_id);
         if (!$parent) {
             return false;
         }
         if ($parent['review_id']) {
             $review['review_id'] = $parent['review_id'];
         } else {
             $review['review_id'] = $parent['id'];
         }
     }
     if (!isset($review['ip']) && ($ip = waRequest::getIp())) {
         $ip = ip2long($ip);
         if ($ip > 2147483647) {
             $ip -= 4294967296;
         }
         $review['ip'] = $ip;
     }
     if (!empty($review['contact_id'])) {
         $user = wa()->getUser();
         if ($user->getId() && !$user->get('is_user')) {
             $user->addToCategory(wa()->getApp());
         }
     }
     if (!isset($review['datetime'])) {
         $review['datetime'] = date('Y-m-d H:i:s');
     }
     if (isset($review['site']) && $review['site']) {
         if (!preg_match('@^https?://@', $review['site'])) {
             $review['site'] = 'http://' . $review['site'];
         }
     }
     $before_id = null;
     $id = parent::add($review, $parent_id, $before_id);
     if (!$id) {
         return false;
     }
     if (empty($review['review_id']) && !empty($review['rate'])) {
         $this->recalcProductRating($review['product_id'], $review['rate']);
     }
     return $id;
 }
예제 #2
0
 /**
  * Delete records from table and fire evenets
  *
  * @param $value
  * @return bool
  */
 public function deleteByField($field, $value = null)
 {
     if (is_array($field)) {
         $items = $this->getByField($field, $this->id);
     } else {
         $items = $this->getByField($field, $value, $this->id);
     }
     $res = false;
     if ($comment_ids = array_keys($items)) {
         /**
          * @event comment_predelete
          * @param array $comment_ids array of comment's ID
          * @return void
          */
         wa()->event('comment_predelete', $comment_ids);
         $res = parent::deleteByField('id', $comment_ids);
         if ($res) {
             /**
              * @event comment_delete
              * @param array $comment_ids array of comment's ID
              * @return void
              */
             wa()->event('comment_delete', $comment_ids);
         }
     }
     return $res;
 }
 public function add($comment, $parent = null)
 {
     if (!isset($comment['datetime'])) {
         $comment['datetime'] = date('Y-m-d H:i:s');
     }
     if (isset($comment['site']) && $comment['site']) {
         if (!preg_match('@^https?://@', $comment['site'])) {
             $comment['site'] = 'http://' . $comment['site'];
         }
     }
     return parent::add($comment, $parent);
 }
예제 #4
0
 /**
  * Insert new item to on some level (parent)
  * @param array $data
  * @param int $parent_id If 0 than root level
  * @param int|null $before_id If null than place at the end of level
  * @return int|false record id
  */
 public function add($data, $parent_id = null, $before_id = null)
 {
     if (empty($data)) {
         return false;
     }
     $data['full_url'] = null;
     if (isset($data['url']) && !$data['url']) {
         unset($data['url']);
     }
     if (!isset($data['create_datetime'])) {
         $data['create_datetime'] = date('Y-m-d H:i:s');
     }
     $before_id = null;
     if (!$parent_id) {
         $before_id = $this->query("SELECT id FROM `{$this->table}` ORDER BY `{$this->left}` LIMIT 1")->fetchField('id');
         if ($before_id === false) {
             $before_id = null;
         }
         if (!empty($data['url'])) {
             $data['url'] = $this->suggestUniqueUrl($data['url'], null, 0);
             $data['full_url'] = $data['url'];
         }
     } else {
         $parent = $this->getById($parent_id);
         if (empty($parent)) {
             return false;
         }
         $before_id = $this->query("\n            SELECT id FROM `{$this->table}` WHERE parent_id = i:parent_id \n            ORDER BY `{$this->left}` LIMIT 1\n        ", array('parent_id' => $parent_id))->fetchField('id');
         if ($before_id === false) {
             $before_id = null;
         }
         if (!empty($data['url'])) {
             $data['url'] = $this->suggestUniqueUrl($data['url'], null, $parent_id);
             $data['full_url'] = $this->fullUrl($parent['full_url'], $data['url']);
         }
     }
     $id = parent::add($data, $parent_id, $before_id);
     if (!$id) {
         return false;
     }
     if (empty($data['url'])) {
         $data = array();
         $data['url'] = $this->suggestUniqueUrl("category_{$id}", $id, $parent_id);
         if (!$parent_id) {
             $data['full_url'] = $data['url'];
         } else {
             $data['full_url'] = $this->fullUrl($parent['full_url'], $data['url']);
         }
         $this->updateById($id, $data);
     }
     $this->clearCache();
     return $id;
 }