Skip to content

Commit

Permalink
update ecjia/system
Browse files Browse the repository at this point in the history
  • Loading branch information
王正东 committed Jan 28, 2021
1 parent ce3a349 commit 3b5d5ed
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
10 changes: 10 additions & 0 deletions content/system/classes/Notifications/DatabaseNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Ecjia\System\Notifications;

class DatabaseNotification extends \Royalcms\Component\Notifications\DatabaseNotification
{
use Timestamp;


}
24 changes: 24 additions & 0 deletions content/system/classes/Notifications/NotifiableModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php


namespace Ecjia\System\Notifications;


use Royalcms\Component\Notifications\Notifiable;
use Royalcms\Component\Database\Eloquent\Model;

class NotifiableModel extends Model
{
use Notifiable;

/**
* Get the entity's notifications.
*
* @return \Royalcms\Component\Database\Eloquent\Relations\MorphMany
*/
public function notifications()
{
return $this->morphMany(DatabaseNotification::class, 'notifiable')->orderBy('created_at', 'desc');
}

}
41 changes: 41 additions & 0 deletions content/system/classes/Notifications/Timestamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php


namespace Ecjia\System\Notifications;


trait Timestamp
{

public function getCreatedAtAttribute($raw_time)
{
return $this->changeTimeZone($raw_time, '', config('system.timezone'));
}

public function getUpdatedAtAttribute($raw_time)
{
return $this->changeTimeZone($raw_time, '', config('system.timezone'));
}

public function changeTimeZone($dateString, $timeZoneSource = null, $timeZoneTarget = null)
{

if (empty($timeZoneSource)) {
$timeZoneSource = date_default_timezone_get();
}
if (empty($timeZoneTarget)) {
$timeZoneTarget = date_default_timezone_get();
}

try {
$dt = new \DateTime($dateString, new \DateTimeZone($timeZoneSource));
$dt->setTimezone(new \DateTimeZone($timeZoneTarget));
return $dt->format('Y-m-d H:i:s');
} catch (\Exception $e) {
ecjia_log_error($e->getMessage());
}

return $dateString;
}

}
7 changes: 2 additions & 5 deletions content/system/classes/admin/ecjia_admin_notifiable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,10 @@
//
// ---------------------------------------------------------------------------------
//
use Royalcms\Component\Notifications\Notifiable;
use Royalcms\Component\Database\Eloquent\Model;
use Ecjia\System\Notifications\NotifiableModel;

class ecjia_admin_notifiable extends Model
class ecjia_admin_notifiable extends NotifiableModel
{
use Notifiable;

/**
* The table associated with the model.
*
Expand Down

0 comments on commit 3b5d5ed

Please sign in to comment.