/** * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function storeAction(Request $request) { $this->assertUserRights(UserRole::ROLE_ADMIN); $tool = $request->get('tool'); if (array_key_exists("id", $tool)) { $toolObject = $this->getDoctrine()->getRepository('BauerIncidentDashboardCoreBundle:Tool')->find($tool["id"]); } else { $toolObject = new Tool(); $toolObject->setProject($this->getProject()); } if ($tool["identifier"] != "") { $toolObject->setIdentifier($tool["identifier"]); } else { $this->addFlash('notice', 'The parameter "identifier" is required'); return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()])); } if ($tool["name"] != "") { $toolObject->setName($tool["name"]); } else { $this->addFlash('notice', 'The parameter "name" is required'); return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()])); } $toolObject->setDescription($tool["description"]); if (array_key_exists('active', $tool)) { $toolObject->setActive(true); } else { $toolObject->setActive(false); } if (array_key_exists('notify', $tool)) { $toolObject->setNotify(true); } else { $toolObject->setNotify(false); } if (array_key_exists('systemSpecific', $tool)) { $toolObject->setSystemSpecific(true); } else { $toolObject->setSystemSpecific(false); } $toolObject->setInterval((int) $tool["interval"]); $em = $this->getDoctrine()->getManager(); $em->persist($toolObject); $em->flush(); $this->addFlash('success', 'Tool "' . $toolObject->getName() . '" successfully saved.'); return $this->redirect($this->generateUrl('koalamon_default_tool_admin', ['project' => $this->getProject()->getIdentifier()])); }
public function load(ObjectManager $manager) { foreach ($this->fixtures as $file) { /** @var SplFileInfo $file */ $fixture = json_decode($file->getContents()); $tool = new Tool(); $tool->setIdentifier($fixture->identifier); $tool->setName($fixture->name); $tool->setImage($fixture->image); $tool->setNotify($fixture->notify); $tool->setDescription($fixture->description); /** @var Project $project */ $project = $this->getReference('project-' . $fixture->project); $tool->setProject($project); $manager->persist($tool); } $manager->flush(); }