[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/lesson/ -> locallib.php (summary)

Local library file for Lesson.  These are non-standard functions that are used only by Lesson.

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
File Size: 3476 lines (133 kb)
Included or required:0 times
Referenced: 18 times
Includes or requires: 0 files

Defines 3 classes

lesson:: (68 methods):
  create()
  load()
  delete()
  delete_override()
  delete_all_overrides()
  update_effective_access()
  get_messages()
  get_attempts()
  get_firstpage()
  get_lastpage()
  get_firstpageid()
  get_lastpageid()
  get_next_page()
  add_message()
  is_accessible()
  start_timer()
  update_timer()
  stop_timer()
  has_pages()
  link_for_activitylink()
  load_page()
  load_all_pages()
  jumpto_is_correct()
  time_remaining()
  cluster_jump()
  get_sub_pages_of()
  is_sub_page_of_type()
  resort_pages()
  __construct()
  __set()
  __get()
  __isset()
  properties()
  create()
  load()
  delete()
  move()
  get_answers()
  get_lesson()
  get_type()
  record_attempt()
  get_jump_name()
  __construct()
  earned_score()
  callback_on_view()
  save_answers_files()
  rewrite_answers_urls()
  update()
  add_page_link()
  is_unseen()
  is_unanswered()
  create_answers()
  check_answer()
  has_option()
  max_answers()
  properties()
  get_jumptooptions()
  get_contents()
  get_displayinmenublock()
  option_description_string()
  display_answers()
  get_grayout()
  stats()
  report_answers()
  get_jumps()
  requires_manual_grading()
  override_next_page()
  valid_page_and_view()

lesson_page_answer:: (2 methods):
  load()
  create()

lesson_page_type_manager:: (9 methods):
  get()
  load_lesson_types()
  get_page_type_strings()
  get_page_type_idstring()
  load_page()
  check_page_order()
  load_all_pages()
  get_page_form()
  get_add_page_type_links()

Defines 9 functions

  lesson_display_teacher_warning()
  lesson_unseen_question_jump()
  lesson_unseen_branch_jump()
  lesson_random_question_jump()
  lesson_grade()
  lesson_displayleftif()
  lesson_add_fake_blocks()
  lesson_mediafile_block_contents()
  lesson_clock_block_contents()
  lesson_menu_block_contents()
  lesson_add_header_buttons()
  lesson_get_media_html()
  lesson_process_group_deleted_in_course()
  custom_definition()
  get_answer_format()
  get_response_format()
  is_standard()
  definition()
  add_jumpto()
  add_score()
  add_answer()
  add_response()
  construction_override()

Class: lesson  - X-Ref

Class representation of a lesson

This class is used the interact with, and manage a lesson once instantiated.
If you need to fetch a lesson object you can do so by calling

<code>
lesson::load($lessonid);
// or
$lessonrecord = $DB->get_record('lesson', $lessonid);
$lesson = new lesson($lessonrecord);
</code>

The class itself extends lesson_base as all classes within the lesson module should

These properties are from the database
create($properties)   X-Ref
Simply generates a lesson object given an array/object of properties
Overrides {@see lesson_base->create()}

param: object|array $properties
return: lesson

load($lessonid)   X-Ref
Generates a lesson object from the database given its id

param: int $lessonid
return: lesson

delete()   X-Ref
Deletes this lesson from the database


delete_override($overrideid)   X-Ref
Deletes a lesson override from the database and clears any corresponding calendar events

param: int $overrideid The id of the override being deleted
return: bool true on success

delete_all_overrides()   X-Ref
Deletes all lesson overrides from the database and clears any corresponding calendar events


update_effective_access($userid)   X-Ref
Updates the lesson properties with override information for a user.

Algorithm:  For each lesson setting, if there is a matching user-specific override,
then use that otherwise, if there are group-specific overrides, return the most
lenient combination of them.  If neither applies, leave the quiz setting unchanged.

Special case: if there is more than one password that applies to the user, then
lesson->extrapasswords will contain an array of strings giving the remaining
passwords.

param: int $userid The userid.

get_messages()   X-Ref
Fetches messages from the session that may have been set in previous page
actions.

<code>
// Do not call this method directly instead use
$lesson->messages;
</code>

return: array

get_attempts($retries, $correct=false, $pageid=null, $userid=null)   X-Ref
Get all of the attempts for the current user.

param: int $retries
param: bool $correct Optional: only fetch correct attempts
param: int $pageid Optional: only fetch attempts at the given page
param: int $userid Optional: defaults to the current user if not set
return: array|false

get_firstpage()   X-Ref
Returns the first page for the lesson or false if there isn't one.

This method should be called via the magic method __get();
<code>
$firstpage = $lesson->firstpage;
</code>

return: lesson_page|bool Returns the lesson_page specialised object or false

get_lastpage()   X-Ref
Returns the last page for the lesson or false if there isn't one.

This method should be called via the magic method __get();
<code>
$lastpage = $lesson->lastpage;
</code>

return: lesson_page|bool Returns the lesson_page specialised object or false

get_firstpageid()   X-Ref
Returns the id of the first page of this lesson. (prevpageid = 0)

return: int

get_lastpageid()   X-Ref
Returns the id of the last page of this lesson. (nextpageid = 0)

return: int

get_next_page($nextpageid)   X-Ref
Gets the next page id to display after the one that is provided.

param: int $nextpageid
return: bool

add_message($message, $class="notifyproblem", $align='center')   X-Ref
Sets a message against the session for this lesson that will displayed next
time the lesson processes messages

param: string $message
param: string $class
param: string $align
return: bool

is_accessible()   X-Ref
Check if the lesson is accessible at the present time

return: bool True if the lesson is accessible, false otherwise

start_timer()   X-Ref
Starts the lesson time for the current user

return: bool Returns true

update_timer($restart=false, $continue=false, $endreached =false)   X-Ref
Updates the timer to the current time and returns the new timer object

param: bool $restart If set to true the timer is restarted
param: bool $continue If set to true AND $restart=true then the timer
return: stdClass The new timer

stop_timer()   X-Ref
Updates the timer to the current time then stops it by unsetting the user var

return: bool Returns true

has_pages()   X-Ref
Checks to see if the lesson has pages


link_for_activitylink()   X-Ref
Returns the link for the related activity

return: array|false

load_page($pageid)   X-Ref
Loads the requested page.

This function will return the requested page id as either a specialised
lesson_page object OR as a generic lesson_page.
If the page has been loaded previously it will be returned from the pages
array, otherwise it will be loaded from the database first

param: int $pageid
return: lesson_page A lesson_page object or an object that extends it

load_all_pages()   X-Ref
Loads ALL of the pages for this lesson

return: array An array containing all pages from this lesson

jumpto_is_correct($pageid, $jumpto)   X-Ref
Determines if a jumpto value is correct or not.

returns true if jumpto page is (logically) after the pageid page or
if the jumpto value is a special value.  Returns false in all other cases.

param: int $pageid Id of the page from which you are jumping from.
param: int $jumpto The jumpto number.
return: boolean True or false after a series of tests.

time_remaining($starttime)   X-Ref
Returns the time a user has remaining on this lesson

param: int $starttime Starttime timestamp
return: string

cluster_jump($pageid, $userid=null)   X-Ref
Interprets LESSON_CLUSTERJUMP jumpto value.

This will select a page randomly
and the page selected will be inbetween a cluster page and end of clutter or end of lesson
and the page selected will be a page that has not been viewed already
and if any pages are within a branch table or end of branch then only 1 page within
the branch table or end of branch will be randomly selected (sub clustering).

param: int $pageid Id of the current page from which we are jumping from.
param: int $userid Id of the user.
return: int The id of the next page.

get_sub_pages_of($pageid, array $ends)   X-Ref
Finds all pages that appear to be a subtype of the provided pageid until
an end point specified within $ends is encountered or no more pages exist

param: int $pageid
param: array $ends An array of LESSON_PAGE_* types that signify an end of
return: array An array of specialised lesson_page objects

is_sub_page_of_type($pageid, array $types, array $ends)   X-Ref
Checks to see if the specified page[id] is a subpage of a type specified in
the $types array, until either there are no more pages of we find a type
corresponding to that of a type specified in $ends

param: int $pageid The id of the page to check
param: array $types An array of types that would signify this page was a subpage
param: array $ends An array of types that mean this is not a subpage
return: bool

resort_pages($pageid, $after)   X-Ref
Move a page resorting all other pages.

param: int $pageid
param: int $after
return: void

__construct($properties)   X-Ref
The constructor

param: stdClass $properties

__set($key, $value)   X-Ref
Magic property method

Attempts to call a set_$key method if one exists otherwise falls back
to simply set the property

param: string $key
param: mixed $value

__get($key)   X-Ref
Magic get method

Attempts to call a get_$key method to return the property and ralls over
to return the raw property

param: str $key
return: mixed

__isset($key)   X-Ref
Stupid PHP needs an isset magic method if you use the get magic method and
still want empty calls to work.... blah ~!

param: string $key
return: bool

properties()   X-Ref
Fetches all of the properties of the object

return: stdClass

create($properties, lesson $lesson, $context, $maxbytes)   X-Ref
Creates a new lesson_page within the database and returns the correct pagetype
object to use to interact with the new lesson

param: object $properties
param: lesson $lesson
return: lesson_page Specialised object that extends lesson_page

load($id, lesson $lesson)   X-Ref
This method loads a page object from the database and returns it as a
specialised object that extends lesson_page

param: int $id
param: lesson $lesson
return: lesson_page Specialised lesson_page object

delete()   X-Ref
Deletes a lesson_page from the database as well as any associated records.

return: bool

move($nextpageid=null, $prevpageid=null)   X-Ref
Moves a page by updating its nextpageid and prevpageid values within
the database

param: int $nextpageid
param: int $prevpageid

get_answers()   X-Ref
Returns the answers that are associated with this page in the database

return: array

get_lesson()   X-Ref
Returns the lesson this page is associated with

return: lesson

get_type()   X-Ref
Returns the type of page this is. Not to be confused with page type

return: int

record_attempt($context)   X-Ref
Records an attempt at this page

param: stdClass $context
return: stdClass Returns the result of the attempt

get_jump_name($jumpto)   X-Ref
Returns the string for a jump name

param: int $jumpto Jump code or page ID
return: string

__construct($properties, lesson $lesson)   X-Ref
Constructor method

param: object $properties
param: lesson $lesson

earned_score($answers, $attempt)   X-Ref
Returns the score for the attempt
This may be overridden by page types that require manual grading

param: array $answers
param: object $attempt
return: int

callback_on_view($canmanage)   X-Ref
This is a callback method that can be override and gets called when ever a page
is viewed

param: bool $canmanage True if the user has the manage cap
return: mixed

save_answers_files($context, $maxbytes, &$answer, $answereditor = '', $responseeditor = '')   X-Ref
save editor answers files and update answer record

param: object $context
param: int $maxbytes
param: object $answer
param: object $answereditor
param: object $responseeditor

rewrite_answers_urls($answer, $rewriteanswer = true)   X-Ref
Rewrite urls in response and optionality answer of a question answer

param: object $answer
param: bool $rewriteanswer must rewrite answer
return: object answer with rewritten urls

update($properties, $context = null, $maxbytes = null)   X-Ref
Updates a lesson page and its answers within the database

param: object $properties
return: bool

add_page_link($previd)   X-Ref
Can be set to true if the page requires a static link to create a new instance
instead of simply being included in the dropdown

param: int $previd
return: bool

is_unseen($param)   X-Ref
Returns true if a page has been viewed before

param: array|int $param Either an array of pages that have been seen or the
return: bool

is_unanswered($nretakes)   X-Ref
Checks to see if a page has been answered previously

param: int $nretakes
return: bool

create_answers($properties)   X-Ref
Creates answers within the database for this lesson_page. Usually only ever
called when creating a new page instance

param: object $properties
return: array

check_answer()   X-Ref
This method MUST be overridden by all question page types, or page types that
wish to score a page.

The structure of result should always be the same so it is a good idea when
overriding this method on a page type to call
<code>
$result = parent::check_answer();
</code>
before modifying it as required.

return: stdClass

has_option()   X-Ref
True if the page uses a custom option

Should be override and set to true if the page uses a custom option.

return: bool

max_answers($default)   X-Ref
Returns the maximum number of answers for this page given the maximum number
of answers permitted by the lesson.

param: int $default
return: int

properties()   X-Ref
Returns the properties of this lesson page as an object

return: stdClass;

get_jumptooptions($pageid, lesson $lesson)   X-Ref
Returns an array of options to display when choosing the jumpto for a page/answer

param: int $pageid
param: lesson $lesson
return: array

get_contents()   X-Ref
Returns the contents field for the page properly formatted and with plugin
file url's converted

return: string

get_displayinmenublock()   X-Ref
Set to true if this page should display in the menu block

return: bool

option_description_string()   X-Ref
Get the string that describes the options of this page type

return: string

display_answers(html_table $table)   X-Ref
Updates a table with the answers for this page

param: html_table $table
return: html_table

get_grayout()   X-Ref
Determines if this page should be grayed out on the management/report screens

return: int 0 or 1

stats(array &$pagestats, $tries)   X-Ref
Adds stats for this page to the &pagestats object. This should be defined
for all page types that grade

param: array $pagestats
param: int $tries
return: bool

report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n)   X-Ref
Formats the answers of this page for a report

