Commit 6d0ad109 authored by Ruslan Kabalin's avatar Ruslan Kabalin Committed by Gerrit Code Review
Browse files

Merge changes I62fd21c2,I4bf35942,Ieb5e109a

* changes:
  Improve portfolio search (bug #931481)
  Fix portfolio search (bug #931481)
  Fix artefact::get_views_instances (bug #931467)
parents c7d7a773 00ca5fe7
......@@ -708,8 +708,5 @@ class ArtefactTypeHtml extends ArtefactType {
}
public static function get_links($id) {
return array(
'_default' => get_config('wwwroot'),
);
}
}
......@@ -207,14 +207,22 @@ abstract class ArtefactType {
$this->atime = time();
}
/**
* Returns the instances of all views where this artefact is used.
*
* @return array Array of view instances.
*/
public function get_views_instances() {
// @todo test this
if (!isset($this->viewsinstances)) {
$this->viewsinstances = false;
if ($views = $this->get_views_metadata()) {
$this->viewsinstances = array();
if (!class_exists('View')) {
require_once(get_config('libroot') . 'view.php');
}
foreach ($views as $view) {
$this->viewsinstances[] = new View($view->id, $view);
$this->viewsinstances[] = new View($view->view);
}
}
}
......
......@@ -92,6 +92,7 @@ $string['viewssubmittedtogroup'] = 'Pages submitted to this group';
$string['submitaviewtogroup'] = 'Submit a page to this group';
$string['youhavesubmitted'] = 'You have submitted <a href="%s">%s</a> to this group';
$string['youhavesubmittedon'] = 'You submitted <a href="%s">%s</a> to this group on %s';
$string['listedinpages'] = 'Listed in pages';
// access levels
$string['public'] = 'Public';
......
......@@ -804,6 +804,7 @@ class PluginSearchInternal extends PluginSearch {
);
if ($results['data']) {
require_once(get_config('docroot') . 'artefact/lib.php');
foreach ($results['data'] as &$result) {
$newresult = array();
foreach ($result as $key => &$value) {
......@@ -812,10 +813,13 @@ class PluginSearchInternal extends PluginSearch {
}
}
$newresult['type'] = 'artefact';
$artefactplugin = get_field('artefact_installed_type', 'plugin', 'name', $newresult['artefacttype']);
if ($artefactplugin == 'internal') {
$artefact = artefact_instance_from_id($newresult['id']);
$artefactplugin = $artefact->get_plugin_name();
if ($artefactplugin == 'internal' && in_array($artefact->get('artefacttype'), PluginArtefactInternal::get_profile_artefact_types())) {
// Profile artefact
$newresult['summary'] = $newresult['title'];
$newresult['title'] = get_string($newresult['artefacttype'], 'artefact.' . $artefactplugin);
$newresult['title'] = get_string($artefact->get('artefacttype'), 'artefact.' . $artefactplugin);
}
else {
$newresult['summary'] = $newresult['description'];
......
......@@ -127,14 +127,23 @@ abstract class PluginSearch extends Plugin {
*/
public static abstract function self_search($query_string, $limit, $offset, $type = 'all');
protected static function self_search_make_links($data) {
protected static function self_search_make_links(&$data) {
$wwwroot = get_config('wwwroot');
if ($data['count']) {
foreach ($data['data'] as &$result) {
switch ($result['type']) {
case 'artefact':
safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $result['artefacttype']));
$result['links'] = call_static_method(generate_artefact_class_name($result['artefacttype']), 'get_links', $result['id']);
$artefact = artefact_instance_from_id($result['id']);
if ($artefact->in_view_list() && $views = $artefact->get_views_instances()) {
foreach ($views as $view) {
$result['views'][$view->get('title')] = get_config('wwwroot') . 'view/artefact.php?artefact='
. $result['id'] . '&view=' . $view->get('id');
}
}
if ($links = $artefact->get_links($result['id'])) {
$result['links'] = $links;
}
break;
case 'view':
$result['links'] = array(
......
......@@ -34,6 +34,7 @@ $artefacttype = param_variable('artefacttype','all');
$enc_jsonscript = json_encode(get_config('wwwroot') . 'json/selfsearch.php');
$enc_noresults = json_encode(get_string('noresultsfound'));
$enc_pages = json_encode(get_string('listedinpages', 'view'));
$javascript = <<<EOF
var results = new TableRenderer(
......@@ -44,32 +45,38 @@ var results = new TableRenderer(
results.statevars.push('query');
results.statevars.push('type');
results.emptycontent = {$enc_noresults};
results.rowfunction = function (r, n, d) {
results.rowfunction = function (r, rownumber, d) {
var titleElement;
if (r.links._default) {
if (r.links && r.links._default) {
titleElement = [H3(null, A({'href': r.links._default}, r.title))];
delete r.links._default;
}
else {
titleElement = [H3(null, A(null, r.title))];
titleElement = [H3(null, r.title)];
}
for ( var k in r.links ) {
var button = BUTTON(null, k);
connect(button, 'onclick', partial(
function (link) { document.location.href = link },
r.links[k]
));
titleElement.push(button);
var link = A({'href': r.links[k]}, k);
titleElement.push(link);
}
if (r.views) {
var viewsList = UL(null);
var viewsElement = P(null, STRONG(null, $enc_pages), viewsList);
for ( var k in r.views ) {
var link = A({'href': r.views[k]}, k);
viewsList.appendChild(LI(null, link));
}
}
var descriptionElement = P(null);
descriptionElement.innerHTML = r.summary;
return TR(null, TD(null,
return TR({'class': 'r' + (rownumber % 2)}, TD(null,
titleElement,
descriptionElement
descriptionElement,
viewsElement
));
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment