Esempio n. 1
0
 public function testGetContent()
 {
     Yii::app()->getModule('news');
     Yii::import('application.modules.news.models.*');
     $model = new News();
     $model->setAttributes(array('text' => 'comment 1', 'status' => News::STATE_ACTIVE), false);
 }
Esempio n. 2
0
 public function actionManage()
 {
     $model = new News('search');
     $model->unsetAttributes();
     if (isset($_GET['News'])) {
         $model->setAttributes($_GET['News']);
     }
     $this->render('manage', array('model' => $model));
 }
Esempio n. 3
0
 public function actionIndex()
 {
     $model = new News('search');
     $model->unsetAttributes();
     if (isset($_GET['News'])) {
         $model->setAttributes($_GET['News']);
     }
     $dataProvider = $model->search();
     $this->render('//news/index', array('dataProvider' => $dataProvider, 'model' => $model));
 }
 /**
  * Manages all models.
  *
  * @return void
  */
 public function actionIndex()
 {
     $model = new News('search');
     $model->unsetAttributes();
     // clear any default values
     $model->setAttributes(Yii::app()->getRequest()->getParam('News', array()));
     $this->render('index', array('model' => $model));
 }
Esempio n. 5
0
 public function actionAdd()
 {
     $this->layout = '//layouts/admin';
     $this->pageTitle = 'Новая новость';
     $this->breadcrumbs = array('Новости' => array('/admin/news'), 'Новая новость');
     $success = false;
     if (isset($_POST['data'])) {
         $model = new News();
         $tags = array();
         if (isset($_POST['data']['tags'])) {
             $tags = $_POST['data']['tags'];
             unset($_POST['data']['tags']);
         }
         $dataArray = $_POST['data'];
         $dataArray['timestamp'] = time();
         $dataArray['publish_time'] = isset($dataArray['publish_time']) && $dataArray['publish_time'] ? strtotime($dataArray['publish_time']) : time();
         $dataArray['views_count'] = 0;
         $dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0;
         $dataArray['is_deleted'] = 0;
         $model->setAttributes($dataArray);
         if ($model->save()) {
             $success = true;
             if (isset($_FILES['anons_pic']) && $_FILES['anons_pic']['name'] || isset($_FILES['content_pic']) && $_FILES['content_pic']['name']) {
                 $uploaddir = 'images/upload/' . date("d.m.Y", time());
                 if (!is_dir($uploaddir)) {
                     mkdir($uploaddir);
                 }
                 if (isset($_FILES['anons_pic'])) {
                     $tmp_name = $_FILES["anons_pic"]["tmp_name"];
                     $name = $_FILES["anons_pic"]["name"];
                     if ($name) {
                         $ext = explode(".", $name);
                         $uploadfile = $uploaddir . '/na_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext);
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("anons_pic" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
                 if (isset($_FILES['content_pic'])) {
                     $tmp_name = $_FILES["content_pic"]["tmp_name"];
                     $name = $_FILES["content_pic"]["name"];
                     if ($name) {
                         $ext = explode(".", $name);
                         $uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext);
                         if (move_uploaded_file($tmp_name, $uploadfile)) {
                             $model->setAttributes(array("content_pic" => "/" . $uploadfile));
                             $model->save();
                         }
                     }
                 }
                 if (is_array($tags) && count($tags)) {
                     foreach ($tags as $tag) {
                         $tagModel = Tags::model()->findByAttributes(array("name" => $tag));
                         if (!is_object($tagModel)) {
                             $tagModel = new Tags();
                             $tagModel->setAttributes(array("name" => $tag, "count" => 0));
                         }
                         $tagModel->count += 1;
                         $tagModel->save();
                         $tagsRelations = new TagsRelations();
                         $tagsRelations->setAttributes(array("tag_id" => $tagModel->id, "object_id" => $model->id, "model" => "news"));
                         $tagsRelations->save();
                     }
                 }
             }
         }
     }
     if ($success) {
         $this->redirect("/admin/news");
     }
     if (!isset($model) || !is_object($model)) {
         $model = new News();
     }
     $this->render('add', array("errors" => $model->errors));
 }
Esempio n. 6
0
 /**
  * Manages all models.
  */
 public function actionAdmin()
 {
     $model = new News('search');
     $model->unsetAttributes();
     // clear any default values
     if (isset($_GET['News'])) {
         $model->setAttributes($_GET['News']);
     }
     $this->render('admin', array('model' => $model));
 }