Beispiel #1
0
 public static function createEvent($input)
 {
     $started_at = empty($input['started_at']) ? 'no' : preg_split("/([\\/: ])/", $input['started_at']);
     $ended_at = empty($input['ended_at']) ? 'no' : preg_split("/([\\/: ])/", $input['ended_at']);
     $input = array('event_category_id' => $input['event_category_id'], 'city_id' => $input['city_id'], 'email' => $input['email'], 'creator_fname' => $input['creator_fname'], 'creator_lname' => $input['creator_fname'], 'creator_email' => $input['creator_email'], 'name' => $input['name'], 'user_id' => Auth::check() ? Auth::user()->id : '', 'stewardship' => $input['stewardship'], 'description' => $input['description'], 'location' => $input['location'], 'website_url' => $input['website_url'], 'social_media_urls' => $input['social_media_urls'], 'started_at' => $started_at == 'no' ? '' : mktime((int) $started_at[3], (int) $started_at[4], 0, (int) $started_at[0], (int) $started_at[1], (int) $started_at[2]), 'ended_at' => $ended_at == 'no' ? '' : mktime((int) $ended_at[3], (int) $ended_at[4], 0, (int) $ended_at[0], (int) $ended_at[1], (int) $ended_at[2]));
     $rules = array('event_category_id' => 'required', 'city_id' => 'required', 'creator_fname' => 'required', 'creator_lname' => 'required', 'creator_email' => 'required|email', 'email' => 'required|email', 'name' => 'required', 'stewardship' => 'required|min:5', 'description' => 'required|min:5', 'location' => 'required', 'started_at' => 'required', 'ended_at' => 'required');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         try {
             // Mencatat pembuat target sosial
             if (Auth::check()) {
                 $input['user_id'] = Auth::user()->id;
             } else {
                 // Check apakah user ada di database
                 $check_user = User::where('email', $input['creator_email']);
                 if ($check_user->count() > 0) {
                     $input['user_id'] = $check_user->pluck('id');
                 } else {
                     // Membuat user baru dengan status draft (status:2)
                     $post = new User();
                     $post->firstname = $input['creator_fname'];
                     $post->lastname = $input['creator_lname'];
                     $post->email = $input['creator_email'];
                     $post->status = 2;
                     $post->save();
                     $input['user_id'] = $post->id;
                 }
             }
             unset($input['creator_fname']);
             unset($input['creator_lname']);
             unset($input['creator_email']);
             $event = new Events();
             $event->fill($input);
             $event->save();
             // digunakan untuk mengambil id user yang belum login
             if (!Auth::check()) {
                 Session::put('update_id', $event->id);
             }
             // update
             $update = Events::find($event->id);
             $update->fill(array('slug' => Events::checkSlugName(Str::slug($input['name'])) > 0 ? strtolower(Str::slug($input['name'])) . $event->id : strtolower(Str::slug($input['name']))));
             $update->save();
             return "ok";
         } catch (Exception $e) {
             return "no";
         }
     }
 }
Beispiel #2
0
 public static function createEvent($input)
 {
     $started_at = empty($input['started_at']) ? 'no' : preg_split("/([\\/: ])/", $input['started_at']);
     $ended_at = empty($input['ended_at']) ? 'no' : preg_split("/([\\/: ])/", $input['ended_at']);
     $input = array('event_category_id' => $input['event_category_id'], 'city_id' => $input['city_id'], 'email' => $input['email'], 'name' => $input['name'], 'user_id' => Auth::check() ? Auth::user()->id : '', 'stewardship' => $input['stewardship='], 'description' => $input['description'], 'location' => $input['location'], 'website_url' => $input['website_url'], 'social_media_urls' => $input['social_media_urls'], 'started_at' => $started_at == 'no' ? '' : mktime((int) $started_at[3], (int) $started_at[4], 0, (int) $started_at[0], (int) $started_at[1], (int) $started_at[2]), 'ended_at' => $ended_at == 'no' ? '' : mktime((int) $ended_at[3], (int) $ended_at[4], 0, (int) $ended_at[0], (int) $ended_at[1], (int) $ended_at[2]));
     $rules = array('event_category_id' => 'required', 'city_id' => 'required', 'name' => 'required', 'stewardship' => 'required|min:5', 'description' => 'required|min:5', 'location' => 'required', 'started_at' => 'required', 'ended_at' => 'required');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         try {
             $event = new Events();
             $event->fill($input);
             $event->save();
             // digunakan untuk mengambil id user yang belum login
             if (!Auth::check()) {
                 Session::put('update_id', $event->id);
             }
             // update
             $update = Events::find($event->id);
             $update->fill(array('slug' => Events::checkSlugName(Str::slug($input['name'])) > 0 ? strtolower(Str::slug($input['name'])) . $event->id : strtolower(Str::slug($input['name']))));
             $update->save();
             return "ok";
         } catch (Exception $e) {
             return "no";
         }
     }
 }