param: object $answerpage
param: object $answerdata
param: object $useranswer
param: array $pagestats
param: int $i Count of first level answers
param: int $n Count of second level answers
return: object The answer page for this

get_jumps()   X-Ref
Gets an array of the jumps used by the answers of this page

return: array

requires_manual_grading()   X-Ref
Informs whether this page type require manual grading or not

return: bool

override_next_page()   X-Ref
A callback method that allows a page to override the next page a user will
see during when this page is being completed.

return: false|int

valid_page_and_view(&$validpages, &$pageviews)   X-Ref
This method is used to determine if this page is a valid page

param: array $validpages
param: array $pageviews
return: int The next page id to check

Class: lesson_page_answer  - X-Ref

Class used to represent an answer to a page

load($id)   X-Ref
Loads an page answer from the DB

param: int $id
return: lesson_page_answer

create($properties, lesson_page $page)   X-Ref
Given an object of properties and a page created answer(s) and saves them
in the database.

param: stdClass $properties
param: lesson_page $page
return: array

Class: lesson_page_type_manager  - X-Ref

A management class for page types

This class is responsible for managing the different pages. A manager object can
be retrieved by calling the following line of code:
<code>
$manager  = lesson_page_type_manager::get($lesson);
</code>
The first time the page type manager is retrieved the it includes all of the
different page types located in mod/lesson/pagetypes.

