예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $om)
 {
     $noteType = new NoteType();
     $noteType->setName('Basic');
     $om->persist($noteType);
     $frontField = new FieldLabel();
     $frontField->setName('Front');
     $frontField->setNoteType($noteType);
     $om->persist($frontField);
     $backField = new FieldLabel();
     $backField->setName('Back');
     $backField->setNoteType($noteType);
     $om->persist($backField);
     $cardType = new CardType();
     $cardType->setName('Forward');
     $cardType->setNoteType($noteType);
     $cardType->addQuestion($frontField);
     $cardType->addAnswer($backField);
     $om->persist($cardType);
     $om->flush();
 }
예제 #2
0
 /**
  * @EXT\Route(
  *     "/note_type/get/{noteTypeId}",
  *     name="claroline_get_note_type"
  * )
  *
  * @param int $noteTypeId
  *
  * @return JsonResponse
  */
 public function findNoteTypeAction($noteTypeId)
 {
     $this->assertIsAuthenticated();
     $noteType = $this->manager->get($noteTypeId);
     if (!$noteType) {
         $noteType = new NoteType();
         $noteType->setName('Basic');
         $frontField = new FieldLabel();
         $frontField->setName('Front');
         $noteType->addFieldLabel($frontField);
         $backField = new FieldLabel();
         $backField->setName('Back');
         $noteType->addFieldLabel($backField);
         $cardType = new CardType();
         $cardType->setName('Forward');
         $cardType->addQuestion($frontField);
         $cardType->addAnswer($backField);
         $noteType->addCardType($cardType);
     }
     $response = new JsonResponse();
     $context = new SerializationContext();
     $context->setGroups('api_flashcard_note_type');
     $response->setData(json_decode($this->serializer->serialize($noteType, 'json', $context)));
     return $response;
 }