/** * Creates a new inventory stock record. * * @return bool|static */ public function create() { $this->dbStartTransaction(); try { $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'stock_id' => $this->getInput('stock_id'), 'before' => $this->getInput('before'), 'after' => $this->getInput('after'), 'cost' => $this->getInput('cost'), 'reason' => $this->getInput('reason', 'Stock Adjustment', true)]; /* * Only create a record if the before and after quantity differ * if enabled in config */ if ($this->config->setPrefix('inventory')->get('allow_duplicate_movements')) { if ($insert['before'] != $insert['after']) { $record = $this->model->create($insert); $this->dbCommitTransaction(); return $record; } else { /* * Return true if before and after quantity are the same * and prevent duplicate movements is enabled */ return true; } } else { /* * Prevent duplicate movements is disabled, create the record */ $record = $this->model->create($insert); $this->dbCommitTransaction(); return $record; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }
/** * Creates a user with Sentry by the supplied corp user object. * * @param User $user * * @return bool|User */ private function createUser(User $user) { if ($user->username && $user->email) { $first_name = ''; $last_name = ''; /* * An LDAP user may not have a name, so we'll explode it * by a comma to see if they have a fully separated name */ if ($user->name) { $name = explode(',', $user->name); if (array_key_exists(0, $name)) { $last_name = $name[0]; } if (array_key_exists(1, $name)) { $first_name = $name[1]; } } $data = ['email' => $user->email, 'password' => str_random(20), 'username' => $user->username, 'last_name' => $last_name, 'first_name' => $first_name]; $roles = []; if ($user->group) { $roles[] = $this->sentry->createOrUpdateRole($user->group); } if ($user->type) { $roles[] = $this->sentry->createOrUpdateRole($user->type); } $user = $this->sentry->createUser($data, $roles); return $user; } return false; }
/** * Performs the seeder actions. */ public function run() { $roles = $this->getSeedData(); foreach ($roles as $roleName => $permissions) { $this->sentry->createOrUpdateRole($roleName, $permissions); } }
/** * Creates attachment records, attaches them to the asset images pivot table, * and moves the uploaded file into it's stationary position (out of the temp folder). * * @return array|bool */ public function create() { $this->dbStartTransaction(); try { // Find the work order $workOrder = $this->workOrder->find($this->getInput('work_order_id')); $uploadDir = $this->getInput('file_path'); // Check if any files have been uploaded $files = $this->getInput('files'); if ($uploadDir && $files) { $records = []; // For each file, create the attachment record, and sync asset image pivot table foreach ($files as $file) { $insert = ['file_name' => $file, 'file_path' => $uploadDir . $file, 'user_id' => $this->sentry->getCurrentUserId()]; // Create the attachment record $attachment = $this->attachment->setInput($insert)->create(); // Attach the attachment record to the work order attachments $workOrder->attachments()->attach($attachment); $records[] = $attachment; } $this->dbCommitTransaction(); // Return attachment record on success return $records; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }
/** * Applies site wide variables to main layout. * * @param $view */ public function compose(View $view) { $siteTitle = $this->config->get('site.title.main'); $currentUser = $this->sentry->getCurrentUser(); $view->with('siteTitle', $siteTitle); $view->with('currentUser', $currentUser); }
/** * Creates a new status. * * @param PriorityRequest $request * * @return bool|Priority */ public function create(PriorityRequest $request) { $priority = $this->model(); $priority->user_id = $this->sentry->getCurrentUserId(); $priority->name = $request->input('name'); $priority->color = $request->input('color'); if ($priority->save()) { return $priority; } return false; }
/** * Creates a new work order report. * * @param ReportRequest $request * @param int|string $workOrderId * * @return bool|WorkOrderReport */ public function create(ReportRequest $request, $workOrderId) { $report = $this->model(); $report->user_id = $this->sentry->getCurrentUserId(); $report->work_order_id = $workOrderId; $report->description = $request->clean($request->input('description')); if ($report->save()) { return $report; } return false; }
/** * Creates a new metric. * * @param MetricRequest $request * * @return bool|Metric */ public function create(MetricRequest $request) { $metric = $this->model(); $metric->name = $request->input('name'); $metric->symbol = $request->input('symbol'); $metric->user_id = $this->sentry->getCurrentUserId(); if ($metric->save()) { return $metric; } return false; }
/** * Creates a new status. * * @param StatusRequest $request * * @return bool|Status */ public function create(StatusRequest $request) { $status = $this->model(); $status->user_id = $this->sentry->getCurrentUserId(); $status->name = $request->input('name'); $status->color = $request->input('color'); if ($status->save()) { return $status; } return false; }
/** * Creates a notification record for a user * indicating what they would like to be notified * about. * * @return bool|static */ public function create() { $this->dbStartTransaction(); try { $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'work_order_id' => $this->getInput('work_order_id'), 'status' => $this->getInput('status', 0), 'priority' => $this->getInput('priority', 0), 'parts' => $this->getInput('parts', 0), 'customer_updates' => $this->getInput('customer_updates', 0), 'technician_updates' => $this->getInput('technician_updates', 0), 'completion_report' => $this->getInput('completion_report', 0)]; $record = $this->model->create($insert); $this->dbCommitTransaction(); return $record; } catch (\Exception $e) { $this->dbRollbackTransaction(); return false; } }
public function create() { $this->dbStartTransaction(); try { $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'name' => $this->getInput('name'), 'color' => $this->getInput('color')]; $record = $this->model->create($insert); $this->dbCommitTransaction(); return $record; } catch (\Exception $e) { $this->dbRollbackTransaction(); return false; } }
/** * Creates a work order report. * * @return bool|static */ public function create() { $this->dbStartTransaction(); try { /* * Find the work order */ $workOrder = $this->workOrder->find($this->getInput('work_order_id')); /* * Set the insert data for the work order report */ $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'work_order_id' => $workOrder->id, 'description' => $this->getInput('description', null, true)]; /* * Create the work order report */ $record = $this->model->create($insert); /* * Get the current time to update the work order */ $now = Carbon::now()->toDateTimeString(); /* * Update the work order with the completed at time since a work order * would be complete once a report has been filled out. If a started_at time exists * then we'll throw null inside so it isn't updated, otherwise we'll throw in today's time */ $update = ['started_at' => $workOrder->started_at ? null : $now, 'completed_at' => $now]; /* * Update the work order */ $workOrder = $this->workOrder->setInput($update)->update($workOrder->id); /* * Close any open sessions that may be open on the work order */ $workOrder->closeSessions(); /* * Fire the work order report created event */ $this->fireEvent('maintenance.work-orders.reports.created', ['report' => $record]); /* * Commit the database transaction */ $this->dbCommitTransaction(); /* * Return the created report */ return $record; } catch (\Exception $e) { $this->dbRollbackTransaction(); return false; } }
/** * Creates a note. * * @return bool|static */ public function create() { $this->dbStartTransaction(); try { $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'content' => $this->getInput('content', null, true)]; $record = $this->model->create($insert); if ($record) { $this->dbCommitTransaction(); return $record; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }
/** * Updates an asset meter. * * @param MeterRequest $request * @param int|string $id * @param int|string $meterId * * @return bool|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null */ public function update(MeterRequest $request, $id, $meterId) { $asset = $this->asset->model()->findOrFail($id); $meter = $asset->meters()->findOrFail($meterId); if ($meter) { $meter->metric_id = $request->input('metric'); $meter->name = $request->input('name'); if ($meter->save()) { $reading = ['user_id' => $this->sentry->getCurrentUserId(), 'reading' => $request->input('reading'), 'comment' => $request->input('comment')]; $meter->readings()->create($reading); return $meter; } } return false; }
/** * Creates a new Asset. * * @param Request $request * * @return bool|Asset */ public function create(Request $request) { $asset = $this->model(); $asset->user_id = $this->sentry->getCurrentUserId(); $asset->location_id = $request->input('location_id'); $asset->category_id = $request->input('category_id'); $asset->tag = $request->input('tag'); $asset->name = $request->input('name'); $asset->description = $request->clean($request->input('description')); $asset->condition = $request->input('condition'); $asset->size = $request->input('size'); $asset->weight = $request->input('weight'); $asset->vendor = $request->input('vendor'); $asset->make = $request->input('make'); $asset->model = $request->input('model'); $asset->serial = $request->input('serial'); $asset->price = $request->input('price'); if ($request->input('acquired_at')) { $asset->acquired_at = $this->strToDate($request->input('acquired_at')); } if ($request->input('end_of_life')) { $asset->end_of_life = $this->strToDate($request->input('end_of_life')); } if ($asset->save()) { return $asset; } return false; }
/** * Creates a new work request. * * @param Request $request * * @return bool|WorkRequest */ public function create(Request $request) { $workRequest = $this->model(); $workRequest->user_id = $this->sentry->getCurrentUserId(); $workRequest->subject = $request->input('subject'); $workRequest->best_time = $request->input('best_time'); $workRequest->description = $request->clean($request->input('description')); if ($workRequest->save()) { $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true); if ($autoGenerate) { $this->workOrder->createFromWorkRequest($workRequest); } return $workRequest; } return false; }
/** * Processes the password update. * * @param string|int $id * @param string|int $key * * @return \Illuminate\Http\JsonResponse|mixed */ public function postReset($id, $key) { if ($this->passwordValidator->passes()) { $user = $this->sentry->findUserById($id); if ($user->checkResetPasswordCode($key)) { if ($user->attemptResetPassword($key, $this->input('password'))) { $link = link_to_route('maintenance.login', 'login'); $this->message = "Successfully updated your password, you can now {$link}."; $this->messageType = 'success'; $this->redirect = route('maintenance.login'); } else { $this->message = 'You have already updated your password.'; $this->messageType = 'danger'; $this->redirect = route('maintenance.login'); } } else { $this->message = 'You have already reset your password.'; $this->messageType = 'danger'; $this->redirect = route('maintenance.login'); } } else { $this->errors = $this->passwordValidator->getErrors(); $this->redirect = route('maintenance.login'); } return $this->response(); }
/** * Creates an asset. * * @return bool|Asset */ public function create() { $this->dbStartTransaction(); try { /* * Set insert data */ $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'category_id' => $this->getInput('category_id'), 'location_id' => $this->getInput('location_id'), 'name' => $this->getInput('name', null, true), 'condition' => $this->getInput('condition'), 'vendor' => $this->getInput('vendor', null, true), 'make' => $this->getInput('make', null, true), 'model' => $this->getInput('model', null, true), 'size' => $this->getInput('size', null, true), 'weight' => $this->getInput('weight', null, true), 'serial' => $this->getInput('serial', null, true), 'acquired_at' => $this->formatDateWithTime($this->getInput('acquired_at')), 'end_of_life' => $this->formatDateWithTime($this->getInput('end_of_life'))]; /* * Create the record and return it upon success */ $record = $this->model->create($insert); if ($record) { $this->fireEvent('maintenance.assets.created', ['asset' => $record]); $this->dbCommitTransaction(); return $record; } $this->dbRollbackTransaction(); /* * Failed to create record, return false */ return false; } catch (\Exception $e) { $this->dbRollbackTransaction(); return false; } }
/** * Updates the specified users password. * * @param $id * * @return \Illuminate\Http\JsonResponse|mixed */ public function update($id) { if ($this->passwordValidator->passes()) { if ($this->sentry->updatePasswordById($id, $this->input('password'))) { $this->message = 'Successfully updated password'; $this->messageType = 'success'; $this->redirect = routeBack('maintenance.admin.users.show', [$id]); } else { $this->message = 'There was an issue resseting this users password. Please try again'; $this->messageType = 'danger'; $this->redirect = routeBack('maintenance.admin.users.show', [$id]); } } else { $this->errors = $this->passwordValidator->getErrors(); $this->redirect = route('maintenance.admin.users.show', [$id]); } return $this->response(); }
/** * Creates a work order. * * @return \Stevebauman\Maintenance\Models\WorkOrder|bool */ public function create() { $this->dbStartTransaction(); try { $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'category_id' => $this->getInput('category_id'), 'location_id' => $this->getInput('location_id'), 'status_id' => $this->getInput('status'), 'priority_id' => $this->getInput('priority'), 'subject' => $this->getInput('subject', null, true), 'description' => $this->getInput('description', null, true), 'started_at' => $this->getInput('started_at'), 'completed_at' => $this->getInput('completed_at')]; $record = $this->model->create($insert); $assets = $this->getInput('assets'); if ($assets) { $record->assets()->attach($assets); } $this->fireEvent('maintenance.work-orders.created', ['workOrder' => $record]); $this->dbCommitTransaction(); return $record; } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }
/** * Creates an item record. * * @return Inventory */ public function create() { $this->dbStartTransaction(); try { // Set insert data $insert = ['category_id' => $this->getInput('category_id'), 'user_id' => $this->sentry->getCurrentUserId(), 'metric_id' => $this->getInput('metric'), 'name' => $this->getInput('name', null, true), 'description' => $this->getInput('description', null, true)]; // If the record is created, return it, otherwise return false $record = $this->model->create($insert); if ($record) { // Fire created event $this->fireEvent('maintenance.inventory.created', ['item' => $record]); $this->dbCommitTransaction(); return $record; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }
/** * Creates a note for the specified inventory. * * @param NoteRequest $request * @param int|string $id * * @return bool|\Stevebauman\Maintenance\Models\Note; */ public function createNote(NoteRequest $request, $id) { $inventory = $this->model()->findOrFail($id); $attributes = ['user_id' => $this->sentry->getCurrentUserId(), 'content' => $request->clean($request->input('content'))]; $note = $inventory->notes()->create($attributes); if ($note) { return $note; } return false; }
/** * @return array|bool */ public function create() { $this->dbStartTransaction(); try { $users = $this->getInput('users'); if ($users) { $records = []; foreach ($users as $user) { $insert = ['work_order_id' => $this->getInput('work_order_id'), 'by_user_id' => $this->sentry->getCurrentUserId(), 'to_user_id' => $user]; $records[] = $this->model->create($insert); } $this->dbCommitTransaction(); return $records; } return false; } catch (\Exception $e) { $this->dbRollbackTransaction(); return false; } }
/** * Updates a work order session. * * @param int|string $workOrderId * * @return bool|WorkOrderSession */ public function update($workOrderId) { $session = $this->workOrder->findLastUserSession($workOrderId); if ($session && $session->user_id === $this->sentry->getCurrentUserId()) { $now = Carbon::now()->toDateTimeString(); $session->out = $now; if ($session->save()) { return $session; } } return false; }
/** * Creates a new report for the specified event. * * @param ReportRequest $request * @param int|string $id * * @return bool */ public function createReport(ReportRequest $request, $id) { $event = $this->find($id); if ($event) { $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'description' => $request->clean($request->input('description'))]; $report = $event->report()->create($insert); if ($report) { return $report; } } return false; }
/** * Creates a work request. * * @return bool|WorkRequest */ public function create() { $this->dbStartTransaction(); try { $workRequest = new $this->model(); $workRequest->user_id = $this->sentry->getCurrentUserId(); $workRequest->subject = $this->getInput('subject', null, true); $workRequest->best_time = $this->getInput('best_time', null, true); $workRequest->description = $this->getInput('description', null, true); if ($workRequest->save()) { $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true); if ($autoGenerate) { $this->workOrder->createFromWorkRequest($workRequest); } $this->dbCommitTransaction(); return $workRequest; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }
/** * Updates the specified work order session. * * @param int|string $id * * @return bool|WorkOrderSession */ public function update($id) { $this->dbStartTransaction(); $record = $this->find($id); // Validate that the current user is the session holder if ($record->user_id === $this->sentry->getCurrentUserId()) { try { $insert = ['out' => Carbon::now()->toDateTimeString()]; if ($record->update($insert)) { $this->dbCommitTransaction(); return $record; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } } return false; }
/** * Creates or updates a user using LDAP and Sentry. * * @param array $credentials * * @return mixed */ public function createOrUpdateLdapUser(array $credentials) { $loginAttribute = $this->config->setPrefix('cartalyst.sentry')->get('users.login_attribute'); $username = $credentials[$loginAttribute]; $password = $credentials['password']; // If a user is found, update their password to match active-directory $user = $this->model()->where('username', $username)->first(); if ($user) { $this->sentry->updatePasswordById($user->id, $password); } else { // If a user is not found, create their web account $ldapUser = $this->ldap->user($username); $fullName = explode(',', $ldapUser->name); $lastName = array_key_exists(0, $fullName) ? $fullName[0] : null; $firstName = array_key_exists(1, $fullName) ? $fullName[1] : null; $data = ['email' => $ldapUser->email, 'password' => $password, 'username' => $username, 'last_name' => (string) $lastName, 'first_name' => (string) $firstName, 'activated' => 1]; $user = $this->sentry->createUser($data, ['all_users', 'customers', 'workers']); } return $user; }
/** * Creates a new work order. * * @param Request $request * * @return bool|WorkOrder */ public function create(Request $request) { $workOrder = $this->model(); $workOrder->category_id = $request->input('category_id'); $workOrder->location_id = $request->input('location_id'); $workOrder->status_id = $request->input('status', $this->status->createDefaultRequested()->getKey()); $workOrder->priority_id = $request->input('priority', $this->priority->createDefaultRequested()->getKey()); $workOrder->user_id = $this->sentry->getCurrentUserId(); $workOrder->subject = $request->input('subject'); $workOrder->description = $request->clean($request->input('description')); $workOrder->started_at = $request->input('started_at'); $workOrder->completed_at = $request->input('completed_at'); if ($workOrder->save()) { $assets = $request->input('assets'); if (count($assets) > 0) { $workOrder->assets()->sync($assets); } return $workOrder; } return false; }
/** * Processes updating a user. * * @param int|string $id * * @return bool|\Illuminate\Support\Collection|null|static */ public function update($id) { try { $this->dbStartTransaction(); /* * Update the user through Sentry first */ $this->sentry->update($id, $this->input); /* * Now we'll update the extra user details Sentry * doesn't manage */ $user = $this->model->find($id); $insert = ['first_name' => $this->getInput('first_name'), 'last_name' => $this->getInput('last_name')]; if ($user->update($insert)) { $this->dbCommitTransaction(); return $user; } } catch (\Exception $e) { $this->dbRollbackTransaction(); } return false; }