예제 #1
0
 function ratePhraseImage(Request $request)
 {
     // валидация
     $paramsToValidate = array('imageId' => Input::get('imageId'), 'rate' => Input::get('rate'));
     $validatorRules = array('imageId' => ['required', 'integer'], 'rate' => ['required', 'integer', 'between:1,5']);
     $validator = Validator::make($paramsToValidate, $validatorRules);
     if ($validator->fails()) {
         return $this->response->validatorError($validator->messages());
     }
     // добавим рейтинг
     $avrgRate = ImageRating::addRate(Input::get('imageId'), Input::get('rate'));
     return $this->response->onSuccess($avrgRate);
 }
 private function relatedImagesOutput($imageList)
 {
     $result = [];
     foreach ($imageList as $image) {
         $result[] = array('id' => $image->id, 'phrase_id' => $image->phrase_id, 'title' => $image->title, 'url' => '//what-it-means.ru/files/phrases/photos/' . $image->id . '/photo.jpg', 'rate' => ImageRating::avrgRating($image->id));
     }
     return $result;
 }