/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); // Create a faker, add en_SG providers $faker->addProvider(new Faker\Provider\en_SG\Address($faker)); $faker->addProvider(new Faker\Provider\en_SG\Enhanced($faker)); $faker->addProvider(new Faker\Provider\en_SG\Person($faker)); $faker->addProvider(new Faker\Provider\en_SG\PhoneNumber($faker)); $faker->seed(9876); // Calling the same script twice with the same seed produces the same results $durations = [30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180]; // Insert 30 dummy records foreach (range(1, 30) as $index) { $startDate = $faker->dateTimeBetween('-3 months', '3 months'); $startHour = ['08', '09', '10', '11', '13', '14', '15', '16']; $startMin = ['00', '15', '30', '45']; while (Carbon::instance($startDate)->dayOfWeek === Carbon::SUNDAY) { $startDate = $faker->dateTimeBetween('-3 months', '3 months'); } if ($startDate === Carbon::SATURDAY) { $startHour = ['08', '09', '10', '11']; } $startTime = $faker->randomElement($startHour) . ":" . $faker->randomElement($startMin) . ":00"; $elderly = Elderly::with('centre')->find($faker->numberBetween(1, 15)); $staffList = $elderly->centre->staff->lists('staff_id')->toArray(); Activity::create(['datetime_start' => $startDate->format('Y-m-d') . " " . $startTime, 'expected_duration_minutes' => $faker->randomElement($durations), 'category' => 'transport', 'more_information' => $faker->optional(0.4, '')->sentence(10, true), 'location_from_id' => $elderly->centre_id, 'location_to_id' => $faker->numberBetween(4, 6), 'elderly_id' => $elderly->elderly_id, 'centre_id' => $elderly->centre_id, 'staff_id' => $faker->randomElement($staffList)]); } }
/** * Execute the command. * * @return void */ public function handle() { $this->menu->updated_at = Carbon::now(); $this->menu->update($this->request->all()); Activity::create(['text' => $this->auth->linkedName() . ' updated menu named ' . $this->menu->linkedName(), 'user_id' => $this->auth->id]); Session::flash('flash_message', 'You have updated menu!'); }
/** * Register any other events for your application. * * @param \Illuminate\Contracts\Events\Dispatcher $events * @return void */ public function boot(DispatcherContract $events) { parent::boot($events); $events->listen('auth.login', function ($user, $remember) { // Record user login Activity::create(['subject_type' => 'User', 'subject_id' => '', 'event' => 'Logged In', 'user_id' => $user->id, 'ip' => Request::server('REMOTE_ADDR')]); }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(ActivityRequest $request) { Activity::create($request->all()); session()->flash('flash_message', 'Actividad creada correctamente.'); // Si flash_message_important esta presente, el mensaje no desaparece hasta que el usuario lo cierre // session()->flash('flash_message_important', true); return Redirect::to('actividades'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { if ($activity = Activity::create($request->all())) { return $activity->toJson(); } else { return $this->response->error('Activity could not be created.', 404); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(StoreActivityRequest $request) { if (Gate::denies('create', Activity::class)) { abort(403); } Activity::create(['date_of_activity' => $request->date_of_activity, 'barangay' => $request->barangay, 'subtitle_id' => $request->subtitle_id, 'day_of_activity' => $request->day_of_activity, 'venue_of_activity' => $request->venue_of_activity, 'conducted_by' => $request->conducted_by, 'remarks' => $request->remarks]); return redirect('/activity')->with('alert-success', 'The record has been saved!'); }
/** * Execute the console command. * * @return mixed */ public function fire() { //register log in DB $dateBegin = new \DateTime(); $activity = Activity::concept(ConstDb::LOAD_CRL)->first(); if ($activity) { $activity->date_begin = $dateBegin->format('Y-m-d H:i:s'); $activity->save(); } else { Activity::create(['concept' => ConstDb::LOAD_CRL, 'date_begin' => $dateBegin->format('Y-m-d H:i:s')]); } //end log $this->info('Begin: ' . date('H:i:s')); $result = DB::connection('mysql_crl')->select($this->getQuery(true)); $rows = $result[0]->total; $this->info("Total de filas: {$rows}"); $begin = 0; $block = 10000; $countBlock = 1; $fCsv = storage_path('app/crl.csv'); if (file_exists($fCsv)) { unlink($fCsv); } $fp = fopen($fCsv, 'w'); fputs($fp, "organization, from, year, quarter, month, total \n"); while ($rows > $begin) { $result = DB::connection('mysql_crl')->select($this->getQuery(false, $begin, $block)); foreach ($result as $key => $value) { $array = json_decode(json_encode($value), true); $replace = ["\n", ',', ' ']; $replaceTo = ["", ';', ' ']; foreach ($array as $key => $value) { $array[$key] = str_replace($replace, $replaceTo, $value); } fputs($fp, implode($array, ',') . "\n"); } $this->info("End block {$countBlock}: " . date('H:i:s')); $begin += $block; $countBlock++; } fclose($fp); $this->info('End export CSV: ' . date('H:i:s')); Schema::drop('crl'); $db = env('MONGO_DATABASE'); $command = "mongoimport -d {$db} -c crl --type csv --file {$fCsv} --headerline"; shell_exec($command); //register log in DB $dateEnd = new \DateTime(); $activity = Activity::concept(ConstDb::LOAD_CRL)->first(); if ($activity) { $activity->date_end = $dateEnd->format('Y-m-d H:i:s'); $activity->save(); } else { Activity::create(['concept' => ConstDb::LOAD_CRL, 'date_end' => $dateEnd->format('Y-m-d H:i:s')]); } //end log $this->info('End: ' . $dateEnd->format('H:i:s')); }
public function recordActivity($event) { if (!Auth::id()) { $user = ['id' => 1, 'name' => 'LENDA']; } else { $user = User::find(Auth::id())->toArray(); } Activity::create(['loan_id' => $this->loan_id, 'user_id' => $user['id'], 'user' => $user['name'], 'subject_id' => $this->id, 'subject_type' => get_class($this), 'name' => $this->getActivityName($this, $event, $user)]); }
public static function fromProduct($productId, $startTime) { $product = Product::findOrFail($productId); $activity = Activity::create($product->toArray()); $activity->product_id = $product->id; $activity->start_date = Carbon::createFromFormat('Y-m-d', $startTime); $activity->thumb = $product->thumb; $activity->banner = $product->banner; $activity->save(); }
/** * Execute the command. * * @return void */ public function handle() { $slug = Slug::create(['name' => $this->request->slug, 'slug_attribute_id' => self::SLUG_ATTRIBUTE_MENU]); $this->request['slug_id'] = $slug->id; $this->request['gallery'] = ''; // not yet implemented $content = Content::create($this->request->all()); Activity::create(['text' => $this->auth->linkedName() . ' created new content named ' . $content->linkedName(), 'user_id' => $this->auth->id]); Session::flash('flash_message', 'Your content has been created!'); }
public function update($id) { // save updated $record = $this->records->find($id); if (!$record) { Activity::create(Input::all()); return $this->respond($record); } $record->fill(Input::all())->save(); return $this->respond($record); }
/** * Record activity for the model. * * @param string $event * @return void */ public function recordActivity($event) { // $activity = new Activity(); // // $activity->subject_id = $this->id; // $activity->subject_type = get_class($this); // $activity->name = $this->getActivityName($this, $event); // $activity->subject_id = $this->id; // // Auth::user()->activity()->save($activity); Activity::create(['subject_id' => $this->id, 'subject_type' => get_class($this), 'name' => $this->getActivityName($this, $event), 'user_id' => $this->user_id]); }
public function recordActivity($event) { if (!empty($this->name)) { $eventText = "{$event}: {$this->name}"; } else { if (!empty($this->number)) { $eventText = "{$event}: {$this->number}"; } else { $eventText = $event; } } Activity::create(['subject_type' => $this->getDisplaySingular(), 'subject_id' => $this->id, 'event' => $eventText, 'user_id' => Auth::user() ? Auth::user()->id : 0, 'ip' => Request::server('REMOTE_ADDR')]); }
/** * Execute the command. * * @return void */ public function handle() { $slug = Slug::create(['name' => $this->request->slug, 'slug_attribute_id' => self::SLUG_ATTRIBUTE_MENU]); $this->request['slug_id'] = $slug->id; $menu = new Menu($this->request->all()); $menu->generateOrder(); if ($menu->location_id == 0) { $parent = Menu::findOrFail($menu->parent_id); $menu->location_id = $parent->location_id; } $menu->save(); Activity::create(['text' => $this->auth->linkedName() . ' created new menu named ' . $menu->linkedName(), 'user_id' => $this->auth->id]); Session::flash('flash_message', 'Your menu has been created!'); }
public function postStore() { if (Request::ajax()) { $data = Input::get('data'); $i = 0; foreach ($data as $key) { Activity::create($data[$i]); $i++; if ($i == count($data)) { return "OK"; } } } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $recordId = 0; if ($request->has('activity')) { $postDataActivity = $request->input('activity', []); try { $activity = Activity::create($postDataActivity); $recordId = $activity->acty_id; } catch (\Exception $ex) { return response()->json(['error' => ['code' => $ex->getCode(), 'reason' => $ex->getMessage()]]); } } else { return response()->json(['error' => ['code' => self::ERR_POSTDATA_FORMAT, 'reason' => 'Post data not provided in required format']], 400); } return response()->json(['recordId' => $recordId]); }
/** * Store a newly created resource in storage. * * @param CreateActivityRequest|Request $request * @return Response */ public function store(CreateActivityRequest $request) { $input = $request->all(); foreach ($input['user_id'] as $index => $user_id) { $name = $input['name'][$index]; $id = null; if ($input['user_id'][$index] !== 'null') { $currentUser = User::find($user_id); $name = $currentUser->first_name . ' ' . $currentUser->last_name; $id = $user_id; } $activityAttributes = ['user_id' => $id, 'cerf_id' => session()->get('cerf_id'), 'name' => $name, 'service_hours' => $input['service_hours'][$index], 'planning_hours' => $input['planning_hours'][$index], 'traveling_hours' => $input['traveling_hours'][$index], 'admin_hours' => $input['admin_hours'][$index], 'social_hours' => $input['social_hours'][$index], 'mileage' => $input['mileage'][$index], 'approved' => false]; Activity::create($activityAttributes); } return redirect()->action('KiwanisAttendeesController@create'); }
public function create(Request $request) { $activity = Activity::create($request->all()); if ($request->schedule_time) { $activity->schedule_time = Carbon::createFromFormat('m/d/Y g:i A', $request->schedule_time)->toDateTimeString(); } else { $activity->schedule_time = Carbon::now()->addDays(3)->toDateTimeString(); } $activity->save(); $lead = $activity->lead; if ($lead->next_action < $activity->schedule_time) { $lead->next_action = $activity->schedule_time; $lead->save(); } return $activity; }
/** * Handle the event. * * @param JobFinished $event * @return void */ public function handle(JobFinished $event) { // Job result is in $event->jobResult Log::debug('RecordActivity listener fired'); Log::debug("Job Instance type is {$event->jobResult->jobinstancetype}"); Log::debug("Command is {$event->jobResult->cmd}"); Log::debug("VM Name is {$event->jobResult->jobresult->virtualmachine->name}"); Log::debug("Auth is " . $event->userId); Log::debug("User IP is " . Request::server('REMOTE_ADDR')); try { $subject = $this->translateSubjectType($event->jobResult->jobinstancetype); $eventType = $this->translateEvent($event->jobResult->cmd); } catch (\Exception $e) { return; } Activity::create(['subject_type' => $subject, 'subject_id' => 0, 'event' => "{$eventType} - {$event->jobResult->jobresult->virtualmachine->name}", 'user_id' => $event->userId, 'ip' => $event->userIpAddress]); }
/** * Execute the command. * * @return void */ public function handle() { $order = $this->order; for ($i = 0; $i < count($order); $i++) { $menu = Menu::findOrFail($order[$i]); $temp_order = $i + 1; if ($menu->order != $temp_order) { $menu->order = $temp_order; $menu->save(); } } if (!$this->parent) { $parent_link = 'Base menu'; } else { $parent_link = $this->parent->linkedName(); } Activity::create(['text' => $this->auth->linkedName() . ' updated order for ' . $parent_link . "'s children menu list", 'user_id' => $this->auth->id]); }
public function run() { $faker = Faker::create(); DB::table('activity_log')->delete(); // Gets an array with event IDs and an array with user IDs. $cerf_ids = Cerf::all()->lists('id')->toArray(); $user_ids = User::all()->lists('id')->toArray(); for ($counter = 0; $counter < 30; $counter++) { // Chooses random keys in both arrays. $rand_cerf_id = $cerf_ids[array_rand($cerf_ids)]; $rand_user_id = $user_ids[array_rand($user_ids)]; // No two activity records should have the same user_id and cerf_id combination. if (Activity::where('user_id', '=', $rand_user_id)->where('cerf_id', '=', $rand_cerf_id)->exists()) { continue; } Activity::create(array('user_id' => $rand_user_id, 'cerf_id' => $rand_cerf_id, 'service_hours' => $faker->randomDigit, 'planning_hours' => $faker->randomDigit, 'traveling_hours' => $faker->randomDigit, 'admin_hours' => $faker->randomDigit, 'social_hours' => $faker->randomDigit, 'mileage' => $faker->randomDigit, 'notes' => $faker->paragraph)); } }
public function saveLog($begin, $concept) { $date = new \DateTime(); $activity = Activity::concept($concept)->first(); if ($activity) { if ($begin) { $activity->date_begin = $date->format('Y-m-d H:i:s'); } else { $activity->date_end = $date->format('Y-m-d H:i:s'); } $activity->save(); } else { if ($begin) { Activity::create(['concept' => $concept, 'date_begin' => $date->format('Y-m-d H:i:s')]); } else { Activity::create(['concept' => $concept, 'date_end' => $date->format('Y-m-d H:i:s')]); } } }
/** * Run the database seeds. * * @return void */ public function run() { //truncate the activities table so that the auto incrementing 'id' field starts counting from 1 again DB::table('activities')->truncate(); //Read in a csv file containing data on some of the activities in the COMSC department $activtiesCSVFile = new CsvFile(__DIR__ . '/_data/Activities.csv'); //Generate a record using data from each line of the CSV file where each row is in the format: //TODO:put the format here //'id' value for each module in the 'modules' table specified in the CSV file, as the module seeder //(and all other seeders including this one) will only be run a single time when it has been put into production foreach ($activtiesCSVFile as $currentRow) { //get an object representing the first module whose module code matches the one in the row //of the CSV file that is currently being processed. The first method returns only the first match //as the modules in the database should have unique module codes anyway. $module = Module::where('module_code', '=', (string) $currentRow[2])->first(); //obtain the 'ID' (primary key) of the module that matches the above 'where' query $moduleID = $module->id; $moduleActivity = Activity::create(['title' => trim($currentRow[0]), 'role_type' => trim($currentRow[1]), 'module_id' => $module->id, 'quant_ppl_needed' => $currentRow[4], 'closing_date_for_applications' => $currentRow[5], 'knowledge_required' => $currentRow[6]]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { // if (Auth::check()) { # code... if (Auth::user()->type == 1) { # code... $rules = ['activity_name' => 'required|unique:activities', 'description' => 'required']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { # code... return redirect()->back()->withErrors($validator); } $input = $request->all(); // dd($input); $activity = Activity::create(['activity_name' => $input['activity_name'], 'description' => $input['description']]); Session::flash('activityCreated', $activity->activity_name . ' has been created!'); return redirect('home'); } return redirect('/'); } return redirect('/'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($name) { $domain = SiteConfig::whereParameter('domainId')->first(); // Call the ACS API and add the ssh key to the necessary account $result = $this->acs->deleteSSHKeyPair(['account' => Auth::User()->email, 'domainid' => $domain->data, 'name' => $name]); Activity::create(['subject_type' => 'SSH Key', 'subject_id' => 0, 'event' => 'Deleted', 'user_id' => Auth::User()->id, 'ip' => $request->server('REMOTE_ADDR')]); return 1; }
/** * Execute the command. * * @return void */ public function handle() { $group = Group::create($this->request->all()); Activity::create(['text' => $this->auth->linkedName() . ' created ' . $group->linkedName(), 'user_id' => $this->auth->id]); Session::flash('flash_message', 'Your group has been created!'); }
public function follow($user) { $this->followed_users()->attach($user->id, ['created_at' => Carbon::now()]); Activity::create(['subject_id' => $user->id, 'subject_type' => get_class($user), 'name' => 'followed_users', 'user_id' => $this->id]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { Activity::create($request->all()); Session::flash('flash_message', 'Activity successfully added!'); return redirect('activity'); }
/** * Record activity for the model. * * @param string $event * @return void */ public function recordActivity($event) { Activity::create(['subject_id' => $this->id, 'subject_type' => get_class($this), 'name' => $this->getActivityName($this, $event), 'user_id' => $this->user_id]); }
public function ModuleAddActAction($user_id, $module_id) { $module__id = Input::get('module_id'); if ($module_id === $module__id and UserMod::where('id', $user_id)->where('role', '=', 'Lecturer')->exists() and Module::where('id', $module_id)->where('module_leader', $user_id)->exists()) { Activity::create(array('module_id' => Input::get('module_id'), 'title' => Input::get('title'), 'role_type' => Input::get('role_type'), 'quant_ppl_needed' => Input::get('quant_ppl_needed'), 'description' => Input::get('description'))); Session::flash('activity_success', "Activity was successfully created"); return back()->withInput(); } else { Session::flash('failed', "Something went wrong, please try again!"); return back()->withInput(); } }