コード例 #1
0
 public function searchUsers($id)
 {
     $user = User::find($id);
     if (!$user) {
         return $this->respond([]);
     }
     return $this->respond($this->collectionTransformer->transformOtherUser($user));
 }
コード例 #2
0
 public function upload()
 {
     if (!Input::hasFile('image')) {
         return $this->respondNotFound('Image not found');
     }
     $this->log('Started');
     $this->log(memory_get_usage(true));
     $attachment = new Image();
     $this->file = Input::file('image');
     $this->log('Init origin image');
     $image = new ImageUtil($this->file);
     $this->log(memory_get_usage(true));
     $this->log('Uploading origin image');
     $this->log(memory_get_usage(true));
     $attachment->origin = $this->uploadImage2($image->getImage());
     $this->log(memory_get_usage(true));
     //		preventMemoryLeak();
     $this->log('Garbage collector');
     $this->log(memory_get_usage(true));
     $this->log('Gallery image upload');
     $attachment->regular = $this->uploadImage2($image->resize2('gallery')->getImage());
     $this->log(memory_get_usage(true));
     $this->log('Destroying gallery image');
     $image->getImage()->destroy();
     $image = null;
     $this->log(memory_get_usage(true));
     //		preventMemoryLeak();
     $this->log('Garbage collector');
     $this->log(memory_get_usage(true));
     $this->log('Init thumbnail image');
     $thumb = new ImageUtil($this->file);
     $thumb->resize2('thumbnail');
     $this->log(memory_get_usage(true));
     $this->log('uploading thumbnail image');
     $attachment->thumbnail = $this->uploadImage2($thumb->getImage());
     $this->log(memory_get_usage(true));
     //		preventMemoryLeak();
     $this->log('Garbage collector');
     $this->log(memory_get_usage(true));
     $attachment->width = $thumb->getWidth();
     $attachment->height = $thumb->getHeight();
     $this->log('Destroying the thumb image');
     $thumb->getImage()->destroy();
     $thumb = null;
     $this->log(memory_get_usage(true));
     $attachment->save();
     return $this->respond($this->collectionTransformer->transformImage($attachment));
 }
コード例 #3
0
ファイル: UsersController.php プロジェクト: SenhorBardell/yol
 public function blacklist()
 {
     $user = Auth::user();
     return $this->respond($user->blockedUsers->map(function ($user) {
         return $this->collectionTransformer->transformUserToSmall($user);
     }));
 }
コード例 #4
0
 /**
  * Create a sub-category
  *
  * @param  int $id
  * @return Response
  */
 public function subStore($id)
 {
     $validator = $this->validateId($id);
     if ($validator->fails()) {
         return $this->respondInsufficientPrivileges($validator->messages()->all());
     }
     $category = Category::find($id);
     if (!$category) {
         return $this->respondNotFound('forum.category-not-found');
     }
     $newCategory = new Category(Input::all());
     if ($category->categories()->save($newCategory)) {
         return $this->respond($this->collectionTransformer->transformCategory($newCategory));
     }
     return $this->respondServerError();
 }
コード例 #5
0
ファイル: LikesController.php プロジェクト: SenhorBardell/yol
 public function users($type, $id)
 {
     $usersIDs = Like::usersIDs($this->str($type), $id);
     if ($usersIDs->count() == 0) {
         return $this->respond([]);
     }
     $users = User::whereIn('id', $usersIDs->toArray())->with('cars')->get();
     if (!$users) {
         return $this->respond([]);
     }
     $response = $users->map(function ($user) {
         $rsp = $this->collectionTransformer->transformUserToSmall($user);
         $rsp['cars'] = $this->collectionTransformer->transformCars($user->cars);
         return $rsp;
     });
     return $this->respond($response);
 }
コード例 #6
0
ファイル: PostsController.php プロジェクト: SenhorBardell/yol
 public function userPosts($id)
 {
     $user = User::find($id);
     if (!$user) {
         return $this->respondNotFound('User not found');
     }
     $max = 25;
     if (Input::has('size')) {
         $max = Input::get('size') > 61 ? $max : Input::get('size');
     }
     if (Input::has('last')) {
         $posts = $user->posts()->where('id', '<', Input::get('last'))->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->orderBy('id', 'desc')->take($max)->get();
     } else {
         $posts = $user->posts()->with('user', 'likes', 'comments', 'images', 'geos', 'cars', 'cars.images', 'category')->orderBy('id', 'desc')->take($max)->get();
     }
     $posts->reverse();
     return $this->respond($this->collectionTransformer->transformPosts($posts));
 }
コード例 #7
0
 /**
  * Show list of subscri
  *
  * @return Response
  */
 public function subscriptions()
 {
     $user = Auth::user();
     return $this->respond($this->collectionTransformer->transformSubscriptions($user->subscriptions));
 }
