/** * Execute the console command. * * @return mixed */ public function fire() { dd('test'); $vehicleTypes = VehicleTypeRef::all(); Category::where('id', '>', 58)->whereNull('parent_id')->get()->each(function ($category) use($vehicleTypes) { $category->categories->each(function ($subCategory) use($category, $vehicleTypes) { // $vehicleTypes->each(function ($vehicleType) use($category, $subCategory) { // if ($subCategory->title != "{$vehicleType->ru} {$category->name}") { $subCategory->description = "Все об {$subCategory->title}"; // } else { // different description // } // }); if ($subCategory->save()) { $this->line($subCategory->title); $this->line($subCategory->description . PHP_EOL); } }); }); $marks = MarkRef::all(); Category::where('id', '>', 58)->whereNotNull('parent_id')->get()->each(function ($category) use($vehicleTypes, $marks) { $marks->each(function ($mark) use($category, $vehicleTypes) { $vehicleTypes->each(function ($vehicleType) use($category, $mark) { if ($category->title == "{$vehicleType->ru} {$mark->name}") { $newTitle = $this->morph($vehicleType) . $mark->name; $this->line("{$category->title} to {$newTitle}"); // $category->title = $newTitle; // $category->save(); } }); }); }); }
/** * Display a listing of the resource. * GET /admin/users * * @return Response */ public function index() { $users = User::withTrashed(); foreach (Input::all() as $key => $input) { if (in_array($key, ['vehicle_type', 'mark', 'model', 'body_type'])) { $users->whereHas('cars', function ($q) use($key, $input) { $q->where($key, $input); }); } elseif ($key == 'city') { $users->where($key, $input); } } $users = $users->with('cityRef')->paginate(); return View::make('admin.users.index', ['title' => 'Пользователи', 'columns' => ['ID', 'Аватар', 'Имя', 'Почта', 'Номер телефона', 'Город', 'Возраст', 'Сообщений', 'Удален в', '', ''], 'data' => $users->transform(function ($user) { return ['id' => $user->id, 'img' => "<img src='{$user->img_small}'>", 'name' => link_to_action('AdminUsersController@show', $user->name, [$user->id]), 'email' => $user->email, 'phone' => $this->returnIfPresent($user, 'phone', 'number'), 'city' => $this->returnIfPresent($user, 'cityRef', 'ru'), 'age' => $user->birthday, 'messages' => $user->messages()->count(), 'deleted' => $user->deleted_at, 'edit' => link_to_action('AdminUsersController@edit', 'ред', [$user->id]), 'delete' => link_to_action('AdminUsersController@edit', 'удал', [$user->id])]; }), 'links' => $users->links(), 'actions' => [link_to('#modal1', 'Разослать', ['class' => 'btn btn-primary btn-md margin']), link_to('#modal1', 'Опубликовать в ленту', ['class' => 'btn btn-primary btn-md margin']), link_to('#model1', 'Удалить выбранное', ['class' => 'btn btn-primary btn-md margin'])], 'filters' => [['param' => 'city', 'name' => 'Город', 'data' => CityRef::all()->transform(function ($city) { return ['id' => $city->id, 'name' => $city->ru]; }), 'active' => Input::get('city')], ['param' => 'vehicle_type', 'name' => 'Тип Авто', 'data' => VehicleTypeRef::all()->transform(function ($v) { return ['id' => $v->id, 'name' => $v->ru]; }), 'active' => Input::has('vehicle_type')], ['param' => 'mark', 'name' => 'Марка', 'data' => MarkRef::all()->transform(function ($m) { return ['id' => $m->id, 'name' => $m->name]; }), 'active' => Input::has('mark')], ['param' => 'model', 'name' => 'Модель', 'data' => ModelRef::all()->transform(function ($m) { return ['id' => $m->id, 'name' => $m->name]; }), 'active' => Input::Has('model')], ['param' => 'body_type', 'name' => 'Кузов', 'data' => BodyTypeRef::all()->transform(function ($b) { return ['id' => $b->id, 'name' => $b->ru]; }), 'active' => Input::has('body_type')]]]); }
/** * Update the specified resource in storage. * PATCH /vehicle-types/{id} * * @param int $id * @return Response */ public function update($id) { $type = VehicleTypeRef::find($id); if (!$type) { return Redirect::action('VehicleTypeRefsController@index'); } $type->fill(Input::all()); if ($type->save()) { return Redirect::action('VehicleTypeRefsController@index'); } return Redirect::action('VehicleTypeRefsController@index'); }
public function run() { VehicleTypeRef::truncate(); BodyTypeRef::truncate(); DB::table('body_type_ref_model_ref')->truncate(); $vehicleTypes = [['az' => 'Truck', 'ru' => 'Грузовик', 'bodyTypes' => [['ru' => 'Фургон', 'az' => 'Van'], ['ru' => 'Бортовой грузовик', 'az' => 'Flatbed truck'], ['ru' => 'Самосвал', 'az' => 'Tipper'], ['ru' => 'Тягач', 'az' => 'Mule'], ['ru' => 'Эвакуатор', 'az' => 'Tow truck'], ['ru' => 'Изотерм', 'az' => 'Isothermal van'], ['ru' => 'Битумовоз', 'az' => 'Bitumen'], ['ru' => 'Бензовоз', 'az' => 'Tanker'], ['ru' => 'Газовоз', 'az' => 'Gas Truck'], ['ru' => 'Водовоз', 'az' => 'Water truck'], ['ru' => 'Рыбовоз', 'az' => 'Fish truck'], ['ru' => 'Химцистерна', 'az' => 'Chemical truck'], ['ru' => 'Пищевая цистерна', 'az' => 'Food truck'], ['ru' => 'Автовоз', 'az' => 'Autotransporter'], ['ru' => 'Контейнеровоз', 'az' => 'Container truck'], ['ru' => 'КУНГ', 'az' => 'Military truck'], ['ru' => 'Лесовоз', 'az' => 'Timber truck'], ['ru' => 'Рефрижератор', 'az' => 'Refrigerator truck'], ['ru' => 'Цементовоз', 'az' => 'Cement truck'], ['ru' => 'Зерновоз', 'az' => 'Grain truck']]], ['az' => 'Car', 'ru' => 'Легковая', 'bodyTypes' => [['ru' => 'Седан', 'az' => 'Sedan'], ['ru' => 'Универсал', 'az' => 'Universal'], ['ru' => 'Хетчбэк', 'az' => 'Hatchback'], ['ru' => 'Лифтбэк', 'az' => 'Liftback'], ['ru' => 'Купе', 'az' => 'Coupe'], ['ru' => 'Кабрио', 'az' => 'Cabrio'], ['ru' => 'Родстер', 'az' => 'Rodster'], ['ru' => 'Тарга', 'az' => 'Targa'], ['ru' => 'Лимузин', 'az' => 'Limousine'], ['ru' => 'Минивен', 'az' => 'Minivan'], ['ru' => 'Компактвен', 'az' => 'Compactvan'], ['ru' => 'Микровен', 'az' => 'Microvan'], ['ru' => 'Внедорожник', 'az' => 'SUV'], ['ru' => 'Кроссовер', 'az' => 'Crossover'], ['ru' => 'Пикап', 'az' => 'Pickup'], ['ru' => 'Caddy-фургон', 'az' => 'Caddyvan'], ['ru' => 'Таун-кар', 'az' => 'Towncar']]], ['az' => 'Bike', 'ru' => 'Мототехника', 'bodyTypes' => [['ru' => 'Мотоцикл', 'az' => 'Motorcycle'], ['ru' => 'Скутер', 'az' => 'Scooter'], ['ru' => 'Мопед', 'az' => 'Moped'], ['ru' => 'Квадроцикл', 'az' => 'ATV'], ['ru' => 'Трицикл', 'az' => 'Tricycle'], ['ru' => 'Багги', 'az' => 'Buggy']]], ['az' => 'Bus', 'ru' => 'Автобус', 'bodyTypes' => [['ru' => 'Микроавтобус', 'az' => 'Minibus'], ['ru' => 'Городской автобус', 'az' => 'City bus'], ['ru' => 'Междугородний автобус', 'az' => 'Intercity bus'], ['ru' => 'Пригородный автобус', 'az' => 'Suburban bus'], ['ru' => 'Экскурсионный автобус', 'az' => 'Tour bus'], ['ru' => 'Школьный автобус', 'az' => 'School bus']]]]; foreach ($vehicleTypes as $vehicleType) { VehicleTypeRef::create(['ru' => $vehicleType['ru'], 'az' => $vehicleType['az']]); // Vehicle types and Body type must be separate array_map(function ($bodyType) { BodyTypeRef::create(['ru' => $bodyType['ru'], 'az' => $bodyType['az']]); }, $vehicleType['bodyTypes']); } }
public function create() { return View::make('admin.marks.create', ['vehicles' => VehicleTypeRef::all()->transform(function ($vehicle) { return ['exists' => false, 'id' => $vehicle->id, 'ru' => $vehicle->ru]; }), 'title' => 'Создать марку']); }
/** * Execute the console command. * * @return mixed */ public function fire() { $locales = ['ru', 'az']; if ($this->option('with_categories')) { $this->info("Compile categories is on"); MarkRef::with('models')->get()->each(function ($mark) { $this->line("Looking for {$mark->name}"); $category = Generator::findOrCreate($mark->name); if ($category) { Generator::findOrCreate("Все о {$mark->name}", '', $category->id); $mark->models->each(function ($model) use($mark, $category) { $this->line("Looking on {$model->name}"); Generator::findOrCreate($mark->name . ' ' . $model->name, 'Все что касается этой модели.', $category->id); }); } }); } $configDate = Carbon::now()->toDateTimeString(); $oldConfigDate = Config::get('database.refs-version'); foreach ($locales as $locale) { $this->info('Compiling models'); $tempDate = Carbon::now(); $chunk = 200; $this->line("Batch {$chunk}"); ModelRef::with('bodyTypes')->chunk($chunk, function ($models) use($oldConfigDate, $configDate, $locale) { Cache::forget("models-{$oldConfigDate}-{$locale}-part{$models->last()->id}"); Cache::forever("models-{$configDate}-{$locale}-part{$models->last()->id}", $models->toArray()); $this->line("End of chunk {$models->last()->id}"); }); Cache::forget("models-{$oldConfigDate}-{$locale}"); Cache::forever("models-{$configDate}-{$locale}", ModelRef::all()); $this->info("Finished compiling models. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->info('Compiling marks'); $tempDate = Carbon::now(); Cache::forget("marks-{$oldConfigDate}-{$locale}"); Cache::forever("marks-{$configDate}-{$locale}", MarkRef::with('vehicleTypes')->get()->toArray()); $this->info("Finished compiling marks.{$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->info('Compiling vehicle types'); $tempDate = Carbon::now(); Cache::forget("vehicle-types-{$oldConfigDate}-{$locale}"); Cache::forever("vehicle-types-{$configDate}-{$locale}", VehicleTypeRef::all()->transform(function ($type) { return ['id' => $type->id, 'name' => $type->ru]; })->toArray()); $this->info("Finished compiling vehicle types. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->line('Compiling cities'); $tempDate = Carbon::now(); Cache::forget("cities-{$oldConfigDate}-{$locale}"); Cache::forever("cities-{$configDate}-{$locale}", CityRef::all()->transform(function ($city) use($locale) { return ['name' => $city->{$locale}, 'id' => $city->id]; })->toArray()); $this->info("Finished compiling cities. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); $this->info('Compiling body types'); $tempDate = Carbon::now(); Cache::forget("body-types-{$oldConfigDate}-{$locale}"); Cache::forever("body-types-{$configDate}-{$locale}", BodyTypeRef::all()->transform(function ($type) use($locale) { return ['id' => $type->id, 'name' => $type->{$locale}]; })->toArray()); $this->info("Finishing compiling body types. {$tempDate->diffInSeconds(Carbon::now(), true)} seconds"); } Cache::forever('database.refs-version', $configDate); }
/** * Get all vehicles * GET /vehicle-types * * @return Response */ public function index() { $locale = in_array(Request::header('Locale'), $this->avaibleLocales) ? Request::header('Locale') : $this->avaibleLocales[0]; $vehicleTypes = VehicleTypeRef::with('bodyTypes')->get(); foreach ($vehicleTypes as $vehicleType) { foreach ($vehicleType->bodyTypes as $bodyType) { $bodyTypesResult[] = ['name' => $bodyType->{$locale}, 'id' => $bodyType->id]; } $result[] = ['name' => $vehicleType->{$locale}, 'id' => $vehicleType->id, 'body-types' => $bodyTypesResult]; } return $this->respond($result); }
public function create() { return View::make('admin.models.create', ['vehicles' => VehicleTypeRef::all()->transform(function ($v) { return ['id' => $v->id, 'ru' => $v->ru, 'exists' => false]; }), 'marks' => MarkRef::all()]); }
/** * Store a new car * POST /api/users/self/cars * * @return Response */ public function selfStore() { $user = Auth::user(); // if (!Input::has('number')) // return $this->respondInsufficientPrivileges('Please select number'); $validator = Car::validate(Input::all()); if ($validator->fails()) { return $this->respondInsufficientPrivileges($validator->messages()->all()); } $number = strtoupper(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) { // smells a bit but whatever 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 = new Car(Input::all()); $mark = MarkRef::find($car->mark); $model = ModelRef::find($car->model); $vehicleType = VehicleTypeRef::find($car->vehicle_type); $this->subscribe($user, "{$this->morphWord($vehicleType)} {$mark->name}"); $this->subscribe($user, $mark->name . ' ' . $model->name); if ($user->cars()->save($car)) { $imgCollection = Image::findMany(Input::get('img')); foreach ($imgCollection as $imgObject) { $car->images()->save($imgObject); } return $this->respond($this->collectionTransformer->transformCar($car)); } return $this->respondServerError(); }