Esempio n. 1
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);
 }
 /**
  *
  * 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);
 }