コード例 #8
0
 /**
  * Update the specified resource in storage.
  * PATCH /comments/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     //		$validator = Comment::validate(Input::all());
     $user = Auth::user();
     //		if ($validator->fails())
     //			return $this->respondInsufficientPrivileges($validator->messages()->all());
     if (Input::get('text') == '' & !Input::has('attachments')) {
         return $this->respondInsufficientPrivileges('Send some text');
     }
     if (strlen(Input::get('text')) > 2500) {
         return $this->respondInsufficientPrivileges('Слишком длинный текст');
     }
     $comment = Comment::find($id);
     if (!$comment) {
         return $this->respondNotFound('Comment not found');
     }
     if (!$user->can('Comment.update', $comment)) {
         return $this->respondInsufficientPrivileges('Unauthorized action');
     }
     $comment->fill(Input::all());
     if ($comment->save()) {
         if (Input::has('attachments') && !empty(Input::get('attachments'))) {
             $attachments = Input::get('attachments');
             $comment->cars()->detach();
             $comment->geos()->detach();
             $comment->carsWithNumbers()->detach();
             foreach ($attachments as $attachment) {
                 $carHelper = new Helpers\carHelper();
                 if ($attachment['type'] == 'Geo') {
                     $geo = Geo::create(['long' => $attachment['long'], 'lat' => $attachment['lat'], 'location' => $attachment['location']]);
                     $comment->geos()->save($geo);
                 }
                 if ($attachment['type'] == 'Car') {
                     $car = $carHelper::fetchCar($user, $attachment['id']);
                     if ($car) {
                         $comment->cars()->attach($car->id);
                     }
                 }
                 if ($attachment['type'] == 'CarNumber') {
                     $car = $carHelper::fetchCar($user, $attachment['id']);
                     if ($car) {
                         $comment->carsWithNumbers()->attach($car->id);
                     }
                 }
                 if ($attachment['type'] == 'Image') {
                     $image = Image::find($attachment['id']);
                     if ($image && !$comment->images()->find($attachment['id'])) {
                         $comment->images()->save($image);
                     }
                     if ($comment->images()->find($attachment['id'])) {
                         $images[] = $image->id;
                     }
                 }
             }
             if (isset($images)) {
                 $comment->images()->whereNotIn('id', $images)->delete();
             } else {
                 $comment->images()->delete();
             }
         } else {
             $comment->images()->delete();
             $comment->cars()->detach();
             $comment->geos()->detach();
             $comment->carsWithNumbers()->detach();
         }
         return $this->respond($this->collectionTransformer->transformComment($comment));
     }
     return $this->respondServerError();
 }
コード例 #9
0
ファイル: CarsController.php プロジェクト: SenhorBardell/yol
 /**
  * Update car from self list
  * @param $id
  * @return Response
  */
 public function selfUpdate($id)
 {
     $user = Auth::user();
     $car = $user->cars()->find($id);
     if (!$car) {
         return $this->respondNotFound('Car not found');
     }
     if (Input::get('number') != $car->number) {
         $validator = Car::validate(Input::all());
         if ($validator->fails()) {
             return $this->respondInsufficientPrivileges($validator->messages()->all());
         }
     }
     $number = Input::get('number');
     if ($number[2] == 'Z' && $number[3] == 'Z') {
         return $this->respondInsufficientPrivileges('Wrong number. There is no ZZ');
     }
     $region = substr($number, 0, 2);
     if (is_numeric($number[0]) && (int) Input::get('vehicle_type') != 3) {
         switch ((int) $region) {
             case $region == 0:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
             case $region >= 73 && $region <= 84:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
             case $region >= 86 && $region <= 89:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
             case $region >= 91 && $region <= 98:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
         }
     }
     if (is_numeric($number[0]) && strlen($number) > 6) {
         $zerosCount = 3;
         // amount of zeros
         // check if all numbers are zeros
         $zeros = array_diff(array_slice(str_split($number), 4), array_fill(0, $zerosCount, 0));
         if (empty($zeros)) {
             return $this->respondInsufficientPrivileges("Номер не может быть с {$zerosCount} нулями");
         }
     } elseif (strlen($number) > 6) {
         $zerosCount = 6;
         $zeros = array_diff(array_slice(str_split($number), 1), array_fill(0, $zerosCount, 0));
         if (empty($zeros)) {
             return $this->respondInsufficientPrivileges("Номер не может быть с {$zerosCount} нулями");
         }
     }
     // if seria in number are in AA, PA, РМ, YP. Which is not allowed.
     if (Car::checkSeria($number)) {
         return $this->respondInsufficientPrivileges('Номера с сериями АА, РА, РМ и YP добавляются в профиль пользователя службой поддержки только при подтверждении факта владения или пользования данной машиной. Обратитесь в техподдержку.');
     }
     $car->fill(Input::all());
     if ($car->save()) {
         $imgs = Image::findMany(Input::get('img'))->map(function ($image) use($car) {
             if (!$car->images()->find($image->id)) {
                 $car->images()->save($image);
                 return $image->id;
             }
             if ($car->images()->find($image->id)) {
                 return $image->id;
             }
         });
         if (!$imgs->isEmpty()) {
             $car->images()->whereNotIn('id', $imgs->toArray())->delete();
         } else {
             $car->images()->delete();
         }
         return $this->respond($this->collectionTransformer->transformCar($car));
     }
     return $this->respondServerError();
 }