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); $sql = 'SELECT max(id) FROM member WHERE is_active != 0'; $maxmemberId = $this->conn->fetchOne($sql); foreach ($memberIds as $id) { // アプリID取得 $sql = 'SELECT application_id FROM member_application WHERE member_id = ?'; $where = array(intval($id)); $appIds = $this->conn->fetchColumn($sql, $where); for ($i=0; $i<$options['number']; ++$i) { // アプリID割り当て $key = array_rand($appIds); $appId = $appIds[$key]; // 送り先は、id1~存在する最大のidからランダムに選出 $sendTo = rand(1,$maxmemberId); $appiv = new ApplicationInvite(); $appiv->setToMemberId($sendTo); $appiv->setFromMemberId($id); $appiv->setApplicationId($appId); $appiv->save(); $appiv->free(); $this->logSection('application invite', sprintf("%s: %s - %s", $appId, $id, $sendTo)); } } }
$t->isa_ok($result, 'Doctrine_Collection', '->getInvitesByToMemberId() return object of Doctrine_Collection'); $t->is(count($result), 1, '->getInvitesByToMemberId() return 1 object'); $result = $table->getInvitesByToMemberId($member2->getId(), true, false); $t->isa_ok($result, 'Doctrine_Collection', '->getInvitesByToMemberId() return object of Doctrine_Collection'); $t->is(count($result), 1, '->getInvitesByToMemberId() return 1 object'); $result = $table->getInvitesByToMemberId($member2->getId(), true, true); $t->isa_ok($result, 'Doctrine_Collection', '->getInvitesByToMemberId() return object of Doctrine_Collection'); $t->is(count($result), 0, '->getInvitesByToMemberId() return empty Doctrine_Collection'); // ->inviteApplicationList() $event = new sfEvent(null, 'name', array('member' => $member2)); $t->ok($table->inviteApplicationList($event), '->inviteApplicationList() returns true'); $t->is(count($event->getReturnValue()), 1, '->inviteApplicationList() return list of one members by sfEvent'); // ->processApplicationConfirm() $invite = $table->find(1); $t->ok($invite, 'invite object is exists'); $event = new sfEvent(null, 'name', array('id' => 1, 'is_accepted' => true)); $t->ok($table->processApplicationConfirm($event), '->processApplicationConfirm() returns true'); // create new invite object $invite = new ApplicationInvite(); $invite->setApplicationId(3); $invite->setToMemberId(2); $invite->setFromMemberId(1); $invite->save(); $event = new sfEvent(null, 'name', array('id' => 2, 'is_accepted' => false)); $t->ok($table->processApplicationConfirm($event), '->processApplicationConfirm() returns true'); $invite = $table->find(2); $t->ok(!$invite, 'invite object was deleted'); $memberApplication = Doctrine::getTable('MemberApplication')->findOneByMemberIdAndApplicationId(2, 3); $t->ok(!$memberApplication, 'don\'t create member application object by ->processApplicationConfirm()'); $event = new sfEvent(null, 'name', array('id' => 999, 'is_accepted' => true)); $t->ok(!$table->processApplicationConfirm($event), '->processApplicationConfirm() returns false');
/** * process invite * * @param sfWebRequest $request */ protected function processInvite(sfWebRequest $request) { $fromMember = $this->getUser()->getMember(); $this->forward404Unless($this->application->isHadByMember($fromMember->getId())); $ids = $request->getParameter('ids', array()); foreach ($ids as $id) { $memberRelationship = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($fromMember->getId(), $id); if ($memberRelationship && !$memberRelationship->isFriend()) { return false; } } $resultIds = array(); foreach ($ids as $id) { $applicationInvite = Doctrine::getTable('ApplicationInvite')->findOneByApplicationIdAndToMemberId($this->application->getId(), $id); if (!$applicationInvite) { $applicationInvite = new ApplicationInvite(); $applicationInvite->setApplication($this->application); $applicationInvite->setToMemberId($id); $applicationInvite->setFromMemberId($fromMember->getId()); $applicationInvite->save(); $resultIds[] = $id; } } return $resultIds; }