Commit 63ed654c authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Added linking to selfsearch

* Added get_links to ArtefactType base class
* Implement get_links for all existing artefact types
* Enabled direct folder/file linking in the my files section
parent 7e16a697
......@@ -382,7 +382,14 @@ class ArtefactTypeBlog extends ArtefactType {
return $this->get('commentsnotify');
}
public static function get_links($id) {
$wwwroot = get_config('wwwroot');
return array(
'_default' => $wwwroot . 'artefact/blog/view/?id=' . $id,
get_string('blogsettings', 'artefact.blog') => $wwwroot . 'artefact/blog/settings/?id=' . $id,
);
}
}
/**
......@@ -844,7 +851,13 @@ class ArtefactTypeBlogPost extends ArtefactType {
return get_field('artefact_blog_blog', 'commentsnotify', 'blog', $parent);
}
public static function get_links($id) {
$wwwroot = get_config('wwwroot');
return array(
'_default' => $wwwroot . 'artefact/blog/post.php?blogpost=' . $id,
);
}
}
?>
......@@ -30,12 +30,41 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('myfiles', 'artefact.file'));
safe_require('artefact', 'file');
$folder_id = param_integer('folder', null);
if ($folder_id) {
$folder_list = array();
$current_folder = get_record('artefact', 'id', $folder_id);
if ($current_folder->artefacttype == 'folder') {
$folder_list[] = array(
'id' => $current_folder->id,
'name' => $current_folder->title,
);
}
while ($current_folder->parent) {
$current_folder = get_record('artefact', 'id', $current_folder->parent);
$folder_list[] = array(
'id' => $current_folder->id,
'name' => $current_folder->title,
);
}
$enc_folders = json_encode(array_reverse($folder_list));
}
else {
$enc_folders = json_encode(array());
}
$copyright = get_field('site_content', 'content', 'name', 'uploadcopyright');
$javascript = <<<JAVASCRIPT
var copyrightnotice = '{$copyright}';
var browser = new FileBrowser('filelist', 'myfiles.json.php');
var browser = new FileBrowser('filelist', 'myfiles.json.php', null, null, null, null, {$enc_folders});
var uploader = new FileUploader('uploader', 'upload.php', {}, null, null,
browser.refresh, browser.fileexists);
browser.changedircallback = uploader.updatedestination;
......
......@@ -4,7 +4,7 @@
// the file uploader because they are used slightly differently in the
// my files screen and the edit blog post screen
function FileBrowser(element, source, statevars, changedircallback, actionname, actioncallback) {
function FileBrowser(element, source, statevars, changedircallback, actionname, actioncallback, startDirectory) {
var self = this;
this.element = element;
this.source = source;
......@@ -25,6 +25,27 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
this.updatemetadatascript = config.wwwroot+'artefact/file/updatemetadata.json.php';
this.downloadscript = config.wwwroot+'artefact/file/download.php';
if (typeof(startDirectory) == 'object') {
var dirWalk = this.rootDirectory;
forEach(startDirectory, function(folder) {
if (folder.id == 0) {
return;
}
var dirNode = {
'folderid': folder.id,
'name': folder.name,
'children': {},
'parent': dirWalk
};
dirWalk.children[folder.name] = dirNode;
dirWalk = dirNode;
});
this.currentDirectory = dirWalk;
}
if (this.actionname) {
this.lastcolumnfunc = function(r) {
if (r.artefacttype != 'folder') {
......@@ -102,7 +123,7 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
return TR({'class': 'r' + (n%2),'id':'row_' + r.id});
};
self.filelist.init();
self.chdir(self.rootDirectory);
self.chdir(self.currentDirectory);
}
this.deleted = function (data) {
......
......@@ -254,7 +254,7 @@ class PluginArtefactFile extends PluginArtefact {
}
class ArtefactTypeFileBase extends ArtefactType {
abstract class ArtefactTypeFileBase extends ArtefactType {
protected $adminfiles = 0;
protected $size;
......@@ -429,8 +429,6 @@ class ArtefactTypeFileBase extends ArtefactType {
'javascript' => null);
}
}
class ArtefactTypeFile extends ArtefactTypeFileBase {
......@@ -698,6 +696,14 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return array(FORMAT_ARTEFACT_LISTSELF, FORMAT_ARTEFACT_RENDERMETADATA);
}
public static function get_links($id) {
$wwwroot = get_config('wwwroot');
return array(
'_default' => $wwwroot . 'artefact/file/download.php?file=' . $id,
get_string('folder', 'artefact.file') => $wwwroot . 'artefact/file/?folder=' . $id,
);
}
}
class ArtefactTypeFolder extends ArtefactTypeFileBase {
......@@ -841,6 +847,13 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
return $data;
}
public static function get_links($id) {
$wwwroot = get_config('wwwroot');
return array(
'_default' => $wwwroot . 'artefact/file/?folder=' . $id,
);
}
}
class ArtefactTypeImage extends ArtefactTypeFile {
......
......@@ -321,6 +321,14 @@ class ArtefactTypeProfile extends ArtefactType {
set_config_plugin('artefact', 'internal', 'profileiconwidth', $values['profileiconwidth']);
set_config_plugin('artefact', 'internal', 'profileiconheight', $values['profileiconheight']);
}
public static function get_links($id) {
$wwwroot = get_config('wwwroot');
return array(
'_default' => $wwwroot . 'artefact/internal/',
);
}
}
class ArtefactTypeProfileField extends ArtefactTypeProfile {
......@@ -496,6 +504,14 @@ class ArtefactTypeProfileIcon extends ArtefactTypeProfileField {
$html .= '>';
return array('html' => $html, 'javascript' => null);
}
public static function get_links($id) {
$wwwroot = get_config('wwwroot');
return array(
'_default' => $wwwroot . 'artefact/internal/profileicons.php',
);
}
}
......
......@@ -629,6 +629,15 @@ abstract class ArtefactType {
return false;
}
/**
* Returns a list of key => value pairs where the key is either '_default'
* or a langauge string, and value is a URL linking to that behaviour for
* this artefact type
*
* @param integer This is the ID of the artefact being linked to
*/
public static abstract function get_links($id);
// ******************** HELPER FUNCTIONS ******************** //
protected function get_artefact_type() {
......
......@@ -162,6 +162,26 @@ 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) {
if ($data['count']) {
foreach ($data['data'] as &$result) {
switch ($result['type']) {
case 'artefact':
if (isset($result['artefacttype'])) {
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']);
}
else {
log_debug($result);
}
break;
default:
break;
}
}
}
}
}
?>
......@@ -210,6 +210,8 @@ END;
}
}
self::self_search_make_links($results);
return $results;
}
......@@ -280,6 +282,7 @@ END;
$doc = array(
'id' => $artefact->get('id'),
'owner' => $artefact->get('owner'),
'ref_artefacttype' => $artefact->get('artefacttype'),
'type' => 'artefact',
'title' => $artefact->get('title'),
'description' => $artefact->get('description'),
......@@ -499,7 +502,7 @@ END;
$result['summary'] = $summary_info[$result['idtype']];
}
if (empty($result['summary'])) {
if (empty($result['summary']) && isset($result['description'])) {
$result['summary'] = $result['description'];
}
......
......@@ -44,7 +44,24 @@ results.statevars.push('query');
results.statevars.push('type');
results.emptycontent = {$enc_noresults};
results.rowfunction = function (r, n, d) {
var titleElement = H3(null, A({'href': config.wwwroot + 'view/view.php?artefactid=' + r.id}, r.title));
var titleElement
if (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))];
}
for ( var k in r.links ) {
var button = BUTTON(null, k);
connect(button, 'onclick', function () {
document.location.href = r.links[k];
});
titleElement.push(button);
}
var descriptionElement = P(null);
descriptionElement.innerHTML = r.summary;
......
Markdown is supported
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