protected function setBusinessPreferences(Business $business, $preferences)
 {
     // Get parameters from app configuration
     $parameters = config()->get('preferences.App\\Models\\Business');
     // Get the keys of the parameters
     $parametersKeys = array_flip(array_keys($parameters));
     // Merge the user input with the parameter keys
     $mergedPreferences = array_intersect_key($preferences, $parametersKeys);
     // Store each parameter key-value pair to the business preferences
     foreach ($mergedPreferences as $key => $value) {
         $this->log->info(sprintf("set preference: businessId:%s key:%s='%s' type:%s", $business->id, $key, $value, $parameters[$key]['type']));
         $business->pref($key, $value, $parameters[$key]['type']);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Business $business, Request $request)
 {
     $this->log->info(__METHOD__);
     $this->log->info(sprintf("  businessId:%s", $business->id));
     ///////////////////////////////
     // TODO: AUTH GATE GOES HERE //
     ///////////////////////////////
     //////////////////
     // FOR REFACTOR //
     //////////////////
     $dates = $request->get('vacancy');
     $changed = false;
     foreach ($dates as $date => $vacancy) {
         foreach ($vacancy as $serviceId => $capacity) {
             switch (trim($capacity)) {
                 case '':
                     // Dont update, leave as is
                     $this->log->info("Blank vacancy capacity value");
                     break;
                 default:
                     $start_at = Carbon::parse($date . ' ' . $business->pref('start_at'))->timezone($business->timezone);
                     $finish_at = Carbon::parse($date . ' ' . $business->pref('finish_at', '20:00:00'))->timezone($business->timezone);
                     $vacancy = Vacancy::updateOrCreate(['business_id' => $business->id, 'service_id' => $serviceId, 'date' => $date], ['capacity' => intval($capacity), 'start_at' => $start_at, 'finish_at' => $finish_at]);
                     $changed = true;
                     break;
             }
         }
     }
     if (!$changed) {
         $this->log->warning("Nothing to update");
         Flash::warning(trans('manager.vacancies.msg.store.nothing_changed'));
         return redirect()->back();
     }
     $this->log->warning("Vacancies updated");
     Flash::success(trans('manager.vacancies.msg.store.success'));
     return redirect()->route('manager.business.show', [$business]);
 }
Exemplo n.º 3
0
 /**
  * Update vacancies.
  *
  * @param Business $business
  * @param array    $dates
  *
  * @return bool
  */
 public function update(Business $business, $dates)
 {
     $changed = false;
     foreach ($dates as $date => $vacancy) {
         foreach ($vacancy as $serviceId => $capacity) {
             switch (trim($capacity)) {
                 case '':
                     // Dont update, leave as is
                     logger()->info(sprintf('businessId:%s %s: Blank vacancy capacity value', $business->id, $date));
                     break;
                 default:
                     $startAt = Carbon::parse($date . ' ' . $business->pref('start_at') . ' ' . $business->timezone)->timezone('UTC');
                     $finishAt = Carbon::parse($date . ' ' . $business->pref('finish_at') . ' ' . $business->timezone)->timezone('UTC');
                     $vacancyKeys = ['business_id' => $business->id, 'service_id' => $serviceId, 'date' => $date];
                     $vacancyValues = ['capacity' => intval($capacity), 'start_at' => $startAt, 'finish_at' => $finishAt];
                     $vacancy = Vacancy::updateOrCreate($vacancyKeys, $vacancyValues);
                     $changed = true;
                     break;
             }
         }
     }
     return $changed;
 }