/** * Create a demo element * @param \Jazzee\Entity\ElementType $type * $param \Doctrine\ORM\EntityManager $entityManager * @return \Jazzee\Entity\Element */ protected function demoElement(\Jazzee\Entity\ElementType $type, \Doctrine\ORM\EntityManager $entityManager) { $element = new \Jazzee\Entity\Element(); $element->setType($type); switch ($type->getClass()) { case '\\Jazzee\\Element\\CheckboxList': case '\\Jazzee\\Element\\RadioList': case '\\Jazzee\\Element\\SelectList': for ($i = 1; $i <= rand(5, 15); $i++) { $item = new \Jazzee\Entity\ElementListItem(); $item->setWeight($i); $item->activate(); $item->setValue(\Foundation\Utility::ordinalValue($i) . ' item'); $entityManager->persist($item); $element->addItem($item); } break; case '\\Jazzee\\Element\\RankingList': for ($i = 1; $i <= rand(5, 15); $i++) { $item = new \Jazzee\Entity\ElementListItem(); $item->setWeight($i); $item->activate(); $item->setValue(\Foundation\Utility::ordinalValue($i) . ' item'); $entityManager->persist($item); $element->addItem($item); } $element->setMin(1); $element->setMax(4); break; case '\\Jazzee\\Element\\Textarea': $element->setMax(500); break; } return $element; }
/** * Copy a Page * @param \Doctrine\ORM\EntityManager $em * @param \Jazzee\Entity\Page $page * @return \Jazzee\Entity\Page */ public function copyPage(\Doctrine\ORM\EntityManager $em, \Jazzee\Entity\Page $page) { $newPage = new \Jazzee\Entity\Page(); $newPage->setTitle($page->getTitle()); $newPage->setMax($page->getMax()); $newPage->setInstructions($page->getInstructions()); $newPage->setLeadingText($page->getLeadingText()); $newPage->setTrailingText($page->getTrailingText()); $newPage->setFixedId($page->getFixedId()); $newPage->setType($em->getRepository('\\Jazzee\\Entity\\PageType')->findOneByClass($page->getType()->getClass())); if ($page->isGlobal()) { $newPage->makeGlobal(); } else { $newPage->notGlobal(); } if ($page->isRequired()) { $newPage->required(); } else { $newPage->optional(); } foreach ($page->getChildren() as $child) { $newPage->addChild($this->copyPage($em, $child)); } foreach ($page->getVariables() as $variable) { $newPage->setVar($variable->getName(), $variable->getValue()); } foreach ($newPage->getVariables() as $variable) { $em->persist($variable); } foreach ($page->getElements() as $element) { $newElement = new \Jazzee\Entity\Element(); $newElement->setType($em->getRepository('\\Jazzee\\Entity\\ElementType')->findOneByClass($element->getType()->getClass())); $newElement->setWeight($element->getWeight()); $newElement->setFixedId($element->getFixedId()); $newElement->setTitle($element->getTitle()); $newElement->setMax($element->getMax()); $newElement->setMin($element->getMin()); $newElement->setInstructions($element->getInstructions()); $newElement->setDefaultValue($element->getDefaultValue()); $newElement->setFormat($element->getFormat()); if ($element->isRequired()) { $newElement->required(); } else { $newElement->optional(); } foreach ($element->getListItems() as $item) { $newItem = new \Jazzee\Entity\ElementListItem(); $newItem->setValue($item->getValue()); $newItem->setWeight($item->getWeight()); $newElement->addItem($newItem); $em->persist($newItem); } $em->persist($newElement); $newPage->addElement($newElement); } $em->persist($newPage); return $newPage; }