Esempio n. 1
0
 public function actionView($id)
 {
     //Ищем запись по id
     $new = News::findOne($id);
     //Отправляем представлению
     return $this->render('view', ['new' => $new]);
 }
 public function execute($user, $item, $params)
 {
     $user_role = Users::findOne($user)->authAssignments->item_name;
     if (isset($params['news'])) {
         $news_status = $params['news']->status;
         $news_category = $params['news']->category_id;
         $relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category]));
         if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') {
             return true;
         }
         if ($news_status == News::MODER_NEWS) {
             if ($user_role == 'moderator') {
                 return $relCat;
             }
         }
         if ($news_status == News::SMODER_NEWS) {
             if ($user_role == 'super_moderator') {
                 return true;
             }
         }
     } elseif (isset($params['question'])) {
         if ($user_role == 'moderator') {
             $news = News::findOne($params['question']->news_id);
             if (!is_null($news)) {
                 if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
 public function actionView()
 {
     $id = Yii::$app->request->get('id');
     $newInfo = News::findOne($id);
     $aboutNewsList = News::getAboutNewsByCategory($newInfo['category_id']);
     return $this->render('view', ['newInfo' => $newInfo, 'aboutNewsList' => $aboutNewsList]);
 }
Esempio n. 4
0
 public function actionView($id)
 {
     $post = News::findOne($id);
     $categories = Category::find()->where(['status' => Category::STATUS_ACTIVE])->orderBy('caption')->all();
     if ($post === null) {
         throw new NotFoundHttpException();
     } elseif ($post->status === News::STATUS_INACTIVE) {
         return $this->redirect(['site/index']);
     }
     return $this->render('view', ['post' => $post, 'categories' => $categories]);
 }
 public function actionEdit()
 {
     $RecId = isset($_GET['id']) ? (int) $_GET['id'] : null;
     $record = News::findOne($RecId);
     $view = new View();
     //echo 'header='.$record->NewsHeader;
     $view->assign('item', $record);
     $template = 'news/news_edit_view.php';
     $view->display($template);
     //header('Location: ./index.php');
 }
Esempio n. 6
0
 public function actionOne()
 {
     $id = isset($_GET['id']) ? (int) $_GET['id'] : null;
     //Если id статьи не задан, то извещаем об этом
     if (is_null($id)) {
         header("HTTP/1.0 404 Not Found");
         throw new \E404Exception('Id cannot be null');
     }
     $item = News::findOne($id);
     //Если не найдено статьи с соответствующим id,то сообщаем об этом
     if ($item == false) {
         header("HTTP/1.0 404 Not Found");
         throw new E404Exception('Record not found');
     }
     $view = new View();
     $view->assign('item', $item);
     $template = 'news/news_one_view.php';
     $view->display($template);
 }
Esempio n. 7
0
use app\models\News;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = '基金指數';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="index-fund-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('创建基金指数', ['create'], ['class' => 'btn btn-success']);
?>
        <?php 
//Html::a('日历模式', ['calendar'], ['class' => 'btn btn-success'])
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'fund_id', 'label' => '基金', 'value' => function ($model) {
    return News::findOne($model->fund_id)->title;
}], 'index_fund', ['attribute' => 'create_time', 'label' => '创建时间', 'value' => function ($model) {
    return date('Y-m', $model->create_time);
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Esempio n. 8
0
 public function actionClientNewsView($id)
 {
     $news = News::findOne(['news_id' => $id]);
     $news->clickcnt++;
     $news->save(false);
     return $this->render('clientNewsView', ['model' => $news]);
 }
Esempio n. 9
0
 public function actionNew($id)
 {
     $new = News::findOne(['id_new' => $id]);
     return $this->render('new', ['new' => $new]);
 }
Esempio n. 10
0
/* @var $this yii\web\View */
/* @var $model app\models\IndexFund */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => '基金指数', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="index-fund-view">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
        <?php 
echo Html::a('删除', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => '你真的要删除这个首页模板吗?', 'method' => 'post']]);
?>
        <?php 
echo Html::a('返回列表页', ['index'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['label' => '基金', 'value' => News::findOne($model->fund_id)->title], 'index_fund', ['format' => 'raw', 'label' => '创建时间', 'value' => date('Y-m', $model->create_time)]]]);
?>

</div>
Esempio n. 11
0
 public function actionDetail($id)
 {
     $model = News::findOne($id);
     \Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $model->seo_title], "detail_description");
     \Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $model->seo_keywords], "detail_keywords");
     \Yii::$app->view->registerMetaTag(['property' => 'og:image', 'content' => $model->images], "detail_image");
     return $this->render('detail', ['model' => $model]);
 }
Esempio n. 12
0
 public function actionDeleteNews()
 {
     $article = ModelNews::findOne($_GET['id']);
     $article->delete();
     header("Location: http://" . $_SERVER['SERVER_NAME'] . "/");
 }
Esempio n. 13
0
 /**
  * Finds the News model based on its slug value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return News the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelBySlug($slug)
 {
     if (($model = News::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 14
0
 public function actionArticle($id)
 {
     $article = News::findOne($id);
     if (!$article) {
         throw new HttpException(404, "该文章已经不存在");
     }
     return $this->render('article', ['article' => $article]);
 }
Esempio n. 15
0
 private function ImportNews($array, $category)
 {
     foreach ($array as $item) {
         if (!$item['active']) {
             continue;
         }
         $save = false;
         $model = News::findOne($item['id']);
         // Checking is this ID free for use
         if ($model === null) {
             $save = true;
             $model = new News();
             $model->id = $item['id'];
         } else {
             // Asking user what he wants
             $question = 'News with the same id alredy exists in data base:' . PHP_EOL . 'Data from database:' . PHP_EOL . $this->NewsObjToSting($model) . 'New data from file:' . PHP_EOL . $this->NewsArrToString($item) . 'category_id = ' . $category->id . PHP_EOL;
             $this->stdout($question);
             $answer = $this->select('What you want to do?' . PHP_EOL . '(a - assign new id and save data, s - keep database data, d - keep id and save data)' . PHP_EOL, ['a' => 'assign new id and save data', 's' => 'keep database data', 'd' => 'keep id and save data']);
             switch ($answer) {
                 case 'a':
                     $model = new News();
                 case 'd':
                     $save = true;
                     break;
                 case 's':
                     break;
             }
         }
         // Saving data if it is needed
         if ($save) {
             $model->headline = $item['title'];
             $model->description = $item['description'];
             $model->date = $item['date'];
             $model->image = $item['image'];
             $model->content = $item['text'];
             $model->link('category', $category);
             $model->status = $item['active'] ? News::STATUS_ACTIVE : News::STATUS_INACTIVE;
             if ($model->save()) {
                 $this->stdout($this->NewsObjToSting($model) . 'saved sucesfully' . PHP_EOL);
             }
         }
     }
 }
Esempio n. 16
0
 public function actionOneShow()
 {
     $id = $_GET['id'];
     $this->view->items = Model::findOne($id);
     $this->view->display('article');
 }
Esempio n. 17
0
 public function actionView_news($id)
 {
     $news = News::findOne(['id' => $id]);
     return $this->render('view_news', ['data' => $news]);
 }
Esempio n. 18
0
 /**
  * Finds the News model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return News the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = News::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 19
0
 /**
  * Finds the News model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return News the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (!\Yii::$app->user->isGuest) {
         if (($model = News::findOne($id)) !== null) {
             return $model;
         } else {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     $model = new LoginForm();
     if ($model->load(\Yii::$app->request->post()) && $model->login()) {
         $searchModel = new NewsSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }