class CourseObjectQuiz in Course 7.2
Same name and namespace in other branches
- 6 modules/course_quiz/course_quiz.classes.inc \CourseObjectQuiz
- 7 modules/course_quiz/course_quiz.classes.inc \CourseObjectQuiz
Hierarchy
- class \Entity implements EntityInterface
- class \CourseHandler
- class \CourseObject
- class \CourseObjectNode
- class \CourseObjectQuiz
- class \CourseObjectNode
- class \CourseObject
- class \CourseHandler
Expanded class hierarchy of CourseObjectQuiz
1 string reference to 'CourseObjectQuiz'
- course_quiz_course_handlers in modules/
course_quiz/ course_quiz.module - Implements hook_course_handlers().
File
- modules/
course_quiz/ course_quiz.classes.inc, line 3
View source
class CourseObjectQuiz extends CourseObjectNode {
/**
* Create the quiz node and set it as this object's instance.
*/
function create($node = NULL) {
if (!$node) {
$node = new stdClass();
}
$node->auto_created = TRUE;
parent::create($node);
}
/**
* The take URL of the quiz is /take.
*/
function getTakeUrl() {
if ($this
->getOption('quiz_goto') == "view") {
return url("node/{$this->getInstanceId()}");
}
else {
return url("node/{$this->getInstanceId()}/take");
}
}
/**
* Course quiz options.
*/
public function optionsDefinition() {
$options = parent::optionsDefinition();
$options['quiz_goto'] = 'view';
$options['passing_grade'] = 75;
return $options;
}
/**
* Add an option only pertinent to quiz?
*/
public function optionsForm(&$form, &$form_state) {
parent::optionsForm($form, $form_state);
$defaults = $this
->getOptions();
$form['quiz_goto'] = array(
'#type' => 'select',
'#title' => t('Quiz entry point'),
'#options' => array(
'view' => t('View Quiz'),
'take' => t('Take Quiz'),
),
'#default_value' => $defaults['quiz_goto'],
'#description' => t('Selecting "Take Quiz" will launch the user directly into taking the quiz, without viewing the quiz body.'),
);
$form['grading']['passing_grade'] = array(
'#title' => t('Passing grade'),
'#type' => 'textfield',
'#size' => 4,
'#default_value' => $defaults['passing_grade'],
'#description' => t('The user will not be able to proceed past this object unless this grade is met.'),
);
}
/**
* Let the user know if they have a Quiz without questions.
*/
public function getWarnings() {
$warnings = parent::getWarnings();
if ($this
->getInstanceId()) {
if (!quiz_get_number_of_questions($this
->getNode()->vid, $this
->getNode()->nid)) {
if (course_quiz_quiz_version() >= 5) {
$link = l('add questions', "node/{$this->getInstanceId()}/quiz/questions");
}
else {
$link = l('add questions', "node/{$this->getInstanceId()}/questions");
}
$warnings[] = t('This Quiz does not have any questions. Please !link.', array(
'!link' => $link,
));
}
}
return $warnings;
}
public function getReports() {
$reports = parent::getReports();
$reports['results'] = array(
'title' => t('Results'),
);
if (module_exists('quiz_stats')) {
$reports['statistics'] = array(
'title' => t('Statistics'),
);
}
return $reports;
}
public function getReport($key) {
module_load_include('inc', 'quiz', 'quiz.admin');
switch ($key) {
case 'results':
if (course_quiz_quiz_version() >= 5) {
$out = views_embed_view('quiz_results', 'default', $this
->getInstanceId());
}
else {
$out = drupal_get_form('quiz_results_manage_results_form', $this
->getNode());
}
return array(
'title' => t('Quiz results'),
'content' => $out,
);
case 'statistics':
module_load_include('inc', 'quiz_stats', 'quiz_stats.admin');
return array(
'title' => t('Quiz statistics'),
'content' => quiz_stats_get_adv_stats($this
->getNode()->vid),
);
}
return parent::getReport($key);
}
function getNodeTypes() {
return array(
'quiz',
);
}
function isGraded() {
return TRUE;
}
function getCloneAbility() {
return t('%object can only be partially cloned. It will be created with the same settings, but without the questions.', array(
'%object' => $this
->getTitle(),
));
}
function getOptionsSummary() {
$summary = parent::getOptionsSummary();
if ($this
->getInstanceId()) {
if (course_quiz_quiz_version() >= 5) {
$summary['questions'] = l(t('Edit questions'), "node/{$this->getInstanceId()}/quiz/questions");
}
else {
$summary['questions'] = l(t('Edit questions'), "node/{$this->getInstanceId()}/questions");
}
}
return $summary;
}
/**
* Get the status of this quiz for the requirements list.
*/
function getStatus() {
global $user;
$grade = $this
->isGraded() ? t('Your grade: %grade_result%<br/>Pass grade: %passing_grade%', array(
'%grade_result' => $this
->getFulfillment($user)
->getOption('grade_result'),
'%passing_grade' => $this
->getOption('passing_grade'),
)) : '';
return $grade;
}
/**
* Course node context handler callback.
*
* If this question is part of a quiz in a course, what quizzes do we belong
* to?
*/
public static function getNodeInstances($node) {
$quizzes = array();
// Finding quizzes this question already belongs to.
$sql = 'SELECT n.nid, r.parent_vid AS vid, n.title FROM {quiz_node_relationship} r
JOIN {node} n ON n.nid = r.parent_nid
WHERE r.child_vid = :child_vid
ORDER BY r.parent_vid DESC';
$res = db_query($sql, array(
':child_vid' => $node->vid,
));
while ($row = $res
->fetch()) {
$quizzes[] = $row->nid;
}
return $quizzes;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseHandler:: |
final public | function | Merge an array of options onto the existing options. | |
CourseHandler:: |
public | function | Get an array of access messages. | |
CourseHandler:: |
protected | function | Return an array of database fields. This determines what fields should be serialized instead of stored. | |
CourseHandler:: |
function | |||
CourseHandler:: |
public | function | Get an handler option's value. | |
CourseHandler:: |
private | function | Merge arrays with replace, not append. | |
CourseHandler:: |
public | function | Set an access message to be displayed along with the course object when it is in the outline. For example, "This activity will open on XYZ" or "Please complete Step 1 to take this activity." | |
CourseHandler:: |
final public | function | Set this entire handler's options. | |
CourseObject:: |
protected | property | ||
CourseObject:: |
protected | property | ||
CourseObject:: |
function |
Builds a structured array representing the entity's content. Overrides Entity:: |
||
CourseObject:: |
function | Get the object component for this course object. | ||
CourseObject:: |
function | Get the object component title for this course object. | ||
CourseObject:: |
function | Get the Course that contains this CourseObject. | ||
CourseObject:: |
function | Get the course node ID this CourseObject belongs to. | ||
CourseObject:: |
public | function | Get a user's fulfillment for this course object. If the user has not started this course object, a new, unsaved fulfillment will be return. | |
CourseObject:: |
function | Get the instance ID. This could be the external component ID, a Node ID... | ||
CourseObject:: |
public static | function | Return the number of occurances that can be in a course at the same time. For example, the design of the Certificate module can only have 1 set of mappings per node. The same goes for Course Credit. We may also want a course object that can only be… | 2 |
CourseObject:: |
function | Get the module that provides this course object. | ||
CourseObject:: |
public | function |
Get options, with session options, except weight, having precedence. Overrides CourseHandler:: |
|
CourseObject:: |
public | function | ||
CourseObject:: |
public | function | Get read-only options. These options have been processed by plugins and may have changed from their definitions. | |
CourseObject:: |
public | function | Return the URL to the course object router. | |
CourseObject:: |
public | function | Specify whether fulfillment uses asynchronous polling. | |
CourseObject:: |
public | function | ||
CourseObject:: |
public | function | Check if the course object is enabled. | |
CourseObject:: |
public | function | Is this course object required for course completion? | |
CourseObject:: |
public | function | If this course object is required, can be it skipped? | |
CourseObject:: |
function | Checks the temporary status of a course object. | ||
CourseObject:: |
public | function | If this course object is required, can be it skipped? | |
CourseObject:: |
private | function | ||
CourseObject:: |
public | function | Override navigation links. | 1 |
CourseObject:: |
public | function | Overrides a course outline list item. | 1 |
CourseObject:: |
function | Give the course object a chance do asynchronous polling and set completion on demand. | ||
CourseObject:: |
public | function | Get all course object implementations of getOptionsSummary(). | |
CourseObject:: |
function | Set the object component for this course object. | ||
CourseObject:: |
public | function | Set the Course for this CourseObject. | |
CourseObject:: |
public | function | Mark this object for deletion. This is not a submit button so we set the values manually. | |
CourseObject:: |
function | Set the internal course object ID. | ||
CourseObject:: |
function | Set this object's instance ID. | ||
CourseObject:: |
function | Set the module that provides this course object. | ||
CourseObject:: |
public | function |
Clear the read only options cache before changing an option. Overrides CourseHandler:: |
|
CourseObject:: |
public | function | Course object entry point for taking. This method should return a value corresponding to the type set in getTakeType(). | 6 |
CourseObject:: |
final public | function | Take a course object. | |
CourseObject:: |
public | function |
Generate URI from course object. Overrides Entity:: |
|
CourseObjectNode:: |
function |
Deny access to objects without content. Overrides CourseObject:: |
||
CourseObjectNode:: |
public static | function |
Course context handler callback. Overrides CourseObject:: |
|
CourseObjectNode:: |
public | function |
Destroy the node instance. Overrides CourseObject:: |
|
CourseObjectNode:: |
function |
Freeze data to persist over cloning/exporting. Overrides CourseObject:: |
3 | |
CourseObjectNode:: |
public | function |
Get the URL to edit this course object, if any. Overrides CourseObject:: |
|
CourseObjectNode:: |
function | |||
CourseObjectNode:: |
public | function |
Simple node course object behavior is to just redirect to the node. Overrides CourseObject:: |
3 |
CourseObjectNode:: |
function |
Get the object title, or return this object's node's title if the option
is set. Overrides CourseObject:: |
||
CourseObjectNode:: |
public | function |
Get the URL to view this course object, if any. Overrides CourseObject:: |
|
CourseObjectNode:: |
public | function | ||
CourseObjectNode:: |
public | function |
Save object configs to cache. Overrides CourseObject:: |
2 |
CourseObjectNode:: |
public | function |
Validate the options form. Check the node type. Overrides CourseObject:: |
|
CourseObjectNode:: |
function |
On object write, set privacy on this node. Overrides CourseObject:: |
1 | |
CourseObjectNode:: |
function |
Thaw data frozen from an earlier export/clone. Overrides CourseObject:: |
2 | |
CourseObjectNode:: |
public | function |
Overrides CourseHandler:: |
|
CourseObjectQuiz:: |
function |
Create the quiz node and set it as this object's instance. Overrides CourseObjectNode:: |
||
CourseObjectQuiz:: |
function |
Returns an translated error message if this object has issues with cloning. Overrides CourseObjectNode:: |
||
CourseObjectQuiz:: |
public static | function |
Course node context handler callback. Overrides CourseObjectNode:: |
|
CourseObjectQuiz:: |
function |
Return a list of valid node types. Overrides CourseObjectNode:: |
||
CourseObjectQuiz:: |
function |
Get core options summary. Overrides CourseObjectNode:: |
||
CourseObjectQuiz:: |
public | function |
Let the course object provide its own reports. Overrides CourseObject:: |
|
CourseObjectQuiz:: |
public | function |
Let the course object provide its own reports. Overrides CourseObject:: |
|
CourseObjectQuiz:: |
function |
Get the status of this quiz for the requirements list. Overrides CourseObject:: |
||
CourseObjectQuiz:: |
function |
The take URL of the quiz is /take. Overrides CourseObjectNode:: |
||
CourseObjectQuiz:: |
public | function |
Let the user know if they have a Quiz without questions. Overrides CourseObjectNode:: |
|
CourseObjectQuiz:: |
function |
Is this object graded? Overrides CourseObject:: |
||
CourseObjectQuiz:: |
public | function |
Course quiz options. Overrides CourseObjectNode:: |
|
CourseObjectQuiz:: |
public | function |
Add an option only pertinent to quiz? Overrides CourseObjectNode:: |
|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Defines the entity label if the 'entity_class_label' callback is used. | 1 |
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. |