Skip to content

Commit

Permalink
Init widget manager in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Jun 9, 2016
1 parent e2fb052 commit 2bf82c3
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions src/Model/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
use DB;
use KodiCMS\Pages\Model\Page;
use Illuminate\Database\Eloquent\Model;
use KodiCMS\Widgets\Contracts\Model as WidgetContract;
use KodiCMS\Widgets\Manager\WidgetManagerDatabase;
use KodiCMS\Widgets\Traits\WidgetStates;
use KodiCMS\Widgets\Contracts\WidgetManager;
use KodiCMS\Widgets\Widget\Temp as TempWidget;
use KodiCMS\Widgets\Exceptions\WidgetException;
use KodiCMS\Widgets\Manager\WidgetManagerDatabase;
use KodiComponents\Support\Filterable;

class Widget extends Model implements WidgetContract
class Widget extends Model
{
use Filterable, WidgetStates;
use Filterable;

/**
* @var array
Expand Down Expand Up @@ -54,7 +51,7 @@ class Widget extends Model implements WidgetContract
protected $widget = null;

/**
* @var WidgetManagerDatabase
* @var WidgetManager
*/
protected $manager;

Expand All @@ -66,18 +63,9 @@ class Widget extends Model implements WidgetContract
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->manager = app('widget.manager');
}

/**
* @return string
*/
public function getWidgetClass()
{
return get_class($this->toWidget());
}

/**
* @param string $template
*/
Expand All @@ -91,7 +79,7 @@ public function setTemplateAttribute($template)
*/
public function getType()
{
$types = app('widget.manager')->getAvailableTypes();
$types = $this->manager->getAvailableTypes();

foreach ($types as $type) {
if ($type->getType() == $this->type) {
Expand Down Expand Up @@ -135,6 +123,54 @@ public function toWidget()
return $this->widget;
}

/**
* @return bool
*/
public function isWidgetable()
{
return ($this->exists and $this->manager->isWidgetable(get_class($this->toWidget())));
}

/**
* @return bool
*/
public function isHandler()
{
return $this->manager->isHandler(get_class($this->toWidget()));
}

/**
* @return bool
*/
public function isRenderable()
{
return $this->manager->isRenderable(get_class($this->toWidget()));
}

/**
* @return bool
*/
public function isCacheable()
{
return $this->manager->isCacheable(get_class($this->toWidget()));
}

/**
* @return bool
*/
public function isClassExists()
{
return $this->manager->isClassExists(get_class($this->toWidget()));
}

/**
* @return bool
*/
public function isCorrupt()
{
return $this->manager->isCorrupt(get_class($this->toWidget()));
}

public function scopeFilterByType($query, array $types)
{
if (count($types) > 0) {
Expand Down

0 comments on commit 2bf82c3

Please sign in to comment.