Cleanup, fix static date property error

This commit is contained in:
Toby Zerner 2015-07-01 16:47:07 +09:30
parent 009b479197
commit 52e55bd503
4 changed files with 24 additions and 13 deletions

View File

@ -45,7 +45,7 @@ class Discussion extends Model
* *
* @var array * @var array
*/ */
protected static $dates = ['start_time', 'last_time']; protected static $dateAttributes = ['start_time', 'last_time'];
/** /**
* The user for which the state relationship should be loaded. * The user for which the state relationship should be loaded.

View File

@ -1,9 +1,20 @@
<?php namespace Flarum\Core\Models; <?php namespace Flarum\Core\Models;
use Flarum\Core\Events\DiscussionWasRead; use Flarum\Core\Events\DiscussionWasRead;
use Flarum\Core\Support\EventGenerator;
use Illuminate\Database\Eloquent\Builder;
/**
* Models a discussion-user state record in the database.
*
* Stores information about how much of a discussion a user has read. Can also
* be used to store other information, if the appropriate columns are added to
* the database, like a user's subscription status for a discussion.
*/
class DiscussionState extends Model class DiscussionState extends Model
{ {
use EventGenerator;
/** /**
* The table associated with the model. * The table associated with the model.
* *
@ -16,11 +27,11 @@ class DiscussionState extends Model
* *
* @var array * @var array
*/ */
protected $dates = ['read_time']; protected static $dateAttributes = ['read_time'];
/** /**
* Mark the discussion as read to a certain point by updating that state's * Mark the discussion as being read up to a certain point. Raises the
* data. * DiscussionWasRead event.
* *
* @param int $number * @param int $number
* @return $this * @return $this
@ -63,7 +74,7 @@ class DiscussionState extends Model
* @param \Illuminate\Database\Eloquent\Builder $query * @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
protected function setKeysForSaveQuery(\Illuminate\Database\Eloquent\Builder $query) protected function setKeysForSaveQuery(Builder $query)
{ {
$query->where('discussion_id', $this->discussion_id) $query->where('discussion_id', $this->discussion_id)
->where('user_id', $this->user_id); ->where('user_id', $this->user_id);

View File

@ -35,14 +35,14 @@ abstract class Model extends Eloquent
* *
* @var array * @var array
*/ */
public static $dates = []; protected static $dateAttributes = [];
/** /**
* The validation rules for this model. * The validation rules for this model.
* *
* @var array * @var array
*/ */
protected static $rules = []; public static $rules = [];
/** /**
* An array of custom relation methods, grouped by subclass. * An array of custom relation methods, grouped by subclass.
@ -176,7 +176,7 @@ abstract class Model extends Eloquent
*/ */
public function getDates() public function getDates()
{ {
return static::$dates; return array_merge(static::$dateAttributes, $this->dates);
} }
/** /**
@ -184,9 +184,9 @@ abstract class Model extends Eloquent
* *
* @param string $attribute * @param string $attribute
*/ */
public static function addDate($attribute) public static function addDateAttribute($attribute)
{ {
static::$dates[] = $attribute; static::$dateAttributes[] = $attribute;
} }
/** /**

View File

@ -90,7 +90,7 @@ class Model implements ExtenderInterface
} }
foreach ($this->dates as $attribute) { foreach ($this->dates as $attribute) {
$model::addDate($attribute); $model::addDateAttribute($attribute);
} }
} }
} }