コード例 #1
0
ファイル: PhotoController.php プロジェクト: hungphongbk/ulibi
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->ajax()) {
         //$this->consolePrintInfo(substr($request->input('internal_url'),0,50));
         $newPhoto = new Photo();
         $newPhoto->des_id = null;
         $newPhoto->internal_url = $request->input('internal_url');
         $content = new ContentBase();
         $content->content_type = 1;
         $content->save();
         $content->photo()->save($newPhoto);
         return response()->json(array('status' => 'succeeded', 'id' => $newPhoto->photo_id));
     } else {
         return response('OK', 200);
     }
 }
コード例 #2
0
ファイル: ArticleSeeder.php プロジェクト: hungphongbk/ulibi
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('Article')->delete();
     $csv = new CSV();
     $articles = $csv->fromFile(dirname(__FILE__) . '/csv/Article.csv')->toArray();
     foreach ($articles as $a) {
         $content = \App\Models\ContentBase::create(["content_type" => 0]);
         $content->article()->create($a);
     }
 }
コード例 #3
0
ファイル: PhotoSeeder.php プロジェクト: hungphongbk/ulibi
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('Photo')->truncate();
     if (($handle = fopen(dirname(__FILE__) . '/csv/Photo.csv', 'r')) !== FALSE) {
         fgetcsv($handle);
         while (($line = fgetcsv($handle, 1000, ',')) !== FALSE) {
             $content = \App\Models\ContentBase::create(["content_type" => 1]);
             $content->photo()->create(array('username' => $line[0], 'des_id' => $line[1], 'photo_like' => $line[2], 'internal_url' => $line[3]));
         }
     }
 }
コード例 #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param Article $article
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, Article $article)
 {
     $comment = new Comment();
     $comment->comment_content = $request->get('comment_content');
     $comment->username = Auth::user()->username;
     /** @var \App\Models\ContentBase $contentBase */
     $contentBase = ContentBase::create(['content_type' => 2]);
     $comment->comment_id = $contentBase->content_id;
     $parent = $request->get('parent_comment');
     if ($parent) {
         $comment->content_id = $parent;
     } else {
         $comment->content_id = $article->content->content_id;
     }
     $comment->save();
     if ($request->ajax()) {
         return response()->json($comment);
     }
     return response('');
 }
コード例 #5
0
ファイル: ArticlePost.php プロジェクト: hungphongbk/ulibi
 /**
  * @param Request $request
  * @return Article
  */
 public function doPost(Request $request)
 {
     // TODO: Implement doPost() method.
     /** @var \App\Models\ContentBase $newContent */
     $newContent = ContentBase::create(['content_type' => 0]);
     $newArticle = $newContent->article()->create($request->only($this->articleFields));
     if ($request->input('cover_id') != 0) {
         $newArticle['cover_id'] = $request->input('cover_id');
         $newArticle->save();
     }
     // get all checked-in destinations
     /** @var array $dest */
     $dest = array_map(function ($item) {
         $rs = Destination::where('des_name', $item->des_name)->first();
         return $rs;
     }, (array) json_decode($request->input('destinations')));
     foreach ($dest as $d) {
         /** @var Destination $d */
         $m = new ArticleDestination();
         $m->article_id = $newArticle->article_id;
         $m->des_id = $d->des_id;
         $m->save();
     }
     // get all tagged tags
     $tags = array_map(function ($item) {
         return Tag::where('tag_name', $item->tag_name)->first();
     }, (array) json_decode($request->input('tagnames')));
     /** @var Tag $t */
     foreach ($tags as $t) {
         $m = new ArticleTag();
         $m->article_id = $newArticle->article_id;
         $m->tag_id = $t->tag_id;
         $m->save();
     }
     return $newArticle;
 }
コード例 #6
0
ファイル: AuthController.php プロジェクト: hungphongbk/ulibi
 /**
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function postLike(Request $request)
 {
     $id = $request->get('content_id');
     if ($id == null) {
         return response()->json(["error" => "content not found"], 400);
     }
     /** @var \App\Models\ContentBase $content */
     /** @var \App\Models\ContentLike|null $likeData */
     $content = ContentBase::findOrFail($id);
     $likeData = $content->like()->where('username', Auth::user()->username)->first();
     $action = '';
     if ($likeData == null) {
         $likeData = new ContentLike();
         $likeData->username = Auth::user()->username;
         $content->like()->save($likeData);
         $action = 'like';
     } else {
         $likeData->delete();
         $action = 'unlike';
     }
     if ($request->ajax()) {
         return response()->json(["like_count" => $content->like_count, "action" => $action]);
     } else {
         return redirect()->back();
     }
 }
コード例 #7
0
ファイル: App.php プロジェクト: diandianxiyu/Yii2Api
 /**
  * 获取
  * @param type $content_cid
  * @param type $user_id
  */
 public static function getContentInfo($content_cid, $user_id, $tag_num = 5)
 {
     $content_id = ContentBase::getIdByCid($content_cid);
     //获取基本信息
     $content = ContentBase::getInfoByCid($content_cid);
     $user_info = self::getUserProfileVer13($content['user_id']);
     unset($content['user_id']);
     $tags = ContentTagCount::getTagList($content_id, $user_id, $tag_num, 0);
     $arr = ['content' => $content, 'user_info' => $user_info, 'tags' => $tags];
     return $arr;
 }