get(lesson $lesson)   X-Ref
Retrieves the lesson page type manager object

If the object hasn't yet been created it is created here.

param: lesson $lesson
return: lesson_page_type_manager

load_lesson_types(lesson $lesson)   X-Ref
Finds and loads all lesson page types in mod/lesson/pagetypes

param: lesson $lesson

get_page_type_strings($type=null, $special=true)   X-Ref
Returns an array of strings to describe the loaded page types

param: int $type Can be used to return JUST the string for the requested type
return: array

get_page_type_idstring($id)   X-Ref
Returns the basic string used to identify a page type provided with an id

This string can be used to instantiate or identify the page type class.
If the page type id is unknown then 'unknown' is returned

param: int $id
return: string

load_page($pageid, lesson $lesson)   X-Ref
Loads a page for the provided lesson given it's id

This function loads a page from the lesson when given both the lesson it belongs
to as well as the page's id.
If the page doesn't exist an error is thrown

param: int $pageid The id of the page to load
param: lesson $lesson The lesson the page belongs to
return: lesson_page A class that extends lesson_page

check_page_order($page1, $page2)   X-Ref
This function detects errors in the ordering between 2 pages and updates the page records.

param: stdClass $page1 Either the first of 2 pages or null if the $page2 param is the first in the list.
param: stdClass $page1 Either the second of 2 pages or null if the $page1 param is the last in the list.

