예제 #1
0
 public function index()
 {
     $paginator = Paginator::factory(1024);
     $pages = $paginator->setItemCountPerPage(30)->setCurrentPageNumber($this->getRequest()->getParam('page', 1))->setPageRange(10)->getPages();
     $this->view = View::factory('pagination');
     $this->view->assign('url', $this->getBaseUrl() . $this->getRequest()->uri() . '/page/');
     $this->view->assign('pages', $pages);
     $this->view->render();
 }
예제 #2
0
파일: Admin.php 프로젝트: DavBfr/BlogMVC
 public function action_index()
 {
     $posts = ORM::factory('Post')->order_by('post.created', 'DESC')->find_all();
     $paginator = Paginator::factory($posts);
     $paginator->set_item_count_per_page(5);
     $paginator->set_current_page_number(Arr::get($_GET, 'page', 1));
     $this->template->title = 'Admin';
     $this->template->content = View::factory('admin/index')->set('posts', $paginator);
 }
예제 #3
0
파일: Posts.php 프로젝트: DavBfr/BlogMVC
 public function action_author()
 {
     $slug = $this->request->param('user');
     $user = ORM::factory('User')->where('user.id', '=', $slug)->find();
     if (!$user->loaded()) {
         throw HTTP_Exception::factory(404);
     }
     $paginator = Paginator::factory($user->posts->order_by('created', 'DESC')->find_all());
     $paginator->set_item_count_per_page(5);
     $paginator->set_current_page_number(Arr::get($_GET, 'page', 1));
     $data = array('user' => $user, 'posts' => $paginator);
     $this->template->title = $user->username;
     $this->template->content = View::factory('blog/author', $data);
 }
예제 #4
0
 /**
  *
  * Get parsed html of user questions div,
  * complete with pagination
  *
  * @todo there has to be an extra request param "tab" and ONLY if
  * it equals to 'questions' then it would mean
  * that sort and pagination is for this block because it could
  * be for 'answer' block since they both come to the same controller
  * OR just make separate controllers and then pagination and sorting
  * will work ONLY with AJAX  and then just hide pagination from
  * non-js browsers!
  *
  * @param Registry $Registry
  * @param User $User
  *
  * @return string html of user questions
  */
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     $pagerLinks = '';
     $pageID = $Registry->Request->get('pageID', 'i', 1);
     /**
      * Default pager path
      */
     $pagerPath = '/tab/q/' . $uid . '/recent';
     /**
      * Default sort condition
      *
      * @var array
      */
     $sort = array('i_ts' => 1);
     //$mode = $Registry->Request->get('tab', 's', '');
     /**
      * sort order possible values:
      * recent, oldest, voted, updated, views
      *
      * default is oldest first
      *
      * $mode 'questions' means that user requested
      * either pagination or sorting specifically
      * for the User Questions
      * This is not necessaraly an ajax request as pagination
      * will work without Ajax too.
      *
      * When there is no explicit 'questions' $mode
      * then we need to just get the cursor
      * with default sort and pageID, treating this
      * request as if it was for pageID 1 and sort=oldest
      */
     //if('q' === $mode){
     $cond = $Registry->Request->get('sort', 's', 'recent');
     switch ($cond) {
         case 'recent':
             $sort = array('i_ts' => -1);
             $pagerPath = '/tab/q/' . $uid . '/recent';
             break;
         case 'voted':
             $sort = array('i_votes' => -1);
             $pagerPath = '/tab/q/' . $uid . '/voted';
             break;
         case 'updated':
             $sort = array('i_etag' => -1);
             $pagerPath = '/tab/q/' . $uid . '/updated';
             break;
         case 'views':
             $sort = array('i_views' => -1);
             $pagerPath = '/tab/q/' . $uid . '/views';
             break;
         default:
             $sort = array('i_ts' => 1);
             $pagerPath = '/tab/q/' . $uid . '/oldest';
             break;
     }
     //}
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any questions then return
      * empty string
      */
     if (0 == $count) {
         d('no user questions');
         return '';
     }
     if ($count > self::PER_PAGE || $pageID > 1) {
         $oPaginator = Paginator::factory($Registry);
         $oPaginator->paginate($cursor, self::PER_PAGE, array('path' => $pagerPath));
         $pagerLinks = $oPaginator->getLinks();
         d('links: ' . $pagerLinks);
     }
     $questions = \tplUquestions::loop($cursor);
     d('questions: ' . $questions);
     $vals = array('{count}' => $count, '{questions}' => $questions, '{pagination}' => $pagerLinks);
     return \tplUserQuestions::parse($vals);
 }
