Esempio n. 1
0
 /**
  * @param string $id
  * @param string $name
  *
  * @return Item
  */
 public function createItem($id, $name)
 {
     $item = new Item();
     $item->setName($name);
     $this->setEntityId($item, $id);
     return $item;
 }
 private function getWeaponsInfo()
 {
     $parameters = array('iDisplayStart' => 0, 'iDisplayLenght' => 50, 'type' => 1);
     $response = file_get_contents($this->url . '?' . http_build_query($parameters));
     $response = json_decode($response, true);
     $data = $response['aaData'];
     $formattedData = array();
     //Formatting Data
     foreach ($data as $value) {
         $index = $value[0]['name'] . $value[0]['requiredLevel'];
         $formattedData[$index] = array('name' => $value[0]['name'], 'description' => $value[0]['description'], 'level' => $value[0]['requiredLevel']);
     }
     $i = 0;
     foreach ($formattedData as $value) {
         $i++;
         $item = new Item();
         $item->setName($value['name']);
         $item->setDescription($value['description']);
         $item->setLevel($value['level']);
         $item->setType('weapon');
         $this->em->persist($item);
         if ($i % 20 === 0) {
             $this->em->flush();
             $this->em->clear();
         }
     }
     $this->em->flush();
     $this->em->clear();
 }
Esempio n. 3
0
 public function itemCreate(Request $request, $typeStr, $responceTo)
 {
     $type = Item::typeToInt($typeStr);
     $user = $this->get('security.token_storage')->getToken()->getUser();
     if ($request->isMethod('POST')) {
         dump("ukladani");
         $name = $request->request->get('name');
         $public = $request->request->get('public');
         $note = $request->request->get('note');
         $category = $request->request->get('category');
         $price = $request->request->get('price');
         $parameters = $request->request->get('parameter');
         $parameters = $request->request->get('parameter') == null ? [] : $request->request->get('parameter');
         dump($parameters);
         $validUntil = date("Y-m-d", strtotime($request->request->get('validUntil')));
         $public = $public === null ? false : true;
         dump($request);
         $categoryObj = $this->getDoctrine()->getRepository('AppBundle:Category')->find($category);
         $item = new Item();
         $item->setName($name);
         $item->setOwner($user);
         $item->setType($type);
         dump($type);
         $item->setResponceTo($responceTo);
         $item->setPublic($public);
         $item->setPrice($price);
         $item->setCategory($categoryObj);
         dump($validUntil);
         $item->setValidUntil(new \DateTime($validUntil));
         $item->setNote($note);
         $item->setDeleted(0);
         $em = $this->getDoctrine()->getManager();
         foreach ($parameters as $definitionId => $value) {
             $definition = $this->getDoctrine()->getRepository("AppBundle:Definition")->find($definitionId);
             $parameter = new Param();
             $parameter->setDefinition($definition);
             $parameter->setItem($item);
             $parameter->setValue($value);
             $em->persist($parameter);
             $item->addParam($parameter);
         }
         $em->persist($item);
         $em->flush();
         if ($type === Item::TYPE_DEMAND) {
             $this->addFlash('success', 'Poptávka úspěšně vytvořena');
             return $this->redirect($this->generateUrl('main_demand'));
         } else {
             $this->addFlash('success', 'Nabídka úspěšně vytvořena');
             return $this->redirect($this->generateUrl('main_offer'));
         }
     }
     $categories = $this->getDoctrine()->getRepository('AppBundle:Category')->findAll();
     return ['categories' => $categories, 'type' => Item::intToType($type), 'responceTo' => $responceTo];
 }