/** * Compare an element to another element * * * @return array */ public function compareWith(\Jazzee\Entity\Element $element) { $differences = array('different' => false, 'title' => $this->_element->getTitle(), 'properties' => array(), 'thisListItems' => array(), 'otherListItems' => array()); $arr = array('title' => 'Title', 'name' => 'Name', 'format' => 'Format', 'min' => 'Minimum Value', 'max' => 'Maximum Value', 'instructions' => 'Instructions', 'defaultValue' => 'Default Value'); foreach ($arr as $name => $niceName) { $func = 'get' . ucfirst($name); if ($this->_element->{$func}() != $element->{$func}()) { $differences['different'] = true; $differences['properties'][] = array('name' => $niceName, 'type' => 'textdiff', 'this' => $this->_element->{$func}(), 'other' => $element->{$func}()); } } foreach ($this->_element->getListItems() as $item) { $differences['thisListItems'][] = $item->getValue(); } foreach ($element->getListItems() as $item) { $differences['otherListItems'][] = $item->getValue(); } return $differences; }
/** * 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 } }