Exemple #1
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 #2
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());
 }