예제 #1
0
 /**
  * items in the form
  */
 public function definition()
 {
     global $CURMAN, $CFG;
     parent::definition();
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('text', 'name', get_string('userset_name', 'local_elisprogram'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->addHelpButton('name', 'userset_name', 'local_elisprogram');
     $mform->addElement('textarea', 'display', get_string('userset_description', 'local_elisprogram'), array('cols' => 40, 'rows' => 2));
     $mform->setType('display', PARAM_CLEAN);
     $mform->addHelpButton('display', 'userset_description', 'local_elisprogram');
     $current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : '';
     //obtain the non-child clusters that we could become the child of, with availability
     //determined based on the edit capability
     $contexts = usersetpage::get_contexts('local/elisprogram:userset_edit');
     $non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts);
     //parent dropdown
     $mform->addElement('select', 'parent', get_string('userset_parent', 'local_elisprogram'), $non_child_clusters);
     $mform->addHelpButton('parent', 'userset_parent', 'local_elisprogram');
     // allow plugins to add their own fields
     $mform->addElement('header', 'userassociationfieldset', get_string('userset_userassociation', 'local_elisprogram'));
     $plugins = get_plugin_list(userset::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         require_once elis::plugin_file(userset::ENROL_PLUGIN_TYPE . '_' . $plugin, 'lib.php');
         call_user_func('cluster_' . $plugin . '_edit_form', $this, $mform, $current_cluster_id);
     }
     // custom fields
     $this->add_custom_fields('cluster', 'local/elisprogram:userset_edit', 'local/elisprogram:userset_view', 'cluster');
     $this->add_action_buttons();
 }
예제 #2
0
파일: checkbox.php 프로젝트: jamesmcq/elis
/**
 * Adds an appropriate editing control to the provided form
 *
 * @param  moodleform or HTML_QuickForm  $form       The form to add the appropriate element to
 * @param  field                         $field      The definition of the field defining the controls
 * @param  boolean                       $as_filter  Whether to display a "choose" message
 * @param  string                        $contextname Optional context name/entity
 */
function checkbox_control_display($form, $mform, $customdata, $field, $as_filter = false, $contextname = 'system')
{
    if (!$form instanceof moodleform) {
        $mform = $form;
        $form->_customdata = null;
    }
    $manual = new field_owner($field->owners['manual']);
    $manual_params = unserialize($manual->params);
    if (!empty($manual_params['options_source']) || !empty($manual_params['options'])) {
        if ($as_filter || $field->multivalued) {
            //            require_once(CURMAN_DIRLOCATION.'/plugins/manual/field_controls/menu.php');
            require_once elis::plugin_file('elisfields_manual', 'field_controls/menu.php');
            return menu_control_display($form, $mform, $customdata, $field, $as_filter);
        }
        $options = array();
        if (!empty($manual_params['options'])) {
            $options = explode("\n", $manual_params['options']);
        }
        $source = '';
        if (!empty($manual_params['options_source'])) {
            $source = $manual_params['options_source'];
        }
        if (!empty($source)) {
            $srcfile = elis::plugin_file('elisfields_manual', "sources/{$source}.php");
            if (file_exists($srcfile)) {
                require_once elis::plugin_file('elisfields_manual', 'sources.php');
                require_once $srcfile;
                $classname = "manual_options_{$source}";
                $plugin = new $classname();
                if ($plugin && $plugin->is_applicable($contextname)) {
                    $options = $plugin->get_options($customdata);
                }
            }
        }
        $controls = array();
        foreach ($options as $option) {
            $option = trim($option);
            if ($field->multivalued) {
                //  FIXME: this doesn't work
                $cb = $controls[] =& $mform->createElement('checkbox', "field_{$field->shortname}", null, $option);
                $cb->updateAttributes(array('value' => $option));
            } else {
                $controls[] =& $mform->createElement('radio', "field_{$field->shortname}", null, $option, $option);
            }
        }
        $mform->addGroup($controls, "field_{$field->shortname}", $field->name, '<br />', false);
    } else {
        $checkbox = $mform->addElement('advcheckbox', "field_{$field->shortname}", $field->name);
    }
    manual_field_add_help_button($mform, "field_{$field->shortname}", $field);
}
예제 #3
0
 /**
  * Method to add ELIS entity's custom fields to entity forms
  *
  * @param string $entity        ELIS entity name: Eg. 'curriculum', 'track', 'course', 'class', 'cluster', 'user'
  * @param string $editcap      The required edit capability
  * @param string $viewcap      The required view capability
  * @param string $parententity The entity name of the parent object (optional)
  */
 function add_custom_fields($entity, $editcap, $viewcap, $parententity = '')
 {
     $mform =& $this->_form;
     $fields = field::get_for_context_level($entity);
     $fields = $fields ? $fields : array();
     if (isset($this->_customdata['obj'])) {
         if (isset($this->_customdata['obj']->id)) {
             // Use the current (existing) entity's context instance
             $contextlevel = \local_eliscore\context\helper::get_level_from_name($entity);
             $contextclass = \local_eliscore\context\helper::get_class_for_level($contextlevel);
             $context = $contextclass::instance($this->_customdata['obj']->id);
         } else {
             if (isset($this->_customdata['obj']->parent) && $parententity != '') {
                 // ELIS-6498 -- Specify the parent entity type to get the correct parent context instance as we are
                 // adding a new "child" entity
                 $contextlevel = \local_eliscore\context\helper::get_level_from_name($parententity);
                 $contextclass = \local_eliscore\context\helper::get_class_for_level($contextlevel);
                 $context = $contextclass::instance($this->_customdata['obj']->parent);
             } else {
                 if (isset($this->_customdata['obj']->courseid) && $parententity == 'course') {
                     // ELIS-6498 -- Special handling of the course -> class hierarchy is required here
                     $context = \local_elisprogram\context\course::instance($this->_customdata['obj']->courseid);
                 } else {
                     $context = context_system::instance();
                 }
             }
         }
     } else {
         $context = context_system::instance();
     }
     require_once elis::plugin_file('elisfields_manual', 'custom_fields.php');
     $lastcat = null;
     $entityid = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : 0;
     foreach ($fields as $rec) {
         $field = new field($rec);
         if (!isset($field->owners['manual'])) {
             continue;
         }
         // Capabilities for editing / viewing this context
         if (manual_field_is_view_or_editable($field, $context, $editcap, $viewcap, $entity, $entityid) != MANUAL_FIELD_NO_VIEW_OR_EDIT) {
             if ($lastcat != $rec->categoryid) {
                 $lastcat = $rec->categoryid;
                 $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname));
             }
             manual_field_add_form_element($this, $mform, $context, $this->_customdata, $field, true, $editcap, $viewcap, $entity, $entityid);
         }
     }
 }
