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

Add filebrowser to internalmedia block config & filter by mimetype

parent 462e767c
......@@ -120,31 +120,11 @@ class PluginBlocktypeImage extends PluginBlocktype {
return $values;
}
public static function artefactchooser_element($default=null, $istemplate=false) {
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('image'),
'defaultvalue' => $default,
'blocktype' => 'image',
'limit' => 10,
'artefacttypes' => array('image', 'profileicon'),
'template' => 'artefact:file:artefactchooser-element.tpl',
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
public static function filebrowser_element(&$instance, $default=null, $istemplate=false) {
$element = array(
'name' => 'filebrowser',
'type' => 'filebrowser',
'title' => get_string('image'),
'name' => 'filebrowser',
'type' => 'filebrowser',
'title' => get_string('image'),
'folder' => param_integer('folder', 0),
'highlight' => null,
'browse' => true,
......@@ -175,6 +155,26 @@ class PluginBlocktypeImage extends PluginBlocktype {
return $element;
}
public static function artefactchooser_element($default=null, $istemplate=false) {
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('image'),
'defaultvalue' => $default,
'blocktype' => 'image',
'limit' => 10,
'artefacttypes' => array('image', 'profileicon'),
'template' => 'artefact:file:artefactchooser-element.tpl',
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
/**
* Optional method. If specified, allows the blocktype class to munge the
* artefactchooser element data before it's templated
......
......@@ -81,22 +81,31 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
public static function instance_config_form($instance, $istemplate) {
$configdata = $instance->get('configdata');
$form = array(
self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
);
$form['width'] = array(
safe_require('artefact', 'file');
$instance->set('artefactplugin', 'file');
return array(
'filebrowser' => self::filebrowser_element($instance, (isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $istemplate),
'width' => array(
'type' => 'text',
'title' => get_string('width'),
'size' => 3,
'defaultvalue' => (isset($configdata['width'])) ? $configdata['width'] : '',
);
$form['height'] = array(
),
'height' => array(
'type' => 'text',
'title' => get_string('height'),
'size' => 3,
'defaultvalue' => (isset($configdata['height'])) ? $configdata['height'] : '',
),
);
return $form;
}
public static function instance_config_save($values) {
if (isset($values['filebrowser']['selected'])) {
$values['artefactid'] = $values['filebrowser']['selected'][0];
}
unset($values['filebrowser']);
return $values;
}
public static function get_artefacts(BlockInstance $instance) {
......@@ -107,6 +116,42 @@ class PluginBlocktypeInternalmedia extends PluginBlocktype {
return false;
}
public static function filebrowser_element(&$instance, $default=null, $istemplate=false) {
$element = array(
'name' => 'filebrowser',
'type' => 'filebrowser',
'title' => get_string('media', 'blocktype.file/internalmedia'),
'folder' => param_integer('folder', 0),
'highlight' => null,
'browse' => true,
'page' => View::make_base_url(),
'config' => array(
'upload' => true,
'uploadagreement' => get_config_plugin('artefact', 'file', 'uploadagreement'),
'createfolder' => false,
'edit' => false,
'select' => true,
'selectone' => true,
'alwaysopen' => true,
),
'filters' => array(
'artefacttype' => array('file'),
'filetype' => self::get_allowed_mimetypes(),
),
'selectlistcallback' => array(
'name' => 'artefact_get_records_by_id',
'args' => array(empty($default) ? array() : array($default)),
),
);
if (!$istemplate) {
// You don't have to choose a file if this view is a template
$element['rules'] = array(
'required' => true,
);
}
return $element;
}
public static function artefactchooser_element($default=null, $istemplate=false) {
$extraselect = 'filetype IN (' . join(',', array_map('db_quote', self::get_allowed_mimetypes())) . ')';
$extrajoin = ' JOIN {artefact_file_files} ON {artefact_file_files}.artefact = a.id ';
......
......@@ -421,7 +421,8 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id
LEFT OUTER JOIN {artefact} c ON c.parent = a.id
LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id';
if ($filters && $filters['artefacttype']) {
if (!empty($filters['artefacttype'])) {
$artefacttypes = $filters['artefacttype'];
$artefacttypes[] = 'folder';
}
......@@ -429,7 +430,12 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
$artefacttypes = array_diff(PluginArtefactFile::get_artefact_types(), array('profileicon'));
}
$where = "
WHERE a.artefacttype IN (" . join(',', array_map('db_quote', $artefacttypes)). ")";
WHERE a.artefacttype IN (" . join(',', array_map('db_quote', $artefacttypes)) . ")";
if (!empty($filters['filetype']) && is_array($filters['filetype'])) {
$where .= "
AND (a.artefacttype = 'folder' OR f.filetype IN (" . join(',', array_map('db_quote', $filters['filetype'])) . '))';
}
$groupby = '
GROUP BY
a.id, a.artefacttype, a.mtime, f.size, a.title, a.description';
......
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