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

Skip my blogs listing when the user only has one blog

parent 6d693c57
......@@ -28,10 +28,8 @@ define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/blogs');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'index');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('myblogs','artefact.blog'));
safe_require('artefact', 'blog');
if ($delete = param_integer('delete', 0)) {
......@@ -49,6 +47,35 @@ $blogs = (object) array(
);
list($blogs->count, $blogs->data) = ArtefactTypeBlog::get_blog_list($blogs->limit, $blogs->offset);
// If the user has exactly one blog, skip the blog listing and display it
if (!$delete && $blogs->offset == 0 && !empty($blogs->data) && count($blogs->data) == 1) {
define('TITLE', get_string('viewblog','artefact.blog'));
define('SECTION_PAGE', 'view');
$record = end($blogs->data);
$id = $record->id;
$blog = new ArtefactTypeBlog($id, $record);
// This javascript is used to generate a list of blog posts.
$js = '';
if ($blog->count_children()) {
$js = require(get_config('docroot') . 'artefact/blog/view/index.js.php');
}
$smarty = smarty(array('tablerenderer'));
$smarty->assign_by_ref('blog', $blog);
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
$smarty->assign('PAGEHEADING', hsc($blog->get('title')));
$smarty->assign('strnopostsaddone',
get_string('nopostsaddone', 'artefact.blog',
'<a href="' . get_config('wwwroot') . 'artefact/blog/post.php?blog=' . $blog->get('id') . '">', '</a>'));
$smarty->display('artefact:blog:view.tpl');
exit;
}
define('TITLE', get_string('myblogs','artefact.blog'));
define('SECTION_PAGE', 'index');
ArtefactTypeBlog::build_blog_list_html($blogs);
$smarty = smarty();
......
......@@ -276,12 +276,8 @@ class ArtefactTypeBlog extends ArtefactType {
public static function get_blog_list($limit, $offset) {
global $USER;
($result = get_records_sql_array("
SELECT id, title, description
FROM {artefact}
WHERE owner = ?
AND artefacttype = 'blog'
ORDER BY title
LIMIT ? OFFSET ?", array($USER->get('id'), $limit, $offset)))
SELECT * FROM {artefact} WHERE owner = ? AND artefacttype = 'blog'
ORDER BY title LIMIT ? OFFSET ?", array($USER->get('id'), $limit, $offset)))
|| ($result = array());
$count = (int)get_field('artefact', 'COUNT(*)', 'owner', $USER->get('id'), 'artefacttype', 'blog');
......
......@@ -5,7 +5,6 @@
</div>
<div id="bloglist">
{$blogs->html}
{*include file="artefact:blog:bloglist.tpl" blogs=$blogs*}
</div>
{$blogs->pagination.html}
{if $blogs->data}{$blogs->pagination.html}{/if}
{include file="footer.tpl"}
......@@ -4,6 +4,7 @@
<div class="rbuttons">
<div><a class="btn-add" href="{$WWWROOT}artefact/blog/post.php?blog={$blog->get('id')}">{str section="artefact.blog" tag="addpost"}</a></div>
<div><a class="btn-edit" href="{$WWWROOT}artefact/blog/settings/?id={$blog->get('id')}">{str section="artefact.blog" tag="settings"}</a></div>
<div><a class="btn-add" href="{$WWWROOT}artefact/blog/new">{str tag=addblog section=artefact.blog}</a></div>
</div>
<p>{$blog->get('description')}</p>
......
......@@ -52,7 +52,7 @@ return <<<EOJAVASCRIPT
var postlist = new TableRenderer(
'postlist',
'index.json.php',
{$enc_wwwroot} + 'artefact/blog/view/index.json.php',
[undefined, undefined, undefined]
);
postlist.limit = $limit;
......
......@@ -46,9 +46,8 @@ if ($blog->count_children()) {
$smarty = smarty(array('tablerenderer'));
$smarty->assign_by_ref('blog', $blog);
$smarty->assign_by_ref('editform', $form);
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
$smarty->assign('PAGEHEADING', hsc(get_string('viewblog', 'artefact.blog') . ' - ' . $blog->get('title')));
$smarty->assign('PAGEHEADING', hsc($blog->get('title')));
$smarty->assign('strnopostsaddone',
get_string('nopostsaddone', 'artefact.blog',
'<a href="' . get_config('wwwroot') . 'artefact/blog/post.php?blog=' . $blog->get('id') . '">', '</a>'));
......
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