/**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $creationDate = new \DateTime();
     $creationDate->setTimezone(self::timezoneUTC());
     //        echo "Incarcare produse default din datafiles/produse.csv!";
     echo "Creare nota receptie default !";
     $receptie = new Reception();
     $furnizor = $manager->getRepository('OviappBundle:Furnizor')->findOneByName('NumeFurnizor1');
     $receptie->setClient($furnizor);
     $receptie->setUser('date_creator');
     $receptie->setDateCreated('data_creare');
     $receptie->setDateUpdated('data_update');
     $receptie->setProducts('array_produse');
     //This should change after phases implementation , should be a link to the phase.
     $manager->persist($receptie);
     $manager->flush();
     echo 'Receptie creata cu success ';
 }
Пример #2
0
 /**
  * @ApiDoc(
  *    description = "Creates and saves a new reception.",
  *    section="A_POST_RECEPTION",
  *    statusCodes = {
  *     201 = "Returned when the reception was added to the database",
  *     400 = "Returned when the validation returns false ",
  *     403 = {"Invalid API KEY", "Incorrect combination of request inputs."},
  *     500 = "Header x-wsse does not exist"
  *    },
  *    requirements = {
  *       {"name"="_format",               "dataType"="string","requirement"="json|xml","description"="Format"},
  *    },
  *    parameters={
  *       {"name"="furnizor_existent",                  "dataType"="text",  "required"=true, "description"="The id of a existing furnizor"},
  *       {"name"="furnizor_nou",                  "dataType"="text",  "required"=true, "description"="The name of a new furnizor"},
  *       {"name"="creator",                "dataType"="string","required"=true,"description"="The reception creator."},
  *       {"name"="produse",                 "dataType"="string","required"=true,"description"="The reception products."},
  * }
  * )
  * return string
  * @View()
  */
 public function postReceptionAction(Request $request)
 {
     $user = $this->getUser();
     $response = new Response();
     $creationDate = new \DateTime();
     $creationDate->setTimezone(self::timezoneUTC());
     $em = $this->getDoctrine()->getManager();
     $key = Uuid::uuid4()->toString();
     $token_key = Uuid::uuid4()->toString();
     $id_furnizor_existent = $request->get('furnizor_existent');
     $string_furnizor_nou = $request->get('furnizor_nou');
     if ($id_furnizor_existent || $string_furnizor_nou) {
         //
         //            print_r($id_furnizor_existent);
         //            print_r(" <br> ");
         //            print_r($string_furnizor_nou);
     } else {
         $response->setStatusCode(403);
         $response->setContent(json_encode(array('status' => 'failed', 'message' => "One of the furnizor fields must be set!")));
         return $response;
     }
     $creator_id = $request->get('creator');
     $produse_id = $request->get('produse');
     $furnizor_existent = $this->getDoctrine()->getRepository('OviappBundle:Furnizor')->find($id_furnizor_existent);
     if ($furnizor_existent) {
         $reception = new Reception();
         $reception->setUser('$client');
         $reception->setClient($furnizor_existent);
         $reception->setProducts('produse_id');
         $reception->setDateCreated('2012-02-02');
         $reception->setDateUpdated('2014-02-02');
         $em->persist($reception);
         $em->flush();
         $response->setStatusCode(201);
         $response->setContent(json_encode(array('success' => true, 'ReceptionId' => $reception->getId())));
         return $response;
     } else {
         $furnizor_nou = new Furnizor();
         $furnizor_nou->setName($string_furnizor_nou);
         $furnizor_nou->setAdress('null');
         $furnizor_nou->setPhone('null');
         $em->persist($furnizor_nou);
         $reception = new Reception();
         $reception->setUser('date_user_aici');
         $reception->setClient($furnizor_nou);
         $reception->setProducts('produse_id');
         $reception->setDateCreated('2016-02-02');
         $reception->setDateUpdated('2015-02-02');
         $em->flush();
         $response->setStatusCode(201);
         $response->setContent(json_encode(array('success' => true, 'ReceptionId' => $reception->getId())));
         return $response;
     }
     $response->setStatusCode(404);
     $response->setContent(json_encode(array('success' => false, 'message' => 'Client/Furnizor Input Error')));
     return $response;
 }