Exemplo n.º 1
0
 public function executeNew(sfWebRequest $request)
 {
     $petition = PetitionTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     /* @var $petition Petition */
     if (!$petition) {
         return $this->notFound();
     }
     if (!$petition->isTicketManager($this->getGuardUser())) {
         return $this->noAccess();
     }
     $token = new PetitionApiToken();
     $token->setPetition($petition);
     $code = '';
     while (strlen($code) < 30) {
         $code .= substr(base_convert(mt_rand(), 10, 36), 1, 5);
     }
     $code = substr($code, 0, 30);
     $token->setToken($code);
     $form = new PetitionApiTokenForm($token);
     if ($request->isMethod('post')) {
         $form->bind($request->getPostParameter($form->getName()));
         if ($form->isValid()) {
             $form->save();
             return $this->ajax()->redirectRotue('petition_tokens', array('id' => $petition->getId()))->render();
         }
         return $this->ajax()->form($form)->render();
     }
     $this->petition = $petition;
     $this->form = $form;
 }
 /**
  *
  * @param PetitionApiToken $api_token
  * @return \Doctrine_Collection
  */
 public function fetchOffsetsByToken(PetitionApiToken $api_token)
 {
     $coll = new Doctrine_Collection('ApiTokenOffset', 'country');
     foreach ($this->createQuery('o')->where('o.petition_api_token_id = ?', $api_token->getId())->execute() as $offset) {
         $coll->add($offset);
     }
     return $coll;
 }