/**
  * Displays a single Article model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $this->layout = 'main2';
     $model = $this->findModel($id);
     $articles = Article::find()->where(['status' => 'ACTIVE', 'type' => 'NEWS', 'category' => $model->category])->limit(4)->all();
     return $this->render('view', ['model' => $model, 'articles' => $articles]);
 }
Beispiel #2
0
 public function actionIndex()
 {
     $query = Article::find();
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count()]);
     $articles = $query->orderBy('id')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['articles' => $articles, 'pagination' => $pagination]);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id = null)
 {
     //返回/resource/view/nweaver/commuity下的create.blade.php页面
     //编辑文章文章
     $article = Article::find($id);
     return view('nweaver.commuity.edit', compact('article'));
 }
 /**
  * Creates a new Visa model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($num = 1)
 {
     $this->layout = "main";
     $model = new Visa();
     $article = Article::find()->where(['type' => 103])->one();
     $visaDetails = [];
     $numApply = isset($_POST['Visa']['numapply']) ? $_POST['Visa']['numapply'] : $num;
     for ($i = 0; $i < $numApply; $i++) {
         $visaDetails[] = new Visadetail();
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $visaId = $model->id;
         if (isset($_POST['Visadetail'])) {
             foreach ($_POST['Visadetail'] as $index => $arr) {
                 foreach ($arr as $i => $val) {
                     $visaDetails[$index - 1][$i] = $val;
                 }
                 $visaDetails[$index - 1]['id_visa'] = $visaId;
             }
             foreach ($visaDetails as $visaDetail) {
                 if ($visaDetail->save()) {
                 }
             }
             Yii::$app->mailer->compose('@app/views/mail/mail-layout', ['model' => $model, 'visaDetails' => $visaDetails])->setFrom($model->email)->setTo('*****@*****.**')->setSubject('Book tour')->send();
             return $this->render('success', ['model' => $model, 'visaDetails' => $visaDetails, 'article' => $article]);
         }
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('create', ['model' => $model, 'article' => $article, 'visaDetails' => $visaDetails]);
         } else {
             return $this->render('create', ['model' => $model, 'visaDetails' => $visaDetails, 'article' => $article]);
         }
     }
 }
 public function destroy($id)
 {
     $article = Article::find($id);
     $article->delete();
     Notification::success('The article was deleted.');
     return Redirect::route('admin.articles.index');
 }
Beispiel #6
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $data['article'] = Article::find($id);
     ArticleStatus::update_view_number($id);
     $this->setCommonData();
     return view('website.article', $data);
 }
Beispiel #7
0
 /**
  * @param $slug
  * @return Article
  */
 protected function findArticle($slug)
 {
     if (($model = Article::find()->where(['slug' => $slug])->one()) !== null) {
         return $model;
     } else {
         return false;
     }
 }
 public function actionView($id)
 {
     $model = Article::find()->published()->with('author')->andWhere(['id' => $id])->one();
     if (!$model) {
         throw new NotFoundHttpException();
     }
     return $this->render('view', ['model' => $model]);
 }
Beispiel #9
0
 public function actionArticle($year, $month, $day, $id)
 {
     $item = Article::find(['id_string' => $id, 'date' => $year . $month . $day]);
     if (is_null($item)) {
         throw new Exception('Нет такой статьи');
     }
     $item->incViewCounter();
     return $this->render(['item' => $item]);
 }
 public function delete(Article $article, $id)
 {
     $data = $article->find($id);
     if (!$data) {
         return response()->json(['error' => 'data not found'], 404);
     }
     $data->delete();
     return response()->json(200);
 }
Beispiel #11
0
 public function actionViewall($cid = 2)
 {
     $query = Article::find()->where(['cid' => $cid, 'published' => 1]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('ordering')->all();
     $cat = \app\models\Categories::findOne($cid);
     return $this->render('viewall', ['model' => $models, 'cat' => $cat, 'pages' => $pages]);
 }
Beispiel #12
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
 public function delete($id)
 {
     $id = intval($id);
     $articleInstance = Article::find($id);
     if (!$articleInstance->trashed()) {
         $articleInstance->delete();
         return Redirect::back()->withResult('operation complete');
     } else {
         return Redirect::back()->withResult('this article has been deleted already.');
     }
 }
 public function postSimpan($value = '')
 {
     $model = new Article();
     if (Input::get('id') > 0) {
         $model = Article::find(Input::get('id'));
     }
     $model->title = Input::get('title');
     $model->description = Input::get('description');
     $model->save();
     return Redirect::to('article');
 }
 /**
  * AJAX
  * Добавляет site_update
  * Делает рассылку
  *
  * @param integer $id - идентификатор новости
  *
  * @return string
  */
 public function actionSubscribe($id)
 {
     $item = Article::find($id);
     if (is_null($item)) {
         return self::jsonError(101, 'Не найдена статья');
     }
     Subscribe::add($item);
     SiteUpdate::add($item);
     $item->update(['is_added_site_update' => 1]);
     return self::jsonSuccess();
 }
Beispiel #16
0
 public function detail($slag)
 {
     $article = Article::where('slag', $slag)->findOrFail();
     if (!Article::find($article->id + 1)) {
         $article->max = true;
     } else {
         $article->max = false;
     }
     $categories = Category::all();
     return view('article.detail')->withArticle($article)->withCategories($categories)->withId($id);
 }
Beispiel #17
0
 /**
  * Display the specified resource.
  *
  * @param int $id
  *
  * @return Response
  */
 public function show($id, Request $request)
 {
     $article = Article::find($id);
     // if (is_null($article)) {
     // abort(404);
     // }
     // dd($request);
     if ($request->ajax()) {
         return json_encode($article);
     }
     return view('article')->with('article', $article);
 }
Beispiel #18
0
 public function update($fieldsCols = null)
 {
     $fields = parent::update(['beforeUpdate' => function ($fields, \app\models\Form\Article $model) {
         if ($fields['description'] == '') {
             $fields['description'] = GsssHtml::getMiniText($fields['content']);
         }
     }]);
     $item = \app\models\Article::find($this->id);
     if ($this->is_add_image) {
         $content = Html::tag('p', Html::img(\cs\Widget\FileUpload2\FileUpload::getOriginal($item->getImage()), ['class' => 'thumbnail', 'style' => 'width:100%;', 'alt' => $item->getField('header')])) . $item->getField('content');
         $item->update(['content' => $content]);
     }
 }
Beispiel #19
0
 public function update($fieldsCols = null)
 {
     parent::update();
     $item = \app\models\Article::find($this->id);
     $fields = [];
     if ($item->getField('description') == '') {
         $fields['description'] = GsssHtml::getMiniText($item->getField('content'));
     }
     if (count($fields) > 0) {
         $item->update($fields);
     }
     return true;
 }
Beispiel #20
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'creation_date' => $this->creation_date]);
     $query->andFilterWhere(['like', 'picture', $this->picture])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'important', $this->important])->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
