Beispiel #1
0
 /**
  * Helper method for fetching the rows and pass them to K2 response.
  * This is triggered by the display function.
  * Usually there will be no need to override this function.
  *
  * @return void
  */
 protected function setRows()
 {
     // Get rows
     $model = $this->getModel();
     $model->setState('id', false);
     $rows = $model->getRows();
     // Prepare rows
     $this->prepareRows($rows);
     // Set K2 response rows
     K2Response::setRows($rows);
 }
 protected function embed($id)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get user
     $user = JFactory::getUser();
     // Get params
     $params = JComponentHelper::getParams('com_k2');
     // Check that comments are enabled
     if (!$params->get('comments')) {
         K2Response::throwError(JText::_('K2_ALERTNOTAUTH'), 404);
     }
     // Get input
     $itemId = $application->input->get('itemId', 0, 'int');
     $offset = $application->input->get('limitstart', 0, 'int');
     if ($itemId) {
         // Get Item
         require_once JPATH_ADMINISTRATOR . '/components/com_k2/resources/items.php';
         $item = K2Items::getInstance($itemId);
         // Check access
         $item->checkSiteAccess();
         // Get model
         $model = K2Model::getInstance('Comments');
         // Set itemId state
         $model->setState('itemId', $item->id);
         // If user cannot edit comments load only the published
         if (!$user->authorise('k2.comment.edit', 'com_k2')) {
             $model->setState('state', 1);
         }
         if ($id) {
             // Calculate the offset of the requested comment
             $model->setState('id', $id);
             $operator = $params->get('commentsOrdering') == 'ASC' ? '<' : '>';
             $model->setState('id.operator', $operator);
             $offset = $model->countRows();
             $page = $offset / (int) $params->get('commentsLimit', 10);
             $page = floor($page);
             $offset = $page * (int) $params->get('commentsLimit', 10);
             // Now get comments of the detected page
             $model->setState('id', false);
             $model->setState('limit', (int) $params->get('commentsLimit', 10));
             $model->setState('limitstart', $offset);
             $model->setState('sorting', 'id.reverse');
             if ($params->get('commentsOrdering') == 'ASC') {
                 $model->setState('sorting', 'id');
             }
             $comments = $model->getRows();
             // Pagination
             jimport('joomla.html.pagination');
             $pagination = new JPagination($model->countRows(), $offset, (int) $params->get('commentsLimit', 10));
         } else {
             // Get comments
             $model->setState('id', false);
             $model->setState('limit', (int) $params->get('commentsLimit', 10));
             $model->setState('limitstart', $offset);
             $model->setState('sorting', 'id.reverse');
             if ($params->get('commentsOrdering') == 'ASC') {
                 $model->setState('sorting', 'id');
             }
             $comments = $model->getRows();
             // Pagination
             jimport('joomla.html.pagination');
             $pagination = new JPagination($model->countRows(), $offset, (int) $params->get('commentsLimit', 10));
         }
         // Response
         K2Response::setRows($comments);
         K2Response::setPagination($pagination);
     }
     K2Response::render();
     // Return
     return $this;
 }