예제 #1
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $i18n = sfContext::getInstance()->getI18N();
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     $form->getObject()->setPrincipalId($this->getUser()->getPrincipalId());
     $form->getObject()->setType('pending');
     $s = $form->getObject();
     if (!$form->isNew()) {
         $this->checkIsMy($form->getObject());
     }
     if ($form->isValid()) {
         $notice = $form->getObject()->isNew() ? $i18n->__('The service has been created.') : $i18n->__('The service has been updated.');
         try {
             $service = $form->save();
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             $this->getUser()->setFlash('error', $message);
             return sfView::SUCCESS;
         }
         if ($form->isNew()) {
             $sp = new ServicePrincipal();
             $sp->setServiceId($form->getObject()->getId());
             $sp->setPrincipalId($this->getUser()->getPrincipalId());
             $sp->save();
         }
         $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $service)));
         $this->getUser()->setFlash('notice', $notice);
         $this->redirect("show/index?id=" . $form->getObject()->getId());
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
예제 #2
0
 public function executeResolve(sfWebRequest $request)
 {
     $i18n = sfContext::getInstance()->getI18N();
     $i = Doctrine::getTable('ServiceInvitation')->findOneByUuid($request->getParameter('uuid'));
     /*  Nincs is ilyen meghívó. */
     if (!$i) {
         $m = $i18n->__("Can't find the requested invitation");
         $this->getUser()->setFlash('error', $m);
         $this->redirect("default/error");
     }
     /*  Elfogadta már? */
     if ($i->getStatus() != "pending") {
         $m = $i18n->__('The invitation is no longer pending: %status%', array("%status%" => $i->getStatus()));
         $this->getUser()->setFlash('error', $m);
         $this->redirect("default/error");
     }
     $p = Doctrine::getTable('Principal')->findOneByFedid($this->getUser()->getUsername());
     /* A felhasználó most van itt először. Berakjuk a principal-ba. */
     if (!$p) {
         $p = new Principal();
         $p->setFedid($this->getUser()->getUsername());
         $p->save();
     }
     /* Ugye nincs még benn a szervezetben? */
     $s = $i->getService();
     foreach ($i->getPrincipal() as $prin) {
         if ($prin and $prin->getId() == $this->getUser()->getPrincipalId()) {
             $i->delete();
             $m = $i18n->__('You are already a member of this service. The invitation has lost its purpose, so we have deleted it.');
             $this->getUser()->setFlash('notice', $m);
             $this->redirect("show/index?id=" . $s->getId());
         }
     }
     $p_id = $this->getUser()->getPrincipalId();
     $i->setAcceptAt(date('Y-m-d H:i:s'));
     $i->setStatus('accepted');
     $i->setPrincipalId($p_id);
     $i->save();
     $sp = new ServicePrincipal();
     $sp->setPrincipalId($p_id);
     $sp->setServiceId($s->getId());
     $sp->save();
     /* Send email */
     $params = array("s" => $s, "p" => $p);
     /* szervezők email címei */
     $to = $s->getManagersEmailArray();
     $email_params = array("to" => $to, "subject" => $i18n->__('%lname% has accepted the invitation to %service%', array("%lname" => $p->getUser()->getLastName(), "%service%" => $s)), "bodyhtml" => $this->getPartial('invitePrincipal/acceptHtml', $params));
     $this->sendEmail($email_params);
     $this->getUser()->setFlash('notice', $i18n->__('You have been successfully added to %service% service.', array("%service%" => $s)));
     $this->redirect("show/index?id=" . $s->getId());
 }