public function getFriends($userID) { $friendModel = new Friend(); $friends = $friendModel->getFriends($userID); $output = array(); if (count($friends) > 0) { foreach ($friends as $friend) { $output[$friend->user_id] = $friend->first_name . ' ' . $friend->last_name; } } return $output; }
public function run() { //We check the level of the user before to allow him to see the content if (isset($this->model->idCategory) && isset($this->filterLevel) && $this->model->idCategory != '') { $levelCategory = Category::model()->findByPk($this->model->idCategory); if ($levelCategory->level > $this->filterLevel) { Yii::app()->user->setFlash('forbiddenLevel', 'Sorry, to have access to this category you need to register a coin which belongs to this category.'); } } //If the user makes a research by username, we shouldn't display the anonymous ones if (isset($this->model->username) && $this->model->username !== '') { $this->model->anonymous = 0; } //We get the generated criterias $criteria = $this->model->getCriteria(); //We set up the number of Truth we want to display if necessary if (isset($this->model->limit)) { $criteria->limit = $this->model->limit; } //We choose the order of display $criteria->order = isset($this->model->order) && $this->model->order !== '' ? $this->model->order . " DESC " : " t.voteUp - t.voteDown DESC "; //Page manager $count = Truth::model()->levelFilter($this->filterLevel)->count($criteria); //Use the $this->limit in Pagination otherwise $pages->pageSize to $criteria overriding the $criteria->limit $pages = new CPagination(isset($this->model->limit) ? $this->model->limit : $count); $pages->pageSize = isset($this->model->limit) ? $this->model->limit : $this->itemsPerPage; $pages->applyLimit($criteria); //Get the datas $datas = Truth::model()->levelFilter($this->filterLevel)->findAll($criteria); //Manage favourites $modelUserList = new UserList(); $userLists = CHtml::listData(array(), 'idUserList', 'name'); if (!Yii::app()->user->isGuest) { $userLists = UserList::model()->findAllByAttributes(array('idUser' => Yii::app()->user->getId())); $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'); } $this->render('truthList', array('datas' => $datas, 'pages' => $pages, 'userLists' => $userLists, 'friends' => $friends)); }
public function actionUserLists() { if (isset($_GET['idUser'])) { $criteria = new CDbCriteria(); $criteria->addCondition('t.idUser = :idUser'); $criteria->params = array(':idUser' => $_GET['idUser']); $criteria->addCondition('t.public = :public'); $criteria->params[':public'] = 1; $userLists = Userlist::model()->with('userListContents', 'userListContents.truth', 'userListContents.dare', 'userListContents.truth.category', 'userListContents.dare.category')->findAll($criteria); $friends = CHtml::listData(Friend::getFriends(Yii::app()->user->getId()), 'idUser', 'username'); $this->render('userLists', array('userlists' => $userLists, 'friends' => $friends, 'idUser' => $_GET['idUser'])); } else { throw new CHttpException(404, 'The page cannot be found.'); } }
} } else { if ($user->pending == 1 || $user->enabled == 0) { header("location: index.php?negative"); } } } else { header("location: index.php?negative"); } $orgbyuser = SchoolUser::getSchoolsImIn($user->id); $ids = array(); foreach ($orgbyuser as $item) { array_push($ids, $item->schoolid); } $matesCount = count(SchoolUser::getUsersInMultipleSchools($ids)); $friendsCount = count(Friend::getFriends($user->id, "")); ?> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=406156986170730"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <div class="container-fluid"> <div class="row-fluid"> <div class="span10 offset2"> <div class="span9" hidden></div>
<?php require_once "../initialize.php"; $input = $_GET['input']; $html = ""; $friends = Friend::getFriends($_GET['studentid'], $_GET['input']); $thestudent = User::get_by_id($_GET['studentid']); if (count($friends) > 0) { foreach ($friends as $friend) { if ($thestudent->id != $friend->touserid) { $userfriend = User::get_by_id($friend->touserid); } else { $userfriend = User::get_by_id($friend->userid); } if (!$userfriend) { continue; } if ($session->is_logged_in()) { if ($session->user_id == $userfriend->id) { continue; } } $html .= '<tr>'; $html .= ' <td><img style="height:40px;" src="data:image/jpeg;base64, ' . $userfriend->picture . '" /></td>'; $html .= ' <td><a href="student.php?id=' . $userfriend->id . '">' . $userfriend->get_full_name() . '</a></td>'; if ($session->is_logged_in()) { $friendship = Friend::getFriendship($session->user_id, $userfriend->id); if (!$friendship) { $html .= '<td><button class="btn-small button-flat-primary btnaddfriend">Add Friend<span hidden>' . $userfriend->id . '</span></button></td>'; } else { if ($friendship->pending == 1) {
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)); }