Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…gets

Conflicts:
	src/Model/Widget.php
	src/Providers/ModuleServiceProvider.php
  • Loading branch information
butschster committed Jun 9, 2016
2 parents 0c8551d + cbe493f commit e2fb052
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 238 deletions.
60 changes: 60 additions & 0 deletions src/Contracts/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace KodiCMS\Widgets\Contracts;

use KodiCMS\Widgets\Exceptions\WidgetException;

interface Model
{

/**
* @return string
*/
public function getWidgetClass();

/**
* @return string
*/
public function getType();

/**
* @return \KodiCMS\Widgets\Contracts\Widget|null
* @throws WidgetException
*/
public function toWidget();

/**
* @return bool
*/
public function isWidgetable();

/**
* @return bool
*/
public function isHandler();

/**
* @return bool
*/
public function isRenderable();

/**
* @return bool
*/
public function isCacheable();

/**
* @return bool
*/
public function isClassExists();

/**
* @return bool
*/
public function isCorrupt();

/**
* @return array
*/
public function getLocations();
}
85 changes: 32 additions & 53 deletions src/Model/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
use DB;
use KodiCMS\Pages\Model\Page;
use Illuminate\Database\Eloquent\Model;
use KodiCMS\Widgets\Contracts\WidgetManager;
use KodiCMS\Widgets\Contracts\Model as WidgetContract;
use KodiCMS\Widgets\Manager\WidgetManagerDatabase;
use KodiCMS\Widgets\Traits\WidgetStates;
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
class Widget extends Model implements WidgetContract
{
use Filterable;
use Filterable, WidgetStates;

/**
* @var array
Expand Down Expand Up @@ -51,6 +53,31 @@ class Widget extends Model
*/
protected $widget = null;

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

/**
* Widget constructor.
*
* @param array $attributes
*/
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 Down Expand Up @@ -91,7 +118,7 @@ public function toWidget()
return $this->widget;
}

if (! is_null($this->widget = app('widget.manager')->makeWidget($this->type, $this->name, $this->description, $this->settings))) {
if (! is_null($this->widget = $this->manager->makeWidget($this->type, $this->name, $this->description, $this->settings))) {
$this->widget->setId($this->id);

if ($this->isRenderable()) {
Expand All @@ -100,62 +127,14 @@ public function toWidget()

$this->widget->setRalatedWidgets($this->related);
} else {
$this->widget = new TempWidget(app('widget.manager'), $this->name, $this->description);
$this->widget = new TempWidget($this->manager, $this->name, $this->description);
}

static::$cachedWidgets[$this->id] = $this->widget;

return $this->widget;
}

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

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

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

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

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

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

public function scopeFilterByType($query, array $types)
{
if (count($types) > 0) {
Expand Down
10 changes: 9 additions & 1 deletion src/Providers/EventsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ public function boot(DispatcherContract $events)

$events->listen('view.page.edit', function ($page) {
if (acl_check('widgets::list') and $page->hasLayout()) {
echo view('widgets::widgets.page.iframe', compact('page'))->render();
// echo view('widgets::widgets.page.iframe', compact('page'))->render();

echo view('widgets::widgets.page.list', [
'page' => $page,
'widgetsCollection' => new PageWidgetCollection(
app('widget.manager'),
$page->id
)
])->render();
}
});

Expand Down
5 changes: 3 additions & 2 deletions src/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public function register()
$this->app->singleton('widget.manager', function () {
return new WidgetManagerDatabase();
});

$this->app->alias('widget.manager', WidgetManager::class);


$this->app['view']->addNamespace('snippets', snippets_path());

$this->registerProviders([
BladeServiceProvider::class,
EventsServiceProvider::class,
Expand Down
1 change: 0 additions & 1 deletion src/Repository/WidgetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace KodiCMS\Widgets\Repository;

use DB;
use Illuminate\Http\Request;
use KodiCMS\Widgets\Model\Widget;
use KodiCMS\CMS\Repository\BaseRepository;

Expand Down
55 changes: 55 additions & 0 deletions src/Traits/WidgetStates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace KodiCMS\Widgets\Traits;


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

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

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

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

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

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

0 comments on commit e2fb052

Please sign in to comment.