protected function executeTransaction($conn, $arguments = array(), $options = array()) { $members = Doctrine::getTable('Member')->findAll(Doctrine::HYDRATE_ARRAY); $communities = Doctrine::getTable('Community')->findAll(Doctrine::HYDRATE_ARRAY); if (count($communities) < $options['number']) { throw new Exception('Too few communities. Please run "opKdt:generate-community" first.'); } $communityIds = array_map(create_function('$c', 'return (int)$c[\'id\'];'), $communities); foreach ($members as $member) { $joinCommunities = Doctrine::getTable('Community')->retrievesByMemberId($member['id'], null); $joinCommunityIds = array(); if ($joinCommunities) { foreach ($joinCommunities as $c) { $joinCommunityIds[] = $c->getId(); } } $candidate = array_diff($communityIds, $joinCommunityIds); shuffle($candidate); $candidateSlices = array_slice($candidate, 0, $options['number']); foreach ($candidateSlices as $communityId) { $cm = new CommunityMember(); $cm->setCommunityId($communityId); $cm->setMemberId($member['id']); $cm->save(); $cm->free(); $this->logSection('added a community member', sprintf("%s - %s", $member['id'], $communityId)); } } }
public function saveMember(Community $community) { if ($this->isNew()) { $member = new CommunityMember(); $member->setPosition('admin'); $member->setMemberId(sfContext::getInstance()->getUser()->getMemberId()); $member->setCommunity($community); $member->save(); } }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $sql = 'SELECT id FROM member WHERE is_active != 0'; $where = array(); if ( $options['min'] && $options['max'] && $options['min'] <= $options['max']) { $sql .= ' AND id BETWEEN ? AND ?'; $where = array(intval($options['min']),intval($options['max'])); } $memberIds = $this->conn->fetchColumn($sql, $where); $communities = Doctrine::getTable('Community')->findAll(Doctrine::HYDRATE_ARRAY); if (count($communities) < $options['number']) { throw new Exception('Too few communities. Please run "opKdt:generate-community" first.'); } $communityIds = array_map(create_function('$c', 'return (int)$c[\'id\'];'), $communities); foreach ($memberIds as $memberid) { $joinCommunities = Doctrine::getTable('Community')->retrievesByMemberId($memberid, null); $joinCommunityIds = array(); if ($joinCommunities) { foreach ($joinCommunities as $c) { $joinCommunityIds[] = $c->getId(); } } $candidate = array_diff($communityIds, $joinCommunityIds); shuffle($candidate); $candidateSlices = array_slice($candidate, 0, $options['number']); foreach ($candidateSlices as $communityId) { $cm = new CommunityMember(); $cm->setCommunityId($communityId); $cm->setMemberId($memberid); $cm->save(); $cm->free(); $this->logSection('added a community member', sprintf("%s - %s", $memberid, $communityId)); } } }
public function join($memberId, $communityId, $isRegisterPolicy = 'open') { if ($this->isPreMember($memberId, $communityId)) { throw new Exception('This member has already applied this community.'); } if ($this->isMember($memberId, $communityId)) { throw new Exception('This member has already joined this community.'); } $communityMember = new CommunityMember(); $communityMember->setMemberId($memberId); $communityMember->setCommunityId($communityId); if ($isRegisterPolicy == 'close') { $communityMember->setIsPre(true); } $communityMember->save(); }
public function listenToPostActionEventCommunityJoin($arguments) { $memberId = sfContext::getInstance()->getUser()->getMemberId(); $communityId = $arguments['actionInstance']->getVar('id'); $communityMember = Doctrine::getTable('CommunityMember')->retrieveByMemberIdAndCommunityId($memberId, $communityId); if (!$communityMember) { $communityMember = new CommunityMember(); $communityMember->setCommunityId($communityId); $communityMember->setMemberId($memberId); $communityMember->setIsPre(true); } if ($communityMember->getIsPre()) { $isInvited = opCommunityIntroductionPlugin::isInvitedCommunity($communityId, $memberId); if ($isInvited) { $communityMember->setIsPre(false); $communityMember->save(); sfContext::getInstance()->getUser()->setFlash('notice', 'You have just joined to this %community%.'); sfContext::getInstance()->getController()->redirect('community/home?id=' . $communityId); } } }