/**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $teachUpload = new Upload();
     if (Request::hasFile('upload')) {
         $file = Request::file('upload');
         $file = $file->move(public_path() . '/uploads/dates', time() . '-' . $file->getClientOriginalName());
         $teachUpload->file_path = $file->getRealPath();
         $teachUpload->save();
         $csvPath = $teachUpload->file_path;
         $reader = Reader::createFromPath($csvPath);
         $reader->setFlags(SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
         $reader->setOffset(1);
         $pattern = '/([(A-Z)|A-Z]* - .+)/';
         $courses = DB::table('courses')->get();
         foreach ($reader as $index => $row) {
             if ($index != 0) {
                 $courseNo = $row[1];
                 $teachDate = $row[5];
                 $startTime = $row[6];
                 $endTime = $row[7];
                 foreach ($courses as $course) {
                     if ($courseNo == $course->course_no) {
                         DB::table('dates')->insert(array('course_id' => $course->id, 'teach_date' => $teachDate, 'session_start' => $startTime, 'session_end' => $endTime));
                     }
                 }
             }
         }
     }
     $teachUpload->save();
     return redirect()->route('admin_dates_index')->with('status', 'Teach dates uploaded');
 }
Exemplo n.º 2
0
 /**
  * Upload the file and store
  * the file path in the DB.
  */
 public function store()
 {
     // Rules
     $rules = array('name' => 'required', 'file' => 'required|max:20000');
     $messages = array('max' => 'Please make sure the file size is not larger then 20MB');
     // Create validation
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $directory = "uploads/files/";
     // Before anything let's make sure a file was uploaded
     if (Input::hasFile('file') && Request::file('file')->isValid()) {
         $current_file = Input::file('file');
         $filename = Auth::id() . '_' . $current_file->getClientOriginalName();
         $current_file->move($directory, $filename);
         $file = new Upload();
         $file->user_id = Auth::id();
         $file->project_id = Input::get('project_id');
         $file->name = Input::get('name');
         $file->path = $directory . $filename;
         $file->save();
         return Redirect::back();
     }
     $upload = new Upload();
     $upload->user_id = Auth::id();
     $upload->project_id = Input::get('project_id');
     $upload->name = Input::get('name');
     $upload->path = $directory . $filename;
     $upload->save();
     return Redirect::back();
 }
Exemplo n.º 3
0
 protected function saveLogo($_user_id, $_file, $_base64_data = false)
 {
     $uid = intval($_user_id);
     if ($uid <= 0) {
         xplog('Invalid user id given', __METHOD__);
         return false;
     }
     $user_company_details = $this->getDetailsByUserId($uid);
     // If logo already exists then delete the file first //
     if (!!$user_company_details && trim($user_company_details->logo) !== '') {
         if (App\Files::isFile($this->logo_dir . '/' . $user_company_details->logo)) {
             App\Cb\Files::deleteAllInstance($this->logo_dir . '/' . $user_company_details->logo);
         }
     }
     if (!$_base64_data) {
         $uploaded_image_details = App\Upload::save($_file, ['destination' => $this->logo_dir . '/']);
     } else {
         $uploaded_image_details = App\Upload::saveBase64($_file->base64, ['destination' => $this->logo_dir . '/', 'extension' => $_file->extension]);
     }
     if (!is_object($uploaded_image_details)) {
         xplog('Unable to save logo', __METHOD__);
         return false;
     }
     // Save in the database //
     $res = DB::table('user_company_details')->where('users_id', $uid)->update(['logo' => $uploaded_image_details->coded_name]);
     if ($res === false) {
         xplog('Unable to save logo in the database', __METHOD__);
         return false;
     }
     return $uploaded_image_details->coded_name;
 }
Exemplo n.º 4
0
 /**
  * Generate unique name based on the
  * uniqid() function
  *
  * @param $file requested file to upload
  */
 public static function put($file)
 {
     if ($file->isValid()) {
         $name = uniqid() . '.' . $file->guessExtension();
         $fileInfo = ['name' => $name, 'type' => $file->getMimeType(), 'size' => $file->getClientSize()];
         $file->move(public_path() . '/uploads', $name);
         $upload = new Upload();
         $upload->name = $fileInfo['name'];
         $upload->type = $fileInfo['type'];
         $upload->size = $fileInfo['size'];
         $upload->save($fileInfo);
         //dd($upload->id);
         return [$upload->id];
     } else {
         return $file->getErrorMessage();
     }
 }
Exemplo n.º 5
0
 protected function save($_property_id, $_files_array = [], $_type = 'doc')
 {
     $pid = intval($_property_id);
     $type = trim(strtolower($_type));
     if ($pid <= 0) {
         xplog('Invalid property id given', __METHOD__);
         return false;
     }
     $insert_data = [];
     $uploaded_file_details = [];
     $destination_dir = $type === 'doc' ? $this->docs_dir . '/' : $this->images_dir . '/';
     foreach ($_files_array as $file) {
         $file = (array) $file;
         $name = isset($file['filename']) ? $file['filename'] : $file['name'];
         if (trim($name) === '') {
             continue;
         }
         if (!isset($file['base64'])) {
             // Web
             $uploaded_file_details = App\Upload::save($file, ['destination' => $destination_dir]);
         } else {
             // Mobile
             $uploaded_file_details = App\Upload::saveBase64($file['base64'], ['destination' => $destination_dir, 'extension' => $file['extension']]);
         }
         if (!is_object($uploaded_file_details)) {
             xplog('Unable to save file "' . $name . '" for property "' . $pid . '"', __METHOD__);
             continue;
         }
         // Gather details for the database //
         $insert_data[] = ['properties_id' => $pid, 'type' => $type === 'doc' ? 'doc' : 'image', 'codedname' => $uploaded_file_details->coded_name, 'filename' => $uploaded_file_details->filename, 'extension' => $uploaded_file_details->extension];
     }
     if (count($insert_data)) {
         // Make sure that their are data to save.
         return is_numeric(DB::table('property_files')->insert($insert_data));
         // Insert the file data to the database
     }
     return true;
 }
