Widget doesn't work in dashboard, but works well in other pages

I have a problem with widget. I'm using Ultimate cool theme 2.1.1 (WISB), and I can add widget to dashboard, it appears but doesn't work, althought it works well in profile page, group page... How can I fix it?!

Below is my dashboard.php file in WISB/pages folder.

<?php
gatekeeper();

$user = elgg_get_logged_in_user_entity();

elgg_set_page_owner_guid($user->guid);

$title = elgg_echo('newsfeed');

$composer = elgg_view('page/elements/composer', array('entity' => $user));


$db_prefix = elgg_get_config('dbprefix');
$activity = elgg_list_river(array(
    'joins' => array("JOIN {$db_prefix}entities object ON object.guid = rv.object_guid"),
    'wheres' => array("
        rv.subject_guid = $user->guid
        OR rv.subject_guid IN (SELECT guid_two FROM {$db_prefix}entity_relationships WHERE guid_one=$user->guid AND relationship='follower')
        OR rv.subject_guid IN (SELECT guid_one FROM {$db_prefix}entity_relationships WHERE guid_two=$user->guid AND relationship='friend')
    "),
));

$options = array();

$page_type = preg_replace('[\W]', '', get_input('page_type', 'all'));
$type = preg_replace('[\W]', '', get_input('type', 'all'));
$subtype = preg_replace('[\W]', '', get_input('subtype', ''));
if ($subtype) {
    $selector = "type=$type&subtype=$subtype";
} else {
    $selector = "type=$type";
}

if ($type != 'all') {
    $options['type'] = $type;
    if ($subtype) {
        $options['subtype'] = $subtype;
    }
}

switch ($page_type) {
    case 'mine':
        $title = elgg_echo('river:mine');
        $page_filter = 'mine';
        $options['subject_guid'] = elgg_get_logged_in_user_guid();
        break;
    case 'friends':
        $title = elgg_echo('river:friends');
        $page_filter = 'friends';
        $options['relationship_guid'] = elgg_get_logged_in_user_guid();
        $options['relationship'] = 'friend';
        break;
    default:
        $title = elgg_echo('river:all');
        $page_filter = 'all';
        break;
}

$activity = elgg_list_river($options);
if (!$activity) {
    $activity = elgg_echo('river:none');
}

$content = elgg_view('core/river/filter', array('selector' => $selector));

//$sidebar = elgg_view('core/river/sidebar');

$params = array(
        'title' => $title,
        'content' =>  $composer . $content . $activity,
        //'sidebar' => $sidebar,
        //'filter_context' => $page_filter,
        'class' => 'elgg-river-layout',
);


elgg_set_page_owner_guid(1);
$content = elgg_view_layout('two_sidebar', $params);

echo elgg_view_page($title, $content);

  • After

    $content = elgg_view('core/river/filter', array('selector' => $selector));

     

    Add this

    elgg_push_context('widgets');

    $widgets = elgg_get_widgets(elgg_get_page_owner_entity()->getGUID(), "dashboard");

    elgg_pop_context();

    $myparams = array(
            'num_columns' => 2,
            'show_access' => true,
            'exact_match' => true,
            'show_add_widgets' => false,
        );

    if(elgg_is_admin_logged_in()) {
    $myparams .= array(
            'show_add_widgets' => true,
        );
    }

    $widgets = elgg_view_layout('widgets', $myparams);

    $body = elgg_view_layout('one_column', array('content' => $widgets));

     

    $params = array(
            'title' => $title,
            'content' =>  $body .$composer . $content . $activity,
            //'sidebar' => $sidebar,
            //'filter_context' => $page_filter,
            'class' => 'elgg-river-layout',
    );


    elgg_set_page_owner_guid(1);
    $content = elgg_view_layout('two_sidebar', $params);

    echo elgg_view_page($title, $content);

  • Thanks RvR, but there's another problem.

    Before I edit the code: the "Add widget" button only appears for admin, not for all user. The widget appears but it doesn't work, nothing in content.

    image

    After I edit the code: the "Add widget" button appears, widget appears and works well, but the old widget column still appears.

    image

    As you can see in these images above, now I want to replace the box 2 by the box 1, and show the "Add widget" button for all user, not only admin. Thank you.

  • $myparams = array(
            'num_columns' => 2, //change on 'num_columns' => 1,
            'show_access' => true,
            'exact_match' => true,
            'show_add_widgets' => false,
        );

    if(elgg_is_admin_logged_in()) { //change on if(elgg_is_logged_in()) {
    $myparams .= array(
            'show_add_widgets' => true,
        );
    }

     

     

  • Thank you RvR but it doesn't work. There's still two column, nothing changes. The column1 is within <div class="elgg-body elgg-main">, and the column2 is within <div class="elgg-sidebar-alt">. Can you help me, please?!

  • If you want to show your widgets on sidebar then try it:

     

    After

    $content = elgg_view('core/river/filter', array('selector' => $selector));

     

    Add this

    elgg_push_context('widgets');

    $widgets = elgg_get_widgets(elgg_get_page_owner_entity()->getGUID(), "dashboard");

    elgg_pop_context();

    $myparams = array(
            'num_columns' => 1,
            'show_access' => true,
            'exact_match' => true,
            'show_add_widgets' => false,
        );

    if(elgg_is_logged_in()) {
    $myparams .= array(
            'show_add_widgets' => true,
        );
    }

    $widgets = elgg_view_layout('widgets', $myparams);

    $params = array(
            'title' => $title,
            'content' =>  $composer . $content . $activity,
             'sidebar' => $widgets,
            //'filter_context' => $page_filter,
            'class' => 'elgg-river-layout',
    );


    elgg_set_page_owner_guid(1);
    $content = elgg_view_layout('two_sidebar', $params);

    echo elgg_view_page($title, $content);

     

    I can't test it now but should be work

  • BTW, better if you'll make

    views\default\pages\sidebar\widgets.php

    with

    elgg_push_context('dashboard');
    elgg_push_context('widgets');
    elgg_pop_context();
        $params = array(
            'exact_match' => true,
            'num_columns' => 1,
            'show_access' => false,
        );
    $title = '';
    $body = elgg_view_layout('widgets', $params);

    echo elgg_view_module('aside', $title, $body);

     

    then into aboving code change on

     

    $sidebar = elgg_view(pages/sidebar/widgets);

    $params = array(
            'title' => $title,
            'content' =>  $composer . $content . $activity,
             'sidebar' => $sidebar,
            //'filter_context' => $page_filter,
            'class' => 'elgg-river-layout',
    );

  • Thanks RvR. I think I didn't provide enought information for you. I'm using Ultimate cool theme, and it uses two sidebar layout, so it has a sidebar on the left, and a sidebar_alt on the right.

    First the widgets appear on the sidebar_alt div tag, but they don't work. After I change the code, they appear within both the body and the sidebar_alt tag.

    I don't know how widget appears before I change my code. It still appears but doesn't work.

    Beside that, there's a file named sidebar_alt.php in the folder mod\WISB\views\default\page\elements contents code below:

    <?php
    $homepage = "/dashboard";
    $currentpage = $_SERVER['REQUEST_URI'];
    if($homepage==$currentpage) {
    echo "<strong><a href=\"../thanks\">Thanks</a></strong><br />
    edit the sidebar for the dashboard in /mod/cool_theme/views/default/page/elements/sidebar_alt.php<br />
    and enjoy";
    }
    ?>

    Hope you understand clearly my problem. I really confused about it.

  • You can change 'sidebar' on 'sidebar_alt'

    $params = array(
            'title' => $title,
            'content' =>  $composer . $content . $activity,
          'sidebar_alt' => $sidebar,
            //'filter_context' => $page_filter,
            'class' => 'elgg-river-layout',
    );

     

    Or edit your sidebar_alt.php in mod\WISB\views\default\page\elements with

    <?php

    elgg_push_context('dashboard');
    elgg_push_context('widgets');
    elgg_pop_context();
        $params = array(
            'exact_match' => true,
            'num_columns' => 1,
            'show_access' => false,
        );
    $title = '';
    $body = elgg_view_layout('widgets', $params);

    echo elgg_view_module('aside', $title, $body);

     

    If this then no need to create views\default\pages\sidebar\widgets.php

     

  • Thanks RvR. I try and it still doesn't work. So complicated. Now the widget appears within the sidebar_alt tag, but it still doesn't work. You can see in the image below. I try all of what you said. I think we have to remove the old sidebar_alt but I don't know how to do that. Can you help me to fix it?

    image

    //Sorry for my bad English :D