public static function instance_config_form(BlockInstance $instance) { global $USER; safe_require('artefact', 'blog'); $configdata = $instance->get('configdata'); require_once get_config('libroot') . 'view.php'; $view = new View($instance->get('view')); $institution = $view->get('institution'); $group = $view->get('group'); if (!empty($configdata['artefactid'])) { $blog = $instance->get_artefact_instance($configdata['artefactid']); } $elements = array(); // If the blog in this block is owned by the owner of the View, then // the block can be configured. Otherwise, the blog was copied in from // another View. We won't confuse users by asking them to choose a blog // to put in this block, when the one that is currently in it isn't // choosable. // // Note: the owner check will have to change when we do group/site // blogs if (empty($configdata['artefactid']) || ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) { $where = array('blog'); $sql = "SELECT a.id FROM {artefact} a\n WHERE a.artefacttype = ?"; if ($institution) { $sql .= " AND a.institution = ?"; $where[] = $institution; } else { if ($group) { $sql .= " AND a.group = ?"; $where[] = $group; } else { $sql .= " AND a.owner = ?"; $where[] = $USER->get('id'); } } $blogids = get_column_sql($sql, $where); $elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $blogids); $elements['count'] = array('type' => 'text', 'title' => get_string('postsperpage', 'blocktype.blog/blog'), 'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 5, 'size' => 3); $elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blog'); } else { $elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('Blog', 'artefact.blog')) . '</div>'); } return $elements; }
public static function instance_config_form(BlockInstance $instance) { global $USER; safe_require('artefact', 'blog'); $configdata = $instance->get('configdata'); if (!empty($configdata['artefactid'])) { $blog = $instance->get_artefact_instance($configdata['artefactid']); } $elements = array(); // If the blog post in this block is owned by the owner of the View, // then the block can be configured. Otherwise, the blog post was // copied in from another View. We won't confuse users by asking them to // choose a blog post to put in this block, when the one that is // currently in it isn't choosable. $institution = $instance->get('view_obj')->get('institution'); $group = $instance->get('view_obj')->get('group'); if (empty($configdata['artefactid']) || ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) { $sql = "SELECT a.id FROM {artefact} a\n INNER JOIN {artefact_blog_blogpost} p ON p.blogpost = a.id\n WHERE p.published = 1"; if ($institution) { $sql .= " AND a.institution = ?"; $where = array($institution); } else { if ($group) { $sql .= " AND a.group = ?"; $where = array($group); } else { $sql .= " AND a.owner = ?"; $where = array($USER->get('id')); } } $publishedposts = get_column_sql($sql, $where); $elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $publishedposts); $elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost'); } else { $elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blogpost', 'artefact.blog')) . '</div>'); } return $elements; }