Esempio n. 1
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;
 }
Esempio n. 2
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;
 }