public function actionAddAjax() { // [my-pic] => Array // ( // [name] => 18348228424229089093.jpg // [type] => image/jpeg // [tmp_name] => Z:\tmp\php2F.tmp // [error] => 0 // [size] => 24698 // ) // print_r($_GET); // print_r($_FILES); // print_r($_POST); // exit; Yii::import('application.vendors.*'); require_once 'MyFunctions.php'; $myFunc = new MyFunctions(); if (!empty($_FILES['my-pic']) && (int) $_FILES['my-pic']['error'] == 0) { $img = $_FILES['my-pic']; $add_arr['date_add'] = time(); $add_arr['file_name'] = $img['name']; $dir = "uploads/images/" . date('Y', $add_arr['date_add']) . "/" . date('m', $add_arr['date_add']) . "/"; $myFunc->prepareDir($dir); $add_arr['file_name'] = $myFunc->getUnickFileName($dir, $add_arr['file_name']); $image = Yii::app()->image->load($img['tmp_name']); //$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20); $image->save($dir . $add_arr['file_name']); $model = new Images(); $add_arr['date_add'] = time(); $add_arr['author_id'] = "1"; $add_arr['date_edit'] = 0; $add_arr['title'] = 'testt'; //Временно $add_arr['description'] = 'testd'; //Временно if (!empty($_GET['page_id'])) { $add_arr['post_id'] = (int) $_GET['page_id']; $add_arr['note_type'] = "page"; } elseif (!empty($_GET['post_id'])) { $add_arr['post_id'] = (int) $_GET['post_id']; $add_arr['note_type'] = "post"; } else { echo "error_id"; Yii::app()->end(); } $model->attributes = $add_arr; if ($res = $model->save()) { echo "/" . $dir . $add_arr['file_name']; //echo "ok"; } else { echo "not_saved"; //print_r($res); } //print_r($_FILES); } else { echo "error_input_file"; } Yii::app()->end(); }
public function beforeAction($action) { Yii::import('application.vendors.*'); require_once 'MyFunctions.php'; $myFunc = new MyFunctions(); $myFunc->counter(); return parent::beforeAction($action); //return true; }
public function actionIndex() { $generalRanking = MyFunctions::getRanking(NULL, 'year', null, null, 5); $truthRanking = MyFunctions::getRanking('truth', 'year', null, null, 5); $dareRanking = MyFunctions::getRanking('dare', 'year', null, null, 5); $searchDareForm = new SearchDareForm(); $searchDareForm->limit = 3; $searchDareForm->order = 'dateSubmit'; $searchTruthForm = new SearchTruthForm(); $searchTruthForm->limit = 3; $searchTruthForm->order = 'dateSubmit'; $searchChallengeDareForm = new SearchChallengeDareForm(); $searchChallengeDareForm->limit = 3; $searchChallengeDareForm->order = 'finishDate'; $searchChallengeTruthForm = new SearchChallengeTruthForm(); $searchChallengeTruthForm->limit = 3; $searchChallengeTruthForm->order = 'finishDate'; $this->render('index', array('generalRanking' => $generalRanking, 'truthRanking' => $truthRanking, 'dareRanking' => $dareRanking, 'searchDareForm' => $searchDareForm, 'searchTruthForm' => $searchTruthForm, 'searchChallengeDareForm' => $searchChallengeDareForm, 'searchChallengeTruthForm' => $searchChallengeTruthForm)); }
/** * Return array with user friends * @return array */ public static function getFriends($idUser, $friendStatus = 1, $orderField = 'username', $orderDirection = 'ASC', $gender = null, $level = null) { $criteria = new CDbCriteria(); //Get users the current user added as Friends $criteria->condition = "idUserFrom=:idUser and accepted=:friendStatus"; $criteria->params = array(':idUser' => $idUser, ':friendStatus' => $friendStatus); if ($gender !== '' && $gender !== null) { $criteria->addCondition("userTo.gender = :gender"); $criteria->params[':gender'] = $gender; } if ($level !== '' && $level !== null) { $criteria->addCondition("levelUserTo.level = :level"); $criteria->params[':level'] = $level; } $friendsFrom = Friend::model()->with('userTo', 'userTo.levelUserTo')->findAll($criteria); //Get users that added the current user as Friends $criteria->condition = "idUserTo=:idUser and accepted=:friendStatus"; $criteria->params = array(':idUser' => $idUser, ':friendStatus' => $friendStatus); if ($gender !== '' && $gender !== null) { $criteria->addCondition("userFrom.gender = :gender"); $criteria->params[':gender'] = $gender; } if ($level !== '' && $level !== null) { $criteria->addCondition("levelUserFrom.level = :level"); $criteria->params[':level'] = $level; } $friendsTo = Friend::model()->with('userFrom', 'userFrom.levelUserFrom')->findAll($criteria); //Gather them together $friends = array(); $i = 0; foreach ($friendsFrom as $row) { $friends[$i]['idUser'] = $row->userTo->idUser; $friends[$i]['username'] = $row->userTo->username; $friends[$i]['profilePicture'] = $row->userTo->profilePicture; $friends[$i]['profilePictureExtension'] = $row->userTo->profilePictureExtension; $friends[$i]['level'] = $row->userTo->levelUserTo->level; $i++; } foreach ($friendsTo as $row) { $friends[$i]['idUser'] = $row->userFrom->idUser; $friends[$i]['username'] = $row->userFrom->username; $friends[$i]['profilePicture'] = $row->userFrom->profilePicture; $friends[$i]['profilePictureExtension'] = $row->userFrom->profilePictureExtension; $friends[$i]['level'] = $row->userFrom->levelUserFrom->level; $i++; } $friends = MyFunctions::arraySort($friends, $orderField, $orderDirection); return $friends; }
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.'); } }
<!--**********--> <!-- Comments --> <!--**********--> <?php foreach ($comments as $row) { ?> <?php echo $row->user->username; ?> - <?php echo MyFunctions::getTruthRankName($row->user->scoreTruth->score) . ' - ' . MyFunctions::getDareRankName($row->user->scoreDare->score); ?> - <?php echo Yii::app()->dateFormatter->format('yyyy-MM-dd', $row->submitDate); ?> <div style="background-color: #B7D6E7;"> <?php echo $row->comment; ?> </div> <br /> <?php } ?>
<!-- Author informations and Date --> <span> - <?php echo $row->anonymous == 1 ? 'Anonymous' : "<a href='index.php?r=user/userPage&idUser="******"'>" . $row->user->username . "</a>"; ?> <?php if ($this->withAuthorScores) { ?> <?php echo MyFunctions::getTruthRankName($row->user->scoreTruth->score); ?> - <?php echo MyFunctions::getDareRankName($row->user->scoreDare->score); ?> - <?php } ?> </span> <!-- Favourite --> <?php if ($this->withFavourites) { ?> <div class='addFavouriteTruth' style='float:right;<?php if ($row->nbFavourite > 0) { echo "background-image: url(/TruthOrDare/images/favouriteChosen.png);";
echo MyFunctions::getDareRankName($row->scoreDare->score); ?> </div> <div id="PBD<?php echo $row->idUser; ?> " style="width:110px; height:10px;"></div> </div> <div style="position:absolute; bottom:23px;right:3px;"> <img onClick="sendFriendRequest(this);return false;" id="<?php echo $row->idUser; ?> " src="/TruthOrDare/images/addFriend.png" style="cursor:pointer;z-index:64000;" width="32px" height="32px" title="Add Friend" /> </div> <div style="position:absolute; bottom:3px;right:3px;font-size:0.7em;">Last login: <?php echo MyFunctions::getNbDaysBetweenDates($row->lastLoginDate, date('Y-m-d, H:i:s')) - 1; ?> days</div> </div> </a> <?php } ?> <br /> <br /> <br /> <br /> <!--************--> <!-- Link Pager -->
/** * 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); }
<?php $myFunctions = new MyFunctions(); ?> <a href="<?php echo $myFunctions->ajouterParametreGET(Yii::app()->request->Url, 'lang', 'fr_fr'); ?> "><img src="<?php echo Yii::app()->request->baseUrl; ?> /images/flag-FR_FR.png" /></a> <a href="<?php echo $myFunctions->ajouterParametreGET(Yii::app()->request->Url, 'lang', 'en_us'); ?> "><img src="<?php echo Yii::app()->request->baseUrl; ?> /images/flag-EN_US.png" /></a> <a href="<?php echo $myFunctions->ajouterParametreGET(Yii::app()->request->Url, 'lang', 'zh_cn'); ?> "><img src="<?php echo Yii::app()->request->baseUrl; ?> /images/flag-ZH_CN.png" /></a>
public function run() { $wallOwner = User::model()->with('scoreTruth', 'scoreDare')->findByPk($this->idWallOwner); //To display notifications from friends if ($this->withFriendsInformations === 1) { $friends = $wallOwner->getIdFriends(); $friends[] = $this->idWallOwner; } //Add message to the Wall $model = new UserWall(); if (isset($_POST['Userwall'])) { $model->attributes = $_POST['Userwall']; $model->idUserFrom = $this->idCurrentUser; $model->idUserTo = $this->idWallOwner; $model->createDate = date('Y-m-d, H:i:s'); $model->save(); $model->content = ''; } //Initialiation of the array $wall = array(); $i = 0; //Get Wall Messages and add them to the Wall array() if ($this->withWallMessages == 1) { $criteria = new CDbCriteria(); $criteria->addCondition('t.idUserTo = :idUser'); $criteria->params = array(':idUser' => $this->idWallOwner); $criteria->order = 'createDate DESC'; $wallComments = UserWall::model()->with('userFrom', 'userFrom.scoreTruth', 'userFrom.scoreDare')->findAll($criteria); foreach ($wallComments as $row) { $wall[$i]['type'] = "WallMessage"; $wall[$i]['id'] = $row->idUserWall; $wall[$i]['content'] = $row->content; $wall[$i]['createDate'] = $row->createDate; $wall[$i]['userPicture'] = $row->userFrom->profilePicture . '_mini' . $row->userFrom->profilePictureExtension; $wall[$i]['category'] = null; $wall[$i]['vote'] = null; $wall[$i]['nbFavourite'] = null; $wall[$i]['nbComment'] = null; $wall[$i]['idDisplayUser'] = $row->userFrom->idUser; $wall[$i]['displayUsername'] = $row->userFrom->username; $wall[$i]['pictureChallengeDareMini'] = null; $wall[$i]['pictureChallengeDare'] = null; $wall[$i]['challengeTruthOrCommentDare'] = null; $wall[$i]['rankTruth'] = MyFunctions::getTruthRankName($row->userFrom->scoreTruth->score); $wall[$i]['rankDare'] = MyFunctions::getDareRankName($row->userFrom->scoreDare->score); $i++; } } //Get Challenges Notifications and add them to the Wall array() $criteria = new CDbCriteria(); $criteria->addCondition('t.status = 1 AND (t.private = 0 OR (t.idUserFrom = :idCurrentUser OR t.idUserTo = :idCurrentUser))'); $criteria->params = array(':idCurrentUser' => $this->idCurrentUser); if ($this->withFriendsInformations === 1) { $criteria->addInCondition('t.idUserTo', $friends); } else { $criteria->addCondition('t.idUserTo = :idUser'); $criteria->params[':idUser'] = $this->idWallOwner; } if (isset($this->filterLevel)) { $criteria->addCondition("(categoryTruth.level IS NOT NULL AND categoryTruth.level <= {$this->filterLevel}) OR (categoryDare.level IS NOT NULL AND categoryDare.level <= {$this->filterLevel})"); } $challenges = Challenge::model()->with('userTo', 'truth', 'dare', 'truth.category', 'dare.category', 'userTo.scoreTruth', 'userTo.scoreDare')->findAll($criteria); foreach ($challenges as $row) { $wall[$i]['type'] = $row->idTruth === null ? "ChallengeDare" : "ChallengeTruth"; $wall[$i]['id'] = $row->idChallenge; $wall[$i]['content'] = isset($row->truth) ? $row->answer : $row->dare->dare; $wall[$i]['createDate'] = $row->createDate; $wall[$i]['userPicture'] = $row->userTo->profilePicture . '_mini' . $row->userTo->profilePictureExtension; $wall[$i]['category'] = isset($row->truth) ? $row->truth->category->category : $row->dare->category->category; $wall[$i]['vote'] = $row->voteUp - $row->voteDown; $wall[$i]['nbFavourite'] = 0; $wall[$i]['nbComment'] = 0; $wall[$i]['idDisplayUser'] = $row->userTo->idUser; $wall[$i]['displayUsername'] = $row->userTo->username; $wall[$i]['pictureChallengeDareMini'] = $row->pictureName . "_mini" . $row->pictureExtension; $wall[$i]['pictureChallengeDare'] = $row->pictureName . "_original" . $row->pictureExtension; $wall[$i]['challengeTruthOrCommentDare'] = isset($row->truth) ? $row->truth->truth : $row->answer; $wall[$i]['rankTruth'] = MyFunctions::getTruthRankName($row->userTo->scoreTruth->score); $wall[$i]['rankDare'] = MyFunctions::getDareRankName($row->userTo->scoreDare->score); $i++; } //Get Truths and add them to the Wall array() $truth = new Truth(); if (isset($this->filterLevel)) { $truth->levelMax = $this->filterLevel; } $criteria = $truth->getCriteria(); if ($this->withFriendsInformations === 1) { $criteria->addInCondition('t.idUser', $friends); } else { $criteria->addCondition('t.idUser = :idUser'); $criteria->params[':idUser'] = $this->idWallOwner; } $truths = Truth::model()->notAnonymous()->findAll($criteria); foreach ($truths as $row) { $wall[$i]['type'] = "Truth"; $wall[$i]['id'] = $row->idTruth; $wall[$i]['content'] = $row->truth; $wall[$i]['createDate'] = $row->dateSubmit; $wall[$i]['userPicture'] = $row->user->profilePicture . '_mini' . $row->user->profilePictureExtension; $wall[$i]['category'] = $row->category->category; $wall[$i]['vote'] = $row->voteUp - $row->voteDown; $wall[$i]['nbFavourite'] = $row->nbFavourite; $wall[$i]['nbComment'] = $row->nbComment; $wall[$i]['idDisplayUser'] = $row->user->idUser; $wall[$i]['displayUsername'] = $row->user->username; $wall[$i]['pictureChallengeDareMini'] = null; $wall[$i]['pictureChallengeDare'] = null; $wall[$i]['challengeTruthOrCommentDare'] = null; $wall[$i]['rankTruth'] = MyFunctions::getTruthRankName($row->user->scoreTruth->score); $wall[$i]['rankDare'] = MyFunctions::getDareRankName($row->user->scoreDare->score); $i++; } //Get Dares and add them to the Wall array() $dare = new Dare(); if (isset($this->filterLevel)) { $dare->levelMax = $this->filterLevel; } $criteria = $dare->getCriteria(); if ($this->withFriendsInformations === 1) { $criteria->addInCondition('t.idUser', $friends); } else { $criteria->addCondition('t.idUser = :idUser'); $criteria->params[':idUser'] = $this->idWallOwner; } $dares = Dare::model()->notAnonymous()->findAll($criteria); foreach ($dares as $row) { $wall[$i]['type'] = "Dare"; $wall[$i]['id'] = $row->idDare; $wall[$i]['content'] = $row->dare; $wall[$i]['createDate'] = $row->dateSubmit; $wall[$i]['userPicture'] = $row->user->profilePicture . '_mini' . $row->user->profilePictureExtension; $wall[$i]['category'] = $row->category->category; $wall[$i]['vote'] = $row->voteUp - $row->voteDown; $wall[$i]['nbFavourite'] = $row->nbFavourite; $wall[$i]['nbComment'] = $row->nbComment; $wall[$i]['idDisplayUser'] = $row->user->idUser; $wall[$i]['displayUsername'] = $row->user->username; $wall[$i]['pictureChallengeDareMini'] = null; $wall[$i]['pictureChallengeDare'] = null; $wall[$i]['challengeTruthOrCommentDare'] = null; $wall[$i]['rankTruth'] = MyFunctions::getTruthRankName($row->user->scoreTruth->score); $wall[$i]['rankDare'] = MyFunctions::getDareRankName($row->user->scoreDare->score); $i++; } //Get Ranks Upgrades of the user $criteria = new CDbCriteria(); if ($this->withFriendsInformations === 1) { $criteria->addInCondition('t.idUser', $friends); } else { $criteria->addCondition('t.idUser = :idUser'); $criteria->params = array(':idUser' => $this->idWallOwner); } $userUpgrades = Userrank::model()->with('rank')->findAll($criteria); foreach ($userUpgrades as $row) { $wall[$i]['type'] = "RankUpgrade"; $wall[$i]['id'] = null; $wall[$i]['content'] = "I just got upgraded to <b>" . $row->rank->name . "</b>!"; $wall[$i]['createDate'] = $row->createDate; $wall[$i]['userPicture'] = $row->user->profilePicture . '_mini' . $row->user->profilePictureExtension; $wall[$i]['category'] = null; $wall[$i]['vote'] = null; $wall[$i]['nbFavourite'] = null; $wall[$i]['nbComment'] = null; $wall[$i]['idDisplayUser'] = $row->user->idUser; $wall[$i]['displayUsername'] = $row->user->username; $wall[$i]['pictureChallengeDareMini'] = null; $wall[$i]['pictureChallengeDare'] = null; $wall[$i]['challengeTruth'] = null; $wall[$i]['rankTruth'] = MyFunctions::getTruthRankName($row->user->scoreTruth->score); $wall[$i]['rankDare'] = MyFunctions::getDareRankName($row->user->scoreDare->score); $i++; } //Manage favourites $modelUserList = new UserList(); $userLists = CHtml::listData(array(), 'idUserList', 'name'); if (!Yii::app()->user->isGuest) { $userLists = UserList::model()->findAllByAttributes(array('idUser' => $this->idCurrentUser)); $userLists = CHtml::listData($userLists, 'idUserList', 'name'); } //Manage send Challenges $friends = CHtml::listData(array(), 'idUser', 'username'); if (!Yii::app()->user->isGuest) { $friends = CHtml::listData(Friend::getFriends(Yii::app()->user->getId()), 'idUser', 'username'); } //Order the Wall array() by createDate DESC $wall = MyFunctions::arraySort($wall, 'createDate', 'DESC'); $this->render('userWallWidget', array('model' => $model, 'wall' => $wall, 'userLists' => $userLists, 'friends' => $friends)); }
<!-- Display User main informations --> <!--********************************--> <div style="height:150px; width:250px; float:left;"> <div style="font-size:2em; font-weight:bold;"><?php echo $user->username; ?> </div> <div> <?php echo isset($user->province) ? $user->province->name : ""; echo isset($user->city) ? " - " . $user->city->name : ""; echo isset($user->district) ? " - " . $user->district->name : ""; ?> </div> <div><?php $myFunctions = new MyFunctions(); echo isset($user->birthDate) ? $myFunctions->getAge($user->birthDate) : ''; ?> </div> <div style="margin-top:10px;"><?php echo MyFunctions::getTruthRankName($user->scoreTruth->score); ?> </div> <div id="progressBarTruth" style="width:100px; height:10px; margin-bottom:10px;"></div> <div><?php echo MyFunctions::getDareRankName($user->scoreDare->score); ?> </div> <div id="progressBarDare" style="width:100px; height:10px;"></div> </div>