/** * updatePost * * @param Xcforum_PostObject $obj * * @return int **/ public function updatePost($obj, $attributes) { //atrace(); $post_id = $obj->get('post_id'); if (!empty($post_id) && (int) $post_id > 0) { $post_obj = $this->get($post_id); foreach ($attributes as $key => $value) { $post_obj->set($key, $value); } } if ($this->insert($post_obj, true) === true) { $this->inserted_obj = $post_obj; return $this->db->getInsertId(); } return -1; }
/** * updateTopicFromPost * * @param Xcforum_PostObject $obj * * @param array $attributes * * @return Xcforum_TopicsObject **/ public function updateTopicFromPost($obj, $attributes) { // called from Posts.class.php $_topic_id = $obj->get('topic_id'); //adump($_topic_id); if (!empty($_topic_id) && (int) $_topic_id > 0) { $topic = $this->get($_topic_id); } else { // add new topic $topic = new Xcforum_TopicsObject(); //$topic->set('forum_id', $forum_id); $topic->set('topic_title', $obj->get('subject')); $topic->set('topic_first_post_id', $obj->get('post_id')); $topic->set('topic_first_post_time', $obj->get('post_time')); } foreach ($attributes as $key => $value) { $topic->set($key, $value); } //adump($topic); // update post information //$topic->set('topic_last_post_id', $obj->get('post_id')); //$topic->set('topic_last_post_time', $obj->get('post_time')); $topic->set('topic_posts_count', (int) $topic->get('topic_posts_count') + 1); if ($topic instanceof Xcforum_TopicsObject) { if ($this->insert($topic, true) === true) { $inserted_id = (int) $this->db->getInsertId(); $tp_id = $inserted_id > 0 ? $inserted_id : $_topic_id; $topic->set('topic_id', $tp_id); return $topic; } } return NULL; }