예제 #5
0
 public static function get(Registry $Registry, User $User)
 {
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     $pagerLinks = '';
     /**
      * Default pager path
      */
     $pagerPath = '/tab/a/' . $uid . '/oldest';
     $cond = $Registry->Request->get('sort', 's', 'recent');
     switch ($cond) {
         case 'oldest':
             $sort = array('_id' => 1);
             $pagerPath = '/tab/a/' . $uid . '/recent';
             break;
         case 'voted':
             $sort = array('i_votes' => -1);
             $pagerPath = '/tab/a/' . $uid . '/voted';
             break;
         case 'updated':
             $sort = array('i_lm_ts' => -1);
             $pagerPath = '/tab/a/' . $uid . '/updated';
             break;
         case 'best':
             $sort = array('accepted' => -1);
             $pagerPath = '/tab/a/' . $uid . '/best';
             break;
         default:
             $sort = array('_id' => -1);
             $pagerPath = '/tab/a/' . $uid . '/oldest';
             break;
     }
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any answers then return
      * empty string, skip any unnecessary template parsing
      */
     if (0 == $count) {
         d('no user answers');
         return '';
     }
     $pageID = $Registry->Request->get('pageID', 'i', 1);
     if ($count > self::PER_PAGE || $pageID > 1) {
         $oPaginator = Paginator::factory($Registry);
         $oPaginator->paginate($cursor, self::PER_PAGE, array('path' => $pagerPath));
         $pagerLinks = $oPaginator->getLinks();
         d('$pagerPath: ' . $pagerPath . ' pagerLinks: ' . $pagerLinks);
     }
     $answers = \tplUanswers::loop($cursor);
     d('$answers: ' . $answers);
     $vals = array('count' => $count, 'answers' => $answers, 'pagination' => $pagerLinks);
     return \tplUserAnswers::parse($vals);
 }
예제 #6
0
 /**
  *
  * Get parsed html of user questions div,
  * complete with pagination
  *
  * @todo there has to be an extra request param "tab" and ONLY if
  *       it equals to 'questions' then it would mean
  *       that sort and pagination is for this block because it could
  *       be for 'answer' block since they both come to the same controller
  *       OR just make separate controllers and then pagination and sorting
  *       will work ONLY with AJAX  and then just hide pagination from
  *       non-js browsers!
  *
  * @param Registry $Registry
  * @param User     $User
  *
  * @return string html of user questions
  */
 public static function get(Registry $Registry, User $User)
 {
     $perPage = $Registry->Ini->PROFILE_QUESTIONS_PER_PAGE;
     $uid = $User->getUid();
     if (0 === $uid) {
         d('not registered user');
         return '';
     }
     /**
      * @var string
      */
     $pagerLinks = '';
     /**
      * @var int
      */
     $pageID = $Registry->Router->getPageID();
     /**
      * @var array
      */
     $aUriMap = $Registry->Ini->getSection('URI_PARTS');
     //$mode = $Registry->Request->get('tab', 's', '');
     /**
      * sort order possible values:
      * recent, oldest, voted, updated, views
      *
      * default is oldest first
      *
      * $mode 'questions' means that user requested
      * either pagination or sorting specifically
      * for the User Questions
      * This is not necessarily an ajax request as pagination
      * will work without Ajax too.
      *
      * When there is no explicit 'questions' $mode
      * then we need to just get the cursor
      * with default sort and pageID, treating this
      * request as if it was for pageID 1 and sort=oldest
      */
     //if('q' === $mode){
     $cond = $Registry->Router->getSegment(3, 's', $aUriMap['SORT_RECENT']);
     d('$cond: ' . $cond);
     switch ($cond) {
         case $aUriMap['SORT_RECENT']:
             $sort = array('i_ts' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_RECENT_}';
             break;
         case $aUriMap['SORT_VOTED']:
             $sort = array('i_votes' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_VOTED_}';
             break;
         case $aUriMap['SORT_UPDATED']:
             $sort = array('i_etag' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_UPDATED_}';
             break;
         case $aUriMap['SORT_VIEWS']:
             $sort = array('i_views' => -1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_VIEWS_}';
             break;
         default:
             $sort = array('i_ts' => 1);
             $pagerPath = '{_WEB_ROOT_}/{_userinfotab_}/q/' . $uid . '/{_SORT_OLDEST_}';
             break;
     }
     //}
     $cursor = self::getCursor($Registry, $uid, $sort);
     $count = $cursor->count(true);
     d('$count: ' . $count);
     /**
      * If this user does not have any questions then return
      * empty string
      */
     if (0 == $count) {
         d('no user questions');
         return '';
     }
     if ($count > $perPage || $pageID > 1) {
         $Paginator = Paginator::factory($Registry);
         $Paginator->paginate($cursor, $perPage, array('path' => $pagerPath, 'currentPage' => $pageID));
         $pagerLinks = $Paginator->getLinks();
         d('links: ' . $pagerLinks);
     }
     $questions = \tplUquestions::loop($cursor);
     $vals = array('{count}' => $count, '{questions}' => $questions, '{pagination}' => $pagerLinks);
     return \tplUserQuestions::parse($vals);
 }
