752 Posts in 310 Topics by 289 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 898 Views |
-
Generating WidgetArea on the fly

29 September 2009 at 10:44am Last edited: 29 September 2009 10:50am
Hi all,
I'm wondering if it is possible to generate a WidgetArea on the fly so that I can add widgets to Pages automatically.
At the moment I want to have at least 3 widgets on a page and if there is less than 3 widgets on a page then I want to 'push' some more widgets into the area.
So far I have tried:
function myWidgets() {
$num = $this->Widgets()->Widgets()->Count();
if ($num < $this->minWidgets){ //if the number of widgets is less than the minimum number defined
$widgets = new DataObjectSet();
//pushing any existing widgets into it
$widgets->push($this->Widgets());
$moreWidgets = WidgetArea::get('Widget','Widget.ID NOT IN (SELECT `ID` FROM `Widget` WHERE `ParentID` = '.$this->WidgetsID.')',null,null,$this->minWidgets - $num);
foreach ($moreWidgets as $widge){
$widgets->push($widge);
}
//unset($moreWidgets);
return $widgets;
}
else {
return $this->Widgets();
}But this doesn't really work. The ultimate goal is to select some widgets that aren't already selected for that page at random.
Is this even possible?
When the else clause returns, the widgets work fine
Any help is much appreciated
| 898 Views | ||
|
Page:
1
|
Go to Top |

