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; }
public function add($comment, $parent = null) { if (!isset($comment['ip']) && ($ip = waRequest::getIp())) { $ip = ip2long($ip); if ($ip > 2147483647) { $ip -= 4294967296.0; } $comment['ip'] = $ip; } 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']; } } $comment[$this->parent] = $parent; blogActivity::setUserActivity(); /** * @event comment_presave_frontend * @event comment_presave_backend * @param array $comment * @param int $comment.id * @param int $comment.parent * @return void */ wa()->event('comment_presave_' . wa()->getEnv(), $comment); $comment['id'] = parent::add($comment, $parent); /** * @event comment_save_frontend * @event comment_save_backend * @param array $comment * @param int $comment.id * @param int $comment.parent * @return void */ wa()->event('comment_save_' . wa()->getEnv(), $comment); return $comment['id']; }
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); }
/** * 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; }