Exemplo n.º 1
0
 public function renderTest($id)
 {
     $campaign = new Campaign($id);
     $form = new DeferoForm('send_test_email');
     $form->addTextElement('email');
     foreach ($campaign->message()->findVariables() as $var) {
         $form->addTextElement($var);
     }
     $form->get('email')->setRequired(true);
     $form->addSubmitElement();
     if ($post = $this->request()->postVariables()) {
         $form->hydrate($post);
         if ($form->isValid() && $form->csrfCheck(true)) {
             try {
                 Defero::pushMessage($id, $form->jsonSerialize());
                 $msg = new TransportMessage("info", 'Test queued for user');
             } catch (\Exception $e) {
                 $msg = new TransportMessage("error", $e->getMessage());
             }
             return Redirect::to("/campaigns/{$id}")->with("msg", $msg);
         }
     }
     return new RenderGroup('<h1>Send a Test Campaign</h1>', $form);
 }
Exemplo n.º 2
0
 public function renderEdit($pid)
 {
     $processors = $this->_campaign->processors;
     $definedProcessors = $this->config('processors')->jsonSerialize();
     if (!isset($processors[$pid])) {
         return $this->renderNew();
     }
     $pData = $processors[$pid];
     $form = new DeferoForm('edit_processor');
     $form->addSelectElement('processorType', array_map('class_shortname', $definedProcessors));
     $form->getElement('processorType')->addAttribute('disabled');
     $processor = $this->config('processors')->getStr($pData->processorType);
     $processor = new $processor();
     // populate types
     $class = new \ReflectionClass($processor);
     foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
         $default = $p->getValue($processor);
         // get property type (enum)
         // use reflection to check for enumclass
         if ($t = DocBlockHelper::getBlock($processor, $p->getName(), 'enumclass')) {
             $form->addSelectElement($p->getName(), (new OptionBuilder(new $t()))->getOptions(), $default);
         } else {
             $form->addTextElement($p->getName(), $default);
         }
     }
     $form->addSubmitElement();
     $form->hydrate((array) $processor);
     $form->hydrate((array) $pData);
     if ($this->request()->postVariables()) {
         $form->hydrate($this->request()->postVariables());
         if ($form->isValid() && $form->csrfCheck()) {
             $processors[$pid] = $form->jsonSerialize();
             $this->_campaign->processors = $processors;
             $this->_campaign->saveChanges();
             return Redirect::to('/campaigns/' . $this->getInt('cid'));
         }
     }
     echo $form;
 }