Ejemplo n.º 1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($user, $project_name, $story_id)
 {
     $project_name = str_post_slug($project_name);
     $project = Project::where('name', $project_name)->first();
     $project_id = $project->id;
     $story = Story::find($story_id);
     return view('user.story.show', compact('user', 'project_name', 'project_id', 'story', 'project'));
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Story::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, 'user_id' => $this->user_id, 'collect' => $this->collect, 'like' => $this->like, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 public static function cheLikeUser($id, $nomination)
 {
     if (isset(Yii::$app->user->identity->id)) {
         if (!isset($id) && $id == null) {
             return false;
         }
         $vote = Vote::find()->where(['user_id' => Yii::$app->user->identity->id, 'story_id' => $id])->one();
         if (!empty($vote) && $vote != null) {
             $story_nomination = Story::find()->where(['id' => $vote->story_id])->one();
             if ($story_nomination->nomination === $nomination) {
                 return true;
             } else {
                 return false;
             }
         } else {
             $vote = Vote::find()->where(['user_id' => Yii::$app->user->identity->id])->all();
             $arr = [];
             foreach ($vote as $k => $v) {
                 $story_nomination = Story::find()->where(['id' => $v->story_id])->one();
                 if ($story_nomination->nomination === $nomination) {
                     $arr[$story_nomination->nomination] = $story_nomination->nomination;
                 }
             }
             if (empty($arr)) {
                 return false;
             } else {
                 return true;
             }
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $story = Story::find($id);
     if ($story == null) {
         return response()->json(['error' => 'Not Found Data'], 422);
     }
     //자신의 글 확인
     if ($story->user_id != $this->token->user_id) {
         return response()->json(['error' => 'Permission denied'], 403);
     }
     $story->delete();
     return response()->json('ok', 200);
 }
Ejemplo n.º 5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Story::find($id)->delete();
     return redirect()->route('admin.story.index');
 }