/** * Retrieve comments from database in function of the status, the type or via a search * * @access private */ private function get_comments() { try { $to_read['table'] = 'comment'; $to_read['columns'] = array('COMMENT_ID'); if (VGet::action() == 'by_type' && VGet::id() && VGet::type() && VGet::comment_status()) { $to_read['condition_columns'][':id'] = 'comment_rel_ID'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = VGet::id(); $to_read['value_types'][':id'] = 'int'; $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } elseif (VPost::search_button(false) || VGet::search()) { $to_read['condition_columns']['group'][':content'] = 'comment_content'; $to_read['condition_select_types'][':content'] = 'LIKE'; $to_read['condition_values'][':content'] = '%' . $this->_search . '%'; $to_read['value_types'][':content'] = 'str'; $to_read['condition_types'][':name'] = 'OR'; $to_read['condition_columns']['group'][':name'] = 'comment_name'; $to_read['condition_select_types'][':name'] = 'LIKE'; $to_read['condition_values'][':name'] = '%' . $this->_search . '%'; $to_read['value_types'][':name'] = 'str'; $to_read['condition_types'][':email'] = 'OR'; $to_read['condition_columns']['group'][':email'] = 'comment_email'; $to_read['condition_select_types'][':email'] = 'LIKE'; $to_read['condition_values'][':email'] = '%' . $this->_search . '%'; $to_read['value_types'][':email'] = 'str'; $to_read['condition_types'][':status'] = 'AND'; $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } elseif (VGet::action() == 'edit' && VGet::comment_id()) { $to_read['condition_columns'][':id'] = 'COMMENT_ID'; $to_read['condition_select_types'][':id'] = '='; $to_read['condition_values'][':id'] = VGet::comment_id(); $to_read['value_types'][':id'] = 'int'; } else { $to_read['condition_columns'][':status'] = 'comment_status'; $to_read['condition_select_types'][':status'] = '='; $to_read['condition_values'][':status'] = $this->_status; $to_read['value_types'][':status'] = 'str'; } //pass $to_read by parameter to have same conditions $this->get_pagination($to_read); $to_read['order'] = array('comment_date', 'desc'); $to_read['limit'] = array($this->_limit_start, parent::ITEMS); $this->_content = $this->_db->read($to_read); if (!empty($this->_content)) { foreach ($this->_content as &$comment) { $comment = new Comment($comment['COMMENT_ID']); if ($comment->_rel_type == 'post') { $post = new Post(); $post->_id = $comment->_rel_id; $post->read('_title'); $post->read('_permalink'); $comment->_rel_title = $post->_title; $comment->_rel_permalink = $post->_permalink; } elseif ($comment->_rel_type == 'media') { $media = new Media(); $media->_id = $comment->_rel_id; $media->read('_name'); $comment->_rel_title = $media->_name; $comment->_rel_permalink = $media->_id; } } } elseif (empty($this->_content) && VGet::action() == 'edit') { $this->_content[0] = new Comment(); throw new Exception('Invalid comment!'); } } catch (Exception $e) { $this->_action_msg = ActionMessages::custom_wrong($e->getMessage()); } }