Beispiel #1
0
 public function topic_detail($topicId)
 {
     $topic = Topic::find($topicId);
     $topic->author;
     $topic->remain_time = time_remain_string(strtotime($topic->deadline));
     $topic->time_create = time_elapsed_string(strtotime($topic->created_at));
     $topic->submits = count(array_unique($topic->products->pluck('author_id')->toArray()));
     $topic->all_products = $topic->products()->orderBy('created_at', 'desc')->get();
     foreach ($topic->all_products as &$product) {
         $product->liked = isset($this->user) && $this->user->likes()->where('product_id', $product->id)->count() > 0;
         $product->author->url = url('profile/' . get_first_part_of_email($product->author->email));
         $product->created_time = time_elapsed_string(strtotime($product->created_at));
         $product->author->avatar_url = $product->author->avatar_url != null ? $product->author->avatar_url : url('img/user.png');
         $product->count_likes = $product->likes()->count();
         $product->count_comments = $product->comments()->count();
         $product->link = url('post/colormevn-' . convert_vi_to_en($product->description) . '?id=' . $product->id);
     }
     unset($topic->products);
     return response()->json($topic, 200);
 }
Beispiel #2
0
 public function store_survey_answer(Request $request)
 {
     $survey_id = $request->survey_id;
     $gen_id = $request->gen_id;
     $survey_user_id = $request->survey_user_id;
     $survey = Survey::find($survey_id);
     $gen = Gen::find($gen_id);
     $survey_user = SurveyUser::find($survey_user_id);
     $data = array($this->user->name, $this->user->email, $this->user->phone);
     foreach ($survey->questions as $question) {
         $field = 'question' . $question->id;
         if (is_array($request->{$field})) {
             $data[] = implode(',', $request->{$field});
         } else {
             $data[] = $request->{$field};
         }
     }
     //        $questions = $survey->questions;
     //        $filename = $gen->name . '_' . $survey->name;
     //        if (!File::exists(storage_path('surveys/' . $filename . '.xls'))) {
     //            Excel::create($filename, function ($excel) use ($survey, $request, $data) {
     //                $excel->sheet($survey->name, function ($sheet) use ($request, $data, $survey) {
     //                    $header = array(
     //                        'Họ tên',
     //                        'email',
     //                        'Số điện thoại'
     //                    );
     //                    foreach ($survey->questions as $question) {
     //                        $header[] = $question->content;
     //                    }
     //                    $sheet->prependRow($data);
     //                    $sheet->prependRow($header);
     //                });
     //
     //            })->store('xls', storage_path('surveys'));
     //        } else {
     //            $path = 'storage/surveys/';
     //            Excel::load($path . $filename . '.xls', function ($excel) use ($survey, $request, $data) {
     //
     //                $excel->sheet($survey->name, function ($sheet) use ($request, $data) {
     //                    $sheet->prependRow(2, $data);
     //                });
     //            })->store('xls', storage_path('surveys'));
     //        }
     $survey_user->status = 1;
     $survey_user->content = json_encode($data);
     $survey_user->save();
     return redirect('profile/' . get_first_part_of_email($this->user->email));
 }
 public function save_cover(Request $request)
 {
     $user = $this->user;
     $cover_name = uploadFileToS3($request, 'cover_url', 1000, $user->cover_name);
     $user->cover_url = $this->s3_url . $cover_name;
     $user->cover_name = $cover_name;
     //            $this->data['isChanged'] = 1;
     $code = get_first_part_of_email($user->email);
     $user->save();
     return redirect('profile/' . $code);
 }
 public function shifts_progress($gen_id = null)
 {
     if ($gen_id) {
         $current_gen = Gen::find($gen_id);
     } else {
         $current_gen = Gen::getCurrentGen();
     }
     $weeks = $current_gen->shifts()->get()->pluck('week')->unique()->sortByDesc(function ($week, $key) {
         return $week;
     });
     $return_arr = [];
     foreach ($weeks as $week) {
         $week_shifts = $current_gen->shifts()->where('week', $week)->get();
         $user_ids = $week_shifts->pluck('user_id');
         $users = User::whereIn('id', $user_ids)->get();
         $shift_count_arr = [];
         $max_count = 0;
         foreach ($users as $user) {
             $count = $user_ids->filter(function ($item) use($user) {
                 return $item == $user->id;
             })->count();
             if ($count > $max_count) {
                 $max_count = $count;
             }
             $shift_count_arr[] = ['count' => $count, 'user' => ['name' => $user->name, 'url' => url('profile/' . get_first_part_of_email($user->email))]];
         }
         $return_arr[] = ['week' => $week, 'progresses' => $shift_count_arr, 'max_count' => $max_count];
     }
     return response()->json($return_arr);
 }
 public function transform($register)
 {
     $student = $register->user;
     return ["code" => $register->code, "name" => $student->name, "email" => $student->email, "avatar_url" => $student->avatar_url ? $student->avatar_url : url('img/user.png'), "phone" => $student->phone, "url" => url('profile/' . get_first_part_of_email($student->email)), 'products_count' => $student->products()->count(), "attendances" => $this->attendanceTransformer->transformCollection($register->attendances)];
 }
Beispiel #6
0
 public function get_product_data(Product $product)
 {
     $product->views += 1;
     $product->rating += 0.2;
     $product->save();
     $product->author;
     $classes = array();
     foreach ($product->author->registers as $register) {
         $register->studyClass->course;
         $classes[] = $register->studyClass;
     }
     if ($product->category != null) {
         $product->category_name = $product->category->name;
         $product->category_url = url('category?cat_id=' . $product->category->id);
     }
     if ($product->type == 2 || $product->type == 3) {
         $product->share_url = url('post/colormevn-' . convert_vi_to_en($product->description) . '?id=' . $product->id);
     }
     $product->parsed_tags = view('components.tag', ['current_product' => $product])->render();
     $product->classes = $classes;
     $product->remain_time = time_elapsed_string(strtotime($product->created_at));
     $product->author->email_name = get_first_part_of_email($product->author->email);
     $product->total_likes = $product->likes()->count();
     $product->total_comments = $product->comments()->count();
     if ($product->type == 3) {
         $product->items = '';
         foreach ($product->images as $image) {
             if ($image->type == 0) {
                 $product->items .= "<img src='{$image->url}'style='width: 100%' />";
             } else {
                 $product->items .= "\n                    <video full=\"{$image->url}\" class=\"responsive-video\"\n                           controls preload='metadata'>\n                        <source src=\"{$product->url}\" type=\"video/mp4\">\n                    </video>\n                    ";
             }
         }
     }
     return $product;
 }
 public function transform($author)
 {
     return ['id' => $author->id, 'username' => $author->username, "name" => $author->name, "email" => $author->email, 'phone' => $author->phone, 'avatar_url' => $author->avatar_url ? $author->avatar_url : url('img/user.png'), 'url' => "http://colorme.vn/profile/" . get_first_part_of_email($author->email)];
 }