public function membersOperate(Model $Model, $ownerId = null) { if (isset($Model->data[$Model->alias]['user_id']) && !empty($Model->data[$Model->alias]['user_id'])) { $ownerId = $Model->data[$Model->alias]['user_id']; } if (empty($ownerId)) { return false; } $remoteModel = $this->settings[$Model->alias]['remoteModel']; App::import('Model', $remoteModel); $remoteModel = new $remoteModel(); $limits = $remoteModel->findByOwnerId($ownerId); App::import('Model', 'Group'); App::import('Model', 'GroupMember'); $groupModel = new Group(); $groupMemberModel = new GroupMember(); $groupModel->recursive = -1; $groups = $groupModel->findAllByOwnerId($ownerId); if ($limits['GroupLimit']['members_limit'] == 0 && $limits['GroupLimit']['members_used'] > 0) { //verify all groups for limit overload foreach ($groups as $group) { $groupMemberModel->recursive = -1; $groupMembers = $groupMemberModel->find('all', array('conditions' => array('GroupMember.group_id' => $group['Group']['id'], 'GroupMember.approved' => true, 'GroupMember.is_deleted' => false), 'order' => array('GroupMember.approve_date' => 'ASC'))); $groupMembers = array_slice($groupMembers, 6); if (count($groupMembers) > 0) { foreach ($groupMembers as $key => $member) { $groupMembers[$key]['GroupMember'] = Hash::merge($member['GroupMember'], array('approved' => false, 'is_invited' => false, 'approve_date' => '0000-00-00 00:00:00')); } $groupMemberModel->saveMany($groupMembers, array('callbacks' => true, 'counterCache' => true)); } } } elseif ($limits['GroupLimit']['members_limit'] < $limits['GroupLimit']['members_used']) { //we need to decrease group members by some algorythm } //debug($groups); }
public function loadMember($uid) { $gid = $this->id; if (empty($uid)) { $uid = Yii::app()->user->id; } $model = new GroupMember(); $criteria = new CDbCriteria(); $criteria->condition .= " 1 AND gid = :gid AND uid = :uid"; $criteria->params = array(':gid' => $gid, ':uid' => $uid); $member = $model->find($criteria); return $member; }