isEmpty()) { return Carbon::now()->year . '00001'; } else { return (int)$invoices->last()->order + 1; } } function get_invoice_data($user, $plan) { $subscription = $user->subscription('main'); $order_number = get_invoice_number(); $token = \Illuminate\Support\Str::random(22); return [ 'token' => $token, 'order' => $order_number, 'user_id' => $user->id, 'plan_id' => $plan->id, 'total' => $plan->price, 'currency' => 'USD', 'bag' => [ [ 'description' => 'Subscription - ' . $plan->name, 'date' => format_date($subscription->starts_at, '%d. %B. %Y') . ' - ' . format_date($subscription->ends_at, '%d. %B. %Y'), 'amount' => $plan->price, ] ], 'seller' => [ 'billing_name' => 'VueFileManager', 'billing_address' => 'Somewhere 32', 'billing_state' => 'Washington', 'billing_city' => 'Manchester', 'billing_postal_code' => '04001', 'billing_country' => 'The USA', 'billing_phone_number' => '490321-6354774', 'billing_vat_number' => '7354724626246', ], 'client' => [ 'billing_name' => $user->settings->billing_name, 'billing_address' => $user->settings->billing_address, 'billing_state' => $user->settings->billing_state, 'billing_city' => $user->settings->billing_city, 'billing_postal_code' => $user->settings->billing_postal_code, 'billing_country' => $user->settings->billing_country, 'billing_phone_number' => $user->settings->billing_phone_number, ], ]; } /** * Get app version from config * * @return \Illuminate\Config\Repository|mixed */ function get_storage() { return env('FILESYSTEM_DRIVER'); } /** * Check if is running AWS s3 as storage * * @return bool */ function is_storage_driver($driver) { if (is_array($driver)) { return in_array(env('FILESYSTEM_DRIVER'), $driver); } return env('FILESYSTEM_DRIVER') === $driver; } /** * Get app version from config * * @return \Illuminate\Config\Repository|mixed */ function get_version() { return config('vuefilemanager.version'); } /** * Check if is demo * * @return mixed */ function is_demo($user_id) { return env('APP_DEMO', false) && $user_id === 1; } /** * Get folder or file item * * @param $type * @param $unique_id * @param $user_id * @return \Illuminate\Database\Eloquent\Builder|Model */ function get_item($type, $unique_id, $user_id) { if ($type === 'folder') { // Return folder item return FileManagerFolder::where('unique_id', $unique_id) ->where('user_id', $user_id) ->firstOrFail(); } // Return file item return FileManagerFile::where('unique_id', $unique_id) ->where('user_id', $user_id) ->firstOrFail(); } /** * Get shared token * * @param $token * @return \Illuminate\Database\Eloquent\Builder|Model */ function get_shared($token) { return Share::where(DB::raw('BINARY `token`'), $token) ->firstOrFail(); } /** * Check if shared permission is editor * * @param $shared * @return bool */ function is_editor($shared) { return $shared->permission === 'editor'; } /** * Get unique id * * @return int */ function get_unique_id(): int { // Get files and folders $folders = FileManagerFolder::withTrashed()->get(); $files = FileManagerFile::withTrashed()->get(); // Get last ids $folders_unique = $folders->isEmpty() ? 0 : $folders->last()->unique_id; $files_unique = $files->isEmpty() ? 0 : $files->last()->unique_id; // Count new unique id $unique_id = $folders_unique > $files_unique ? $folders_unique + 1 : $files_unique + 1; return $unique_id; } /** * Store user avatar to storage * * @param $image * @param $path * @return string */ function store_avatar($image, $path) { // Get directory $path = check_directory($path); // Store avatar $image_path = Str::random(8) . '-' . $image->getClientOriginalName(); // Create intervention image $img = Image::make($image->getRealPath()); // Generate thumbnail $img->fit('150', '150')->stream(); // Store thumbnail to disk Storage::put($path . '/' . $image_path, $img); // Return path to image return $path . '/' . $image_path; } /** * Check if directory exist, if no, then create it * * @param $directory * @return mixed */ function check_directory($directory) { if (!Storage::exists($directory)) { Storage::makeDirectory($directory); } return $directory; } /** * Make input from request * * @param $request * @return array */ function make_single_input($request) { // Create container $data = []; // Add data to array $data[$request->name] = $request->value; // Return input return $data; } /** * Format integer to gigabytes * * @param $gigabytes * @return string */ function format_gigabytes($gigabytes) { if ($gigabytes >= 1000) { return Metric::gigabytes($gigabytes)->format('Tb/'); } else { return Metric::gigabytes($gigabytes)->format('GB/'); } } /** * Get storage usage in percent * * @param $used * @param $capacity * @return string */ function get_storage_fill_percentage($used, $capacity) { // Format gigabytes to bytes $total = intval(Metric::gigabytes($capacity)->numberOfBytes()); // Count progress $progress = ($used * 100) / $total; // Return in 2 decimal return number_format((float)$progress, 2, '.', ''); } /** * Get user capacity fill percentage * * @return string */ function user_storage_percentage() { $user = Auth::user(); return get_storage_fill_percentage($user->used_capacity, $user->settings->storage_capacity); } /** * Find all key values in recursive array * * @param array $array * @param $needle * @return array */ function recursiveFind(array $array, $needle) { $iterator = new RecursiveArrayIterator($array); $recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST); $aHitList = array(); foreach ($recursive as $key => $value) { if ($key === $needle) { array_push($aHitList, $value); } } return $aHitList; } /** * Get values which appears only once in array * @param $arr * @return array */ function appeared_once($arr) { $array_count_values = array_count_values($arr); $single_time_comming_values_array = []; foreach ($array_count_values as $key => $val) { if ($val == 1) { $single_time_comming_values_array[] = $key; } } return $single_time_comming_values_array; } /** * @param $folders * @return array */ function filter_folders_ids($folders, $by_column = 'unique_id') { $folder_unique_ids = recursiveFind($folders->toArray(), $by_column); return appeared_once($folder_unique_ids); } /** * Format localized date * * @param $date * @param string $format * @return string */ function format_date($date, $format = '%d. %B. %Y, %H:%M') { $start = Carbon::parse($date); return $start->formatLocalized($format); } /** * Get file type from mimetype * * @param $file * @return string */ function get_file_type($file) { // Get mimetype from file $mimetype = explode('/', $file->getMimeType()); switch ($mimetype[0]) { case 'image': return 'image'; break; case 'video': return 'video'; break; case 'audio': return 'audio'; break; default: return 'file'; } }