예제 #1
0
 private function createAKeyword($label, KeyWord $parent = null)
 {
     $keyword = new KeyWord();
     $keyword->setKeyWord($label);
     if ($parent instanceof KeyWord) {
         $keyword->setParent($parent);
     }
     $this->em->persist($keyword);
     $this->em->flush($keyword);
     return $keyword;
 }
예제 #2
0
 /**
  * Sets up the fixture.
  */
 public function setUp()
 {
     $this->current_time = new \Datetime();
     $this->keyword = new KeyWord('test');
     $this->keyword->setKeyWord('test');
 }
 /**
  * @return Response
  *
  * @Rest\RequestParam(name="keyword", description="Keyword value", requirements={
  *      @Assert\NotBlank()
  * })
  * @Rest\ParamConverter(name="keyword", class="BackBee\NestedNode\KeyWord")
  * @Rest\Security("is_fully_authenticated() & has_role('ROLE_API_USER')")
  */
 public function putAction(KeyWord $keyword, Request $request)
 {
     try {
         $keywordLabel = trim($request->request->get('keyword'));
         if ($this->keywordAlreadyExists($keywordLabel, $keyword->getUid())) {
             throw new BadRequestHttpException('KEYWORD_ALREADY_EXISTS');
         }
         $keyword->setKeyWord($keywordLabel);
         $this->getEntityManager()->persist($keyword);
         $this->getEntityManager()->flush();
         $response = $this->createJsonResponse(null, 204);
     } catch (\Exception $e) {
         $response = $this->createErrorResponse($e);
     }
     return $response;
 }