function getBookContributionComments() { global $current_user; /* @var $current_user CurrentUser */ $id_book = isset($this->params['book_id']) ? (int) $this->params['book_id'] : false; if (!$id_book) { return; } $book = Books::getInstance()->getByIdLoaded($id_book); /* @var $book Book */ if (!$book->exists) { throw new Exception('book #' . $book->id . ' not exists'); } $cond = new Conditions(); $per_page = 0; if (isset($this->params['per_page'])) { $per_page = (int) $this->params['per_page']; } $per_page = $per_page > 0 ? $per_page : 20; $pagingName = isset($this->params['paging_parameter_name']) ? $this->params['paging_parameter_name'] : 'p'; $cond->setPaging(1000, $per_page, $pagingName); $limit = $cond->getMongoLimit(); list($comments, $count) = MongoDatabase::getBookComments($id_book, $per_page, $limit); $uids = array(); $comments['comments'] = isset($comments['comments']) ? $comments['comments'] : array(); foreach ($comments['comments'] as &$comment) { $comment['commenter_id'] = $comment['user_id']; $comment['type'] = 'book'; $comment['time'] = date('Y/m/d H:i:s', $comment['time']); $uids[$comment['user_id']] = $comment['user_id']; } $cond = new Conditions(); $cond->setPaging($count, $per_page, $pagingName); $this->data['conditions'] = $cond->getConditions(); $this->data['comments'] = isset($comments['comments']) ? $comments['comments'] : array(); $this->data['comments']['title'] = 'Обсуждение книги «' . $book->getTitle(true) . '»'; $this->data['comments']['count'] = $count; $this->data['users'] = $this->getCommentsUsers($uids); }