Exemplo n.º 1
0
 /**
  * Add element
  *
  * @param Entity\Element $element
  */
 public function addElement(\Jazzee\Entity\Element $element)
 {
     $this->elements[] = $element;
     if ($element->getPage() != $this) {
         $element->setPage($this);
     }
 }
Exemplo n.º 2
0
 /**
  * Update all of the elements on a page with an array of elements passed in
  * @param \Jazzee\Entity\Element $element
  * @param array $items
  */
 protected function saveElementListItems(\Jazzee\Entity\Element $element, array $items)
 {
     $htmlPurifier = $this->getFilter();
     foreach ($items as $i) {
         switch ($i->status) {
             case 'delete':
                 //don't try and delete temporary elements
                 if ($item = $element->getItemById($i->id)) {
                     if ($this->_em->getRepository('\\Jazzee\\Entity\\Page')->hasAnswers($element->getPage())) {
                         $this->setLayoutVar('status', 'error');
                         $this->addMessage('error', $item->getValue() . ' could not be deleted becuase it has applicant information associated with it.');
                     } else {
                         $this->_em->remove($item);
                         $element->getListItems()->remove($item->getId());
                     }
                 }
                 break;
             case 'new':
                 $item = new \Jazzee\Entity\ElementListItem();
                 $element->addItem($item);
             default:
                 if (!isset($item)) {
                     $item = $element->getItemById($i->id);
                 }
                 $item->setValue($htmlPurifier->purify($i->value));
                 $item->setWeight($i->weight);
                 $item->setName($i->name);
                 foreach ($i->variables as $v) {
                     $var = $item->setVar($v->name, $v->value);
                     $this->_em->persist($var);
                 }
                 if ($i->isActive) {
                     $item->activate();
                 } else {
                     $item->deActivate();
                 }
                 $this->_em->persist($item);
         }
         unset($item);
         //this isn't for memory management if it stays set it gets re-used at the begning of the default switch
     }
 }