Skip to content

Commit

Permalink
MDL-26105 Block settings should contains less options, and be more us…
Browse files Browse the repository at this point in the history
…er friendly

AMOS BEGIN
    MOV [page-blog-index, pagetype], [page-blog-index, blog]
    MOV [page-blog-x, pagetype], [page-blog-x, blog]
    MOV [page-tag-x, pagetype], [page-tag-x, tag]
    MOV [page-course-view-weeks, pagetype], [page-course-view-weeks, format_weeks]
    MOV [page-course-view-weeks-x, pagetype], [page-course-view-weeks-x, format_weeks]
    MOV [page-course-view-topics, pagetype], [page-course-view-topics, format_topics]
    MOV [page-course-view-topics-x, pagetype], [page-course-view-topics-x, format_topics]
AMOS END
  • Loading branch information
Dongsheng Cai authored and andyjdavis committed Jun 9, 2011
1 parent a56c68e commit b1627a9
Show file tree
Hide file tree
Showing 54 changed files with 570 additions and 38 deletions.
82 changes: 59 additions & 23 deletions blocks/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
}

require_once($CFG->libdir . '/formslib.php');
require_once($CFG->libdir . '/blocklib.php');

/**
* The base class form used by blocks/edit.php to edit block instance configuration.
Expand Down Expand Up @@ -89,40 +90,73 @@ function definition() {
$parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
$mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);

$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext));
$mform->addHelpButton('bui_homecontext', 'createdat', 'block');

// parse pagetype patterns
$bits = explode('-', $this->page->pagetype);

$contextoptions = array();
if ( ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid == SITEID) ||
($parentcontext->contextlevel == CONTEXT_SYSTEM)) { // Home page
$contextoptions[0] = get_string('showonfrontpageonly', 'block');
$contextoptions[1] = get_string('showonfrontpageandsubs', 'block');
$contextoptions[2] = get_string('showonentiresite', 'block');
($parentcontext->contextlevel == CONTEXT_SYSTEM)) { // Home page
if ($bits[0] == 'tag') {
// tag always use system context, the contexts options don't make differences, so we use
// page type patterns only
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_ENTIRE_SITE);
} else {
$contextoptions[BUI_CONTEXTS_FRONTPAGE_ONLY] = get_string('showonfrontpageonly', 'block');
$contextoptions[BUI_CONTEXTS_FRONTPAGE_SUBS] = get_string('showonfrontpageandsubs', 'block');
$contextoptions[BUI_CONTEXTS_ENTIRE_SITE] = get_string('showonentiresite', 'block');
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
$mform->addHelpButton('bui_contexts', 'contexts', 'block');
}
} else if ($parentcontext->contextlevel == CONTEXT_COURSE) {
// 0 means display on current context only, not child contexts
// but if course managers select mod-* as pagetype patterns, block system will overwrite this option
// to 1 (display on current context and child contexts)
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
} else if ($parentcontext->contextlevel == CONTEXT_MODULE or $parentcontext->contextlevel == CONTEXT_USER) {
// module context doesn't have child contexts, so display in current context only
$mform->addElement('hidden', 'bui_contexts', BUI_CONTEXTS_CURRENT);
} else {
$parentcontextname = print_context_name($parentcontext);
$contextoptions[0] = get_string('showoncontextonly', 'block', $parentcontextname);
$contextoptions[1] = get_string('showoncontextandsubs', 'block', $parentcontextname);
$contextoptions[BUI_CONTEXTS_CURRENT] = get_string('showoncontextonly', 'block', $parentcontextname);
$contextoptions[BUI_CONTEXTS_CURRENT_SUBS] = get_string('showoncontextandsubs', 'block', $parentcontextname);
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);
}
$mform->addElement('select', 'bui_contexts', get_string('contexts', 'block'), $contextoptions);

if ($this->page->pagetype == 'site-index') { // No need for pagetype list on home page
$pagetypelist = array('*');
$pagetypelist = array('*'=>get_string('page-x', 'pagetype'));
} else {
$pagetypelist = matching_page_type_patterns($this->page->pagetype);
}
$pagetypeoptions = array();
foreach ($pagetypelist as $pagetype) { // Find human-readable names for the pagetypes
$pagetypeoptions[$pagetype] = $pagetype;
$pagetypestringname = 'page-'.str_replace('*', 'x',$pagetype); // Better names MDL-21375
if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
$pagetypeoptions[$pagetype] .= ' (' . get_string($pagetypestringname, 'pagetype') . ')';
// Generate pagetype patterns by callbacks
$pagetypelist = generate_page_type_patterns($this->page->pagetype, $parentcontext, $this->page->context);
if (!array_key_exists($this->block->instance->pagetypepattern, $pagetypelist)) {
// Pushing block's existing page type pattern
$pagetypestringname = 'page-'.str_replace('*', 'x', $this->block->instance->pagetypepattern);
if (get_string_manager()->string_exists($pagetypestringname, 'pagetype')) {
$pagetyelist[$this->block->instance->pagetypepattern] = get_string($pagetypestringname, 'pagetype');
}
}
}
$mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypeoptions);

// hide page type pattern select box if there is only one choice
if (count($pagetypelist) > 1) {
$mform->addElement('select', 'bui_pagetypepattern', get_string('restrictpagetypes', 'block'), $pagetypelist);
} else {
$value = array_pop(array_keys($pagetypelist));
$mform->addElement('hidden', 'bui_pagetypepattern', $value);
}

if ($this->page->subpage) {
$subpageoptions = array(
'%@NULL@%' => get_string('anypagematchingtheabove', 'block'),
$this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage),
);
$mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
if ($parentcontext->contextlevel == CONTEXT_USER) {
$mform->addElement('hidden', 'bui_subpagepattern', '%@NULL@%');
} else {
$subpageoptions = array(
'%@NULL@%' => get_string('anypagematchingtheabove', 'block'),
$this->page->subpage => get_string('thisspecificpage', 'block', $this->page->subpage),
);
$mform->addElement('select', 'bui_subpagepattern', get_string('subpages', 'block'), $subpageoptions);
}
}

$defaultregionoptions = $regionoptions;
Expand All @@ -131,8 +165,10 @@ function definition() {
$defaultregionoptions[$defaultregion] = $defaultregion;
}
$mform->addElement('select', 'bui_defaultregion', get_string('defaultregion', 'block'), $defaultregionoptions);
$mform->addHelpButton('bui_defaultregion', 'defaultregion', 'block');

$mform->addElement('select', 'bui_defaultweight', get_string('defaultweight', 'block'), $weightoptions);
$mform->addHelpButton('bui_defaultweight', 'defaultweight', 'block');

// Where this block is positioned on this page.
$mform->addElement('header', 'whereheader', get_string('onthispage', 'block'));
Expand Down Expand Up @@ -182,7 +218,7 @@ function set_data($defaults) {

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
if ($defaults->parentcontextid == $systemcontext->id) {
$defaults->bui_contexts = 2; // System-wide and sticky
$defaults->bui_contexts = BUI_CONTEXTS_ENTIRE_SITE; // System-wide and sticky
} else {
$defaults->bui_contexts = $defaults->bui_showinsubcontexts;
}
Expand Down
15 changes: 15 additions & 0 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,18 @@ function blog_comment_validate($comment_param) {
}
return true;
}

/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function blog_pagetypelist($pagetype, $parentcontext, $currentcontext) {
return array(
'*'=>get_string('page-x', 'pagetype'),
'blog-*'=>get_string('page-blog-x', 'blog'),
'blog-index'=>get_string('page-blog-index', 'blog'),
'blog-edit'=>get_string('page-blog-edit', 'blog')
);
}
4 changes: 3 additions & 1 deletion course/format/topics/lang/en/format_topics.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@

$string['sectionname'] = 'Topic';
$string['pluginname'] = 'Topics format';
$string['section0name'] = 'General';
$string['section0name'] = 'General';
$string['page-course-view-topics'] = 'Any course main page in topics format';
$string['page-course-view-topics-x'] = 'Any course page in topics format';
2 changes: 2 additions & 0 deletions course/format/weeks/lang/en/format_weeks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
$string['sectionname'] = 'Week';
$string['pluginname'] = 'Weekly format';
$string['section0name'] = 'General';
$string['page-course-view-weeks'] = 'Any course main page in weeks format';
$string['page-course-view-weeks-x'] = 'Any course page in weeks format';
20 changes: 20 additions & 0 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4211,3 +4211,23 @@ protected function notify($touser, $fromuser, $name='courserequested', $subject,
message_send($eventdata);
}
}

/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function course_pagetypelist($pagetype, $parentcontext, $currentcontext) {
// if above course context ,display all course fomats
list($currentcontext, $course, $cm) = get_context_info_array($currentcontext->id);
if ($course->id == SITEID) {
return array('*'=>get_string('page-x', 'pagetype'));
} else {
return array('*'=>get_string('page-x', 'pagetype'),
'course-*'=>get_string('page-course-x', 'pagetype'),
'course-view-*'=>get_string('page-course-view-x', 'pagetype'),
'mod-*'=>get_string('page-mod-x', 'pagetype')
);
}
}
11 changes: 8 additions & 3 deletions lang/en/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
$string['bracketfirst'] = '{$a} (first)';
$string['bracketlast'] = '{$a} (last)';
$string['contexts'] = 'Page contexts';
$string['contexts_help'] = 'Contexts are more specific types of pages where this block can be displayed within the original block location. You will have different options here depending on the original block location and your current location. For example, you can restrict a block to only appearing on forum pages in a course by adding the block to the course (making it appear on all sub-pages), then going into a forum and editing the block settings again to restrict display to just forum pages.';
$string['createdat'] = 'Original block location';
$string['createdat_help'] = 'This is the original location where the block was created, even though other block settings may cause it to appear in other locations (contexts) within this original location. For example, a block created in a course could be displayed on one or more pages within that course only. A block created on the front page, however, could be displayed throughout the site.';
$string['defaultregion'] = 'Default region';
$string['defaultregion_help'] = 'Themes may define one or more named block regions where blocks are displayed. This setting defines which of these you want this block to appear in by default. The region may be overridden on specific pages if required.';
$string['defaultweight'] = 'Default weight';
$string['defaultweight_help'] = 'The default weight allows you to choose roughly where you want the block to appear in the chosen region, either at the top or the bottom. The final location is calculated from all the blocks in that region (for example, only one block can actually be at the top). This value can be overridden on specific pages if required.';
$string['moveblockhere'] = 'Move block here';
$string['movingthisblockcancel'] = 'Moving this block ({$a})';
$string['onthispage'] = 'On this page';
Expand All @@ -43,9 +48,9 @@
$string['showonfrontpageandsubs'] = 'Display on the front page and any pages added to the front page';
$string['showonfrontpageonly'] = 'Display on the front page only';
$string['site-*'] = 'Any top-level site page';
$string['subpages'] = 'Specific sub-page';
$string['restrictpagetypes'] = 'Restrict to these page types';
$string['thisspecificpage'] = 'This specific page (page {$a})';
$string['subpages'] = 'Select pages';
$string['restrictpagetypes'] = 'Display on page types';
$string['thisspecificpage'] = 'This specific page';
$string['undockall'] = 'Undock all';
$string['undockitem'] = 'Undock this item';
$string['visible'] = 'Visible';
Expand Down
3 changes: 3 additions & 0 deletions lang/en/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,6 @@
$string['viewuserentries'] = 'View all entries by {$a}';
$string['worldblogs'] = 'The world can read entries set to be world-accessible';
$string['wrongpostid'] = 'Wrong blog post id';
$string['page-blog-edit'] = 'Blog editing pages';
$string['page-blog-index'] = 'Blog listing pages';
$string['page-blog-x'] = 'All blog pages';
2 changes: 2 additions & 0 deletions lang/en/notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
$string['notesdisabled'] = 'Notes are disabled, sorry.';
$string['notesnotvisible'] = 'You are not allowed to view the notes.';
$string['nouser'] = 'You must select a user';
$string['page-notes-x'] = 'Any note pages';
$string['page-notes-index'] = 'Notes main page';
$string['personal'] = 'personal';
$string['personalnotes'] = 'Personal notes';
$string['publishstate'] = 'Context';
Expand Down
8 changes: 2 additions & 6 deletions lang/en/pagetype.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['page-blog-index'] = 'Blog listing pages';
$string['page-blog-x'] = 'All blog pages';
$string['page-course-view-topics'] = 'Any course main page in topics format';
$string['page-course-view-weeks'] = 'Any course main page in weeks format';
$string['page-course-view-x'] = 'Any type of course main page';
$string['page-course-x'] = 'Any course page';
$string['page-mod-x'] = 'Any activity module page';
$string['page-mod-x-view'] = 'Any main activity module page';
$string['page-my-index'] = 'Users\' My home page';
$string['page-my-index'] = 'My home page';
$string['page-site-index'] = 'The front page only';
$string['page-site-x'] = 'Any top-level site page';
$string['page-tag-x'] = 'All tag pages';
$string['page-user-view'] = 'Only user profile pages';
$string['page-user-profile'] = 'Only user profile pages';
$string['page-user-x'] = 'All user pages';
$string['page-x'] = 'Any page';
5 changes: 5 additions & 0 deletions lang/en/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
$string['notenoughdatatomovequestions'] = 'You need to provide the question ids of questions you want to move.';
$string['notflagged'] = 'Not flagged';
$string['novirtualquestiontype'] = 'No virtual question type for question type {$a}';
$string['page-question-x'] = 'Any question page';
$string['page-question-edit'] = 'Question editing page';
$string['page-question-category'] = 'Question category page';
$string['page-question-import'] = 'Question import page';
$string['page-question-export'] = 'Question export page';
$string['parentcategory'] = 'Parent category';
$string['parentcategory_help'] = 'The parent category is the one in which the new category will be placed. "Top" means that this category is not contained in any other category. Category contexts are shown in bold type. There must be at least one category in each context.';
$string['parentcategory_link'] = 'question/category';
Expand Down
5 changes: 5 additions & 0 deletions lang/en/tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$string['addedotag'] = '"{$a}" was added as an official tag.';
$string['addotags'] = 'Add official tags';
$string['addtagtomyinterests'] = 'Add "{$a}" to my interests';
$string['alltagpages'] = 'All tag pages';
$string['count'] = 'Count';
$string['delete'] = 'Delete';
$string['deleted'] = 'Deleted';
Expand Down Expand Up @@ -82,3 +83,7 @@
$string['updated'] = 'Updated';
$string['updatetag'] = 'Update';
$string['withselectedtags'] = 'With selected tags...';
$string['page-tag-x'] = 'All tag pages';
$string['page-tag-index'] = 'Single tag page';
$string['page-tag-search'] = 'Tag search page';
$string['page-tag-manage'] = 'Tag manage page';
Loading

0 comments on commit b1627a9

Please sign in to comment.