/**
     * 
     * returns the comma separated id of user friends
     * if no friend exists it returns -1;
     */
    public static function getFriendIdList()
    {
        $sql = 'SELECT IF (friend1!=' . Yii::app()->user->id . ', friend1, friend2) as friend
				FROM ' . Friends::model()->tableName() . '
				WHERE (friend1 = ' . Yii::app()->user->id . '
					   OR friend2 = ' . Yii::app()->user->id . ') 
					  AND status = 1';
        $friendsResult = Yii::app()->db->createCommand($sql)->queryAll();
        $length = count($friendsResult);
        $friends = array();
        for ($i = 0; $i < $length; $i++) {
            array_push($friends, $friendsResult[$i]['friend']);
        }
        $result = -1;
        if (count($friends) > 0) {
            $result = implode(',', $friends);
        }
        return $result;
    }
示例#2
0
 public function actionSetPrivacyRights()
 {
     if (isset($_REQUEST['groupId'])) {
         $groupId = (int) $_REQUEST['groupId'];
     }
     $model = new GroupPrivacySettingsForm();
     $processOutput = true;
     // collect user input data
     if (isset($_POST['GroupPrivacySettingsForm'])) {
         $model->attributes = $_POST['GroupPrivacySettingsForm'];
         if ($model->validate()) {
             //echo $_POST['GroupPrivacySettingsForm']['allowToSeeMyPosition'];
             //echo $model->allowToSeeMyPosition;
             if (isset($model->allowToSeeMyPosition)) {
                 //					if($model->allowToSeeMyPosition) //Checked
                 //					{
                 //						echo 'CHECKED';
                 //					}
                 //					else //Unchecked
                 //					{
                 //						echo 'UNCHECKED';
                 //					}
                 if (Groups::model()->updateByPk($groupId, array("allowedToSeeOwnersPosition" => $model->allowToSeeMyPosition)) >= 0) {
                     //echo 'SAVED';
                     $errorOccured = false;
                     //Take all the user-group relation rows that the selected group added to
                     $relationRowsSelectedGroupBelongsTo = UserGroupRelation::model()->findAll('groupId=:groupId', array(':groupId' => $groupId));
                     //Get only the user ID fields into $group_members from the obtained rows
                     foreach ($relationRowsSelectedGroupBelongsTo as $relationRow) {
                         $friendship = Friends::model()->find(array('condition' => '(friend1=:friend1Id AND friend2=:friend2Id) OR (friend1=:friend2Id AND friend2=:friend1Id)', 'params' => array(':friend1Id' => Yii::app()->user->id, ':friend2Id' => $relationRow->userId)));
                         if ($friendship != null) {
                             if ($friendship->friend1 == Yii::app()->user->id) {
                                 $friendship->friend1Visibility = $model->allowToSeeMyPosition;
                             } else {
                                 $friendship->friend2Visibility = $model->allowToSeeMyPosition;
                             }
                             if ($friendship->save()) {
                                 //Privacy setting saved
                             } else {
                                 $errorOccured = true;
                                 //									if($friendship->friend1 == Yii::app()->user->id)
                                 //									{
                                 //										echo 'f1:user - f2:'.$relationRow->userId.' cannot be saved';
                                 //									}
                                 //									else
                                 //									{
                                 //										echo 'f1:'.$relationRow->userId.' - f2:user cannot be saved';
                                 //									}
                             }
                         } else {
                             //The friendship between the logged in user and $relationRow->userId not found
                             $errorOccured = true;
                             //echo 'friendship does not exist';
                         }
                     }
                     if ($errorOccured == false) {
                         echo CJSON::encode(array("result" => "1"));
                     } else {
                         echo CJSON::encode(array("result" => "0"));
                     }
                     Yii::app()->end();
                 } else {
                     echo CJSON::encode(array("result" => "0"));
                     Yii::app()->end();
                 }
             } else {
                 //$model->allowToSeeMyPosition is UNSET
             }
         }
         if (Yii::app()->request->isAjaxRequest) {
             $processOutput = false;
         }
     } else {
         $group = Groups::model()->findByPk($groupId);
         $model->allowToSeeMyPosition = $group->allowedToSeeOwnersPosition;
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
     $this->renderPartial('groupPrivacySettings', array('model' => $model, 'groupId' => $groupId), false, $processOutput);
 }
 public function actionRejectFrienshipRequest()
 {
     $output = array('errno' => 0, 'html' => '');
     //check session
     if (!Yii::app()->user->isGuest) {
         //check friendship exist
         if ($this->are_they_friends) {
             //Update status of frienship
             $condition = "(from_user = :user_knight1 AND to_user = :knight1 AND status = :status1) OR (from_user = :knight2 AND to_user = :user_knight2 AND status = :status2)";
             $params = array(':knight1' => $this->knight->users_id, ':knight2' => $this->knight->users_id, ':user_knight1' => $this->user_data['knights']->users_id, ':user_knight2' => $this->user_data['knights']->users_id, ':status1' => Friends::STATUS_ACCEPT, ':status2' => Friends::STATUS_ACCEPT);
             $friendRelationship = Friends::model()->find($condition, $params);
             $friendRelationship->delete_by_user = Yii::app()->user->users_id;
             $friendRelationship->end_date = date('Y-m-d H:i:s');
             if ($friendRelationship->from_user == Yii::app()->user->users_id) {
                 $friendRelationship->status = Friends::STATUS_FINISHED_BY_SENDER;
             } else {
                 $friendRelationship->status = Friends::STATUS_FINISHED_BY_RECEIVER;
             }
             if ($friendRelationship->save()) {
                 $output['errno'] = 0;
                 $output['html'] = '<p>Seguro que le has partido el corazón. Ya no sois amigos.</p>';
             } else {
                 $output['html'] = $this->renderPartial('dialog_confirmRejectFrienshipRequest');
                 Yii::trace('[CHARACTER][actionConfirmRejectFrienshipRequest] No se puede actualizar la relación de amistad para terminarla.', 'error');
             }
         } else {
             $output['html'] = '<p>Sir ' . $this->knight->name . ' y tú no sois amigos.</p>';
         }
     } else {
         $output['html'] = '<p>La sessión ha expirado. Debes volver a hacer login.</p>';
     }
     //Show output
     echo CJSON::encode($output);
 }
示例#4
0
 public function actionApproveFriendShip()
 {
     $result = 'Missing Data';
     if (isset($_REQUEST['friendShipId'])) {
         $friendShipId = (int) $_REQUEST['friendShipId'];
         // only friend2 can approve friendship because friend1 makes the request
         $friendShip = Friends::model()->findByPk($friendShipId, array('condition' => 'friend2=:friend2', 'params' => array(':friend2' => Yii::app()->user->id)));
         $result = 'Error occured';
         if ($friendShip != null) {
             $friendShip->status = 1;
             if ($friendShip->save()) {
                 $result = 1;
             }
         }
     }
     echo CJSON::encode(array("result" => $result));
 }