Exemple #1
0
 /**
  * @test
  */
 public function factoryShouldPrepareCorrectEntity()
 {
     $mockUniqueId = $this->getMock('Fiche\\Domain\\Policy\\UniqueIdInterface');
     $id = new $mockUniqueId();
     $word = 'word';
     $explain = 'explain';
     $fiche = FicheFactory::create($id, $this->group, $word, $explain);
     $this->assertInstanceOf(Fiche::class, $fiche);
     $this->assertEquals($word, $fiche->getWord());
     $this->assertEquals($explain, $fiche->getExplainWord());
 }
Exemple #2
0
 public function getById($id) : Fiche
 {
     $data = $this->storage->query(function ($pdo, $operations) use($id) {
         $dbClass = $operations . '\\FetchData';
         return $dbClass::getRow($pdo, ['*'], 'fiche', ['id' => $id]);
     });
     $id = new UniqueId($data['id']);
     $groupRepository = new Group($this->storage);
     $group = $groupRepository->getById($data['group_id']);
     return FicheFactory::create($id, $group, $data['word'], $data['explain_word']);
 }
Exemple #3
0
 public function fetchAllActiveForUserGroup(UserGroup $userGroup, UserFichesCollection $userFichesCollection)
 {
     $result = $this->storage->query(function ($pdo, $operations) use($userGroup) {
         $dbClass = $operations . '\\FetchData';
         return $dbClass::fetchAll($pdo, ['*'], 'user_fiche', ['archived' => false, 'user_id' => $userGroup->getUser()->getId(), 'group_id' => $userGroup->getGroup()->getId()]);
     });
     $fichesRepository = new Fiches($this->storage);
     $fiches = $fichesRepository->getMultipleByIds(array_column($result, 'fiche_id'));
     foreach ($fiches as $fiche) {
         $ficheStatus = $result[array_search($fiche['id'], array_column($result, 'fiche_id'))];
         $ficheObj = FicheFactory::create(new UniqueId($fiche['id']), $userGroup->getGroup(), $fiche['word'], $fiche['explain_word']);
         $ficheStatusObj = new UserFicheStatus($ficheObj, $userGroup, $ficheStatus['level'], new \DateTime($ficheStatus['last_modified']));
         $userFichesCollection->append($ficheStatusObj);
     }
 }
Exemple #4
0
 private function save(Fiche $fiche = null)
 {
     $ficheRepository = new FicheRepository($this->storage);
     $groupRepository = new GroupRepository($this->storage);
     $word = $this->request->get('word');
     $explain = $this->request->get('explain');
     $group = $groupRepository->getById($this->request->get('group'));
     try {
         if (empty($fiche)) {
             $fiche = FicheFactory::create(new UniqueId(), $group, $word, $explain);
             $ficheRepository->insert($fiche);
         }
     } catch (DataNotValid $e) {
         return ['messages' => ['field' => $e->getFieldName(), 'message' => $e->getMessage()], 'data' => ['word' => $word, 'explain' => $explain]];
     }
     return $this->app->redirect('/groups/show/' . $group->getId());
 }