コード例 #1
0
ファイル: NewsManager.php プロジェクト: GeneralCrime/code
 /**
  * Saves the given News.
  *
  * @param News $News
  */
 public function saveNews(News $News)
 {
     if ($News->getAppKey() === '') {
         $News->setAppKey($this->getContext());
     }
     $this->ORM->saveObject($News);
 }
コード例 #2
0
 public function transformContent()
 {
     $appKey = $this->getAppKey();
     $form = $this->getForm('edit');
     $cfg = $this->getConfiguration('APF\\extensions\\news', 'labels.ini');
     $lang = $cfg->getSection($this->getLanguage());
     $newsManager = $this->getNewsManager();
     // If an id is given, an existing news should be updated,
     // so we check here if it really exists.
     $editId = $this->getRequest()->getParameter('editnewsid');
     $news = null;
     if ($editId !== null && $editId !== '') {
         $news = $newsManager->getNewsById((int) $editId);
         if ($news === null) {
             $this->getTemplate('notfound')->transformOnPlace();
             return;
         }
     }
     // Get the form elements we need later
     $formTitle = $form->getFormElementByID('news-edit-title');
     $formText = $form->getFormElementByID('news-edit-text');
     $formUser = $form->getFormElementByID('news-edit-user');
     $button = $form->getFormElementByName('send');
     // If input is valid, save the news.
     if ($form->isSent() && $form->isValid()) {
         if (!isset($news)) {
             $news = new News();
             $news->setAppKey($appKey);
         }
         $news->setTitle($formTitle->getAttribute('value'));
         $news->setAuthor($formUser->getAttribute('value'));
         $news->setText($formText->getContent());
         $newsManager->saveNews($news);
     }
     // Pre-fill form elements if an existing news should be updated
     // and take care of the right text of the button.
     if ($editId !== null && $editId !== '') {
         $buttonValue = $lang->getValue('Form.Button.Edit');
         // retrieve the charset from the registry to guarantee interoperability!
         $charset = Registry::retrieve('APF\\core', 'Charset');
         $formTitle->setAttribute('value', htmlspecialchars($news->getTitle(), ENT_QUOTES, $charset, false));
         $formUser->setAttribute('value', htmlspecialchars($news->getAuthor(), ENT_QUOTES, $charset, false));
         $formText->setContent(htmlspecialchars($news->getText(), ENT_QUOTES, $charset, false));
     } else {
         $buttonValue = $lang->getValue('Form.Button.New');
         // Clear form inputs
         if ($form->isSent() && $form->isValid()) {
             $formText->setContent('');
             $formTitle->setAttribute('value', '');
             $formUser->setAttribute('value', '');
         }
     }
     $button->setAttribute('value', $buttonValue);
     $form->transformOnPlace();
 }