Skip to content

Commit

Permalink
CONTRIB-6190 mod_surveypro: Changed advanced to reserved
Browse files Browse the repository at this point in the history
  • Loading branch information
Kordan committed Mar 21, 2016
1 parent 94736fd commit c0cb213
Show file tree
Hide file tree
Showing 104 changed files with 837 additions and 906 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -9,7 +9,7 @@ The meaning of the less common properties is:
- Availability defines who will see the field in the form. It can be:
-- all: each user will see the field in the survey form;
-- hidden: not any user will see the field in the survey form;
-- advanced: only students with specific permissions (accessadvanceditems) will see the field in the survey form;
-- reserved: only students with specific permissions (accessreserveditems) will see the field in the survey form;
-- search: the field will be available in the search form too (if not hidden).
- Validation options define the range of allowed responses for the students.
- Default is what the blank form will display as predefined value of an element.
Expand Down
6 changes: 3 additions & 3 deletions adminlib.php
Expand Up @@ -64,7 +64,7 @@ public function search($query) {

$found = false;

foreach (core_component::get_plugin_list($this->subtype) as $name => $notused) {
foreach (core_component::get_plugin_list($this->subtype) as $name => $unused) {
if (strpos(core_text::strtolower(get_string('pluginname', $this->subtype.'_'.$name)),
$query) !== false) {
$found = true;
Expand Down Expand Up @@ -119,7 +119,7 @@ public function get_sorted_plugins_list() {

$result = array();

foreach ($names as $name => $notused) {
foreach ($names as $name => $unused) {
$idx = get_config($this->subtype.'_'.$name, 'sortorder');
if (!$idx) {
$idx = 0;
Expand Down Expand Up @@ -458,7 +458,7 @@ public static function add_admin_surveypro_plugin_settings($subtype,
$plugins = core_component::get_plugin_list_with_file($subtype, 'settings.php', false);
// $plugins = get_plugin_list_with_file($subtype, 'settings.php', false);
$pluginsbyname = array();
foreach ($plugins as $plugin => $notused) {
foreach ($plugins as $plugin => $unused) {
$pluginname = get_string('pluginname', $subtype.'_'.$plugin);
$pluginsbyname[$pluginname] = $plugin;
}
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/backup_surveypro_stepslib.php
Expand Up @@ -51,7 +51,7 @@ protected function define_structure() {
$items = new backup_nested_element('items');

$item = new backup_nested_element('item', array('id', 'type', 'plugin'), array(
'hidden', 'insearchform', 'advanced', 'sortindex', 'formpage',
'hidden', 'insearchform', 'reserved', 'sortindex', 'formpage',
'parentid', 'parentvalue', 'timecreated', 'timemodified'));

$submissions = new backup_nested_element('submissions');
Expand Down
4 changes: 4 additions & 0 deletions backup/moodle2/restore_surveypro_stepslib.php
Expand Up @@ -69,6 +69,10 @@ protected function process_surveypro($data) {
$oldid = $data->id;
$data->course = $this->get_courseid();

// Old backups using advanced field map to new reserved field.
if (isset($data->advanced)) {
$data->reserved = $data->advanced;
}
$data->timeopen = $this->apply_date_offset($data->timeopen);
$data->timeclose = $this->apply_date_offset($data->timeclose);
$data->timemodified = $this->apply_date_offset($data->timemodified);
Expand Down
10 changes: 5 additions & 5 deletions classes/formbase.class.php
Expand Up @@ -65,10 +65,10 @@ public function __construct($cm, $context, $surveypro) {
public function noitem_stopexecution() {
global $COURSE, $OUTPUT;

$canaccessadvanceditems = has_capability('mod/surveypro:accessadvanceditems', $this->context, null, true);
$canaccessreserveditems = has_capability('mod/surveypro:accessreserveditems', $this->context, null, true);

$utilityman = new mod_surveypro_utility($this->cm, $this->surveypro);
if (!$utilityman->has_input_items(0, false, false, $canaccessadvanceditems)) {
if (!$utilityman->has_input_items(0, false, false, $canaccessreserveditems)) {
$canmanageitems = has_capability('mod/surveypro:manageitems', $this->context, null, true);

if ($canmanageitems) {
Expand Down Expand Up @@ -98,12 +98,12 @@ public function noitem_stopexecution() {
public function get_prefill_data() {
global $DB;

$canaccessadvanceditems = has_capability('mod/surveypro:accessadvanceditems', $this->context, null, true);
$canaccessreserveditems = has_capability('mod/surveypro:accessreserveditems', $this->context, null, true);
$prefill = array();

if (!empty($this->submissionid)) {
// $canaccessadvanceditems, $searchform=false, $type=SURVEYPRO_TYPEFIELD, $formpage=$this->formpage
list($sql, $whereparams) = surveypro_fetch_items_seeds($this->surveypro->id, $canaccessadvanceditems, false, SURVEYPRO_TYPEFIELD, $this->formpage);
// $canaccessreserveditems, $searchform=false, $type=SURVEYPRO_TYPEFIELD, $formpage=$this->formpage
list($sql, $whereparams) = surveypro_fetch_items_seeds($this->surveypro->id, $canaccessreserveditems, false, SURVEYPRO_TYPEFIELD, $this->formpage);
if ($itemseeds = $DB->get_recordset_sql($sql, $whereparams)) {
foreach ($itemseeds as $itemseed) {
$item = surveypro_get_item($this->cm, $this->surveypro, $itemseed->id, $itemseed->type, $itemseed->plugin);
Expand Down
70 changes: 33 additions & 37 deletions classes/itembase.class.php
Expand Up @@ -66,9 +66,9 @@ class mod_surveypro_itembase {
protected $insearchform;

/**
* $advanced = is this field going to be available only to users with accessadvanceditems capability?
* $reserved = is this field going to be available only to users with accessreserveditems capability?
*/
protected $advanced;
protected $reserved;

/**
* $sortindex = the order of this item in the surveypro form
Expand Down Expand Up @@ -121,7 +121,7 @@ class mod_surveypro_itembase {
'variable' => true,
'indent' => true,
'hidden' => true,
'advanced' => true,
'reserved' => true,
'insearchform' => true,
'parentid' => true
);
Expand Down Expand Up @@ -192,7 +192,7 @@ public function item_force_coherence($record) {
* √ plugin
* √ hidden
* √ insearchform
* √ advanced
* √ reserved
* sortindex
* formpage
* √ parentid
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function item_get_common_settings($record) {
// Plugin and type are already onboard.

// Checkboxes content.
$checkboxessettings = array('hidden', 'insearchform', 'advanced', 'hideinstructions', 'required');
$checkboxessettings = array('hidden', 'insearchform', 'reserved', 'hideinstructions', 'required');
foreach ($checkboxessettings as $checkboxessetting) {
if ($this->insetupform[$checkboxessetting]) {
$record->{$checkboxessetting} = isset($record->{$checkboxessetting}) ? 1 : 0;
Expand Down Expand Up @@ -389,7 +389,7 @@ public function item_save($record) {
// End of: hide/unhide 1.

// Begin of: Limit/unlimit access part 1.
$oldadvanced = $this->get_advanced(); // Used later.
$oldreserved = $this->get_reserved(); // Used later.
// End of: limit/unlimit access part 1.

// Sortindex.
Expand Down Expand Up @@ -419,7 +419,7 @@ public function item_save($record) {

$transaction->allow_commit();

$this->item_manage_chains($record->itemid, $oldhidden, $record->hidden, $oldadvanced, $record->advanced);
$this->item_manage_chains($record->itemid, $oldhidden, $record->hidden, $oldreserved, $record->reserved);

// Event: item_modified.
$eventdata = array('context' => $context, 'objectid' => $record->itemid);
Expand Down Expand Up @@ -526,13 +526,11 @@ public function item_validate_variablename($record, $itemid) {
* @param integer $itemid
* @param boolean 0/1 $oldhidden
* @param boolean 0/1 $newhidden
* @param boolean 0/1 $oldadvanced
* @param boolean 0/1 $newadvanced
* @param boolean 0/1 $oldreserved
* @param boolean 0/1 $newreserved
* @return void
*/
private function item_manage_chains($itemid, $oldhidden, $newhidden, $oldadvanced, $newadvanced) {
global $DB;

private function item_manage_chains($itemid, $oldhidden, $newhidden, $oldreserved, $newreserved) {
$context = context_module::instance($this->cm->id);

// Now hide or unhide (whether needed) chain of ancestors or descendents.
Expand Down Expand Up @@ -565,9 +563,9 @@ private function item_manage_chains($itemid, $oldhidden, $newhidden, $oldadvance
}


// Manage ($oldadvanced != $newadvanced).
if ($oldadvanced != $newadvanced) {
$action = ($oldadvanced) ? SURVEYPRO_MAKESTANDARD : SURVEYPRO_MAKEADVANCED;
// Manage ($oldreserved != $newreserved).
if ($oldreserved != $newreserved) {
$action = ($oldreserved) ? SURVEYPRO_MAKESTANDARD : SURVEYPRO_MAKEADVANCED;

$itemlistman = new mod_surveypro_itemlist($this->cm, $context, $this->surveypro);
$itemlistman->set_type($this->type);
Expand All @@ -578,14 +576,14 @@ private function item_manage_chains($itemid, $oldhidden, $newhidden, $oldadvance
$itemlistman->set_confirm(SURVEYPRO_CONFIRMED_YES);

// Begin of: Limit/unlimit access part 2.
if ( ($oldadvanced == 1) && ($newadvanced == 0) ) {
if ( ($oldreserved == 1) && ($newreserved == 0) ) {
if ($itemlistman->item_makestandard_execute()) {
// A chain of parent items has been made available for all.
$this->itemeditingfeedback += 16; // 1*2^4.
}
}
if ( ($oldadvanced == 0) && ($newadvanced == 1) ) {
if ($itemlistman->item_makeadvanced_execute()) {
if ( ($oldreserved == 0) && ($newreserved == 1) ) {
if ($itemlistman->item_makereserved_execute()) {
// A chain of child items got a limited access.
$this->itemeditingfeedback += 32; // 1*2^5
}
Expand Down Expand Up @@ -650,7 +648,7 @@ protected function item_builtin_string_load_support() {
}

if ($multilangfields = $this->item_get_multilang_fields()) {
foreach ($multilangfields as $plugin => $fieldnames) {
foreach ($multilangfields as $fieldnames) {
foreach ($fieldnames as $fieldname) {
$stringkey = $this->{$fieldname};
$this->{$fieldname} = get_string($stringkey, 'surveyprotemplate_'.$template);
Expand Down Expand Up @@ -758,7 +756,7 @@ public function item_get_content_array($content, $field) {
$options = surveypro_textarea_to_array($this->{$field});

$values = array();
foreach ($options as $k => $option) {
foreach ($options as $option) {
if (preg_match('~^(.*)'.SURVEYPRO_VALUELABELSEPARATOR.'(.*)$~', $option, $match)) {
$values[] = $match[$index];
} else {
Expand Down Expand Up @@ -838,7 +836,7 @@ public function item_mandatory_is_allowed() {
public function item_add_mandatory_base_fields(&$record) {
$record->hidden = 0;
$record->insearchform = 0;
$record->advanced = 0;
$record->reserved = 0;
$record->formpage = 0;
$record->timecreated = time();
}
Expand All @@ -864,26 +862,24 @@ public function item_get_multilang_fields() {
* @return string $schema
*/
public static function item_get_item_schema() {

// Fields: surveyproid, formpage, timecreated and timemodified are not supposed to be part of the file!
$schema = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$schema .= '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">'."\n";
$schema .= ' <xs:element name="surveypro_item">'."\n";
$schema .= ' <xs:complexType>'."\n";
$schema .= ' <xs:sequence>'."\n";
// $schema .= ' <xs:element type="xs:int" name="surveyproid"/>'."\n";

$schema .= ' <xs:element type="xs:int" name="hidden"/>'."\n";
$schema .= ' <xs:element type="xs:int" name="insearchform"/>'."\n";
$schema .= ' <xs:element type="xs:int" name="advanced"/>'."\n";

// sortindex has been dropped on December 30, 2015. Next line only for backword compatibility.
// "advanced" has been replaced by "reserved" on March 21, 2016. Next lines guarantee backword compatibility.
$schema .= ' <xs:choice>'."\n";
$schema .= ' <xs:element name="advanced" type="xs:int" minOccurs="0" maxOccurs="1" />'."\n";
$schema .= ' <xs:element name="reserved" type="xs:int" minOccurs="0" maxOccurs="1" />'."\n";
$schema .= ' </xs:choice>'."\n";
// "sortindex" has been dropped on December 30, 2015. Next line only for backword compatibility.
$schema .= ' <xs:element type="xs:int" name="sortindex" minOccurs="0"/>'."\n";
// $schema .= ' <xs:element type="xs:int" name="formpage"/>'."\n";

$schema .= ' <xs:element type="xs:int" name="parentid" minOccurs="0"/>'."\n";
$schema .= ' <xs:element type="xs:string" name="parentvalue" minOccurs="0"/>'."\n";

// $schema .= ' <xs:element type="xs:int" name="timecreated"/>'."\n";
// $schema .= ' <xs:element type="xs:int" name="timemodified"/>'."\n";
$schema .= ' </xs:sequence>'."\n";
$schema .= ' </xs:complexType>'."\n";
$schema .= ' </xs:element>'."\n";
Expand Down Expand Up @@ -1143,13 +1139,13 @@ public function get_insearchform() {
}

/**
* get_advanced
* get_reserved
*
* @param none
* @return the content of the $advanced property
* @return the content of the $reserved property
*/
public function get_advanced() {
return $this->advanced;
public function get_reserved() {
return $this->reserved;
}

/**
Expand Down Expand Up @@ -1468,10 +1464,10 @@ public function userform_child_item_allowed_static($submissionid, $childitemreco
* In the frame of this method the parent item is calculated and is requested to provide the disabledif conditions to disable its child item
*
* @param $mform
* @param $canaccessadvanceditems
* @param $canaccessreserveditems
* @return void
*/
public function userform_add_disabledif($mform, $canaccessadvanceditems) {
public function userform_add_disabledif($mform, $canaccessreserveditems) {
global $DB;

if (!$this->parentid || ($this->type == SURVEYPRO_TYPEFORMAT)) {
Expand Down

0 comments on commit c0cb213

Please sign in to comment.