예제 #1
0
 /**
  * Handles editing of an existing article, assuming user has permission
  * to the parent category.
  *
  * @return string|bool
  */
 public function editSection()
 {
     $this->setOutputType(self::_OT_CONFIG);
     if (!$this->_acl->check('article_edit_article')) {
         throw new Module_NoPermission();
     }
     // Get the ID of the article we're to be editing
     try {
         $aid = $this->_router->getArgument('id');
         $article = $this->_model()->getArticle($aid);
         // Check user has permission
         $resource = 'article-cat-' . $article['cat_id'];
         if (!$this->_acl->resourceExists($resource) || !$this->_acl->check($resource)) {
             throw new Module_NoPermission();
         }
         if ($article['published']) {
             $this->setTitle(sprintf(t('Edit article "%1$s"'), $article['title']));
         } else {
             $this->setTitle(sprintf(t('Edit unpublished article "%1$s"'), $article['title']));
         }
         // Prepare form validation
         $form = new View_form('config/form_article_edit.html', 'article');
         $form->addElement('article/cid', $article['cat_id'], t('Category'), new Validator_Int());
         $form->addElement('article/title', $article['title'], t('Title'), new Validator_Length(1, 255));
         $form->addElement('article/published', $article['published'], t('Published'), new Validator_Bool());
         $form->setContentUrl('article/view/' . $article['identifier']);
         if ($form->hasInput() && $form->isValid()) {
             $fd = $form->getValues('article');
             $this->_model()->editArticle($article['id'], $fd['title'], $fd['published'], $fd['cid']);
             $form->success('article/view/' . $article['identifier']);
             $this->_event->success(t('Edited article'));
             return zula_redirect($this->_router->makeUrl('article', 'config', 'edit', null, array('id' => $article['id'])));
         } else {
             // Add additional data
             $form->assign(array('ARTICLE_ID' => $article['id'], 'CATEGORIES' => $this->_model()->getAllCategories(), 'PARTS' => $this->_model()->getArticleParts($article['id'])));
             return $form->getOutput();
         }
     } catch (Router_ArgNoExist $e) {
         $this->_event->error(t('No article selected'));
     } catch (Article_NoExist $e) {
         $this->_event->error(t('Article does not exist'));
     }
     return zula_redirect($this->_router->makeUrl('article', 'config'));
 }