Example #1
0
 public function actionUserChallenges()
 {
     if (isset($_GET['idUser'])) {
         //Filter and order criterias
         if (isset($_GET['idCategory'])) {
             Yii::app()->session['idCategoryChallenge'] = $_GET['idCategory'];
         }
         if (isset($_GET['idGender'])) {
             Yii::app()->session['idGenderChallenge'] = $_GET['idGender'];
         }
         if (isset($_GET['idTypeChallenge'])) {
             Yii::app()->session['idTypeChallenge'] = $_GET['idTypeChallenge'];
         }
         if (isset($_GET['idStatusChallenge'])) {
             Yii::app()->session['idStatusChallenge'] = $_GET['idStatusChallenge'];
         }
         if (isset($_GET['minDateChallenge'])) {
             Yii::app()->session['minDateChallenge'] = $_GET['minDateChallenge'];
         }
         if (isset($_GET['idUserFrom'])) {
             Yii::app()->session['idUserFrom'] = $_GET['idUserFrom'];
         }
         $challenges = Challenge::getChallenges($_GET['idUser'], Yii::app()->session['idCategoryChallenge'], Yii::app()->session['idGenderChallenge'], Yii::app()->session['idTypeChallenge'], Yii::app()->session['idStatusChallenge'], Yii::app()->session['minDateChallenge'], 0, Yii::app()->session['idUserFrom']);
         $categories = CHtml::listData(Category::model()->findAll(), 'idCategory', 'category');
         $genders = array('0' => 'Female', '1' => 'Male');
         $typeChallenges = array('Truth' => 'Truth', 'Dare' => 'Dare');
         $statusChallenges = array('0' => 'Waiting', '1' => 'Success');
         $period = array(MyFunctions::getFirstDayWeek() => 'Week', MyFunctions::getFirstDayMonth() => 'Month', MyFunctions::getFirstDayYear() => 'Year');
         $userFrom = CHtml::listData(Friend::getFriends($_GET['idUser']), 'idUser', 'username');
         $model = new Challenge();
         $this->render('userChallenges', array('model' => $model, 'categories' => $categories, 'idCategory' => Yii::app()->session['idCategoryChallenge'], 'genders' => $genders, 'idGender' => Yii::app()->session['idGenderChallenge'], 'typeChallenges' => $typeChallenges, 'idTypeChallenge' => Yii::app()->session['idTypeChallenge'], 'statusChallenges' => $statusChallenges, 'idStatusChallenge' => Yii::app()->session['idStatusChallenge'], 'period' => $period, 'minDateChallenge' => Yii::app()->session['minDateChallenge'], 'userFrom' => $userFrom, 'idUserFrom' => Yii::app()->session['idUserFrom'], 'challenges' => $challenges, 'idUser' => $_GET['idUser']));
     } else {
         throw new CHttpException(404, 'The page cannot be found.');
     }
 }
Example #2
0
 /**
  * Returns the Truth score of the User $idUser related to the vote of the Challenges he/she successfuly realized
  * @return array()
  */
 public function getScoreVoteChallenges($type)
 {
     //Prepare Query
     $criteria = new CDbCriteria();
     $criteria->group = " t.idUserTo ";
     $criteria->select = " SUM(CASE WHEN t.finishDate >= :minDateSubmitWeek THEN t.voteUp - t.voteDown END) AS scoreWeek, ";
     $criteria->select .= " SUM(CASE WHEN t.finishDate >= :minDateSubmitMonth THEN t.voteUp - t.voteDown END) AS scoreMonth, ";
     $criteria->select .= " SUM(CASE WHEN t.finishDate >= :minDateSubmitYear THEN t.voteUp - t.voteDown END) AS scoreYear, ";
     $criteria->select .= " SUM(t.voteUp - t.voteDown) AS score ";
     $criteria->addCondition(' t.status = 1 ');
     $criteria->addCondition(' t.idUserTo = :idUser ');
     if ($type !== null) {
         $criteria->addCondition(" t.id{$type} IS NOT NULL ");
     }
     //Bind Parameters
     $criteria->params = array(':idUser' => $this->idUser);
     $criteria->params[':minDateSubmitWeek'] = MyFunctions::getFirstDayWeek();
     $criteria->params[':minDateSubmitMonth'] = MyFunctions::getFirstDayMonth();
     $criteria->params[':minDateSubmitYear'] = MyFunctions::getFirstDayYear();
     //Execute Query
     $result = Challenge::model()->find($criteria);
     //Fetch results
     $scoreTotal = $result['score'] === null ? 0 : $result->score;
     $scoreWeek = $result['scoreWeek'] === null ? 0 : $result->scoreWeek;
     $scoreMonth = $result['scoreMonth'] === null ? 0 : $result->scoreMonth;
     $scoreYear = $result['scoreYear'] === null ? 0 : $result->scoreYear;
     return array('total' => $scoreTotal, 'week' => $scoreWeek, 'month' => $scoreMonth, 'year' => $scoreYear);
 }