예제 #4
0
파일: menu.php 프로젝트: jamesmcq/elis
/**
 * Adds an appropriate editing control to the provided form
 *
 * @param  moodleform or HTML_QuickForm  $form       The form to add the appropriate element to
 * @param  field                         $field      The definition of the field defining the controls
 * @param  boolean                       $as_filter  Whether to display a "choose" message
 * @param  string                        $contextname Optional context name/entity
 */
function menu_control_display($form, $mform, $customdata, $field, $as_filter = false, $contextname = 'system')
{
    if (!$form instanceof moodleform) {
        $mform = $form;
        $form->_customdata = null;
        $customdata = null;
    }
    $manual = new field_owner($field->owners['manual']);
    if ($field->datatype != 'bool') {
        if (!isset($manual->param_options_source) || $manual->param_options_source == '') {
            $tmpoptions = explode("\n", $manual->param_options);
            if ($as_filter) {
                $options = array('' => get_string("choose"));
            }
            foreach ($tmpoptions as $key => $option) {
                $option = trim($option, "\n\r");
                $options[$option] = format_string($option);
                // multilang formatting
            }
        } else {
            $options = array();
            $source = $manual->param_options_source;
            $srcfile = elis::plugin_file('elisfields_manual', "sources/{$source}.php");
            if (file_exists($srcfile)) {
                require_once elis::plugin_file('elisfields_manual', 'sources.php');
                require_once $srcfile;
                $classname = "manual_options_{$source}";
                $plugin = new $classname();
                if ($plugin && $plugin->is_applicable($contextname)) {
                    $options = $plugin->get_options($customdata);
                }
            }
        }
    } else {
        if ($as_filter) {
            $options = array('' => get_string("choose"), 0 => get_string('no'), 1 => get_string('yes'));
        } else {
            $options = array(0 => get_string('no'), 1 => get_string('yes'));
        }
    }
    $menu = $mform->addElement('select', "field_{$field->shortname}", $field->name, $options);
    if ($field->multivalued && !$as_filter) {
        $menu->setMultiple(true);
    }
    manual_field_add_help_button($mform, "field_{$field->shortname}", $field);
}
예제 #5
0
/**
 * sync_profile_field_settings_to_moodle function synchronizes ELIS custom user field settings to corresponding Moodle field if possible.
 *
 * @param  object $field  the field object to sync
 * @return mixed          void or true (may throw DB exceptions)
 * @uses   $DB
 */
function sync_profile_field_settings_to_moodle($field)
{
    global $DB;
    if (!isset($field->owners['moodle_profile']) || $field->owners['moodle_profile']->exclude == pm_moodle_profile::sync_from_moodle) {
        // not owned by the Moodle plugin, or set to sync from Moodle
        return true;
    }
    // check if sync is possible with current field settings
    if (!moodle_profile_can_sync($field->shortname)) {
        return true;
    }
    // Sync field settings first, since they could prevent field data sync
    $moodlefield = $DB->get_record('user_info_field', array('shortname' => $field->shortname));
    if (empty($moodlefield)) {
        // pre-caution
        return true;
    }
    // Check if we have settings to sync
    $ownersyncfields = get_owner_sync_fields($moodlefield->datatype);
    if (!empty($ownersyncfields)) {
        if (empty($field->owners) || !isset($field->owners['manual'])) {
            return true;
            // TBD
        }
        $fieldowner = new field_owner($field->owners['manual']);
        if (!empty($fieldowner)) {
            $sqlparts = array();
            $params = array();
            foreach ($ownersyncfields as $key => $val) {
                $sqlparts[] = "{$key} = ?";
                $optionsrc = '';
                if (!empty($fieldowner->param_options_source)) {
                    $optionsrc = $fieldowner->param_options_source;
                }
                if ($val == 'options' && !empty($optionsrc)) {
                    // special case where options from another source
                    $srcfile = elis::plugin_file('elisfields_manual', 'sources') . "/{$optionsrc}.php";
                    $nooptions = true;
                    if (is_readable($srcfile)) {
                        require_once elis::plugin_file('elisfields_manual', 'sources.php');
                        require_once $srcfile;
                        $classname = "manual_options_{$optionsrc}";
                        $plugin = new $classname();
                        if (!empty($plugin) && ($options = $plugin->get_options(array())) && !empty($options)) {
                            $nooptions = false;
                            $params[] = implode("\n", $options);
                        }
                    }
                    if ($nooptions) {
                        array_pop($sqlparts);
                    }
                } else {
                    // temp fix for CRs in options
                    if ($val == 'options') {
                        $fieldowner->{'param_' . $val} = str_replace("\r", '', $fieldowner->{'param_' . $val});
                    }
                    $params[] = $fieldowner->{'param_' . $val};
                }
            }
            if (!empty($sqlparts)) {
                $select = implode(' AND ', array_merge(array('shortname = ?'), $sqlparts));
                if (!$DB->count_records_select('user_info_field', $select, array_merge(array($field->shortname), $params))) {
                    // settings not correct, must update
                    $sql = 'UPDATE {user_info_field} SET ' . implode(', ', $sqlparts) . ' WHERE shortname = ?';
                    $DB->execute($sql, array_merge($params, array($field->shortname)));
                }
            }
        }
    }
}
예제 #6
0
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    local_elisprogram
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once dirname(__FILE__) . '/../../eliscore/test_config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
// Libs.
require_once elis::file('elisprogram/healthpage.class.php');
require_once elis::plugin_file('eliscore_etl', 'health.php');
require_once elis::plugin_file('eliscore_etl', 'etl.php');
/**
 * Test health checks.
 * @group local_elisprogram
 */
