Esempio n. 1
0
 private static function loadCategoriesFromDb(DbEntry $article)
 {
     $categories = new CategoryCollection();
     foreach ($article->related("article_category") as $category) {
         $categories->addItem(CategoryService::loadFromDb($category->category));
     }
     return $categories;
 }
Esempio n. 2
0
 public function addCategoryFormSucceeded(Form $form, $values)
 {
     if ($values->categoryId == 0) {
         $values->rank = $this->categoryFacade->findMaxRank() + 1;
         $category = CategoryService::create($values);
     } else {
         $category = CategoryService::loadForUpdate($values);
     }
     $this->categoryFacade->save($category);
     if ($form->getPresenter()->isAjax()) {
         if ($values->categoryId == 0) {
             $form->setValues([], true);
             $form->getPresenter()->redrawControl("addCategoryForm");
         } else {
             $form->getPresenter()->getTemplate()->edit = true;
             $form->getPresenter()->redrawControl("editCategoryForm");
         }
         $form->getPresenter()->redrawControl("categories");
     } else {
         $form->getPresenter()->flashMessage("Nová kategorie byla úspěšně vytvořena.", "alert-success");
         $form->getPresenter()->redirect("this");
     }
 }
Esempio n. 3
0
 private function toEntity(DbEntry $category)
 {
     return CategoryService::loadFromDb($category);
 }
Esempio n. 4
0
 private function formValuesToEntity(Form $form)
 {
     $values = (object) $form->getHttpData();
     $user = UserService::loadFromSession($form->getPresenter()->getUser());
     $photo = PhotoService::loadForArticle($values->photoId);
     $tags = new TagCollection();
     foreach ($values->tagList as $tag) {
         $tags->addItem(TagService::create($tag));
     }
     $categories = new CategoryCollection();
     foreach ($values->categories as $categoryId) {
         $categories->addItem(CategoryService::loadForArticle($categoryId));
     }
     $articleId = $form->getPresenter()->getParameter("articleId");
     if ($articleId) {
         return ArticleService::loadForUpdate($articleId, $values, $user, $photo, $tags, $categories);
     } else {
         return ArticleService::create($values, $user, $photo, $tags, $categories);
     }
 }