コード例 #1
0
ファイル: Fiches.php プロジェクト: mejt/Krauza
 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']);
 }
コード例 #2
0
ファイル: FichesController.php プロジェクト: mejt/Krauza
 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());
 }
コード例 #3
0
ファイル: GroupsController.php プロジェクト: mejt/Krauza
 private function save(Group $group = null)
 {
     $groupRepository = new GroupRepository($this->storage);
     try {
         if (empty($group)) {
             $groupName = new GroupName($this->request->get('name'));
             $group = new Group(new UniqueId(), $this->getCurrentUser(), $groupName, new Fiches($this->storage));
             $groupRepository->insert($group);
             $userGroupsRepository = new UserGroups($this->storage);
             $userGroupsRepository->insert($group, $this->currentUser);
         } else {
             $group->setName(new GroupName($this->request->get('name')));
             $groupRepository->update($group);
         }
     } catch (DataNotValid $e) {
         return ['messages' => ['field' => $e->getFieldName(), 'message' => $e->getMessage()], 'data' => ['name' => $this->request->get('name')]];
     }
     return $this->app->redirect('/groups');
 }