Exemple #1
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 #2
0
 public function edit($id)
 {
     $groupRepository = new GroupRepository($this->storage);
     $group = $groupRepository->getById($id);
     if (!$group->isOwner($this->currentUser)) {
         throw new IncorrectPrivileges();
     }
     $result = ['group' => $group];
     if ($this->request->isMethod('PUT')) {
         $result = $this->save($group);
     }
     return $result;
 }
Exemple #3
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());
 }