public static function GetBestRankingOfTheMonth() { $month = date('m') * 1; $year = date('Y'); if ($month == 1) { $month = 12; $year--; } else { $month--; } $month = $month * 1; if ($month < 10) { $month = "0{$month}"; } $year_month = "{$year}{$month}"; $ShortMonth = date('M', strtotime($year_month . '01')); $criteria = new CDbCriteria(); $criteria->compare('month(t.received_on)', $month); $criteria->compare('year(t.received_on)', $year); $criteria->compare('t.status', STATUS_GEN_RECEIPT); $criteria->select = "t.user_id, SUM(t.received_commission) as received_commission"; $criteria->group = "t.user_id"; $criteria->order = "SUM(t.received_commission) DESC"; $criteria->limit = 100; $models = self::model()->findAll($criteria); $uid = Yii::app()->user->id; foreach ($models as $key => $item) { if ($item->user_id == $uid) { $top = MyFormat::addOrdinalNumberSuffix($key + 1); return "You are top {$top} achiever for {$ShortMonth} {$year}"; } } return ''; }