Beispiel #21
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['aid' => $this->aid, 'time' => $this->time, 'type' => $this->type, 'cid' => $this->cid]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'info', $this->info]);
     return $dataProvider;
 }
Beispiel #22
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'author_id' => $this->author_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'create_time', $this->create_time])->andFilterWhere(['like', 'update_time', $this->update_time]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['regdate' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'regdate' => $this->regdate, 'editdate' => $this->editdate, 'id_user' => $this->id_user, 'hot' => $this->hot, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'briefinfo', $this->briefinfo])->andFilterWhere(['like', 'smallimg', $this->smallimg])->andFilterWhere(['like', 'detailinfo', $this->detailinfo]);
     return $dataProvider;
 }
Beispiel #24
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'commit' => $this->commit, 'created' => $this->created, 'status' => $this->status, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'keywords', $this->keywords])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'h1', $this->h1])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['title' => 'required', 'story' => 'required', 'date_expires' => 'required']);
     $article = Article::find($id);
     $article->title = $request->get('title');
     $article->story = $request->get('story');
     $article->page_id = 1;
     $article->date_expires = date('Y-m-d', strtotime($request->get('date_expires')));
     $article->screenshot = $request->get('screenshot');
     $article->flyer = $request->get('flyer');
     $article->save();
     Flash::success('Article updated successfully.');
     return redirect('admin/articles');
 }
Beispiel #26
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Article::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'short_text', $this->short_text]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array   $params    The search query params.
  * @param integer $pageSize  The number of results to be displayed per page.
  * @param boolean $published Whether or not articles have to be published.
  *
  * @return ActiveDataProvider
  */
 public function search($params, $pageSize = 3, $published = false)
 {
     $query = Article::find();
     // this means that editor is trying to see articles
     // we will allow him to see published ones and drafts made by him
     if ($published === true) {
         $query->where(['status' => Article::STATUS_PUBLISHED]);
         $query->orWhere(['user_id' => Yii::$app->user->id]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => $pageSize]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'status' => $this->status, 'category' => $this->category]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
 public function update($id)
 {
     $article = Article::find($id);
     $article->user_id_edited = \Auth::user()->id;
     $article->title = Input::get('title');
     $article->category_id = Input::get('cate');
     $article->tag = str_replace(',', ',', Input::get('tag'));
     $article->content = Input::get('content');
     $article->ip = \Request::getClientIp();
     $article->updated_at = Carbon::now();
     if ($article->save()) {
         Session::flash('notify', ['status' => 'success', 'msg' => 'Article update success!']);
         return Redirect::to(route('admin.article.index'));
     } else {
         Session::flash('notify', ['status' => 'error', 'msg' => 'Article update fail!']);
         return Redirect::back()->withInput()->withErrors('更新失败!');
     }
 }
 public function store()
 {
     $comment = new Comment();
     $comment->author_nickname = Input::get('nickname');
     $comment->author_email = Input::get('email');
     $comment->author_ip = \Request::getClientIp();
     $comment->text = Input::get('content');
     $comment->article_id = Input::get('article_id');
     $comment->parent_id = Input::get('p_id');
     $comment->created_at = Carbon::now();
     if ($comment->save()) {
         $article = Article::find($comment->article_id);
         $article->setUpdatedAt(Carbon::now());
         $article->save();
         return Redirect::back();
     } else {
         return Redirect::back()->withInput()->withErrors('评论发表失败!');
     }
 }
Beispiel #30
0
 public function actionRss()
 {
     $dataProvider = new ActiveDataProvider(['query' => Article::find()->with(['user'])->orderby('id DESC'), 'pagination' => ['pageSize' => 10]]);
     $response = \Yii::$app->getResponse();
     \Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
     header("Content-Type: application/xml; charset=UTF-8");
     $response->content = \Zelenin\yii\extensions\Rss\RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->name, 'link' => Url::toRoute('/', true), 'description' => 'Articles ', 'language' => Yii::$app->language], 'items' => ['title' => function ($model, $widget) {
         return $model->title;
     }, 'description' => function ($model, $widget) {
         return StringHelper::truncateWords($model->content, 50);
     }, 'link' => function ($model, $widget) {
         return Url::toRoute(['article/view', 'id' => $model->id], true);
     }, 'author' => function ($model, $widget) {
         return $model->user->email . ' (' . $model->user->name . ')';
     }, 'pubDate' => function ($model, $widget) {
         $date = \DateTime::createFromFormat('Y-m-d H:i:s', $model->date);
         return $date->format(DATE_RSS);
     }]]);
 }