Commit ae246f79 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show owner and full path when choosing artefacts in File download, image blocks

parent b4af0112
......@@ -124,27 +124,9 @@ class PluginBlocktypeFiledownload extends PluginBlocktype {
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*
* Note: same as the 'image' blocktype's version of this
*/
public static function artefactchooser_get_element_data($artefact) {
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
if ($artefact->artefacttype == 'profileicon') {
$artefact->hovertitle = $artefact->note;
if ($artefact->title) {
$artefact->hovertitle .= ': ' . $artefact->title;
}
}
else {
$artefact->hovertitle = $artefact->title;
if ($artefact->description) {
$artefact->hovertitle .= ': ' . $artefact->description;
}
}
$artefact->title = str_shorten($artefact->title, 20);
$artefact->description = ($artefact->artefacttype == 'profileicon') ? $artefact->title : $artefact->description;
return $artefact;
return ArtefactTypeFileBase::artefactchooser_get_file_data(&$artefact);
}
}
......
......@@ -103,21 +103,13 @@ class PluginBlocktypeFolder extends PluginBlocktype {
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*
* Note: this method is the same as the one for the 'filedownload' blocktype
*/
public static function artefactchooser_get_element_data($artefact) {
global $USER;
// Grab data about all folders this user has, so we can make full paths to them
static $folderdata = null;
if ($folderdata === null) {
$folderdata = get_records_select_assoc('artefact', "artefacttype='folder' AND owner = ?", array($USER->get('id')), '', 'id, title, parent');
}
$folderdata = ArtefactTypeFileBase::artefactchooser_folder_data(&$artefact);
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
$artefact->hovertitle = $artefact->description;
$artefact->description = self::get_full_folder_path($artefact->id, $folderdata);
$artefact->description = $folderdata->ownername . ArtefactTypeFileBase::get_full_path($artefact->id, $folderdata->data);
return $artefact;
}
......@@ -126,24 +118,6 @@ class PluginBlocktypeFolder extends PluginBlocktype {
return 'parent, title';
}
/**
* Works out a full path to a folder, given an ID. Implemented this way so
* only one query is made.
*/
private static function get_full_folder_path($id, $folderdata) {
$path = '';
foreach ($folderdata as $folder) {
if ($folder->id == $id) {
$path = $folder->title;
while ($folder->parent !== null) {
$folder = $folderdata[$folder->parent];
$path = $folder->title . '/' . $path;
}
}
}
return $path;
}
}
?>
......@@ -124,27 +124,9 @@ class PluginBlocktypeImage extends PluginBlocktype {
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
*
* Note: this method is the same as the one for the 'filedownload' blocktype
*/
public static function artefactchooser_get_element_data($artefact) {
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
if ($artefact->artefacttype == 'profileicon') {
$artefact->hovertitle = $artefact->note;
if ($artefact->title) {
$artefact->hovertitle .= ': ' . $artefact->title;
}
}
else {
$artefact->hovertitle = $artefact->title;
if ($artefact->description) {
$artefact->hovertitle .= ': ' . $artefact->description;
}
}
$artefact->title = str_shorten($artefact->title, 20);
$artefact->description = ($artefact->artefacttype == 'profileicon') ? $artefact->title : $artefact->description;
return $artefact;
return ArtefactTypeFileBase::artefactchooser_get_file_data(&$artefact);
}
}
......
......@@ -583,6 +583,76 @@ JAVASCRIPT;
);
}
public static function artefactchooser_get_file_data($artefact) {
$artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
if ($artefact->artefacttype == 'profileicon') {
$artefact->hovertitle = $artefact->note;
if ($artefact->title) {
$artefact->hovertitle .= ': ' . $artefact->title;
}
}
else {
$artefact->hovertitle = $artefact->title;
if ($artefact->description) {
$artefact->hovertitle .= ': ' . $artefact->description;
}
}
$folderdata = self::artefactchooser_folder_data(&$artefact);
if ($artefact->artefacttype == 'profileicon') {
$artefact->description = $artefact->title;
}
else {
$path = $artefact->parent ? self::get_full_path($artefact->parent, $folderdata->data) : '';
$artefact->description = $folderdata->ownername . $path . $artefact->title;
}
return $artefact;
}
public static function artefactchooser_folder_data($artefact) {
// Grab data about all folders the artefact owner has, so we
// can make full paths to them, and show the artefact owner if
// it's a group or institution.
static $folderdata = array();
$ownerkey = $artefact->owner . '::' . $artefact->group . '::' . $artefact->institution;
if (!isset($folderdata[$ownerkey])) {
$ownersql = artefact_owner_sql($artefact->owner, $artefact->group, $artefact->institution);
$folderdata[$ownerkey]->data = get_records_select_assoc('artefact', "artefacttype='folder' AND $ownersql", array(), '', 'id, title, parent');
if ($artefact->group) {
$folderdata[$ownerkey]->ownername = get_field('group', 'name', 'id', $artefact->group) . ':';
}
else if ($artefact->institution) {
if ($artefact->institution == 'mahara') {
$folderdata[$ownerkey]->ownername = get_string('Site') . ':';
}
else {
$folderdata[$ownerkey]->ownername = get_field('institution', 'displayname', 'name', $artefact->institution) . ':';
}
}
else {
$folderdata[$ownerkey]->ownername = '';
}
}
return $folderdata[$ownerkey];
}
/**
* Works out a full path to a folder, given an ID. Implemented this way so
* only one query is made.
*/
public static function get_full_path($id, $folderdata) {
$path = '';
while (!empty($id)) {
$path = $folderdata[$id]->title . '/' . $path;
$id = $folderdata[$id]->parent;
}
return $path;
}
}
class ArtefactTypeFile extends ArtefactTypeFileBase {
......
......@@ -254,6 +254,7 @@ $string['captchatitle'] = 'CAPTCHA Image';
$string['captchaimage'] = 'CAPTCHA Image';
$string['captchadescription'] = 'Enter the characters you see in the picture. Letters are not case sensitive';
$string['captchaincorrect'] = 'Enter the letters as they are shown in the image';
$string['Site'] = 'Site';
// Misc. register stuff that could be used elsewhere
$string['emailaddress'] = 'Email address';
......
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