Example #1
0
function build_portfolio_search_html(&$data)
{
    global $THEME;
    $artefacttypes = get_records_assoc('artefact_installed_type');
    require_once 'view.php';
    require_once 'collection.php';
    foreach ($data->data as &$item) {
        $item->ctime = format_date($item->ctime);
        if ($item->type == 'view') {
            $item->typestr = get_string('view');
            $item->icon = $THEME->get_image_url('page');
            $v = new View(0, (array) $item);
            $v->set('dirty', false);
            $item->url = $v->get_url();
        } else {
            if ($item->type == 'collection') {
                $item->typestr = get_string('Collection', 'collection');
                $item->icon = $THEME->get_image_url('collection');
                $c = new Collection(0, (array) $item);
                $item->url = $c->get_url();
            } else {
                // artefact
                safe_require('artefact', $artefacttypes[$item->artefacttype]->plugin);
                $links = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_links', $item->id);
                $item->url = $links['_default'];
                $item->icon = call_static_method(generate_artefact_class_name($item->artefacttype), 'get_icon', array('id' => $item->id));
                if ($item->artefacttype == 'task') {
                    $item->typestr = get_string('Task', 'artefact.plans');
                } else {
                    $item->typestr = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin);
                }
            }
        }
    }
    $data->baseurl = get_config('wwwroot') . 'tags.php' . (is_null($data->tag) ? '' : '?tag=' . urlencode($data->tag));
    $data->sortcols = array('name', 'date');
    $data->filtercols = array('all' => get_string('tagfilter_all'), 'file' => get_string('tagfilter_file'), 'image' => get_string('tagfilter_image'), 'text' => get_string('tagfilter_text'), 'view' => get_string('tagfilter_view'), 'collection' => get_string('tagfilter_collection'));
    $smarty = smarty_core();
    $smarty->assign_by_ref('data', $data->data);
    $smarty->assign('owner', $data->owner->id);
    $data->tablerows = $smarty->fetch('portfoliosearchresults.tpl');
    $pagination = build_pagination(array('id' => 'results_pagination', 'class' => 'center', 'url' => $data->baseurl . ($data->sort == 'name' ? '' : '&sort=' . $data->sort) . ($data->filter == 'all' ? '' : '&type=' . $data->filter), 'jsonscript' => 'json/tagsearch.php', 'datatable' => 'results', 'count' => $data->count, 'limit' => $data->limit, 'offset' => $data->offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2, 'numbersincludefirstlast' => false, 'resultcounttextsingular' => get_string('result'), 'resultcounttextplural' => get_string('results')));
    $data->pagination = $pagination['html'];
    $data->pagination_js = $pagination['javascript'];
}
Example #2
0
 /**
  * Get more info for the collections: owner, url, tags, views
  *
  * @param array a list of collections $collectiondata
  * @return array updated collection data
  */
 public static function get_extra_collection_info(&$collectiondata, $gettags = true)
 {
     if ($collectiondata) {
         // Get view owner details for display
         $owners = array();
         $groups = array();
         $institutions = array();
         foreach ($collectiondata as $c) {
             if (!empty($c->owner) && !isset($owners[$c->owner])) {
                 $owners[$c->owner] = (int) $c->owner;
             } else {
                 if (!empty($c->group) && !isset($groups[$c->group])) {
                     $groups[$c->group] = (int) $c->group;
                 } else {
                     if (!empty($c->institution) && !isset($institutions[$c->institution])) {
                         $institutions[$c->institution] = $c->institution;
                     }
                 }
             }
         }
         if ($gettags) {
             $collectionidlist = join(',', array_map('intval', array_keys($collectiondata)));
             $tags = get_records_select_array('collection_tag', 'collection IN (' . $collectionidlist . ')');
             if ($tags) {
                 foreach ($tags as &$tag) {
                     $collectiondata[$tag->collection]->tags[] = $tag->tag;
                 }
             }
         }
         if (!empty($owners)) {
             global $USER;
             $userid = $USER->get('id');
             $fields = array('id', 'username', 'firstname', 'lastname', 'preferredname', 'admin', 'staff', 'studentid', 'email', 'profileicon', 'urlid', 'suspendedctime');
             if (count($owners) == 1 && isset($owners[$userid])) {
                 $owners = array($userid => new StdClass());
                 foreach ($fields as $f) {
                     $owners[$userid]->{$f} = $USER->get($f);
                 }
             } else {
                 $owners = get_records_select_assoc('usr', 'id IN (' . join(',', array_fill(0, count($owners), '?')) . ')', $owners, '', join(',', $fields));
             }
         }
         if (!empty($groups)) {
             $groups = get_records_select_assoc('group', 'id IN (' . join(',', $groups) . ')', null, '', 'id,name,urlid');
         }
         if (!empty($institutions)) {
             $institutions = get_records_assoc('institution', '', '', '', 'name,displayname');
             $institutions['mahara']->displayname = get_config('sitename');
         }
         $wwwroot = get_config('wwwroot');
         $needsubdomain = get_config('cleanurlusersubdomains');
         foreach ($collectiondata as &$c) {
             if (!empty($c->owner)) {
                 $c->sharedby = display_name($owners[$c->owner]);
                 $c->user = $owners[$c->owner];
             } else {
                 if (!empty($c->group)) {
                     $c->sharedby = $groups[$c->group]->name;
                     $c->groupdata = $groups[$c->group];
                 } else {
                     if (!empty($c->institution)) {
                         $c->sharedby = $institutions[$c->institution]->displayname;
                     }
                 }
             }
             $c = (array) $c;
             // Now that we have the owner & group records, create a temporary Collection object
             // so that we can use get_url method.
             require_once get_config('libroot') . 'collection.php';
             $collection = new Collection(0, $c);
             $c['url'] = $collection->get_url(false);
             $c['fullurl'] = $needsubdomain ? $collection->get_url(true) : $wwwroot . $c['url'];
             // Get any views that are part of this collection
             $c['views'] = get_records_sql_assoc('SELECT v.id, v.title, v.mtime FROM {view} v, {collection_view} cv, {collection} c
                                                  WHERE cv.collection = c.id AND cv.view = v.id AND c.id = ?', array($c['id']));
             // Set the collection modified time as the highest view
             // modified time if higher than collection modified time
             foreach ($c['views'] as $view) {
                 $cmodified = new DateTime($c['mtime']);
                 $vmodified = new DateTime($view->mtime);
                 if ($vmodified > $cmodified) {
                     $c['mtime'] = $view->mtime;
                 }
             }
         }
     }
 }
Example #3
0
function get_views_for_user($username, $query = null)
{
    global $REMOTEWWWROOT, $USER;
    list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT);
    if (!$user) {
        return false;
    }
    $USER->reanimate($user->id, $authinstance->instanceid);
    require_once 'view.php';
    $data = View::view_search($query, null, (object) array('owner' => $USER->get('id')), null, null, 0, true, null, null, true);
    require_once 'collection.php';
    $data->collections = Collection::get_mycollections_data(0, 0, $USER->get('id'));
    foreach ($data->collections->data as $c) {
        $cobj = new Collection($c->id);
        if ($c->numviews > 0) {
            $c->url = $cobj->get_url();
        } else {
            $c->url = '';
        }
    }
    $data->displayname = display_name($user);
    return $data;
}