示例#1
0
 public function load(ObjectManager $manager)
 {
     $contrats = ['CDI', 'CDD', 'Intermitent', 'Freelance', 'Auto-entrepreneur', 'Mi-temps'];
     $skills = ['Scénarisation', 'Design', 'Modelisation', 'Animation', 'Texturing', 'Lighting', 'Rendering', 'Rendering', 'Setup', 'FX', 'Montage', 'Etallonage', 'Réalisation', 'Sound design', 'Doublage', 'Gestion de projet', 'Management', 'Relations clients', 'Budgétisation', 'Création d\'entreprise', 'Autres'];
     $softwares = ['3dsmax', 'Maya', 'Blender', 'Zbrush', 'Mudbox', '3D Coat', 'Toon Boon', 'Flash', 'Flame', 'Photoshop', 'Illustrator', 'Première', 'After Effetcs', 'Nuke', 'Vegas', 'Final Cut', 'Avid', 'Pack Office', 'Autres'];
     $languages = ['Français', 'Anglais', 'Allemand', 'Japonais', 'Mandarin', 'Russe', 'Espagnol', 'Italien', 'Autres'];
     foreach ($contrats as $contrat) {
         $entity = new Attribute();
         $entity->setType(Attribute::TYPE_CONTRACT);
         $entity->setName($contrat);
         $manager->persist($entity);
     }
     foreach ($skills as $skill) {
         $entity = new Attribute();
         $entity->setType(Attribute::TYPE_SKILL);
         $entity->setName($skill);
         $manager->persist($entity);
     }
     foreach ($softwares as $software) {
         $entity = new Attribute();
         $entity->setType(Attribute::TYPE_SOFTWARE);
         $entity->setName($software);
         $manager->persist($entity);
     }
     foreach ($languages as $language) {
         $entity = new Attribute();
         $entity->setType(Attribute::TYPE_LANGUAGE);
         $entity->setName($language);
         $manager->persist($entity);
     }
     $manager->flush();
 }
 /**
  * @param $id
  * @param $action
  * @param Request $request
  * @Route("/attribute/{action}/{id}", name="admin_attribute_edit",
  *     defaults={"id": 0, "action": "new"},
  *     requirements={
  *      "action": "new|edit",
  *      "id": "\d+"
  *     })
  * @Method({"GET", "POST"})
  * @Template("AppBundle:admin/attributes/form:attribute.html.twig")
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function attributeEditAction($id, $action, Request $request)
 {
     //        TODO: Add check on unique options for attribute
     $em = $this->getDoctrine()->getManager();
     $originalOptions = new ArrayCollection();
     if ($action == "edit") {
         $attribute = $em->getRepository('AppBundle:Attribute')->find($id);
         $title = 'Edit attribute id: ' . $id;
         foreach ($attribute->getOptions() as $option) {
             $originalOptions->add($option);
         }
     } else {
         $attribute = new Attribute();
         $attribute->addOption(new AttributeOption());
         $title = 'Create new attribute';
     }
     $form = $this->createForm(AttributeType::class, $attribute, ['em' => $em, 'action' => $this->generateUrl('admin_attribute_edit', ['action' => $action, 'id' => $id]), 'method' => Request::METHOD_POST])->add('save', SubmitType::class, array('label' => 'Save'));
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             foreach ($originalOptions as $option) {
                 if (false === $attribute->getOptions()->contains($option)) {
                     $em->remove($option);
                 }
             }
             $em->persist($attribute);
             $em->flush();
             if ($attribute->getId()) {
                 return $this->redirectToRoute('admin_attribute_edit', ['action' => 'edit', 'id' => $attribute->getId()]);
             } else {
                 return $this->redirectToRoute('admin_attribute_edit');
             }
         }
     }
     $formData = $form->createView();
     return ['title' => $title, 'form' => $formData];
 }
 /**
  * Add filter
  *
  * @param \AppBundle\Entity\Attribute $filter
  *
  * @return SearchFilter
  */
 public function addFilter(Attribute $filter)
 {
     $this->filters[$filter->getId()] = $filter;
     return $this;
 }