protected function execute($arguments = array(), $options = array()) { if ( !$options['appmin'] || !$options['appmax'] || ($options['appmin'] > $options['appmax'])) { throw new Exception("invalid option: "); } $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $sql = 'SELECT id FROM application'; $appIds = $this->conn->fetchColumn($sql); $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); foreach ($memberIds as $memberid) { $appids = $this->setrandomappid($appIds, $options['appmin'], $options['appmax']); foreach ($appids as $application_id) { $sql = 'SELECT id FROM member_application WHERE member_id = ? AND application_id = ?'; $where = array(intval($memberid), intval($application_id)); $ma = $this->conn->fetchOne($sql, $where); if (!$ma) { $memberApplication = new MemberApplication(); $memberApplication->setMemberId($memberid); $memberApplication->setApplicationId($application_id); $memberApplication->setPublicFlag('public'); $memberApplication->save(); $memberApplication->free(); $this->logSection('member_application', sprintf("%s - %s", $memberid, $application_id)); } } } }
/** * add this application to member * * @param Member $member * @param array $applicationSettings * @param array $reason * @return MemberApplication */ public function addToMember(Member $member, $applicationSettings = array(), $reason = null) { $memberApplication = Doctrine::getTable('MemberApplication')->findOneByApplicationAndMember($this, $member); if (!$memberApplication) { $memberApplication = new MemberApplication(); $memberApplication->setApplication($this); $memberApplication->setMember($member); $memberApplication->save(); // to use Lifecycle Event (event.addapp) $params = array('memberApplication' => $memberApplication, 'reason' => $reason); $event = new sfEvent($this, 'op_opensocial.addapp', $params); sfContext::getInstance()->getEventDispatcher()->notify($event); } foreach ($applicationSettings as $name => $value) { $memberApplication->setApplicationSetting($name, $value); } $invites = Doctrine::getTable('ApplicationInvite')->findByApplicationIdAndToMemberId($this->getId(), $member->getId()); $invites->delete(); return $memberApplication; }