/**
 * Sticky widgets defaults configuration page.
 *
 * Initializes the sticky widgets objects and give you an UI for specify default users values
 *
 * @package StickyWidgets
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Diego Andrés Ramírez Aragón <*****@*****.**>
 * @author Steve Suppe <*****@*****.**>
 */
global $CONFIG;
$context = $vars["context"];
$swType = $vars["swType"];
$widgets = $vars["widgets"];
$sticky_widgets = get_sticky_widgets(2, $swType, $context);
if (!is_array($sticky_widgets)) {
    $sticky_widgets = array();
}
$handlers = array_keys($widgets);
$existing = array();
foreach ($sticky_widgets as $sticky) {
    $handler = $sticky->get("handler");
    if (in_array($handler, $handlers)) {
        $existing[] = $handler;
    }
}
$new_handlers = array_diff($handlers, $existing);
// SPS: Unsure why we should do it this way - I only want to create SW objects if we
// need them.  If removed from the configuration, they should not show up here.
//if(!empty($new_handlers)){
Example #2
0
/**
 * Create the user widgets based on the sticky widgets in the DB.  Only happens
 * a) if StickyWidgets has been used for this context and b) if the SWs were updated
 * since the user has refreshed this context in their browser.
 *
 * TODO: Shouldn't just be context checking, should also be user subtype.
 *
 * @param unknown_type $user_guid
 * @param unknown_type $swType
 * @param unknown_type $context
 * @return unknown
 */
function get_user_widgets_from_sticky($user_guid, $swType, $context)
{
    // First, let's do a compare of the last updated 'sticky_widgets'
    // to this user's SW Timestamp...
    $uTime = getSWTimestampForUser($user_guid, $context);
    $mTime = getSWMasterTimestamp($context);
    // If there was no mTime, then there has been no save, so continue to
    // use the default widgets;
    if ($mTime > 0 && $uTime <= $mTime) {
        $widgetspanel = array();
        foreach (array(1, 2, 3) as $column) {
            // First, get the STICKY widgets for this column/context
            $swidgets = get_sticky_widgets(2, $swType, $context, $column);
            // Create the necessary string to pass to the reorder panel
            $w = "";
            $i = 0;
            if (!empty($swidgets)) {
                foreach ($swidgets as $sw) {
                    //			$sw = $swidgets[$i];
                    $w = $w . $sw->handler . "::" . 0;
                    if ($i != sizeof($swidgets) - 1) {
                        $w .= "::";
                        $i++;
                    }
                }
            }
            $widgetspanel[] = $w;
        }
        $ctx = get_context();
        set_context('add_sticky_widgets');
        if (!reorder_widgets_from_panel_via_sticky($widgetspanel[0], $widgetspanel[1], $widgetspanel[2], $context, $user_guid)) {
            system_message(elgg_echo('sw:usercheck:fail'));
        }
        set_context($ctx);
        setSWTimestampForUser($user_guid, $context);
    }
    $widgets[0] = get_widgets($user_guid, $context, 1);
    $widgets[1] = get_widgets($user_guid, $context, 2);
    $widgets[2] = get_widgets($user_guid, $context, 3);
    return $widgets;
}
Example #3
0
 *
 *
 * @package Elgg
 * @subpackage StickyWidget
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Steve Suppe <*****@*****.**>
 */
admin_gatekeeper();
$type = get_input('swType');
// sticky Widget type (see types.php)
$context = get_input('context');
$widgettypes = sw_get_widget_types($context);
// These 'getters' have hardcoded contexts because I maintain that for uniqueness
$area1widgets = get_sticky_widgets(2, $type, $context, 1);
$area2widgets = get_sticky_widgets(2, $type, $context, 2);
$area3widgets = get_sticky_widgets(2, $type, $context, 3);
if (empty($area1widgets) && empty($area2widgets) && empty($area3widgets)) {
    if (isset($vars['area3'])) {
        $vars['area1'] = $vars['area3'];
    }
    if (isset($vars['area4'])) {
        $vars['area2'] = $vars['area4'];
    }
}
$seenWidgets = array();
// Keep track of the widgets we've seen, so that we don't show them in the gallery.
$left = drawSetDraggables($area1widgets, $widgettypes, $seenWidgets);
$middle = drawSetDraggables($area2widgets, $widgettypes, $seenWidgets);
$right = drawSetDraggables($area3widgets, $widgettypes, $seenWidgets);
$gallery = drawGallery($widgettypes, $seenWidgets);
// Output