public function execute()
 {
     $contact_photo_size = 20;
     $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page')));
     $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT));
     $blog_models = new blogBlogModel();
     $user = $this->getUser();
     $blogs = blogHelper::getAvailable();
     $comment_model = new blogCommentModel();
     $offset = $comments_per_page * ($page - 1);
     $prepare_options = array('datetime' => blogActivity::getUserActivity());
     $fields = array("photo_url_{$contact_photo_size}");
     $blog_ids = array_keys($blogs);
     $comments = $comment_model->getList($offset, $comments_per_page, $blog_ids, $fields, $prepare_options);
     $comments_all_count = $comment_model->getCount($blog_ids, null, null, null, null, null);
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     //get related posts info
     $post_model = new blogPostModel();
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $extend_data = array('blog' => $blogs);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     $comments_count = ($page - 1) * $comments_per_page + count($comments);
     if ($page == 1) {
         $this->setLayout(new blogDefaultLayout());
         $this->getResponse()->setTitle(_w('Comments'));
     }
     /**
      * Backend comments view page
      * UI hook allow extends backend comments view page
      * @event backend_comments
      * @param array[int][string]mixed $comments
      * @param array[int][string]int $comments[%id%][id] comment id
      * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html
      */
     $this->view->assign('backend_comments', wa()->event('backend_comments', $comments));
     $this->view->assign('comments', $comments);
     $this->view->assign('comments_count', $comments_count);
     $this->view->assign('comments_total_count', $comments_all_count);
     $this->view->assign('comments_per_page', $comments_per_page);
     $this->view->assign('pages', ceil($comments_all_count / $comments_per_page));
     $this->view->assign('page', $page);
     $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend'));
     $this->view->assign('current_contact_id', $user->getId());
     $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size)));
 }
 protected function getComments($search_options)
 {
     if (empty($search_options['post_id'])) {
         $search_options['post_id'] = null;
     }
     if (!isset($search_options['blog_id'])) {
         $search_options['blog_id'] = array_keys(blogHelper::getAvailable());
     } else {
         if (is_numeric($search_options['blog_id'])) {
             $search_options['blog_id'] = array((int) $search_options['blog_id']);
         } else {
             if (!is_array($search_options['blog_id'])) {
                 $search_options['blog_id'] = array();
             }
         }
     }
     if (is_numeric($search_options['filter'])) {
         $search_options['filter'] = (int) $search_options['filter'];
         if (in_array($search_options['filter'], $search_options['blog_id'])) {
             $search_options['blog_id'] = array($search_options['filter']);
         } else {
             $search_options['blog_id'] = array();
         }
     } else {
         if ($search_options['filter'] == 'myposts') {
             if (empty($search_options['blog_id'])) {
                 $search_options['post_id'] = array();
             } else {
                 $post_model = new blogPostModel();
                 $search_options['post_id'] = array_keys($post_model->select('id')->where('contact_id=? AND blig_id IN (?)', array($this->getUser()->getId(), $search_options['blog_id']))->fetchAll('id'));
             }
         }
     }
     $search_options['approved'] = true;
     $comment_model = new blogCommentModel();
     return $comment_model->getList($search_options, array("photo_url_20"), array('datetime' => blogActivity::getUserActivity()));
 }
 public function getComments($search_options, $fields, $prepare_options)
 {
     $comment_model = new blogCommentModel();
     $post_ids = null;
     $blog_ids = $search_options['blog_id'];
     if (is_numeric($search_options['filter'])) {
         $k = array_search((int) $search_options['filter'], $blog_ids);
         if ($k !== false) {
             $blog_ids = $blog_ids[$k];
         } else {
             $blog_ids = array();
         }
         $search_options['blog_id'] = $blog_ids;
     } else {
         if ($search_options['filter'] == 'myposts') {
             $post_model = new blogPostModel();
             $post_ids = array_keys($post_model->select('id')->where('contact_id=' . $this->getUser()->getId())->fetchAll('id'));
             $search_options['post_id'] = $post_ids;
         }
     }
     $counts = (array) $comment_model->getCount($blog_ids, $post_ids, null, null, null, null);
     return array('comments' => $comment_model->getList($search_options, $fields, $prepare_options), 'comments_all_count' => array_sum($counts));
 }
 public function comments($blog_id = null, $limit = 10)
 {
     $contact_photo_size = 20;
     $limit = max(1, intval($limit));
     $blogs = blogHelper::getAvailable(true, $blog_id);
     $comment_model = new blogCommentModel();
     $prepare_options = array('datetime' => blogActivity::getUserActivity());
     $fields = array("photo_url_{$contact_photo_size}");
     $blog_ids = array_keys($blogs);
     $comments = $comment_model->getList(0, $limit, $blog_ids, $fields);
     $post_ids = array();
     foreach ($comments as $comment) {
         $post_ids[$comment['post_id']] = true;
     }
     //get related posts info
     $post_model = new blogPostModel();
     $search_options = array('id' => array_keys($post_ids));
     $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false);
     $extend_data = array('blog' => $blogs);
     $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false);
     $comments = blogCommentModel::extendRights($comments, $posts);
     self::escape($comments, array('*' => array('posts' => array('text' => true), 'plugins' => true)));
     return $comments;
 }