Cleaned book-show and page sidebar by hiding inactive chapter contents

This commit is contained in:
Dan Brown
2015-11-29 18:06:55 +00:00
parent 62338e4a8f
commit 03096c2fcd
4 changed files with 51 additions and 7 deletions

View File

@ -36,6 +36,32 @@ abstract class Entity extends Model
return [get_class($this), $this->id] === [get_class($entity), $entity->id];
}
/**
* Checks if an entity matches or contains another given entity.
* @param Entity $entity
* @return bool
*/
public function matchesOrContains(Entity $entity)
{
$matches = [get_class($this), $this->id] === [get_class($entity), $entity->id];
if ($matches) return true;
if ($entity->isA('chapter') && $this->isA('book')) {
return $entity->book_id === $this->id;
}
if ($entity->isA('page') && $this->isA('book')) {
return $entity->book_id === $this->id;
}
if ($entity->isA('page') && $this->isA('chapter')) {
return $entity->chapter_id === $this->id;
}
return false;
}
/**
* Gets the activity objects for this entity.
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
@ -106,7 +132,7 @@ abstract class Entity extends Model
$search = $search->with('book');
}
if(static::isA('page')) {
if (static::isA('page')) {
$search = $search->with('chapter');
}