Here is the scenario:
In the theme layouts, i want to define certain regions where i want to inject extensions(well, widgets matter a fact).
So let’s assume i would have 4 regions into a layout top/right/bottom/left, smth like:
<div class="top"> [Inject extesions for TOP here] </div>
<div class="main">
<div class="left">[Inject extesions for LEFT here]</div>
<div class="content"> [Inject content here] </div>
<div class="right">[Inject extesions for RIGHT here]</div>
</div>
<div class="top"> [Inject extesions for BOTTOM here] </div>
Now, for each of my regions, i would call a "master" widget which would do a database lookup, more or less like:
<div class="top"><?php $this->widget('CmsWidget',array('region'=>'top')); ?></div>
<div class="main">
<div class="left"><?php $this->widget('CmsWidget',array('region'=>'left'));?></div>
<div class="content"> [Inject content here] </div>
<div class="right"><?php $this->widget('CmsWidget',array('region'=>'right'));?></div>
</div>
<div class="top"><?php $this->widget('CmsWidget',array('region'=>'bottom'));?></div>
The CmsWidget, would look into database and get the widgets for that region and render them into a view, so it would be smth like:
<?php
class CmsWidget extends CWidget{
public $region;
public function run()
{
$widgets=$this->getRegionWidgets($this->region);
$this->render('widgetsList',array('widgets'=>$widgets));
}
private function getRegionWidgets($region='')
{
[RUN SQL QUERY and return widget objects by their sort_order if they are enabled.]
}
}
And in the view file of the master widget, it will be like:
<?php
foreach($widgets AS $widget)
{
$this->widget($widget->full_path,@unserialize($widget->params));
}
?>
The database structure would be simple enough:
- widget_id
- region (top/left/right/bottom)
- full_path
- name
- description
- params
- sort_order (int defaults to 0)
- status (enum enabled/disabled)
This would offer a way into admin panel to enable/disable the extensions/widgets easily.
Now, the install part of the widget.
I was thinking, when a widget is added, it will be zip archived, so all that the install process does, is to unzip it, move it to the /extensions folder (into it’s own folder of course) and add a new record in the database.
Now, because the extension might have some configuration params(ie:name/description/ etc), i was thinking to allow a configuration file into the widget so that i can read it before i save the widget into database.
The configuration file would just return an array of default values, like:
<?php
return array(
'name' => 'Multi Level Menu',
'description'=>'Some description here to be shown into database',
'region'=>'left',
'status'=>'disabled',
'params'=>array(
//extra params here, which will be serialized and passed when the extension is initialized by the master widget. Also, these params will be saved into database and the admin can change them accordingly.
),
);
So i have a way to automatically install the widgets and also to manage them as i want to.
P.S: i am also thinking to add a param to decide for what pages this widget should be shown.
Any thoughts regarding this ?
Bright ideas that would extend my initial idea ?