コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return \Illuminate\Http\Response
  */
 public function store(SiteIssueRequest $request)
 {
     // Check authorisation and throw 404 if not
     if (!Auth::user()->allowedTo('add', 'issue.report')) {
         return view('errors/404');
     }
     $issue_request = $request->except('action');
     $site = Site::findOrFail($issue_request['site_id']);
     $issue = SiteIssue::create($issue_request);
     //Create action taken + attach image to issue
     if ($issue) {
         $action_request = $request->only('action');
         $action = $issue->actions()->save(new SiteIssueAction($action_request));
         // Handle attached Photo or Video
         if ($request->hasFile('media')) {
             $issue->saveAttachedMedia($request->file('media'));
         }
         // Email issue
         $issue->emailIssue($action);
     }
     Toastr::success("Lodged safety issue");
     $worksite = Site::findOrFail($issue_request['site_id']);
     return view('pages/home', compact('worksite'));
 }
コード例 #2
0
 /**
  * Migrate Issues
  */
 public function issues()
 {
     echo "<h1>Migrating Site Actions</h1>";
     $issues = zAction::all();
     $issues->each(function ($issue) {
         echo "<b>" . $issue->jobnum . "</b>({$issue->sub_id})<br>";
         if ($issue->jobnum) {
             if ($issue->jobnum == '003') {
                 $issue->jobnum = '0003';
             }
             $site = Site::where('code', $issue->jobnum)->first();
             $user = User::where('username', $issue->sub_id)->first();
             $status = '1';
             if ($issue->resolved == "y") {
                 $status = '0';
             }
             $req = '1';
             if ($issue->codreq == "y") {
                 $req = '0';
             }
             $newIssue = SiteIssue::create(array('site_id' => $site->id, 'reason' => reformatOldStr($issue->reason), 'action_required' => $req, 'notes' => reformatOldStr($issue->notes), 'resolved_date' => $issue->resdate, 'status' => $status, 'created_at' => $issue->date, 'updated_at' => $issue->date, 'created_by' => $user->id));
             if ($issue->photo) {
                 list($s, $u, $photo) = explode('_', $issue->photo, 3);
                 $newIssue->photo = 'issue-' . $site->code . '-' . $newIssue->id . '-' . $user->id . '-' . $photo;
                 $newIssue->save();
                 // Copy file to new location
                 if (file_exists('filebankOrig/photos/' . $issue->photo)) {
                     $dir = 'filebank/site/' . $site->id . '/issue/';
                     $newfile = $dir . $newIssue->photo;
                     if (!file_exists($dir)) {
                         mkdir($dir, 0777, true);
                         echo "created directory {$dir} <br>";
                     }
                     if (!file_exists($newfile)) {
                         echo "copying to {$newfile}<br>";
                         if (!copy('filebankOrig/photos/' . $issue->photo, $newfile)) {
                             echo "*** FAILED to copy {$issue->photo}...\n";
                         }
                     }
                 }
             }
             $newIssueAction = SiteIssueAction::create(array('issue_id' => $newIssue->id, 'action' => reformatOldStr($issue->sub_action), 'created_by' => $user->id, 'created_at' => $issue->date, 'updated_at' => $issue->date));
             $site_super = $site->supervisors->pluck('id')->toArray();
             if ($issue->cod_action) {
                 $newIssueAction2 = SiteIssueAction::create(array('issue_id' => $newIssue->id, 'action' => reformatOldStr($issue->cod_action), 'created_by' => $site_super[0], 'created_at' => $issue->date, 'updated_at' => $issue->date));
             }
             if ($issue->notes) {
                 $newIssueAction3 = SiteIssueAction::create(array('issue_id' => $newIssue->id, 'action' => reformatOldStr($issue->notes), 'created_by' => $site_super[0], 'created_at' => $issue->resdate, 'updated_at' => $issue->resdate));
             }
         }
     });
     echo "<h1>Completed</h1>";
 }