class user_activity_health_testcase extends elis_database_test
{
    /**
     * Test the user_activity_health_check
     */
    public function test_etlbehindmorethanweek()
    {
        global $DB;
        $dataset = $this->createCsvDataSet(array('log' => elis::file('elisprogram/tests/fixtures/log_data.csv')));
        $this->loadDataSet($dataset);
        elis::$config->eliscore_etl->last_run = time() - DAYSECS;
예제 #7
0
파일: upgrade.php 프로젝트: jamesmcq/elis
 * Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elisprogram_usetdisppriority
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
defined('MOODLE_INTERNAL') || die;
require_once dirname(__FILE__) . '/../../../../../config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::plugin_file('elisprogram_usetdisppriority', 'lib.php');
function xmldb_elisprogram_usetdisppriority_upgrade($oldversion = 0)
{
    $result = true;
    return $result;
}
예제 #8
0
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    local_eliscore
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once dirname(__FILE__) . '/../test_config.php';
global $CFG;
require_once $CFG->dirroot . '/local/eliscore/lib/setup.php';
require_once $CFG->dirroot . '/local/eliscore/accesslib.php';
require_once elis::lib('data/customfield.class.php');
require_once elis::plugin_file('elisfields_moodleprofile', 'custom_fields.php');
// NOTE: needed because this is used in customfield.class.php :-(.
if (!defined('CONTEXT_ELIS_USER')) {
    define('CONTEXT_ELIS_USER', 15);
}
/**
 * Class for testing the syncing of custom field settings.
 *
 * @group local_eliscore
 */
class custom_field_sync_testcase extends elis_database_test
{
    /**
     * Method to create ELIS field & owner objects given test data array.
     *
     * @param array $inputarray The test data array with params to build elis field object & owner
예제 #9
0
/**
 * Add an element to a form for a field.
 *
 * @param object $form the moodle form object we are adding the element to
 * @param object $mform the moodle quick form object belonging to the moodle form
 * @param mixed $context Moodle context
 * @param array $customdata any additional information to pass along to the element
 * @param object $field the custom field we are viewing / editing
 * @param boolean $checkrequired if true, add a required rule for this field
 * @param string $contexteditcap the edit capability to check if the field owner
 *                                 is set up to use the "edit this context" option for editing
 * @param string $contextviewcap the view capability to check if the field owner
 *                                 is set up to use the "view this context" option for viewing
 * @param int $entityid The id of the entity.  Required only if an entity is passed.
 * @param string $entity  optional entity/context name
 */
function manual_field_add_form_element($form, $mform, $context, $customdata, $field, $checkrequired = true, $contexteditcap = NULL, $contextviewcap = NULL, $entity = 'system', $entityid = 0)
{
    $isvieworeditable = manual_field_is_view_or_editable($field, $context, $contexteditcap, $contextviewcap, $entity, $entityid);
    if ($isvieworeditable == MANUAL_FIELD_NO_VIEW_OR_EDIT) {
        return;
    }
    $elem = "field_{$field->shortname}";
    $manual = new field_owner($field->owners['manual']);
    $control = $manual->param_control;
    require_once elis::plugin_file('elisfields_manual', "field_controls/{$control}.php");
    call_user_func("{$control}_control_display", $form, $mform, $customdata, $field, false, $entity);
    $manualparams = unserialize($manual->params);
    // Set default data if no over-riding value set!
    if (!isset($customdata['obj']->{$elem})) {
        $defaultdata = field_data::get_for_context_and_field(NULL, $field);
        if (!empty($defaultdata)) {
            if ($field->multivalued) {
                $values = array();
                foreach ($defaultdata as $defdata) {
                    $values[] = $defdata->data;
                }
                $defaultdata = $values;
                // implode(',', $values)
            } else {
                foreach ($defaultdata as $defdata) {
                    $defaultdata = $defdata->data;
                    break;
                }
            }
        }
        // Format decimal numbers.
        if ($field->datatype == 'num' && $manualparams['control'] != 'menu') {
            $defaultdata = $field->format_number($defaultdata);
        }
        if (!is_null($defaultdata) && !is_object($defaultdata) && $defaultdata !== false) {
            if (is_string($defaultdata)) {
                $defaultdata = trim($defaultdata, "\r\n");
                // Radio buttons!
            }
            $mform->setDefault($elem, $defaultdata);
        }
    }
    if ($isvieworeditable == MANUAL_FIELD_VIEWABLE) {
        // Have view but not edit permission.
        $mform->freeze($elem);
    } else {
        if ($checkrequired) {
            if (!empty($manualparams['required'])) {
                $mform->addRule($elem, null, 'required', null, 'client');
                // TBD
            }
        }
    }
}
예제 #10
0
파일: text.php 프로젝트: jamesmcq/elis
<?php

defined('MOODLE_INTERNAL') || die;
require_once elis::plugin_file('elisfields_manual', 'custom_fields.php');
/**
 * Adds an appropriate editing control to the provided form
 *
 * @param  moodleform or HTML_QuickForm  $form   The form to add the appropriate element to
 * @param  field                         $field  The definition of the field defining the controls
 */
function text_control_display($form, $mform, $customdata, $field)
{
    if (!$form instanceof moodleform) {
        $mform = $form;
        $form->_customdata = null;
    }
    $param = '';
    if (isset($field->owners['manual'])) {
        $manual = new field_owner($field->owners['manual']);
        if (isset($manual->param_maxlength) && isset($manual->param_columns)) {
            $param = "maxlength=\"{$manual->param_maxlength}\" size=\"{$manual->param_columns}\"";
        }
    }
    $fieldname = "field_{$field->shortname}";
    $mform->addElement('text', $fieldname, $field->name, $param);
    $mform->setType($fieldname, PARAM_MULTILANG);
    manual_field_add_help_button($mform, $fieldname, $field);
}
function text_control_get_value($data, $field)
{
    $name = "field_{$field->shortname}";
예제 #11
0
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    local_elisprogram
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2013 Remote Learner.net Inc http://www.remote-learner.net
 * @author     James McQuillan <*****@*****.**>
 *
 */
require_once elis::plugin_file('usetenrol_manual', 'lib.php');
/**
 * An action to assign usersets to a user.
 */
class deepsight_action_useruserset_assign extends deepsight_action_confirm
{
    public $label = 'Assign';
    public $icon = 'elisicon-assoc';
    /**
     * Constructor.
     * @param moodle_database $DB The active database connection.
     * @param string $name The unique name of the action to use.
     * @param string $descsingle The description when the confirmation is for a single element.
     * @param string $descmultiple The description when the confirmation is for the bulk list.
     */
    public function __construct(moodle_database &$DB, $name, $descsingle = '', $descmultiple = '')
예제 #12
0
 /**
  * Get the menu options for field.
  * Only valid for 'menu' datatypes
  *
  * @param  object $data   optional data for menu options source class
  * @return array          the menu options for the field (empty if N/A)
  */
 public function get_menu_options($data = array())
 {
     global $DB;
     $menu_options = array();
     $params = unserialize($this->params);
     if (!empty($params['control']) && $params['control'] == field::MENU) {
         if (!empty($params['options_source'])) {
             $menu_options_src = $params['options_source'];
             require_once elis::plugin_file('elisfields_manual', 'sources.php');
             $basedir = elis::plugin_file('elisfields_manual', 'sources');
             $src_file = $basedir . '/' . $menu_options_src . '.php';
             if (file_exists($src_file)) {
                 require_once $src_file;
                 $classname = "manual_options_{$menu_options_src}";
                 $plugin = new $classname();
                 $menu_options = $plugin->get_options($data);
             } else {
                 error_log("field_owner::get_menu_options() - ERROR: no source file {$src_file} for fieldid = {$this->fieldid}");
             }
         } else {
             if (!empty($params['options'])) {
                 $options = explode("\n", $params['options']);
                 if (!empty($options)) {
                     $menu_options = array_combine($options, $options);
                 }
             } else {
                 error_log("field_owner::get_menu_options() - no menu options found for fieldid = {$this->fieldid}");
             }
         }
     }
     return $menu_options;
 }
예제 #13
0
 /**
  * Create a new customuserfieldtable object.
  *
  * @param mixed $items array (or other iterable) of items to be displayed
  * in the table.  Each element in the array should be an object, with
  * fields matching the names in {@var $columns} containing the data.
  * @param array $columns mapping of column IDs to column configuration.
  * The column configuration is an array with the following entries:
  * - header (optional): the plain-text name, used for the table header.
  *   Can either be a string or an array (for headers that allow sorting on
  *   multiple values, e.g. first-name/last-name).  If it is an array, then
  *   the key is an ID used for sorting (if applicable), and the value is
  *   an array of similar form to the $columns array, but only the 'header'
  *   and 'sortable' keys are used.  (Defaults to empty.)
  * - display_function (optional): the function used to display the column
  *   entry.  This can either be the name of a method, or a PHP callback.
  *   Takes two arguments: the column ID, and the item (from the $items
  *   array).  Returns a string (or something that can be cast to a string).
  *   (Defaults to the get_item_display_default method, which just returns
  *   htmlspecialchars($item->$column), where $column is the column ID.)
  * - decorator (optional): a function used to decorate the column entry
  *   (e.g. add links, change the text style, etc).  This is a PHP callback
  *   that takes three arguments: the column contents (the return value from
  *   display_function), the column ID, and the item.  (Defaults to doing
  *   nothing.)
  * - sortable (optional): whether the column can be used for sorting.  Can
  *   be either true, false, display_table::ASC (which indicates that
  *   the table is sorted by this column in the ascending direction), or
  *   display_table::DESC.  This has no effect if the header entry is an
  *   array.  (Defaults to the return value of is_sortable_default, which
  *   defaults to true unless overridden by a  subclass.)
  * - wrapped (optional): whether the column data should be wrapped if it is
  *   too long.  (Defaults to the return value of is_column_wrapped_default,
  *   which defaults to true unless overridden by a subclass.)
  * - align (optional): how the column data should be aligned (left, right,
  *   center).  (Defaults to the return value of get_column_align_default(),
  *   which defaults to left unless overridden by a subclass.)
  * @param moodle_url $base_url base url to the page, for changing sort
  * order. Only needed if the table can be sorted.
  * @param string $sort_param the name of the URL parameter to add to
  * $pageurl to specify the column to sort by.
  * @param string $sortdir_param the name of the URL parameter to add to
  * $pageurl to specify the direction of the sort.
  * @param array $attributes associative array of table attributes like:
  * 'id' => 'tableid', 'width' => '90%', 'cellpadding', 'cellspacing' ...
  */
 public function __construct($items, $columns, moodle_url $base_url = null, $sort_param = 'sort', $sortdir_param = 'dir', array $attributes = array())
 {
     parent::__construct($items, $columns, $base_url, $sort_param, $sortdir_param, $attributes);
     if (is_readable(elis::plugin_file("elisfields_moodleprofile", 'custom_fields.php'))) {
         include_once elis::plugin_file("elisfields_moodleprofile", 'custom_fields.php');
         if (function_exists('moodle_profile_can_sync')) {
             $this->cansyncfcn = 'moodle_profile_can_sync';
         }
     }
 }
예제 #14
0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    block_elisadmin
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elispm::lib('lib.php');
require_once elis::plugin_file('block_elisadmin', 'lib.php');
require_once elispm::lib('menuitem.class.php');
require_once elispm::lib('data/userset.class.php');
require_once elispm::lib('deprecatedlib.php');
/// Add curriculum stylesheets...
/*
if (file_exists($CFG->dirroot.'/curriculum/styles.css')) {
//    echo '<link style="text/css" REL=StyleSheet HREF="' . $CFG->wwwroot . '/curriculum/styles.css" />';
    $CFG->stylesheets[] = $CFG->wwwroot . '/curriculum/styles.css';
}
*/
class block_elisadmin extends block_base
{
    var $currentdepth;
    var $spancounter;
    var $tempcontent;
예제 #15
0
파일: lib.php 프로젝트: jamesmcq/elis
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    usetenrol_moodleprofile
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
defined('MOODLE_INTERNAL') || die;
require_once dirname(__FILE__) . '/../../../../../config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elispm::lib('data/userset.class.php');
require_once elispm::lib('data/user.class.php');
require_once elis::plugin_file('usetenrol_moodleprofile', 'userset_profile.class.php');
function cluster_moodleprofile_delete_for_cluster($id)
{
    userset_profile::delete_records(new field_filter('clusterid', $id));
}
/* adds to form:
 * profile_field1 -select box
 * profile_value1 -select box corresponding to profile_field1
 *
 * profile_field2 -select box
 * profile_value2 -select box corresponding to profile_field2
 */
function cluster_moodleprofile_edit_form($form, $mform, $clusterid)
{
    global $CFG, $DB, $PAGE;
    /// Only get--at most--two profile field associations for this cluster.
예제 #16
0
 /**
  * Get a list of the clusters assigned to this curriculum.
  *
  * @uses           $CURMAN
  * @param   int    $curriculumid     The cluster id
  * @param   int    $parentclusterid  If non-zero, a required direct-parent cluster
  * @param   int    $startrecord      The index of the record to start with
  * @param   int    $perpage          The number of records to include
  * @param   array  $extrafilters     Additional filters to apply to the listing
  * @return  array                    The appropriate cluster records
  */
 public static function get_clusters($curriculumid = 0, $parentclusterid = 0, $sort = 'name', $dir = 'ASC', $startrec = 0, $perpage = 0, $extrafilters = array())
 {
     global $DB;
     if (empty($DB)) {
         return NULL;
     }
     //require plugin code if enabled
     $plugins = get_plugin_list('elisprogram');
     $display_priority_enabled = isset($plugins['usetdisppriority']);
     if ($display_priority_enabled) {
         require_once elis::plugin_file('elisprogram_usetdisppriority', 'lib.php');
     }
     $select = 'SELECT clstcur.id, clstcur.clusterid, clst.name, clst.display, clstcur.autoenrol ';
     $tables = 'FROM {' . self::TABLE . '} clstcur ';
     $join = 'LEFT JOIN {' . userset::TABLE . '} clst ' . 'ON clst.id = clstcur.clusterid ';
     //handle empty sort case
     if (empty($sort)) {
         $sort = 'name';
         $dir = 'ASC';
     }
     //get the fields we are sorting
     $sort_fields = explode(',', $sort);
     //convert the fields into clauses
     $sort_clauses = array();
     foreach ($sort_fields as $key => $value) {
         $new_value = trim($value);
         if ($display_priority_enabled && $new_value == 'priority') {
             $sort_clauses[$key] = $new_value . ' DESC';
         } else {
             $sort_clauses[$key] = $new_value . ' ' . $dir;
         }
     }
     //determine if we are handling the priority field for ordering
     if ($display_priority_enabled && in_array('priority', $sort_fields)) {
         userset_display_priority_append_sort_data('clst.id', $select, $join);
     }
     $where = 'WHERE clstcur.curriculumid = :curriculumid ';
     $params = array('curriculumid' => $curriculumid);
     //apply the parent-cluster condition if applicable
     if (!empty($parentclusterid)) {
         $where .= " AND clst.parent = :parentclusterid ";
         $params['parentclusterid'] = $parentclusterid;
     }
     if (!empty($extrafilters['contexts'])) {
         //apply a filter related to filtering on particular PM cluster contexts
         $filter_object = $extrafilters['contexts']->get_filter('id', 'cluster');
         $filter_sql = $filter_object->get_sql(false, 'clst', SQL_PARAMS_NAMED);
         if (!empty($filter_sql)) {
             //user does not have access at the system context
             $where .= 'AND (' . $filter_sql['where'] . ") ";
             $params = array_merge($params, $filter_sql['where_parameters']);
         }
     }
     $group = 'GROUP BY clstcur.id ';
     $sort_clause = 'ORDER BY ' . implode($sort_clauses, ', ') . ' ';
     $sql = $select . $tables . $join . $where . $group . $sort_clause;
     return $DB->get_records_sql($sql, $params, $startrec, $perpage);
 }
예제 #17
0
 function is_applicable($contextlevel)
 {
     return $contextlevel === 'cluster' && is_readable(elis::plugin_file('elisprogram_usetclassify', 'usersetclassification.class.php'));
 }
예제 #18
0
파일: upgrade.php 프로젝트: jamesmcq/elis
 * Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elisprogram_archive
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
defined('MOODLE_INTERNAL') || die;
require_once dirname(__FILE__) . '/../../../../../config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::plugin_file('elisprogram_archive', 'lib.php');
function xmldb_elisprogram_archive_upgrade($oldversion = 0)
{
    $result = true;
    return $result;
}
예제 #19
0
 function setupForm(&$mform)
 {
     $fieldname = "field_{$this->_field->shortname}";
     if (isset($this->_field->owners['manual'])) {
         $manual = new field_owner($this->_field->owners['manual']);
         if (isset($manual->param_control)) {
             $control = $manual->param_control;
         }
     }
     if (!isset($control)) {
         $control = 'text';
     }
     require_once elis::plugin_file('elisfields_manual', "field_controls/{$control}.php");
     $mform->setAdvanced($fieldname);
     // ELIS-3894: moved up
     call_user_func("{$control}_control_display", $mform, $mform, null, $this->_field, true);
 }
예제 #20
0
 * Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    usetenrol_moodleprofile
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once '../../../lib/setup.php';
require_once elis::plugin_file('usetenrol_moodleprofile', 'lib.php');
$id = required_param('field', PARAM_INT);
$elementName = required_param('elementName', PARAM_TEXT);
$value = optional_param('value', null, PARAM_TEXT);
require_login(0, false);
$prof_field = new stdClass();
$prof_field->fieldid = $id;
//output the innerHTML of the surrounding DIV tag
echo get_moodle_profile_field_options($prof_field, $elementName, $value);
예제 #21
0
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
defined('MOODLE_INTERNAL') or die;
require_once elispm::lib('lib.php');
require_once elispm::lib('deepsightpage.class.php');
require_once elispm::lib('associationpage.class.php');
require_once elispm::lib('data/user.class.php');
require_once elispm::lib('data/userset.class.php');
require_once elispm::lib('data/clusterassignment.class.php');
require_once elispm::file('userpage.class.php');
require_once elispm::file('usersetpage.class.php');
require_once elis::plugin_file('usetenrol_manual', 'lib.php');
require_once elis::plugin_file('usetenrol_manual', 'usersetassignment_form.php');
require_once elis::plugin_file('usetenrol_manual', 'selectpage.class.php');
/**
 * A base user-userset association implementation for code shared between userclusterpage and clusteruserpage.
 */
abstract class userclusterbase extends deepsightpage
{
    public $section = 'users';
    public $data_class = 'clusterassignment';
    public $parent_page;
    /**
     * Determine whether the current can manage the association between a given user and userset.
     * @param int $userid The ID of a user.
     * @param int $clustid The ID of a userset.
     * @return bool Success status.
     */
    public static function can_manage_assoc($userid, $usersetid)
예제 #22
0
 public function save()
 {
     $plugins = get_plugin_list(self::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         require_once elis::plugin_file(self::ENROL_PLUGIN_TYPE . '_' . $plugin, 'lib.php');
     }
     if (!empty($this->id)) {
         // cache the database values, so we can know if the parent changed
         $old = new userset($this->id);
         $old->load();
     }
     // figure out the right depth for the cluster
     if (empty($this->depth) || !empty($this->id)) {
         if ($this->parent == 0) {
             $this->depth = 1;
         } else {
             $this->depth = $this->parentset->depth + 1;
         }
     }
     parent::save();
     if (isset($old) && $this->parent != $old->parent) {
         $cluster_context_instance = \local_elisprogram\context\userset::instance($this->id);
         // find all subclusters and adjust their depth
         $delta_depth = $this->depth - $old->depth;
         $LIKE = $this->_db->sql_like('path', '?');
         $sql = 'UPDATE {' . self::TABLE . "}\n                       SET depth = depth + ?\n                     WHERE id IN (SELECT instanceid\n                                    FROM {context}\n                                   WHERE contextlevel = ?\n                                     AND {$LIKE})";
         $this->_db->execute($sql, array($delta_depth, CONTEXT_ELIS_USERSET, "{$cluster_context_instance->path}/%"));
         // Blank out the depth and path for associated records and child records in context table
         $sql = "UPDATE {context}\n                       SET depth=0, path=NULL\n                     WHERE id=? OR {$LIKE}";
         $this->_db->execute($sql, array($cluster_context_instance->id, "{$cluster_context_instance->path}/%"));
         // Rebuild any blanked out records in context table
         \local_eliscore\context\helper::build_all_paths(false, array(CONTEXT_ELIS_USERSET));
     }
     $plugins = get_plugin_list(self::ENROL_PLUGIN_TYPE);
     foreach ($plugins as $plugin => $plugindir) {
         call_user_func('userset_' . $plugin . '_update', $this);
     }
     if (isset($old)) {
         //signal that the cluster was created
         events_trigger('pm_userset_updated', $this);
     } else {
         events_trigger('pm_userset_created', $this);
     }
 }
예제 #23
0
파일: setup.php 프로젝트: jamesmcq/elis
 public function &__get($name)
 {
     global $DB;
     if (!isset($this->configs[$name])) {
         $config = new stdClass();
         // load the defaults
         if (file_exists(elis::plugin_file($name, 'defaults.php'))) {
             $defaults = array();
             include elis::plugin_file($name, 'defaults.php');
             foreach ($defaults as $key => $value) {
                 $config->{$key} = $value;
             }
         }
         $configrecs = $DB->get_recordset('config_plugins', array('plugin' => $name));
         foreach ($configrecs as $rec) {
             $key = $rec->name;
             $config->{$key} = $rec->value;
         }
         unset($configrecs);
         $this->configs[$name] = $config;
     }
     return $this->configs[$name];
 }
예제 #24
0
파일: edit.php 프로젝트: jamesmcq/elis
 *
 * @package    enrol_elis
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
// based on /enrol/manual/edit.php
require_once '../../config.php';
global $DB;
$elisprogramexists = file_exists($CFG->dirroot . '/local/elisprogram/lib/setup.php') && $DB->record_exists('config_plugins', array('plugin' => 'local_elisprogram', 'name' => 'version'));
if (!$elisprogramexists) {
    print_error(get_string('missing_elisprogram_dependency', 'enrol_elis'));
}
require '../../local/elisprogram/lib/setup.php';
require elis::plugin_file('enrol_elis', 'edit_form.php');
$courseid = required_param('courseid', PARAM_INT);
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
require_login($course);
require_capability('enrol/elis:config', $context);
$PAGE->set_url('/enrol/elis/edit.php', array('courseid' => $course->id));
$PAGE->set_pagelayout('admin');
$return = new moodle_url('/enrol/instances.php', array('id' => $course->id));
if (!enrol_is_enabled('elis')) {
    redirect($return);
}
$plugin = enrol_get_plugin('elis');
if ($instances = $DB->get_records('enrol', array('courseid' => $course->id, 'enrol' => 'elis'), 'id ASC')) {
    $instance = array_shift($instances);
    if ($instances) {
예제 #25
0
 function get_default_object_for_add()
 {
     $parent = $this->optional_param('parent', 0, PARAM_INT);
     if ($parent) {
         $obj = new stdClass();
         $obj->parent = $parent;
         if ($parent) {
             require_once elis::plugin_file('elisprogram_usetclassify', 'usersetclassification.class.php');
             require_once elis::plugin_file('elisprogram_usetclassify', 'lib.php');
             if ($classification = usersetclassification::get_for_cluster($parent)) {
                 $fieldname = 'field_' . USERSET_CLASSIFICATION_FIELD;
                 if ($classification->param_child_classification) {
                     $obj->{$fieldname} = $classification->param_child_classification;
                 } else {
                     $obj->{$fieldname} = $classification->shortname;
                 }
                 //default groups and groupings settings
                 if ($classification->param_autoenrol_groups) {
                     $obj->field_userset_group = $classification->param_autoenrol_groups;
                 }
                 if ($classification->param_autoenrol_groupings) {
                     $obj->field_userset_groupings = $classification->param_autoenrol_groupings;
                 }
             }
         }
         return $obj;
     } else {
         return NULL;
     }
 }
예제 #26
0
파일: upgrade.php 프로젝트: jamesmcq/elis
 * Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elisprogram_usetclassify
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
defined('MOODLE_INTERNAL') || die;
require_once dirname(__FILE__) . '/../../../../../config.php';
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
require_once elis::plugin_file('elisprogram_usetclassify', 'lib.php');
function xmldb_elisprogram_usetclassify_upgrade($oldversion = 0)
{
    $result = true;
    return $result;
}
예제 #27
0
파일: lib.php 프로젝트: jamesmcq/elis
/**
 * Migrate a single Moodle user to the Program Management system.  Will
 * only do this for users who have an idnumber set.
 *
 * @param object $mu Moodle user object
 * @return boolean Whether user was synchronized or not
 */
function pm_moodle_user_to_pm($mu)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/lib/moodlelib.php';
    require_once elis::lib('data/customfield.class.php');
    require_once elispm::lib('data/user.class.php');
    require_once elispm::lib('data/usermoodle.class.php');
    require_once elis::lib('data/data_filter.class.php');
    require_once $CFG->dirroot . '/user/profile/lib.php';
    require_once elis::lib('lib.php');
    if (!isset($mu->id)) {
        return true;
    }
    // re-fetch, in case this is from a stale event
    $mu = $DB->get_record('user', array('id' => $mu->id));
    if (user_not_fully_set_up($mu) || !$mu->confirmed) {
        // Prevent the sync if a bare-bones user record is being created by create_user_record
        // or Moodle user has not yet been confirmed.
        return true;
    }
    //not going to be concerned with city or password for now
    if (empty($mu->idnumber) && elis::$config->local_elisprogram->auto_assign_user_idnumber) {
        //make sure the current user's username does not match up with some other user's
        //idnumber (necessary since usernames and idnumbers aren't bound to one another)
        if (!$DB->record_exists('user', array('idnumber' => $mu->username))) {
            $mu->idnumber = $mu->username;
            $DB->update_record('user', $mu);
        }
    }
    // skip user if no ID number set
    if (empty($mu->idnumber)) {
        return true;
    }
    // track whether we're syncing an idnumber change over to the PM system
    $idnumber_updated = false;
    // track whether an associated Moodle user is linked to the current PM user
    $moodle_user_exists = false;
    // determine if the user is already noted as having been associated to a PM user
    // this will join to Moodle user and PM user table to ensure data correctness
    $filters = array();
    $filters[] = new join_filter('muserid', 'user', 'id');
    $filters[] = new join_filter('cuserid', user::TABLE, 'id');
    $filters[] = new field_filter('muserid', $mu->id);
    if ($um = usermoodle::find($filters)) {
        if ($um->valid()) {
            $um = $um->current();
            //signal that an associated user already exists
            $moodle_user_exists = true;
            // determine if the Moodle user idnumber was updated
            if ($um->idnumber != $mu->idnumber) {
                //signal that the idnumber was synced over
                $idnumber_updated = true;
                // update the PM user with the new idnumber
                $cmuser = new user();
                $cmuser->id = $um->cuserid;
                $cmuser->idnumber = $mu->idnumber;
                $cmuser->save();
                // update the association table with the new idnumber
                $um->idnumber = $mu->idnumber;
                $um->save();
            }
        }
    }
    // find the linked PM user
    //filter for the basic condition on the Moodle user id
    $condition_filter = new field_filter('id', $mu->id);
    //filter for joining the association table
    $association_filter = new join_filter('muserid', 'user', 'id', $condition_filter);
    //outermost filter
    $filter = new join_filter('id', usermoodle::TABLE, 'cuserid', $association_filter);
    $cu = user::find($filter);
    if ($cu->valid()) {
        $cu = $cu->current();
    } else {
        // if a user with the same username but different idnumber exists,
        // we can't sync over because it will violate PM user uniqueness
        // constraints
        $cu = user::find(new field_filter('username', $mu->username));
        if ($cu->valid()) {
            return true;
        }
        // if no such PM user exists, create a new one
        $cu = new user();
        $cu->transfercredits = 0;
        $cu->timecreated = time();
    }
    // synchronize standard fields
    $cu->username = $mu->username;
    $cu->password = $mu->password;
    // only need to update the idnumber if it wasn't handled above
    if (!$idnumber_updated) {
        $cu->idnumber = $mu->idnumber;
    }
    $cu->firstname = $mu->firstname;
    $cu->lastname = $mu->lastname;
    $cu->email = $mu->email;
    $cu->address = $mu->address;
    $cu->city = $mu->city;
    $cu->country = $mu->country;
    if (!empty($mu->phone1)) {
        $cu->phone = $mu->phone1;
    }
    if (!empty($mu->phone2)) {
        $cu->phone2 = $mu->phone2;
    }
    if (!empty($mu->lang)) {
        $cu->language = $mu->lang;
    }
    $cu->timemodified = time();
    // synchronize custom profile fields
    profile_load_data($mu);
    fix_moodle_profile_fields($mu);
    $fields = field::get_for_context_level(CONTEXT_ELIS_USER);
    $fields = $fields ? $fields : array();
    require_once elis::plugin_file('elisfields_moodleprofile', 'custom_fields.php');
    foreach ($fields as $field) {
        $field = new field($field);
        if (!moodle_profile_can_sync($field->shortname)) {
            continue;
        }
        if (isset($field->owners['moodle_profile']) && isset($mu->{"profile_field_{$field->shortname}"})) {
            // check if should sync user profile field settings
            if ($field->owners['moodle_profile']->exclude == pm_moodle_profile::sync_from_moodle) {
                sync_profile_field_settings_from_moodle($field);
            }
            $fieldname = "field_{$field->shortname}";
            $cu->{$fieldname} = $mu->{"profile_field_{$field->shortname}"};
        }
    }
    //specifically tell the user save not to use the local_elisprogram_usr_mdl for syncing
    //because the record hasn't been inserted yet (see below)
    try {
        $cu->save(false);
    } catch (Exception $ex) {
        if (in_cron()) {
            mtrace(get_string('record_not_created_reason', 'local_elisprogram', array('message' => $ex->getMessage() . " [{$mu->id}]")));
            return false;
        } else {
            throw new Exception($ex->getMessage());
        }
    }
    // if no user association record exists, create one
    if (!$moodle_user_exists) {
        $um = new usermoodle();
        $um->cuserid = $cu->id;
        $um->muserid = $mu->id;
        $um->idnumber = $mu->idnumber;
        $um->save();
    }
    return true;
}
예제 #28
0
 function validation($data, $files)
 {
     // copied from /user/profile/definelib.php
     global $CFG, $USER, $DB;
     $err = array();
     $fid = $this->_customdata['id'];
     //ob_start();
     //var_dump($this->defaultdata_menu);
     //$tmp = ob_get_contents();
     //ob_end_clean();
     //error_log("customfieldform::validation(); defaultdata_menu = {$tmp}");
     if ($this->defaultdata_menu && $data['manual_field_control'] == 'menu' && empty($data['manual_field_options_source'])) {
         $menu_options = explode("\n", $data['manual_field_options']);
         array_walk($menu_options, array($this, 'trim_crlf'));
         $select_options = array();
         foreach ($menu_options as $menu_option) {
             // ELIS-8066: Disallow blank/empty menu options
             if (empty($menu_option)) {
                 $err['manual_field_options'] = get_string('no_blank_menuoption', 'local_elisprogram');
             }
             $select_options[] = array('text' => $menu_option, 'attr' => array('value' => $menu_option));
         }
         //ob_start();
         //var_dump($this->defaultdata_menu->_options);
         //$tmp = ob_get_contents();
         //ob_end_clean();
         //error_log("customfieldform::validation(); defaultdata_menu->_options = {$tmp}");
         $this->defaultdata_menu->_options = $select_options;
     }
     /// Check the shortname was not truncated by cleaning
     if (empty($data['shortname'])) {
         $err['shortname'] = get_string('required');
     } else {
         // Check for duplicate shortnames
         $level = $this->_customdata['level'];
         $contextlevel = \local_eliscore\context\helper::get_level_from_name($level);
         if (!$contextlevel) {
             print_error('invalid_context_level', 'local_elisprogram');
         }
         $editsql = '';
         // We are in edit mode
         if (!empty($fid)) {
             $editsql = "AND ef.id != {$fid}";
         }
         $sql = "SELECT ef.id\n                    FROM {" . field::TABLE . "} ef\n                    INNER JOIN {" . field_contextlevel::TABLE . "} cl ON ef.id = cl.fieldid\n                    WHERE ef.shortname = ?\n                    AND cl.contextlevel = ?\n                    {$editsql}";
         $params = array($data['shortname'], $contextlevel);
         if ($DB->record_exists_sql($sql, $params)) {
             $err['shortname'] = get_string('profileshortnamenotunique', 'admin');
         }
     }
     $plugins = core_component::get_plugin_list('elisfields');
     foreach ($plugins as $plugin => $dir) {
         if (is_readable(elis::plugin_file("elisfields_{$plugin}", 'custom_fields.php'))) {
             include_once elis::plugin_file("elisfields_{$plugin}", 'custom_fields.php');
             if (function_exists("{$plugin}_field_edit_form_validation")) {
                 $err += call_user_func("{$plugin}_field_edit_form_validation", $this, $data, $files);
             }
         }
     }
     /// No further checks necessary as the form class will take care of it
     return $err;
 }