예제 #1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     $data = array('content' => table_content::where('content_id', '=', $id)->get(), 'media_manager' => DB::select('select media_manager_id as id, media_manager_title as name from table_media_manager'), 'users_detail' => DB::select('select users_id as id, users_name as value, users_name as label from table_users_detail'), 'content_category' => DB::select('select content_category_id as id, content_category_title as value, content_category_title as label from table_content_category'), 'hashtag' => json_encode(DB::select('select hashtag_id as id, hashtag_title as name from table_hashtag')), 'content_from' => DB::select('select content_id as id, content_title as value, content_title as label from table_content'));
     //Ambil data nama media manager
     foreach ($data['content'] as $key => $value) {
         $exp = $value->content_media_id;
         $usrUp = $value->content_users_uploader;
         $usrEdit = $value->content_last_editor;
         $contCat = $value->content_category_id;
         $contFrom = $value->content_repost_from;
         $contHash = $value->hashtag_id;
     }
     $tempExp = explode(",", $exp);
     $i = 0;
     for ($i; $i < count($tempExp); $i++) {
         //$newArray = DB::select('select media_manager_id as id, media_manager_title as name from table_media_manager where media_manager_id='.$tempExp[$i]);
         $newArray = DB::table('table_media_manager')->select('media_manager_id as id', 'media_manager_title as name')->where('media_manager_id', '=', $tempExp[$i])->first();
         if ($newArray != null) {
             $dataMediaManager[$newArray->id] = $newArray->name;
         }
     }
     if (isset($dataMediaManager)) {
         $data['dataMediaManager'] = $dataMediaManager;
     }
     $data['dataIdMediaManager'] = $exp;
     //END Ambil data nama media manager
     $tempHash = explode(",", $contHash);
     $i = 0;
     for ($i; $i < count($tempHash); $i++) {
         //$newArray = DB::select('select media_manager_id as id, media_manager_title as name from table_media_manager where media_manager_id='.$tempExp[$i]);
         $newArray = DB::table('table_hashtag')->select('hashtag_id as id', 'hashtag_title as name')->where('hashtag_id', '=', $tempHash[$i])->first();
         if ($newArray != null) {
             $dataHashtag[$newArray->id] = $newArray->name;
         }
     }
     if (isset($dataHashtag)) {
         $data['dataHashtag'] = $dataHashtag;
     }
     $data['dataIdHashtag'] = $contHash;
     //Ambil data users_name
     $users_name = DB::table('table_users_detail')->select('users_id as id', 'users_name as value')->where('users_id', '=', $usrUp)->first();
     $users_name2 = DB::table('table_users_detail')->select('users_id as id', 'users_name as value')->where('users_id', '=', $usrEdit)->first();
     if ($users_name != null) {
         $data['dataUsers'] = $users_name;
     } else {
         $data['dataUsers'] = '';
     }
     if ($users_name2 != null) {
         $data['dataUsers2'] = $users_name2;
     } else {
         $data['dataUsers2'] = '';
     }
     //END Ambil data users_name
     //Ambil data Content Category
     $content_category = DB::table('table_content_category')->select('content_category_id as id', 'content_category_title as value')->where('content_category_id', '=', $contCat)->first();
     if ($content_category != null) {
         $data['dataContentCategory'] = $content_category;
     } else {
         $data['dataContentCategory'] = '';
     }
     //END Ambil data Content Category
     $content_from = DB::table('table_content')->select('content_id as id', 'content_title as value')->where('content_id', '=', $contFrom)->first();
     if ($content_from != null) {
         $data['dataContentFrom'] = $content_from;
     } else {
         $data['dataContentFrom'] = '';
     }
     return view('admin.database.content.content-edit', compact('data'));
 }
예제 #2
0
 public function repost()
 {
     $app = app();
     if (Request::has('token')) {
         $token = Request::input('token', '');
         $compare = GlobalLibrary::tokenExtractor($token);
         $users_checker = GlobalLibrary::CheckUsersToken($compare);
         //echo '<pre>'.print_r($compare).'</pre>';
         if ($users_checker[0]) {
             $uname = $users_checker[1];
             $uid = $users_checker[2];
             $email = $users_checker[3];
             if (Request::input('cid') == null) {
                 return (new Response(array('status' => true, 'msg' => 'Please select a content that you want to repost '), 200))->header('content-Type', "json");
             } else {
                 //get content resource
                 $target = table_content::where('content_id', '=', Request::input('cid'))->first();
                 //input content
                 $field_content = array('content_title' => $target->content_title, 'content_headline' => $target->headline, 'content_detail' => $target->content_detail, 'content_media_id' => $target->content_media_id, 'content_users_uploader' => $uid, 'content_last_editor' => $target->content_last_editor, 'content_date_insert' => date('Y-m-d H:i:s'), 'content_date_expired' => $target->content_date_expired, 'content_publish' => $target->content_publish, 'content_category_id' => $target->content_category_id, 'content_hashtag_id' => $target->content_hashtag_id, 'content_repost_from' => $target->content_id);
                 $content = table_content::create($field_content);
                 //notification repost
                 //input content
                 $field_notiication = array('users_id' => $target->content_users_uploader, 'datetime' => date('Y-m-d H:i:s'), 'status' => 'send');
                 $content = table_notification::create($field_notiication);
                 /*
                 //it always return 1 iterate. i made it but i don't know where a message of notiication store?
                  $dataConverted = array();
                  $app = app();
                  $i=0;
                 $whorepost = table_users_detail::where('users_id', '=',$uid)->first();
                 foreach($whorepost as $row){
                     $dataConverted[$i]->uid = $row->users_id; //send user ID who repost his/her content
                     $dataConverted[$i]->unm = $row->users_name; //send user Name who repost his/her content
                     $dataConverted[$i]->ttl = $target->content_title; //send the Title that reposted
                     $dataConverted[$i]->nci = $whorepost; //send the new content ID to him/her 
                     $dataConverted[$i]->cdi = date('Y-m-d H:i:s'); //send the date repost (insert)
                 
                 }
                 */
                 return (new Response(array('status' => true, 'msg' => 'success'), 200))->header('content-Type', "json");
             }
         } else {
             return (new Response(array('status' => false, 'msg' => 'Authentication Failed2'), 200))->header('content-Type', "json");
         }
     } else {
         return (new Response(array('status' => false, 'msg' => 'Authentication Failed1'), 200))->header('content-Type', "json");
     }
 }