예제 #7
0
 /**
  * Get html div with answers for this one question,
  * sorted according to param passed in request
  *
  * Enclose result in <div> and add pagination to bottom
  * of div if there is any pagination necessary!
  * 
  * @todo add skip() and limit() to cursor
  * in order to use pagination. 
  *
  * @param Question $Question
  *
  * @param string desired format of result. Possible
  * options are: html, array or json object
  * This will be useful for when we have an API
  *
  *
  * @return string html block
  */
 public function getAnswers(Question $Question, $result = 'html')
 {
     $Tr = $this->Registry->Tr;
     $qid = $Question['_id'];
     $url = $Question['url'];
     d('url: ' . $url);
     d('_GET: ' . print_r($_GET, 1));
     $cond = $this->Registry->Request->get('sort', 's', 'i_lm_ts');
     d('cond: ' . $cond);
     $noComments = false === (bool) $this->Registry->Ini->MAX_COMMENTS;
     d('no comments: ' . $noComments);
     $aFields = $noComments || false === (bool) $this->Registry->Ini->SHOW_COMMENTS ? array('comments' => 0) : array();
     /**
      * Extra security validation,
      * IMPORTANT because we should never use
      * anything in Mongo methods directly from
      * user input
      */
     if (!in_array($cond, array('i_ts', 'i_votes', 'i_lm_ts'))) {
         throw new Exception('invalid value of param "cond" was: ' . $cond);
     }
     $where = array('i_qid' => $qid);
     if (!$this->Registry->Viewer->isModerator()) {
         d('not moderator');
         $where['i_del_ts'] = null;
     }
     switch ($cond) {
         case 'i_ts':
             $sort = array('i_ts' => 1);
             break;
         case 'i_votes':
             $sort = array('i_votes' => -1);
             break;
         default:
             $sort = array($cond => -1);
     }
     $cursor = $this->Registry->Mongo->ANSWERS->find($where, $aFields);
     d('$cursor: ' . gettype($cursor));
     $cursor->sort($sort);
     $oPager = Paginator::factory($this->Registry);
     $oPager->paginate($cursor, $this->Registry->Ini->PER_PAGE_ANSWERS, array('path' => $this->Registry->Ini->SITE_URL . '/q' . $qid . '/' . $url . '/' . $cond, 'append' => false));
     //, 'fileName' => '&pageID=%d'
     $pagerLinks = $oPager->getLinks();
     $func = null;
     $ownerId = $Question['i_uid'];
     $showLink = $ownerId > 0 && ($this->Registry->Viewer->isModerator() || $ownerId == $this->Registry->Viewer->getUid());
     d('adding accept link callback function');
     /**
      * @todo Translate strings
      */
     $accept = $Tr['Accept'];
     $alt = $Tr['Click to accept this as best answer'];
     $alt2 = $Tr['Owner of the question accepted this as best answer'];
     $noComments = $noComments ? ' nocomments' : '';
     $addcomment = $Tr['add comment'];
     $edited = $Tr['Edited'];
     $reply = $Tr['Reply'];
     $reply_t = $Tr['Reply to this comment'];
     $func = function (&$a) use($accept, $alt, $alt2, $addcomment, $reply, $reply_t, $edited, $showLink, $noComments) {
         /**
          * Don't show Accept link for
          * already accepted answer
          */
         if (!$a['accepted']) {
             if ($showLink) {
                 $a['accept_link'] = '<a class="accept ttt" title="' . $alt . '" href="/accept/' . $a['_id'] . '">' . $accept . '</a>';
             }
         } else {
             $a['accepted'] = '<img src="/images/accepted.png" alt="Best answer" class="ttt" title="' . $alt2 . '">';
         }
         $a['add_comment'] = $addcomment;
         $a['nocomments'] = $noComments;
         $a['reply'] = $reply;
         $a['reply_t'] = $reply_t;
         $a['edited'] = $edited;
     };
     /**
      * Create div with answers, append pagination links
      * to bottom and return the whole div block
      */
     $answers = \tplAnswer::loop($cursor, true, $func) . $pagerLinks;
     return $answers;
 }