load_all_pages(lesson $lesson)   X-Ref
This function loads ALL pages that belong to the lesson.

param: lesson $lesson
return: array An array of lesson_page_type_*

get_page_form($type, $arguments)   X-Ref
Fetches an mform that can be used to create/edit an page

param: int $type The id for the page type
param: array $arguments Any arguments to pass to the mform
return: lesson_add_page_form_base

get_add_page_type_links($previd)   X-Ref
Returns an array of links to use as add page links

param: int $previd The id of the previous page
return: array

Functions
Functions that are not part of a class:

lesson_display_teacher_warning($lesson)   X-Ref
Checks to see if a LESSON_CLUSTERJUMP or
a LESSON_UNSEENBRANCHPAGE is used in a lesson.

This function is only executed when a teacher is
checking the navigation for a lesson.

param: stdClass $lesson Id of the lesson that is to be checked.
return: boolean True or false.

lesson_unseen_question_jump($lesson, $user, $pageid)   X-Ref
Interprets the LESSON_UNSEENBRANCHPAGE jump.

will return the pageid of a random unseen page that is within a branch

param: lesson $lesson
param: int $userid Id of the user.
param: int $pageid Id of the page from which we are jumping.
return: int Id of the next page.

lesson_unseen_branch_jump($lesson, $userid)   X-Ref
Handles the unseen branch table jump.

