/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { sfContext::createInstance($this->configuration); $displayName = $this->ask("Enter a minyan display name (Darchei Noam Glenbrook)"); $identifier = $this->ask("Enter minyan identifier (dng)"); $email = $this->ask("Enter username for minyan admin"); $user = Doctrine::getTable('SfGuardUser')->findOneByUsername(trim(strtolower($email))); if (!$user) { throw new Exception("User with email {$email} does not exist"); } try { $con = Doctrine::getConnectionByTableName("SfGuardUser"); $con->beginTransaction(); $minyan = new Minyan(); $minyan->setName($displayName); $minyan->setIdentifier(Utils::formatPermalink($identifier)); $minyan->save(); $minyanUser = new MinyanUser(); $minyanUser->setIsAdmin(true); $minyanUser->setUserId($user->getId()); $minyanUser->setMinyanId($minyan->getId()); $minyanUser->save(); $this->logSection('mam', "Minyan {$identifier} created successfully!"); $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; } }
public function executeSubscribe(sfWebRequest $request) { $minyan = Utils::extractDomainObjectFromRequest($request, 'Minyan', 'id'); if (!$minyan) { echo Utils::ajaxResponse(false, "No minyan could be found with this id."); return sfView::NONE; } $user = $this->getUser()->getGuardUser(); if ($minyan->hasSubscriber($user->getId())) { echo Utils::ajaxResponse(false, 'You are already subscribed to this minyan!'); return sfView::NONE; } $contactMethods = array(); $contactMethods['phone'] = Utils::toBoolean($request->getParameter('use_phone')); $contactMethods['text'] = Utils::toBoolean($request->getParameter('use_text')); $contactMethods['email'] = Utils::toBoolean($request->getParameter('use_email')); if ($contactMethods['phone'] == false && $contactMethods['text'] == false && $contactMethods['email'] == false) { echo Utils::ajaxResponse(false, 'You must select at least one contact method!'); return sfView::NONE; } $minyanUser = new MinyanUser(); $minyanUser->setMinyanId($minyan->getId()); $minyanUser->setUserId($user->getId()); $minyanUser->setUsePhone($contactMethods['phone']); $minyanUser->setUseSms($contactMethods['text']); $minyanUser->setUseEmail($contactMethods['email']); $minyanUser->save(); echo Utils::ajaxResponse(true); return sfView::NONE; }
public function executeAddNewSubscriber(sfWebRequest $request) { $this->minyan = Utils::extractDomainObjectFromRequest($request, 'Minyan', 'minyanId', true); $this->form = new SignupForm(); unset($this->form['password']); if ($request->isMethod('post')) { $this->form->bind($request->getParameter('signup')); if ($this->form->isValid()) { $fields = $this->form->getValues(); $con = Doctrine::getConnectionByTableName('SfGuardUser'); try { $con->beginTransaction(); $this->logMessage("Executing signup for new user for minyan {$this->minyan->getName()}: {$fields['email']}", 'notice'); $sgu = new SfGuardUser(); $sgu->setFirstName($fields['first_name']); $sgu->setLastName($fields['last_name']); $sgu->setUsername($fields['email']); $sgu->setEmailAddress($fields['email']); $sgu->setPhone($fields['phone']); $sgu->setPassword(sfConfig::get('app_temp_password')); $sgu->setIsActive(true); $sgu->save(); $contactMethods = $request->getParameter('contact_method'); foreach ($contactMethods as $name => $method) { $contactMethods[$name] = Utils::toBoolean($method); } $minyanUser = new MinyanUser(); $minyanUser->setMinyanId($this->minyan->getId()); $minyanUser->setUserId($sgu->getId()); $minyanUser->setUsePhone($contactMethods['phone']); $minyanUser->setUseSms($contactMethods['text']); $minyanUser->setUseEmail($contactMethods['email']); $minyanUser->save(); $con->commit(); } catch (Exception $e) { $con->rollback(); $this->logMessage("Problem when signing up user {$fields['email']}: {$e->getMessage()}", 'notice'); throw $e; } MAMUtils::sendInternalEmail("New Make a Minyan User Alert for minyan {$this->minyan->getName()}! - {$sgu->getFullName()}", ""); //send email $options = array(); $options['template'] = 'welcomeToMinyan'; $options['subject'] = 'Welcome!'; $options['minyan'] = $this->minyan; $options['user'] = $sgu; $options['minyanUser'] = $minyanUser; $options['first_name'] = $sgu->getFirstName(); $options['to'] = $sgu->getUsername(); EmailUtils::send($options); $this->logMessage('Welcome email sent to ' . $sgu->getUsername(), 'notice'); $this->getUser()->setFlash('subscribersSuccess', 'Added ' . $sgu->getUsername() . ' successfully!'); echo Utils::ajaxResponse(true, $this->minyan->getId()); return sfView::NONE; } } }