Commit a012b7e9 authored by Christopher Stebe's avatar Christopher Stebe

added global route option, adjust widget content query, add some code docs, cleanup

parent ae460eb8
......@@ -3,6 +3,7 @@
namespace hrzg\widget\models\crud;
use hrzg\widget\models\crud\base\Widget as BaseWidget;
use hrzg\widget\widgets\Cell;
use yii\helpers\ArrayHelper;
/**
......@@ -10,6 +11,10 @@ use yii\helpers\ArrayHelper;
*/
class WidgetContent extends BaseWidget
{
/**
* @inheritdoc
* @return array
*/
public function rules()
{
return ArrayHelper::merge(
......@@ -20,6 +25,25 @@ class WidgetContent extends BaseWidget
);
}
/**
* Global route needs empty request param
* @param bool $insert
*
* @return bool
*/
public function beforeSave($insert)
{
parent::beforeSave($insert);
if ($this->route === Cell::GLOBAL_ROUTE) {
$this->request_param = Cell::EMPTY_REQUEST_PARAM;
}
return true;
}
/**
* @return array
*/
public static function optsWidgetTemplateId()
{
return ArrayHelper::merge(
......@@ -28,6 +52,9 @@ class WidgetContent extends BaseWidget
);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTemplate()
{
return $this->hasOne(WidgetTemplate::className(), ['id' => 'widget_template_id']);
......
......@@ -21,10 +21,29 @@ use yii\helpers\Url;
class Cell extends Widget
{
/**
* Global route
*/
const GLOBAL_ROUTE = '*';
/**
* Empty request param
*/
const EMPTY_REQUEST_PARAM = '';
/**
* Class prefix
*/
const CSS_PREFIX = 'hrzg-widget';
/**
* @var string
*/
public $requestParam = 'pageId';
/**
* @inheritdoc
*/
public function init()
{
\Yii::$app->trigger('registerMenuItems', new Event(['sender' => $this]));
......@@ -33,6 +52,10 @@ class Cell extends Widget
}
}
/**
* @inheritdoc
* @return string
*/
public function run()
{
Url::remember('', $this->getRoute());
......@@ -78,25 +101,32 @@ class Cell extends Widget
->orderBy('rank ASC')
->andFilterWhere(
[
'request_param' => \Yii::$app->request->get($this->requestParam),
'request_param' => [\Yii::$app->request->get($this->requestParam), self::EMPTY_REQUEST_PARAM],
]
)
->andWhere(
[
'container_id' => $this->id,
'route' => [$this->getRoute(), '*'],
'access_domain' => \Yii::$app->language,
'route' => [$this->getRoute(), self::GLOBAL_ROUTE],
'access_domain' => mb_strtolower(\Yii::$app->language),
])
->all();
return $models;
}
/**
* @return string
*/
private function getRoute()
{
return \Yii::$app->controller->module->id.'/'.\Yii::$app->controller->id.'/'.\Yii::$app->controller->action->id;
}
/**
* @return string
* @throws \yii\base\InvalidConfigException
*/
private function renderWidgets()
{
$html = Html::beginTag(
......@@ -129,10 +159,9 @@ class Cell extends Widget
return $html;
}
private function createWidget()
{
}
/**
* @return string
*/
private function generateContainerControls()
{
$html = Html::beginTag('div', ['class' => 'hrzg-widget-container-controls pull-right']);
......@@ -152,6 +181,11 @@ class Cell extends Widget
return $html;
}
/**
* @param $widget
*
* @return string
*/
private function generateWidgetControls($widget)
{
$html = Html::beginTag('div', ['class' => 'hrzg-widget-widget-controls btn-group', 'role' => 'group']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment