當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Registration::sortDesc方法代碼示例

本文整理匯總了PHP中Registration::sortDesc方法的典型用法代碼示例。如果您正苦於以下問題:PHP Registration::sortDesc方法的具體用法?PHP Registration::sortDesc怎麽用?PHP Registration::sortDesc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Registration的用法示例。


在下文中一共展示了Registration::sortDesc方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: search

 /**
  * Retrieves a list of models based on the current search/filter conditions.
  *
  * Typical usecase:
  * - Initialize the model fields with values from filter form.
  * - Execute this method to get CActiveDataProvider instance which will filter
  * models according to data in model fields.
  * - Pass data provider to CGridView, CListView or any similar widget.
  *
  * @return CActiveDataProvider the data provider that can return the models
  * based on the search/filter conditions.
  */
 public function search(&$columns = array())
 {
     // @todo Please modify the following code to remove attributes that should not be searched.
     $criteria = new CDbCriteria();
     $criteria->order = 't.date';
     $criteria->with = array('user', 'user.country', 'user.province', 'user.city', 'competition');
     $criteria->compare('t.id', $this->id, true);
     $criteria->compare('t.competition_id', $this->competition_id);
     $criteria->compare('t.user_id', $this->user_id);
     $criteria->compare('t.events', $this->events, true);
     $criteria->compare('t.comments', $this->comments, true);
     $criteria->compare('t.date', $this->date, true);
     $criteria->compare('t.status', $this->status);
     $criteria->compare('user.status', User::STATUS_NORMAL);
     $registrations = $this->findAll($criteria);
     $number = 1;
     $statistics = array();
     $statistics['number'] = 0;
     $statistics['new'] = 0;
     $statistics['paid'] = 0;
     $statistics['unpaid'] = 0;
     $statistics[User::GENDER_MALE] = 0;
     $statistics[User::GENDER_FEMALE] = 0;
     //detect sort attribute
     $sort = Yii::app()->controller->sGet('sort');
     $sort = explode('.', $sort);
     if (isset($sort[1]) && $sort[1] === 'desc') {
         self::$sortDesc = true;
     }
     $sort = $sort[0];
     if ($sort !== '') {
         switch ($sort) {
             case 'name':
             case 'gender':
             case 'country_id':
             case 'birthday':
             case 'email':
             case 'mobile':
                 self::$sortByUserAttribute = true;
             case 'number':
             case 'user_id':
             case 'location_id':
                 self::$sortAttribute = $sort;
                 break;
             default:
                 self::$sortByEvent = true;
                 self::$sortAttribute = $sort;
                 break;
         }
     }
     $wcaIds = array();
     foreach ($registrations as $registration) {
         if ($registration->isAccepted()) {
             $registration->number = $number++;
         }
         $statistics['number']++;
         $statistics[$registration->user->gender]++;
         if ($registration->user->wcaid === '') {
             $statistics['new']++;
         }
         foreach ($registration->events as $event) {
             if (!isset($statistics[$event])) {
                 $statistics[$event] = 0;
             }
             $statistics[$event]++;
         }
         $fee = $registration->getTotalFee();
         if ($registration->isPaid()) {
             $statistics['paid'] += $fee;
         } else {
             $statistics['unpaid'] += $fee;
         }
         //store wcaids
         if ($registration->user->wcaid) {
             $wcaIds[$registration->user->wcaid] = $registration;
         }
     }
     if (self::$sortByEvent === true && !empty($wcaIds)) {
         switch ($sort) {
             case '333bf':
             case '444bf':
             case '555bf':
             case '333mbf':
                 $modelName = 'RanksSingle';
                 break;
             default:
                 $modelName = 'RanksAverage';
                 break;
//.........這裏部分代碼省略.........
開發者ID:sunshy360,項目名稱:cubingchina,代碼行數:101,代碼來源:Registration.php


注:本文中的Registration::sortDesc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。