private static function loadThreeColLayout($userId, $tabTitle, $xmlLayout) { $xmlSections = $xmlLayout->getElementsByTagName('section'); foreach ($xmlSections as $xmlSection) { $colPosition = $xmlSection->getAttribute('position'); $xmlWidgets = $xmlSection->getElementsByTagName('widget'); $rowPosition = 0; foreach ($xmlWidgets as $xmlWidget) { $widgetId = $xmlWidget->getAttribute('widgetid'); $minimized = $xmlWidget->getAttribute('minimized'); $widgetState = array(array('column' => $colPosition, 'position' => $rowPosition, 'minimized' => $minimized, 'widgetid' => $widgetId)); # import the widget $widgetInstanceId = UserInterface::insertWidget($userId, $widgetId, $widgetState, $tabTitle); # import widget preferences $xmlProperties = $xmlWidget->getElementsByTagName('property'); foreach ($xmlProperties as $xmlProperty) { $xmlName = $xmlProperty->getElementsByTagName('name'); $xmlValue = $xmlProperty->getElementsByTagName('value'); if ($xmlName->length > 0 && $xmlValue->length > 0) { $propertyName = $xmlName->item(0)->nodeValue; $propertyValue = $xmlValue->item(0)->nodeValue; UserInterface::updateWidgetPreferences($userId, $widgetInstanceId, array($propertyName => $propertyValue), array()); } } $rowPosition++; } } }
public function insertWidgetInstance($widgetId, $tabId, $column = null, $position = null) { if (!Auth::isAuth()) { throw new ServiceException(MwwException::ACTION, 'updateInterface', ServiceException::SERV_AUTH); } # Insert widget into a specific position $widgetState = array(); if ($column != null && $position != null) { $widgetState[] = array('widgetid' => $widgetId, 'column' => $column, 'position' => $position, 'minimized' => 0); } $newWidgetInstanceId = UserInterface::insertWidget(Auth::getUserId(), $widgetId, $widgetState, $tabId); # Properties values is provided, add them to the widget if (isset($_POST['properties'])) { $widgetProperties = json_decode(stripcslashes($_POST['properties']), true); if (is_array($widgetProperties)) { UserInterface::updateWidgetPreferences(Auth::getUserId(), $newWidgetInstanceId, $widgetProperties, array()); } } echo $newWidgetInstanceId; }