Exemplo n.º 6
0
 private function uploadFile($request, $name_input)
 {
     $application_id = $request->input('request_id', 0);
     $file = $request->file($name_input, null);
     $filetype = intval(str_replace('file_', '', $name_input));
     print $filetype;
     $upload = Upload::where('application_id', $application_id)->where('filetype', $filetype)->first();
     if (!$upload) {
         $upload = new Upload();
     }
     if ($request->hasFile($name_input)) {
         if ($upload->file_path) {
             // Remove old file from directory
             if (file_exists($upload->file_path)) {
                 unlink($upload->file_path);
             }
         }
         // Copy new file to directory
         $hash = md5(microtime());
         $fileName = $hash . '.' . $file->getClientOriginalExtension();
         $file->move('file/', $fileName);
         $upload->file_path = 'file/' . $fileName;
         $upload->status = 'uploaded';
         $upload->filetype = $filetype;
         $upload->application_id = $application_id;
         $upload->save();
     }
 }
 public function storeAll()
 {
     $upload = new Upload();
     if (Request::hasFile('upload')) {
         // Gets uploaded file move to courses directory store contents in $reader
         $file = Request::file('upload');
         $file = $file->move(public_path() . '/uploads/courses', time() . '-' . $file->getClientOriginalName());
         $upload->file_path = $file->getRealPath();
         $upload->save();
         $csvPath = $upload->file_path;
         $reader = Reader::createFromPath($csvPath);
         $reader->setFlags(SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY);
         $reader->setOffset(1);
         /**
          * Get data from Centres / Qualifications / Sittings / Papers tables
          * Regex CSV data with exising table data - create new row in Courses
          *
          */
         $pattern = '/([(A-Z)|A-Z]* - .+)/';
         $qualPattern = '/\\b(ACCA|CIMA)\\b/';
         $paperPattern = '/(.)(\\d)/';
         $elementPattern = '/(Tuition|QB Day|QB Evening|Revision|Full Time Short|Full Time Long)/i';
         $methodPattern = '/(Classroom|Live Online|Distance Learning)/i';
         $levelPattern = '/(Skills|Essentials|Options)/i';
         $weekPattern = '/(Weekday|Weekend)/i';
         $centres = DB::table('centres')->get();
         $courses = DB::table('courses')->get();
         $qualifications = DB::table('qualifications')->get();
         $sittings = DB::table('sittings')->get();
         $papers = DB::table('papers')->get();
         foreach ($reader as $index => $row) {
             if ($index != 0) {
                 $centreCode = $row[0];
                 $courseNo = $row[1];
                 $courseName = $row[2];
                 $sittingDate = $row[3];
                 $startDate = $row[5];
                 $courseMethod = $row[8];
                 $status = $row[9];
                 $price = $row[10];
                 $centreId;
                 $sittingId;
                 //Get Course title
                 $courseTitle = preg_match($pattern, $courseName, $courseMatch);
                 //Get qualification Id
                 $courseQual = preg_match($qualPattern, $courseName, $qualMatch);
                 $qual = DB::table('qualifications')->where('qualification_name', $qualMatch[0])->get();
                 $qualId = $qual[0]->id;
                 // Get Paper Id
                 $coursePaper = preg_match($paperPattern, $courseName, $paperMatch);
                 $paper = DB::table('papers')->where('paper_name', $paperMatch[0])->get();
                 $paperId = $paper[0]->id;
                 // Get Method Id
                 $courseMethod = preg_match($methodPattern, $courseMethod, $methodMatch);
                 $method = DB::table('methods')->where('method_name', $methodMatch[0])->get();
                 $methodId = $method[0]->id;
                 // Get Element Id
                 $courseElement = preg_match($elementPattern, $courseName, $elementMatch);
                 $element = DB::table('elements')->where('element_name', $elementMatch[0])->get();
                 $elementId = $element[0]->id;
                 //Get Level Id
                 $courseLevel = preg_match($levelPattern, $courseName, $levelMatch);
                 $level = DB::table('levels')->where('level_name', $levelMatch[0])->get();
                 $levelId = $level[0]->id;
                 //Get Week Id
                 $courseWeek = preg_match($weekPattern, $courseName, $weekMatch);
                 if ($courseWeek != 0) {
                     $week = DB::table('weektimes')->where('name', $weekMatch[0])->get();
                     $weekId = $week[0]->id;
                 } else {
                     $weekId = null;
                 }
                 //Get centre Id
                 foreach ($centres as $centre) {
                     if ($centreCode == $centre->centre_code) {
                         $centreId = $centre->id;
                     }
                 }
                 // Get Sitting Id
                 foreach ($sittings as $sitting) {
                     $sittingVal = $sitting->year . $sitting->month;
                     if ($sittingDate == $sittingVal) {
                         $sittingId = $sitting->id;
                     }
                 }
                 // Insert data into Courses
                 DB::table('courses')->insert(array('course_no' => $courseNo, 'name' => $courseMatch[0], 'start_date' => $startDate, 'price' => $price, 'status' => $status, 'qualification_id' => $qualId, 'centre_id' => $centreId, 'sitting_id' => $sittingId, 'paper_id' => $paperId, 'method_id' => $methodId, 'level_id' => $levelId, 'element_id' => $elementId, 'weektime_id' => $weekId));
             }
         }
     }
     $upload->save();
 }