public static function get_extra_view_info(&$viewdata, $getartefacts = true, $gettags = true) { if ($viewdata) { // Get view owner details for display $owners = array(); $groups = array(); $institutions = array(); foreach ($viewdata as $v) { if (!empty($v->owner) && !isset($owners[$v->owner])) { $owners[$v->owner] = (int) $v->owner; } else { if (!empty($v->group) && !isset($groups[$v->group])) { $groups[$v->group] = (int) $v->group; } else { if (!empty($v->institution) && !isset($institutions[$v->institution])) { $institutions[$v->institution] = $v->institution; } } } } $viewidlist = join(',', array_map('intval', array_keys($viewdata))); if ($getartefacts) { $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin ORDER BY a.title, va.artefact', array()); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $viewdata[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } } if ($gettags) { $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); if ($tags) { foreach ($tags as &$tag) { $viewdata[$tag->view]->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)) { require_once 'group.php'; $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 ($viewdata as &$v) { $v->anonymous = FALSE; if (!empty($v->owner)) { $v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]); $v->user = $owners[$v->owner]; // Get a real view object so we can do the checks. $view_obj = new View($v->id); $v->anonymous = $view_obj->is_anonymous(); $v->staff_or_admin = $view_obj->is_staff_or_admin_for_page(); } else { if (!empty($v->group)) { $v->sharedby = $groups[$v->group]->name; $v->groupdata = $groups[$v->group]; } else { if (!empty($v->institution)) { $v->sharedby = $institutions[$v->institution]->displayname; } } } $v = (array) $v; // Now that we have the owner & group records, create a temporary View object // so that we can use display_title_editing and get_url methods. $view = new View(0, $v); $view->set('dirty', false); $v['displaytitle'] = $view->display_title_editing(); $v['url'] = $view->get_url(false); $v['fullurl'] = $needsubdomain ? $view->get_url(true) : $wwwroot . $v['url']; } } }
/** * @param array $data Parameters: * - view (int) * - oldusers (array of user IDs) */ public function __construct($data, $cron = false) { parent::__construct($data, $cron); if (!($viewinfo = new View($this->view))) { if (!empty($this->cron)) { // probably deleted already return; } throw new ViewNotFoundException(get_string('viewnotfound', 'error', $this->view)); } $this->url = $viewinfo->get_url(false); $this->users = array_diff_key(activity_get_viewaccess_users($this->view), $this->oldusers); if ($viewinfo->get_collection()) { $this->incollection = true; $this->title = $viewinfo->get_collection()->get('name'); $this->add_urltext(array('key' => 'Collection', 'section' => 'collection')); } else { $this->title = $viewinfo->get('title'); $this->add_urltext(array('key' => 'View', 'section' => 'view')); } $this->ownername = $viewinfo->formatted_owner(); }
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']; }
/** * Makes a URL for a collection * * @param bool $full return a full url * @param bool $useid ignore clean url settings and always return a url with an id in it * * @return string */ public function get_url($full = true, $useid = false) { global $USER; $views = $this->views(); if (!empty($views)) { $v = new View(0, $views['views'][0]); $v->set('dirty', false); return $v->get_url($full, $useid); } log_warn("Attempting to get url for an empty collection"); if ($this->owner === $USER->get('id')) { $url = 'collection/views.php?id=' . $this->id; } else { $url = ''; } if ($full) { $url = get_config('wwwroot') . $url; } return $url; }
/** * This function returns a list of browsable items. * * @param limit how many items to display per page * @param offset current page to display * @return array (count: integer, data: array) */ public static function get_browsable_items($filters, $offset=0, $limit=20) { global $USER; $contents = array(); $texttitletrim = 20; $onetimeclause = false; $count = 0; if (is_postgres()) { $selectclause = 'SELECT * FROM ( SELECT DISTINCT ON (va.view) va.view, a.id, v.mtime, v.owner'; $grouporderclause = ') p ORDER BY mtime DESC'; } else if (is_mysql()) { $selectclause = 'SELECT va.view, a.id, v.mtime, v.owner'; $grouporderclause = 'GROUP BY va.view ORDER BY a.mtime DESC'; } $fromclause = ' FROM {view_access} va'; $joinclause = " INNER JOIN {view} v ON (va.view = v.id AND v.type = 'profile')"; $join2clause = " JOIN {view_artefact} var ON v.id = var.view"; $join3clause = " JOIN {artefact} a ON (a.artefacttype = 'image' AND a.id = var.artefact)"; $join4clause = ''; $whereclause = ' WHERE (v.owner > 0)'; $andclause = " AND (v.startdate IS NULL OR v.startdate < current_timestamp) AND (v.stopdate IS NULL OR v.stopdate > current_timestamp) AND (va.startdate IS NULL OR va.startdate < current_timestamp) AND (va.stopdate IS NULL OR va.stopdate > current_timestamp)"; foreach ($filters as $filterkey => $filterval) { switch ($filterkey) { case 'keyword': $join4clause = ' LEFT JOIN {usr} u ON u.id = v.owner'; // replace spaces with commas so that we can search on each term separately $filterval = str_replace(' ', ',', $filterval); $keywords = explode(",", $filterval); if (count($keywords) == 1 ) { $andclause .= " AND ( LOWER(u.firstname) LIKE LOWER('%$filterval%') OR LOWER(u.lastname) LIKE LOWER('%$filterval%') OR LOWER(u.preferredname) LIKE LOWER('%$filterval%') )"; } else { foreach($keywords as $key => $word) { if ($key == 0) { $andclause .= " AND (( LOWER(u.firstname) LIKE LOWER('%$word%') OR LOWER(u.lastname) LIKE LOWER('%$word%') OR LOWER(u.preferredname) LIKE LOWER('%$word%') )"; } else { $andclause .= " AND ( LOWER(u.firstname) LIKE LOWER('%$word%') OR LOWER(u.lastname) LIKE LOWER('%$word%') OR LOWER(u.preferredname) LIKE LOWER('%$word%') )"; } if ($key == count($keywords)-1) { $andclause .= ')'; } } } break; case 'college' : if (!empty($filterval) && !$onetimeclause) { $join4clause .= ' JOIN {usr_enrolment} e ON e.usr = v.owner'; $selectclause .= ', e.college, e.course'; $ontimeclause = true; } $andclause .= " AND e.college IN ($filterval)"; break; case 'course' : if (!empty($filterval) && !$onetimeclause) { $join4clause .= ' JOIN {usr_enrolment} e ON e.usr = v.owner'; $selectclause .= ', e.college, e.course'; $ontimeclause = true; } $courseidgroups = explode(";", $filterval); if (count($courseidgroups) == 1) { // one course submitted, could have multiple csv ids if selected by name $courseids = explode(",", $courseidgroups[0]); if (count($courseids) == 1 ) { $andclause .= " AND (e.course LIKE '%$courseids[0]%' AND e.usr = v.owner)"; } else if (count($courseids) > 1 ) { foreach($courseids as $key => $id) { if ($key == 0) { $andclause .= " AND (e.course LIKE '%$id%'"; } else { $andclause .= " OR e.course LIKE '%$id%'"; } if ($key == count($courseids)-1) { $andclause .= ')'; } } } } else if (count($courseidgroups) > 1) { // more than one course submitted foreach($courseidgroups as $key => $coursegroup) { if ($key == 0) { $courseids = explode(",", $coursegroup); if (count($courseids) == 1 ) { $andclause .= " AND ((e.course LIKE '%$courseids[0]%')"; } else if (count($courseids) > 1 ) { foreach($courseids as $key => $id) { if ($key == 0) { $andclause .= " AND ((e.course LIKE '%$id%'"; } else { $andclause .= " OR e.course LIKE '%$id%'"; } if ($key == count($courseids)-1) { $andclause .= ')'; } } } } else { // key != 0 $courseids = explode(",", $coursegroup); if (count($courseids) == 1 ) { $andclause .= " AND (e.course LIKE '%$courseids[0]%')"; } else if (count($courseids) > 1 ) { foreach($courseids as $key => $id) { if ($key == 0) { $andclause .= " AND (e.course LIKE '%$id%'"; } else { $andclause .= " OR e.course LIKE '%$id%'"; } if ($key == count($courseids)-1) { $andclause .= ')'; } } } } } } break; } } /** * The query checks for profile page images. */ $profileimagesids = get_records_sql_array(" $selectclause $fromclause $joinclause $join2clause $join3clause $join4clause $whereclause $andclause $grouporderclause ", array(), $offset, $limit); if ($profileimagesids) { foreach ($profileimagesids as $key => $profileimageid) { $view = new View($profileimageid->view); $view->set('dirty', false); $fullurl = $view->get_url(); $avatarurl = profile_icon_url($profileimageid->owner,50,50); $pagetitle = str_shorten_text(display_name($profileimageid->owner), $texttitletrim, true); $contents['profiles'][] = array("id" => "p" . $profileimageid->id, "type" => "profile", "image" => array( "id" => $profileimageid->id, "view" => $profileimageid->view ), "page" => array( "url" => $fullurl, "title" => $pagetitle ), "owner" => array( "avatarurl" => $avatarurl ) ); } // foreach } if ($profileimagesids) { $allprofileswithimages = get_records_sql_array(" SELECT va.view $fromclause $joinclause $join2clause $join3clause $join4clause $whereclause $andclause GROUP BY va.view ", array()); $count = count($allprofileswithimages); } $items = array( 'count' => $count, 'data' => $contents, 'offset' => $offset, 'limit' => $limit, ); return $items; }
$SESSION->set('exportdata', ''); $SESSION->set('exportfile', ''); $exportoptions = array(); $exportplugins = plugins_installed('export'); if (!$exportplugins) { die_info(get_string('noexportpluginsenabled', 'export')); } foreach ($exportplugins as $plugin) { safe_require('export', $plugin->name); $exportoptions[$plugin->name] = array('text' => call_static_method(generate_class_name('export', $plugin->name), 'get_title'), 'description' => call_static_method(generate_class_name('export', $plugin->name), 'get_description')); } $elements = array('format' => array('type' => 'radio', 'options' => $exportoptions, 'defaultvalue' => 'html'), 'what' => array('type' => 'radio', 'options' => array('all' => get_string('allmydata', 'export'), 'views' => get_string('justsomeviews', 'export')), 'defaultvalue' => 'all'), 'includefeedback' => array('type' => 'switchbox', 'class' => 'last', 'title' => get_string('includefeedback', 'export'), 'description' => get_string('includefeedbackdescription', 'export'), 'defaultvalue' => 1)); if ($viewids = get_column_sql('SELECT id FROM {view} WHERE owner = ? AND type = ? ORDER BY title', array($USER->get('id'), 'portfolio'))) { foreach ($viewids as $viewid) { $view = new View($viewid); $elements['view_' . $viewid] = array('type' => 'checkbox', 'class' => 'checkbox', 'title' => $view->get('title'), 'description' => $view->get('description'), 'viewlink' => $view->get_url(true, true)); } $jsfiles = array('js/preview.js', 'js/export.js'); $collections = get_records_sql_array(' SELECT c.id, c.name, c.description FROM {collection} c JOIN {collection_view} cv ON c.id = cv.collection WHERE c.owner = ? GROUP BY c.id, c.name, c.description HAVING COUNT(cv.view) > 0', array($USER->get('id'))); if ($collections) { $elements['what']['options']['collections'] = get_string('justsomecollections', 'export'); foreach ($collections as $collection) { $elements['collection_' . $collection->id] = array('type' => 'checkbox', 'class' => 'checkbox', 'title' => $collection->name, 'description' => $collection->description); } } } else {
public static function get_links($id) { $annotation = new ArtefactTypeAnnotation($id); require_once get_config('libroot') . 'view.php'; $v = new View($annotation->get('view')); return array('_default' => $v->get_url()); }