Commit 8c048333 authored by Penny Leach's avatar Penny Leach Committed by Nigel McNie
Browse files

thumbnails for blocktypes, implemented the view_build_category_list function...

thumbnails for blocktypes, implemented the view_build_category_list function to actually go look in the database
parent e5389b31
......@@ -76,7 +76,7 @@ abstract class PluginBlocktype extends Plugin {
return false;
}
public static function title_from_name($name) {
public static function category_title_from_name($name) {
$title = get_string('blocktypecategory.'. $name);
if (strpos($title, '[[') !== 0) {
return $title;
......@@ -84,6 +84,33 @@ abstract class PluginBlocktype extends Plugin {
// else we're an artefact
return get_string('pluginname', 'artefact.' . $name);
}
public static function get_blocktypes_for_category($category) {
$sql = 'SELECT bti.name,bti.artefactplugin
FROM {blocktype_installed} bti
JOIN {blocktype_installed_category} btic ON btic.blocktype = bti.name
WHERE btic.category = ?';
if (!$bts = get_records_sql_array($sql, array($category))) {
return false;
}
$blocktypes = array();
foreach ($bts as $bt) {
$namespaced = blocktype_single_to_namespaced($bt->name, $bt->artefactplugin);
safe_require('blocktype', $namespaced);
$temp = array(
'name' => $bt->name,
'title' => call_static_method(generate_class_name('blocktype', $namespaced), 'get_title'),
'description' => call_static_method(generate_class_name('blocktype', $namespaced), 'get_description'),
'artefactplugin' => $bt->artefactplugin,
'thumbnail_path' => get_config('wwwroot') . 'thumb.php?type=blocktype&bt=' . $bt->name .'&ap=' . $bt->artefactplugin
);
$blocktypes[] = $temp;
}
return $blocktypes;
}
}
class BlockInstance {
......
......@@ -74,6 +74,22 @@ switch ($type) {
}
readfile(theme_get_path('images/no_userphoto40x40.png'));
break;
case 'blocktype':
$bt = param_alpha('bt'); // blocktype
$ap = param_alpha('ap', null); // artefact plugin (optional)
$basepath = 'blocktype/' . $bt;
if (!empty($ap)) {
$basepath = 'artefact/' . $ap . '/' . $basepath;
}
header('Content-type: image/png');
if (is_readable(get_config('docroot') . $basepath . '/thumb.png')) {
readfile($path);
exit;
}
readfile(theme_get_path('images/no_thumbnail.png'));
break;
}
?>
......@@ -180,7 +180,7 @@ function view_build_category_list($defaultcategory, $javascript=false) {
'$a = $a->name;
return array(
"name" => $a,
"title" => call_static_method("PluginBlockType", "title_from_name", $a),
"title" => call_static_method("PluginBlockType", "category_title_from_name", $a),
);'
),
$cats
......@@ -218,37 +218,10 @@ function view_build_category_list($defaultcategory, $javascript=false) {
* alone should be output
*/
function view_build_blocktype_list($category, $javascript=false) {
// TODO: This data structure needs to be sourced from the database
$blocktypes = array(
array(
'id' => 1,
'name' => 'blocktype1',
'title' => 'Block Type ' . $category,
'description' => 'This is the description for block type 1',
'thumbnail_path' => 'theme/default/static/images/no_thumbnail.gif',
),
array(
'id' => 2,
'name' => 'blocktype2',
'title' => 'Block Type ' . $category,
'description' => 'This is the description for block type 2',
'thumbnail_path' => 'theme/default/static/images/no_thumbnail.gif',
),
array(
'id' => 3,
'name' => 'blocktype3',
'title' => 'Block Type ' . $category,
'description' => 'This is the description for block type 3',
'thumbnail_path' => 'theme/default/static/images/no_thumbnail.gif',
),
array(
'id' => 4,
'name' => 'blocktype4',
'title' => 'Block Type ' . $category,
'description' => 'This is the description for block type 4',
'thumbnail_path' => 'theme/default/static/images/no_thumbnail.gif',
),
);
if (!$blocktypes = PluginBlockType::get_blocktypes_for_category($category)) {
return '';
}
$template =<<<EOF
<li>
......@@ -266,7 +239,7 @@ EOF;
$blocktypehtml = str_replace('{TITLE}', hsc($blocktype['title']), $blocktypehtml);
$blocktypehtml = str_replace('{DESCRIPTION}', format_whitespace(hsc($blocktype['description'])), $blocktypehtml);
$blocktypehtml = str_replace('{THUMBNAIL_PATH}', hsc($blocktype['thumbnail_path']), $blocktypehtml);
$radio = ($javascript) ? '' : '<input type="radio" class="blocktype-radio" name="blocktype" value="' . $blocktype['id'] . '">';
$radio = ($javascript) ? '' : '<input type="radio" class="blocktype-radio" name="blocktype" value="' . $blocktype['name'] . '">';
$blocktypehtml = str_replace('{RADIO}', $radio, $blocktypehtml);
$result .= $blocktypehtml;
......
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