add methods to get icon on article natures
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use function League\Period\interval_after;
|
||||
use League\Period\Period;
|
||||
|
||||
use function League\Period\interval_after;
|
||||
|
||||
class DateRange
|
||||
{
|
||||
public static function today()
|
||||
@@ -60,9 +61,10 @@ class DateRange
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $withActual = true)
|
||||
{
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
||||
$data = [];
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $withActual));
|
||||
$labels = DateRange::getMonthNames($periods);
|
||||
foreach ($labels as $label) {
|
||||
$data[$label] = $periods;
|
||||
@@ -76,13 +78,12 @@ class DateRange
|
||||
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
||||
public static function getPeriodsLastMonth($nb = 1, $withActual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
||||
$t = self::getPeriodsbyMonth($begin, $end);
|
||||
$end = $withActual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = $nb === 1 ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
||||
|
||||
return self::getPeriodsbyMonth($begin, $end);
|
||||
return self::getPeriodsByMonth($begin, $end);
|
||||
}
|
||||
|
||||
public static function getMonthNamesByPeriods($periods)
|
||||
@@ -106,20 +107,20 @@ class DateRange
|
||||
return $months;
|
||||
}
|
||||
|
||||
public static function getPeriodsLastWeek($nb = 1, $with_actual = true)
|
||||
public static function getPeriodsLastWeek($nb = 1, $withActual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$end = $withActual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
|
||||
return self::getPeriodsbyWeek($begin, $end);
|
||||
return static::getPeriodsByWeek($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
||||
public static function getPeriodsLastDay($nb = 1, $withActual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$end = $withActual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
|
||||
return self::getPeriodsbyDay($begin, $end);
|
||||
return static::getPeriodsByDay($begin, $end);
|
||||
}
|
||||
|
||||
public static function byDay()
|
||||
@@ -156,6 +157,8 @@ class DateRange
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return [$date, $date->addMonth(6)];
|
||||
@@ -181,32 +184,38 @@ class DateRange
|
||||
return Carbon::now()->subDay()->startOfDay();
|
||||
}
|
||||
|
||||
public static function getPeriodsbyMonth($begin, $end, $interval = 1)
|
||||
public static function getPeriodsByMonth($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval MONTH");
|
||||
return self::getPeriods($begin, $end, "{$interval} MONTH");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyWeek($begin, $end, $interval = 1)
|
||||
public static function getPeriodsByWeek($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval WEEK");
|
||||
return self::getPeriods($begin, $end, "{$interval} WEEK");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyDay($begin, $end, $interval = 1)
|
||||
public static function getPeriodsByDay($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval DAY");
|
||||
return self::getPeriods($begin, $end, "{$interval} DAY");
|
||||
}
|
||||
|
||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
||||
public static function getPeriods($begin, $end, $duration)
|
||||
{
|
||||
$period = new Period($begin, $end, $interval);
|
||||
$range = [];
|
||||
$period = new Period($begin, $end);
|
||||
foreach ($period->getDatePeriod($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
$range[] = interval_after($day, $duration);
|
||||
}
|
||||
|
||||
return $daterange;
|
||||
/*
|
||||
foreach ($period->dateRangeForward($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
}
|
||||
*/
|
||||
return $range;
|
||||
}
|
||||
|
||||
public static function PeriodsToCarbon($periods)
|
||||
public static function periodsToCarbon($periods)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($periods as $period) {
|
||||
@@ -216,13 +225,39 @@ class DateRange
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function PeriodToCarbon($period)
|
||||
public static function periodToCarbon($period)
|
||||
{
|
||||
return ['start' => self::DatePointToCarbon($period->getStartDate()), 'end' => self::DatePointToCarbon($period->getEndDate())];
|
||||
return [
|
||||
'start' => self::DatePointToCarbon($period->getStartDate()),
|
||||
'end' => self::DatePointToCarbon($period->getEndDate()),
|
||||
];
|
||||
}
|
||||
|
||||
public static function DatePointToCarbon($date)
|
||||
public static function datePointToCarbon($date)
|
||||
{
|
||||
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function convertPeriod($txt)
|
||||
{
|
||||
return array_values(self::convertDaterange($txt));
|
||||
}
|
||||
|
||||
public static function convertDaterange($txt)
|
||||
{
|
||||
$dates = explode('-', $txt);
|
||||
|
||||
return [
|
||||
'start' => DateTime::convert(trim($dates[0])),
|
||||
'end' => DateTime::convert(trim($dates[1])),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPeriodByLocale($start, $end)
|
||||
{
|
||||
return [
|
||||
'start' => DateTime::convert($start),
|
||||
'end' => DateTime::convert($end),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
@@ -28,60 +28,90 @@ class DateTime
|
||||
return $short ? $date->shortDayName : $date->dayName;
|
||||
}
|
||||
|
||||
public static function DatetoLocale($date = null)
|
||||
public static function getDateTime()
|
||||
{
|
||||
return self::datetimeToLocale(date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function getDate()
|
||||
{
|
||||
return self::dateToLocale(date('Y-m-d'));
|
||||
}
|
||||
|
||||
public static function getLang()
|
||||
{
|
||||
return App::currentLocale();
|
||||
// return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
|
||||
public static function datetoLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
if (! is_null($date) && ! empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
} elseif ($date === 'now') {
|
||||
$date = today()->format($format);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function DatetimeToLocale($date = null)
|
||||
public static function datetimeToLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (! is_null($date) && ! empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
} elseif ($date === 'now') {
|
||||
$date = now()->format($format);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function getDateTime()
|
||||
public static function countDaysFrom($date)
|
||||
{
|
||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
||||
$begin = DateTime::getCarbonTime($date);
|
||||
|
||||
return $begin->diffInDays(now()) + 1;
|
||||
}
|
||||
|
||||
public static function getDate()
|
||||
public static function getCarbonTime($date)
|
||||
{
|
||||
return self::DateToLocale(date('Y-m-d'));
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (strlen($date) === 16) {
|
||||
$date .= ':00';
|
||||
}
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date) : null;
|
||||
}
|
||||
|
||||
public static function getLang()
|
||||
public static function getCarbonDate($date)
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
$format = self::getLocaleFormatDate();
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date) : null;
|
||||
}
|
||||
|
||||
public static function convert($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
||||
return ! empty($date) ? self::getCarbonDate($date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (strlen($date) == 16) {
|
||||
$date .= ':00';
|
||||
}
|
||||
return ! empty($date) ? self::getCarbonTime($date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
public static function toLocale($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
|
||||
return ! empty($date) ? Carbon::parse($date)->Format($format) : null;
|
||||
}
|
||||
|
||||
public static function toISO($date)
|
||||
{
|
||||
return ! empty($date) ? Carbon::parse($date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
@@ -97,7 +127,7 @@ class DateTime
|
||||
public static function getYearFromDate($date)
|
||||
{
|
||||
// return date_format(DateTime::convert($signature_date), 'Y');
|
||||
$date = DateTime::convert($date);
|
||||
$date = self::convert($date);
|
||||
$date = date_create($date);
|
||||
|
||||
return date_format($date, 'Y');
|
||||
@@ -118,6 +148,20 @@ class DateTime
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function checkDateFormat($date)
|
||||
{
|
||||
if (preg_match("/^\d{2}\/\d{2}\/\d{4}$/", $date)) {
|
||||
$day = substr($date, 0, 2);
|
||||
$month = substr($date, 3, 2);
|
||||
$year = substr($date, 6, 4);
|
||||
if (checkdate($month, $day, $year)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getLocaleFormatDatetime()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
@@ -165,7 +209,8 @@ class DateTime
|
||||
return Carbon::parse($date)->isoFormat($format);
|
||||
}
|
||||
|
||||
public static function relativeTime()
|
||||
public static function convertTimeToDate($date)
|
||||
{
|
||||
return substr($date, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,66 @@ use SoftCreatR\MimeDetector\MimeDetectorException;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function copy($source, $target)
|
||||
{
|
||||
$source = self::sanitize($source);
|
||||
$target = self::sanitize($target);
|
||||
if (! self::checkFile($source)) {
|
||||
return false;
|
||||
}
|
||||
$dirname = self::relative(dirname($target));
|
||||
self::checkDirOrCreate($dirname);
|
||||
|
||||
return copy($source, $target);
|
||||
}
|
||||
|
||||
public static function checkDirOrCreate($dir)
|
||||
{
|
||||
return self::checkDir($dir) ? true : self::createDir($dir);
|
||||
}
|
||||
|
||||
public static function sanitize($filename)
|
||||
{
|
||||
return str_replace('\\', '/', $filename);
|
||||
}
|
||||
|
||||
public static function relative($filename)
|
||||
{
|
||||
return str_replace(self::getStorageAppPath(), '', $filename);
|
||||
}
|
||||
|
||||
public static function getStorageAppPath()
|
||||
{
|
||||
return self::sanitize(storage_path()).'/app';
|
||||
}
|
||||
|
||||
public static function getTree($path)
|
||||
{
|
||||
$tree = [];
|
||||
|
||||
$branch = [
|
||||
'label' => basename($path),
|
||||
];
|
||||
|
||||
foreach (\File::files($path) as $file) {
|
||||
$branch['children'][] = basename($file);
|
||||
}
|
||||
|
||||
foreach (\File::directories($path) as $directory) {
|
||||
$branch['children'][] = self::getTree($directory);
|
||||
}
|
||||
|
||||
return array_merge($tree, $branch);
|
||||
}
|
||||
|
||||
public static function list($dir, $mask = '/*')
|
||||
{
|
||||
return glob($dir);
|
||||
}
|
||||
|
||||
public static function checkDir($dir)
|
||||
{
|
||||
// return File::isDirectory($dir)
|
||||
return is_dir($dir);
|
||||
}
|
||||
|
||||
@@ -25,19 +78,17 @@ class File
|
||||
|
||||
public static function createDir($dir)
|
||||
{
|
||||
return mkdir($dir, '0777', true);
|
||||
return Storage::makeDirectory($dir);
|
||||
}
|
||||
|
||||
public static function deleteDir($dir)
|
||||
{
|
||||
Storage::deleteDirectory($dir);
|
||||
|
||||
return true;
|
||||
return Storage::deleteDirectory($dir);
|
||||
}
|
||||
|
||||
public static function createFile($file, $content)
|
||||
{
|
||||
Storage::put($file, $content);
|
||||
return Storage::put($file, $content);
|
||||
}
|
||||
|
||||
public static function getFile($file)
|
||||
@@ -68,4 +119,27 @@ class File
|
||||
exit('An error occured while trying to load the given file.');
|
||||
}
|
||||
}
|
||||
|
||||
public static function replaceInFile($path, $string, $replace)
|
||||
{
|
||||
set_time_limit(0);
|
||||
$temp = false;
|
||||
|
||||
if (is_file($path) === true) {
|
||||
$file = fopen($path, 'r');
|
||||
$temp = tempnam('./', 'tmp');
|
||||
|
||||
if (is_resource($file) === true) {
|
||||
while (feof($file) === false) {
|
||||
file_put_contents($temp, str_replace($string, $replace, fgets($file)), FILE_APPEND);
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
return $temp ? rename($temp, $path) : false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ use Carbon\Carbon;
|
||||
|
||||
class HelperDate
|
||||
{
|
||||
public static $is_debug = true;
|
||||
|
||||
public static function toLocaleFormat($date)
|
||||
{
|
||||
if (! (! is_null($date) && ! empty($date))) {
|
||||
@@ -24,9 +22,8 @@ class HelperDate
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
}
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
|
||||
return $date;
|
||||
return Carbon::parse($date)->format($format);
|
||||
}
|
||||
|
||||
public static function fromLocale($d)
|
||||
@@ -61,7 +58,7 @@ class HelperDate
|
||||
|
||||
public static function toFrenchDate($d)
|
||||
{
|
||||
if ($d && $d != '0000-00-00') {
|
||||
if ($d && $d !== '0000-00-00') {
|
||||
return Carbon::createFromFormat('Y-m-d', $d)->format('d/m/Y');
|
||||
}
|
||||
|
||||
|
||||
31
app/Repositories/Core/MediaPathGenerator.php
Normal file
31
app/Repositories/Core/MediaPathGenerator.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator;
|
||||
|
||||
class MediaPathGenerator implements PathGenerator
|
||||
{
|
||||
public function getPath(Media $media): string
|
||||
{
|
||||
return $this->getBasePath($media).'/';
|
||||
}
|
||||
|
||||
public function getPathForConversions(Media $media): string
|
||||
{
|
||||
return $this->getBasePath($media).'/conversions/';
|
||||
}
|
||||
|
||||
public function getPathForResponsiveImages(Media $media): string
|
||||
{
|
||||
return $this->getBasePath($media).'/responsive-images/';
|
||||
}
|
||||
|
||||
protected function getBasePath(Media $media): string
|
||||
{
|
||||
$model = basename(str_replace('\\', '/', $media->model_type));
|
||||
|
||||
return basename($model).'/images/'.$media->getKey();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,16 @@ class Storage
|
||||
return Storage2::disk('local')->has($dir);
|
||||
}
|
||||
|
||||
public static function move($source, $target)
|
||||
{
|
||||
return Storage2::move($source, $target);
|
||||
}
|
||||
|
||||
public static function copy($source, $target)
|
||||
{
|
||||
return Storage2::copy($source, $target);
|
||||
}
|
||||
|
||||
public static function checkFile($file)
|
||||
{
|
||||
return Storage2::exists($file);
|
||||
|
||||
Reference in New Issue
Block a user