Exemple #1
0
 public function action_new()
 {
     $this->title('New');
     $this->view = $this->theme->view('admin/articles/new');
     $article = Model_Article::forge();
     $this->view->set('article', $article);
     if (Input::param() != array()) {
         $article->values(array('title' => Input::param('title'), 'body' => Input::param('body'), 'status' => Input::param('status'), 'user_id' => $this->current_user->id));
         if ($article->is_valid()) {
             $article->save();
             Session::set_flash('success', 'Article created');
             Response::redirect('-admin/articles');
         } else {
             $this->view->set('errors', $article->errors());
         }
     }
 }
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Article::validate('create');
         if ($val->run()) {
             $article = Model_Article::forge(array('nombre' => Input::post('nombre'), 'periodista_id' => Input::post('periodista_id'), 'seccion_id' => Input::post('seccion_id'), 'dimension_id' => Input::post('dimension_id'), 'fecha' => Input::post('fecha')));
             if ($article and $article->save()) {
                 Session::set_flash('success', 'Added article #' . $article->id . '.');
                 Response::redirect('articles');
             } else {
                 Session::set_flash('error', 'Could not save article.');
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Articles";
     $this->template->content = View::forge('articles/create');
 }
Exemple #3
0
 /**
  * Страница создания статьи
  */
 public function action_create()
 {
     // Если форма была отправлена
     if (\Input::method() == 'POST') {
         $val = \Model_Article::validate('create');
         if ($val->run()) {
             // Создаём статью в таблице `articles`
             $article = \Model_Article::forge(array('title' => \Input::post('title'), 'preview' => \Input::post('preview'), 'full_text' => \Input::post('full_text'), 'category_id' => \Input::post('category_id'), 'on_main_page' => \Input::post('on_main_page', 0), 'vk_comments_count' => 0));
             $article->save();
             \Session::set_flash('success', e('Добавлена новая статья "' . $article->title . '".'));
             \Response::redirect('admin/articles');
         } else {
             \Session::set_flash('error', $val->error());
         }
     }
     // Категории статей
     $data['categories'] = \Model_Category::get_categories_for_select();
     $this->template->title = "Статьи";
     $this->template->content = \View::forge('articles/create', $data, false);
 }
 /**
  * Upload slider
  *
  * @author Nguyen Van Hiep
  * @access public
  *
  * @version 1.0
  * @since 1.0
  */
 public function action_add($current_cat_view = '', $current_lang_view = '')
 {
     $view = View::forge('admin/article/add');
     $view->err = array();
     $view->langs = $this->langs;
     $view->cats = Model_Categories::get_cat_list();
     if ($current_cat_view != 'cat' and $current_lang_view != 'lang') {
         $view->current_cat_view = "cat={$current_cat_view}&lang={$current_lang_view}";
     } elseif ($current_cat_view != 'cat') {
         $view->current_cat_view = "cat={$current_cat_view}&lang=";
     } elseif ($current_lang_view != 'lang') {
         $view->current_cat_view = "cat=&lang={$current_lang_view}";
     } else {
         $view->current_cat_view = "cat=&lang=";
     }
     if (Input::method() == 'POST') {
         if (count(Input::file()) == 0) {
             Session::set_flash('error', __('message.upload_files_error'));
             Response::redirect('admin/article/add');
         }
         $a = Model_Article::forge();
         $a->title = Input::post('title');
         $a->title_search = str_replace('-', ' ', Input::post('slug'));
         $a->slug = Input::post('slug');
         $val = Model_Article::validate('add', $a);
         // Custom configuration for this upload
         Upload::process($this->config);
         if ($val->run() and count(Upload::get_errors()) == 0) {
             $a->desc = Input::post('desc');
             $a->content = Input::post('content');
             $a->content_search = preg_replace('/[\\s]+/mu', ' ', strip_tags(Input::post('content')));
             $content = Input::vn_str_filter(strip_tags(Input::post('content')));
             $a->content_search_no_mark = preg_replace('/[\\s]+/mu', ' ', $content);
             $a->thumb = '';
             $a->views = 0;
             $a->lang = Input::post('lang');
             $a->created_at = date('Y-m-d h:i:s', time());
             $a->updated_at = date('Y-m-d h:i:s', time());
             //save article
             if ($a->save()) {
                 // Save Product-Slug
                 Model_Article::save_slug($a->id);
                 // Save Article-Category
                 Model_ArtCat::save_art_cat($a->id, Input::post('cat') ? Input::post('cat') : array(), false);
                 //Save images
                 $this->save_thumb($a->id, true);
                 //redirect to index page
                 Session::set_flash('success', __('message.art_added'));
                 Response::redirect("admin/article?{$view->current_cat_view}");
             } else {
                 //fail in transaction
                 Session::set_flash('error', __('message.registration_failed'));
             }
         } else {
             $view->err = $val->error_message();
             $err = $this->upload_errors(Upload::get_errors());
             $view->err = array_merge($view->err, $err);
             Session::set_flash('error', __('message.validation_error'));
         }
     }
     $this->template->title = __('art.add_new');
     $this->template->content = $view;
 }
Exemple #5
0
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Article::validate('create');
         if ($val->run()) {
             $article = Model_Article::forge(array('category_id' => Input::post('category_id'), 'user_id' => $this->current_user->id, 'name' => Input::post('name'), 'url_title' => str_replace(" ", "-", strtolower(Input::post('name'))), 'description' => Input::post('description'), 'keywords' => Input::post('keywords'), 'image' => Input::post('image')));
             if ($article and $article->save()) {
                 $article->getDetail();
                 Session::set_flash('success', 'Added article #' . $article->id . '.');
                 Response::redirect('admin/article');
             } else {
                 Session::set_flash('error', 'Could not save article.');
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $data['categories'] = Model_Category::getSelectList();
     $this->template->title = "Articles";
     $this->template->content = View::forge('admin/article/create', $data);
 }
Exemple #6
0
 /**
  * $oldPostからModel_Articleを復元(バリデーションエラー時の復元用)
  * @param type $oldPost 投稿データ
  * @return type
  */
 public function getOldPostedData($oldPost)
 {
     $oldAr = Model_Article::forge();
     $oldAr->authorName = $oldPost['authorName'];
     $oldAr->authorAge = $oldPost['authorAge'];
     $oldAr->authorAge = $oldPost['authorAge'];
     $oldAr->authorPrefecture = $oldPost['authorPrefecture'];
     $oldAr->authorProfile = $oldPost['authorProfile'];
     $oldAr->authorEmail = $oldPost['authorEmail'];
     $oldAr->authorIsMale = $oldPost['authorIsMale'];
     $oldAr->body = $oldPost['body'];
     return $oldAr;
 }