'bool',
'special' => 'bool',
];
protected static $days;
public function getDateAttribute()
{
return isset($this->attributes['date']) ? Carbon::parse($this->attributes['date'])->format('d.m.Y') : '';
}
public function setDateAttribute($value)
{
if (!$value) {
$this->attributes['date'] = null;
} else {
$this->attributes['date'] = Carbon::parse($value)->format('Y-m-d');
}
}
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,
'wday' => $wday,
]);
}
$content->fill($values);
$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;
}
}