param: lesson $lesson
param: int $userid User id.
return: int Will return the page id of a branch table or end of lesson

lesson_random_question_jump($lesson, $pageid)   X-Ref
Handles the random jump between a branch table and end of branch or end of lesson (LESSON_RANDOMPAGE).

param: lesson $lesson
param: int $pageid The id of the page that we are jumping from (?)
return: int The pageid of a random page that is within a branch table

lesson_grade($lesson, $ntries, $userid = 0)   X-Ref
Calculates a user's grade for a lesson.

param: object $lesson The lesson that the user is taking.
param: int $retries The attempt number.
param: int $userid Id of the user (optional, default current user).
return: object { nquestions => number of questions answered

lesson_displayleftif($lesson)   X-Ref
Determines if a user can view the left menu.  The determining factor
is whether a user has a grade greater than or equal to the lesson setting
of displayleftif

param: object $lesson Lesson object of the current lesson
return: boolean 0 if the user cannot see, or $lesson->displayleft to keep displayleft unchanged

lesson_add_fake_blocks($page, $cm, $lesson, $timer = null)   X-Ref

param: $cm
param: $lesson
param: $page
return: unknown_type

lesson_mediafile_block_contents($cmid, $lesson)   X-Ref
If there is a media file associated with this
lesson, return a block_contents that displays it.

param: int $cmid Course Module ID for this lesson
param: object $lesson Full lesson record object
return: block_contents

lesson_clock_block_contents($cmid, $lesson, $timer, $page)   X-Ref
If a timed lesson and not a teacher, then
return a block_contents containing the clock.

param: int $cmid Course Module ID for this lesson
param: object $lesson Full lesson record object
param: object $timer Full timer record object
return: block_contents

lesson_menu_block_contents($cmid, $lesson)   X-Ref
If left menu is turned on, then this will
print the menu in a block

param: int $cmid Course Module ID for this lesson
param: lesson $lesson Full lesson record object
return: void

lesson_add_header_buttons($cm, $context, $extraeditbuttons=false, $lessonpageid=null)   X-Ref
Adds header buttons to the page for the lesson

param: object $cm
param: object $context
param: bool $extraeditbuttons
param: int $lessonpageid

lesson_get_media_html($lesson, $context)   X-Ref
This is a function used to detect media types and generate html code.

param: object $lesson
param: object $context
return: string $code the html code of media

lesson_process_group_deleted_in_course($courseid, $groupid = null)   X-Ref
Logic to happen when a/some group(s) has/have been deleted in a course.

param: int $courseid The course ID.
param: int $groupid The group id if it is known
return: void

custom_definition()   X-Ref
Each page type can and should override this to add any custom elements to
the basic form that they want


get_answer_format()   X-Ref
Returns answer format used by question type.


get_response_format()   X-Ref
Returns response format used by question type.


is_standard()   X-Ref
Used to determine if this is a standard page or a special page

return: bool

definition()   X-Ref
Add the required basic elements to the form.

This method adds the basic elements to the form including title and contents
and then calls custom_definition();

add_jumpto($name, $label=null, $selected=LESSON_NEXTPAGE)   X-Ref
Convenience function: Adds a jumpto select element

param: string $name
param: string|null $label
param: int $selected The page to select by default

add_score($name, $label=null, $value=null)   X-Ref
Convenience function: Adds a score input element

param: string $name
param: string|null $label
param: mixed $value The default value

add_answer($count, $label = null, $required = false, $format= '')   X-Ref
Convenience function: Adds an answer editor

param: int $count The count of the element to add
param: string $label, null means default
param: bool $required
param: string $format
return: void

add_response($count, $label = null, $required = false)   X-Ref
Convenience function: Adds an response editor

param: int $count The count of the element to add
param: string $label, null means default
param: bool $required
return: void

construction_override($pageid, lesson $lesson)   X-Ref
A function that gets called upon init of this object by the calling script.

This can be used to process an immediate action if required. Currently it
is only used in special cases by non-standard page types.

return: bool



Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1