Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 /**
  * 此方法专为删除用户时,删除其与所有群组的关系
  */
 public function deleteUserRelation($userIds)
 {
     if ($userIds != '' && strlen($userIds) > 0) {
         UserGroupRelation::model()->deleteAll("user_id in (" . $userIds . ")");
     }
 }
Exemplo n.º 3
0
 /**
  * 查询未分组的用户
  */
 public function unbindUsers($offset, $limit)
 {
     $items = UserGroupRelation::model()->findAll();
     $value = array();
     if (isset($items)) {
         foreach ($items as $item) {
             $group = MiniGroup::getInstance()->findById($item->group_id);
             if (isset($group)) {
                 if ($group['user_id'] > 0) {
                     continue;
                 }
             }
             $value[] = $item->user_id;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addNotInCondition('id', $value);
     $count = User::model()->count($criteria);
     $criteria->limit = $limit;
     $criteria->offset = $offset;
     $users = User::model()->findAll($criteria);
     $data = array();
     $data['users'] = $this->db2list($users);
     $data['total'] = $count;
     return $data;
 }