CMS Info for Header, dyn. Tage, API
This commit is contained in:
parent
7294ccc1d0
commit
bed91c4f4a
49 changed files with 3476 additions and 1562 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\HTMLHelper;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
|
|
@ -27,6 +29,10 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @mixin \Eloquent
|
||||
* @property int $wday
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereWday($value)
|
||||
* @property int|null $special
|
||||
* @property string|null $date
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereDate($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereSpecial($value)
|
||||
*/
|
||||
class CMSInfoAvailable extends Model
|
||||
{
|
||||
|
|
@ -34,21 +40,78 @@ class CMSInfoAvailable extends Model
|
|||
protected $table = 'c_m_s_info_availables';
|
||||
|
||||
protected $fillable = [
|
||||
'type', 'wday', 'active', 'from', 'to'
|
||||
'type', 'wday', 'active', 'from', 'to', 'special', 'date'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'active' => 'bool',
|
||||
'special' => 'bool',
|
||||
];
|
||||
|
||||
protected static $days;
|
||||
|
||||
public static function getContentBySlug($type, $wday){
|
||||
return CMSInfoAvailable::whereType($type)->whereWday($wday)->first();
|
||||
public function getDateAttribute()
|
||||
{
|
||||
return isset($this->attributes['date']) ? Carbon::parse($this->attributes['date'])->format('d.m.Y') : '';
|
||||
}
|
||||
|
||||
public static function setContentBySlug($type, $wday, $values){
|
||||
public function setDateAttribute($value)
|
||||
{
|
||||
if (!$value) {
|
||||
$this->attributes['date'] = null;
|
||||
} else {
|
||||
$this->attributes['date'] = Carbon::parse($value)->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
|
||||
$content = CMSInfoAvailable::whereType($type)->whereWday($wday)->first();
|
||||
public static function getWeekWithDate($wday = false)
|
||||
{
|
||||
if(!self::$days){
|
||||
self::createWeekWithDate();
|
||||
}
|
||||
if($wday){
|
||||
return self::$days[$wday];
|
||||
}
|
||||
return self::$days;
|
||||
}
|
||||
public static function createWeekWithDate(){
|
||||
|
||||
$days = HTMLHelper::getDeDays();
|
||||
$now = \Carbon::now();
|
||||
$day_of = $now->dayOfWeekIso;
|
||||
|
||||
//days after now
|
||||
for ($i = $day_of; $i<=7; $i++){
|
||||
$days[$i] = [
|
||||
'name'=>$days[$i],
|
||||
'date'=>$now->format("d.m.Y"),
|
||||
];
|
||||
$now->modify('+1 day');
|
||||
}
|
||||
|
||||
//days before now
|
||||
for ($i = 1; $i<$day_of; $i++) {
|
||||
$days[$i] = [
|
||||
'name'=>$days[$i],
|
||||
'date'=>$now->format("d.m.Y"),
|
||||
];
|
||||
$now->modify('+1 day');
|
||||
}
|
||||
|
||||
//add
|
||||
self::$days = $days;
|
||||
}
|
||||
public static function getContentBySlug($type, $wday, $special = false){
|
||||
$model = CMSInfoAvailable::whereType($type)->whereWday($wday)->whereSpecial($special)->first();
|
||||
if($model){
|
||||
return $model;
|
||||
}
|
||||
return new CMSInfoAvailable();
|
||||
}
|
||||
|
||||
public static function setContentBySlug($type, $wday, $values, $special = false){
|
||||
|
||||
$content = CMSInfoAvailable::whereType($type)->whereWday($wday)->whereSpecial($special)->first();
|
||||
if(!$content) {
|
||||
$content = CMSInfoAvailable::create([
|
||||
'type' => $type,
|
||||
|
|
@ -59,4 +122,46 @@ class CMSInfoAvailable extends Model
|
|||
$content->save();
|
||||
return $content;
|
||||
}
|
||||
|
||||
public static function getSpecialsBy($type){
|
||||
return CMSInfoAvailable::whereType($type)->whereSpecial(true)->get();
|
||||
|
||||
}
|
||||
|
||||
public static function getNextSpecialDateBy($type, $wday){
|
||||
$content = CMSInfoAvailable::whereType($type)->whereWday($wday)->whereSpecial(true)->orderBy('date', 'DESC')->first();
|
||||
$now = \Carbon::now();
|
||||
$week = 7;
|
||||
if($content){
|
||||
$now = \Carbon::parse($content->date);
|
||||
}
|
||||
$day_of = $now->dayOfWeekIso;
|
||||
$week += ($wday - $day_of);
|
||||
$now->modify('+'.$week.' days');
|
||||
return $now;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function fromMinutes (){
|
||||
|
||||
if(strpos($this->from, ":")){
|
||||
$from = explode(":", $this->from);
|
||||
$hours = isset($from[0]) ? (int) $from[0] : 0;
|
||||
$minute = isset($from[1]) ? (int) $from[1] : 0;
|
||||
return $hours * 60 + $minute;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function toMinutes (){
|
||||
|
||||
if(strpos($this->to, ":")){
|
||||
$to = explode(":", $this->to);
|
||||
$hours = isset($to[0]) ? (int) $to[0] : 0;
|
||||
$minute = isset($to[1]) ? (int) $to[1] : 0;
|
||||
return $hours * 60 + $minute;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue