Ejemplo n.º 1
0
 public function addFile(Request $request)
 {
     if ($request->hasFile('file')) {
         $file = $request->file('file');
         $entry = new FileRecord();
         $entry->mime = $file->getClientMimeType();
         $entry->filename = $file->getClientOriginalName();
         $entry->total_versions = 1;
         $entry->public_version = 1;
         $entry->owner_id = Auth::User()->id;
         $users = [];
         $departments = [];
         $mass = "0";
         $sharing_array = ['users' => $users, 'departments' => $departments, 'mass' => $mass];
         $sharing = json_encode($sharing_array);
         $entry->sharing = $sharing;
         $entry->doc_type_id = 1;
         $version = $entry->total_versions - 1;
         $note = "Initial upload";
         $date = Carbon::now();
         $user = Auth::User()->fname . ' ' . Auth::User()->lname;
         $versionArray = [$version => array('user' => $user, 'stamp' => $date, 'note' => $note)];
         $finalVer = json_encode($versionArray);
         $entry->version_details = $finalVer;
         $entry->save();
         Storage::disk('local')->put(Auth::User()->id . $entry->id . $file->getClientOriginalName() . "/1", File::get($file));
         //Email Section
         $admins = User::get()->where('user_type_id', 1);
         $uploader = Auth::user()->fname . " " . Auth::user()->lname . " (" . Auth::user()->username . ")";
         $data = ['uploader' => $uploader, 'fileName' => $entry->filename, 'id' => $entry->id];
         foreach ($admins as $admin) {
             Mail::queue('mail.newUpload', $data, function ($message) use(&$admin) {
                 $message->to($admin->email, 'Admin')->subject('New Upload');
             });
         }
     } else {
         return "No file";
     }
 }
 public function addAchievement(Request $request)
 {
     /*
      * This part takes the data from the file and sets them
      * to the appropriate field in each model for the File
      * Record table.
      */
     $file = $request->file('file');
     $entry = new FileRecord();
     $entry->mime = $file->getClientMimeType();
     $entry->filename = $request->name;
     $entry->total_versions = 1;
     $entry->public_version = 1;
     $entry->owner_id = Auth::User()->id;
     $users = [];
     $departments = [];
     $mass = "0";
     $sharing_array = ['users' => $users, 'departments' => $departments, 'mass' => $mass];
     $sharing = json_encode($sharing_array);
     $entry->sharing = $sharing;
     $entry->doc_type_id = 2;
     $entry->save();
     // End of FileRecord storing section.
     /*
      * This part instantiates a new Achievement modal. This handles
      * the part of the request that contains all the details  of the
      * uploaded credential.
      */
     $achievement = new Achievements();
     $achievement->name = $request->name;
     $achievement->received = $request->received;
     $achievement->type = $request->type;
     $achievement->validity = $request->validity;
     $achievement->details = $request->details;
     $achievement->achievement_id = $entry->id;
     $achievement->save();
     // End of Achievement storing section.
     /*
      * This is where the file gets stored into the server's disk.
      * The file's location is defined as: <userID><fileID><fileName>
      */
     Storage::disk('local')->put(Auth::User()->id . $entry->id . $request->name . "/1", File::get($file));
     // At this point, the file has been successfully saved.
     /*
      * This part handles sending emails to the system admins and HR
      * to notify them of a new credential. This way, HR knows that
      * there is a credential they need to verify.
      */
     $admins = User::get()->where('user_type_id', 1);
     $hrs = User::get()->where('user_dept_id', 2);
     $uploader = Auth::user()->fname . " " . Auth::user()->lname . " (" . Auth::user()->username . ")";
     $data = ['uploader' => $uploader, 'fileName' => $entry->filename, 'id' => $entry->id];
     foreach ($admins as $admin) {
         Mail::queue('mail.newUpload', $data, function ($message) use(&$admin) {
             $message->to($admin->email, 'Admin')->subject('New Upload');
         });
     }
     foreach ($hrs as $hr) {
         Mail::queue('mail.newUpload', $data, function ($message) use(&$hr) {
             $message->to($hr->email, 'Admin')->subject('New Achievement Upload');
         });
     }
     // End of email sender section.
     return redirect('/dashboard/awards');
 }