Esempio n. 1
0
 public static function getCatgoryFullContentByPageID($cat_id, $page_id)
 {
     $itemsPerPage = 5;
     $contentPerSubject = 3;
     $resultArr = [];
     $subjectObj = Subjects::where('cat_id', $cat_id)->orderBy('last_reply_time', 'desc')->get();
     foreach ($subjectObj as $subject) {
         $contentObj = Contents::where('content_id', $subject->subject_id)->first();
         $userObj = User::find($subject->po_id);
         $cookieObj = ChCookie::where('id', $userObj->cookie_id)->first();
         $shortCookie = $cookieObj->short_cookie;
         $tmpArr = ['subject_id' => $contentObj->content_id, 'subject_text' => $contentObj->content, 'subject_cookie' => $shortCookie, 'subject_create_time' => $subject->created_at, 'subject_img' => $contentObj->image, 'contents' => []];
         $contentObj = Contents::where('subject_id', $subject->subject_id)->where('content_id', '!=', $subject->subject_id)->orderBy('content_id', 'desc')->get();
         foreach ($contentObj as $content) {
             $userObj = User::find($content->po_id);
             $cookieObj = ChCookie::where('id', $userObj->id)->first();
             $shortCookie = $cookieObj->short_cookie;
             $tmpContent = ['content_id' => $content->content_id, 'content_text' => $content->content, 'content_cookie' => $shortCookie, 'content_create_time' => $content->created_at, 'content_img' => $content->image];
             array_push($tmpArr['contents'], $tmpContent);
         }
         array_push($resultArr, $tmpArr);
     }
     //var_dump($resultArr);
     return $resultArr;
 }
Esempio n. 2
0
function labsSuggestion($subject, $n, $id)
{
    $subject = \App\Subjects::select('id')->where('name', $subject)->first()->toArray();
    $rel = App\SubjectsLabs::where('subject_id', $subject['id'])->where('lab_id', '<>', $id)->take($n)->get();
    $labs = [];
    foreach ($rel as $one) {
        $lab = App\Labs::find($one->lab_id);
        array_push($labs, $lab);
    }
    return $labs;
}
Esempio n. 3
0
 public function postSubject(Request $request, $cat_id)
 {
     $data = $request->all();
     $vdtor = Validator::make($data, ['content' => 'required|min:15', 'file' => 'image|max:4096']);
     if ($vdtor->fails()) {
         return Redirect::to("/cat/{$cat_id}")->withErrors($vdtor);
     }
     $tmpCookie = $request->cookie('neupchan');
     $data['cookie'] = $request->cookie('neupchan');
     $cookieObj = ChCookie::where('cookie', $tmpCookie->cookie)->first();
     $userObj = User::where('cookie_id', $cookieObj->id)->first();
     $contentObj = new Contents();
     $contentObj->content = nl2br($data['content']);
     $contentObj->po_id = $userObj->id;
     $uploadFile = $request->file('file');
     if ($uploadFile) {
         if (!$uploadFile->isValid()) {
             return Redirect::to("/cat/{$cat_id}")->withErrors($uploadFile->getErrorMessage());
         }
         var_dump($uploadFile);
         $fileName = $uploadFile->getRealPath() . $request->cookie('neupchan')->cookie . time();
         $fileName = md5($fileName) . "." . $uploadFile->guessExtension();
         echo $fileName;
         $contentObj->image = $fileName;
         Storage::put('images/' . $fileName, file_get_contents($uploadFile->getRealPath()));
     }
     $contentObj->save();
     //var_dump($contentObj);
     Contents::find($contentObj->content_id)->update(['subject_id' => $contentObj->content_id]);
     $subjectObj = new Subjects();
     $subjectObj->subject_id = $contentObj->id;
     $subjectObj->cat_id = $cat_id;
     $subjectObj->last_reply_time = time();
     $subjectObj->po_id = $userObj->id;
     $subjectObj->save();
     //var_dump($subjectObj);
     return Redirect::to("/cat/{$cat_id}")->with('post', 1);
 }