/**
  * Test successful userset delete
  */
 public function test_success()
 {
     global $DB;
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_USERSET;
     $fieldctx->save();
     $this->give_permissions(array('local/elisprogram:userset_delete'));
     $userset = array('name' => 'testuserset', 'recursive' => true);
     // Setup userset to delete.
     $us = new userset(array('name' => 'testuserset'));
     $us->save();
     $response = local_datahub_elis_userset_delete::userset_delete($userset);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertEquals(get_string('ws_userset_delete_success_code', 'local_datahub', get_string('ws_userset_delete_recursive', 'local_datahub')), $response['messagecode']);
     $this->assertEquals(get_string('ws_userset_delete_success_msg', 'local_datahub', get_string('ws_userset_delete_subsets', 'local_datahub')), $response['message']);
 }
 /**
  * Test successful program delete
  */
 public function test_success()
 {
     global $DB;
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_PROGRAM;
     $fieldctx->save();
     // Create test program to delete.
     $cur = new curriculum(array('idnumber' => 'testprogram', 'name' => 'testprogram'));
     $cur->save();
     $program = array('idnumber' => 'testprogram');
     $this->give_permissions(array('local/elisprogram:program_delete'));
     $response = local_datahub_elis_program_delete::program_delete($program);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertEquals(get_string('ws_program_delete_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_program_delete_success_msg', 'local_datahub'), $response['message']);
     $this->assertFalse($DB->record_exists(curriculum::TABLE, array('idnumber' => 'testprogram')));
 }
Esempio n. 3
0
 /**
  * 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
  *        input array format:
  *        array('field' => array(fieldparam => fieldparam_value [,...]),
  *              'context' => contextlevel,
  *              'manual' => array(fieldowners_manual_param => fomp_value [,...]),
  *              'moodle_profile' => array(fieldowners_moodleprofile_param => fompp_value [,...]),
  *        )
  * @return object The ELIS field object created
  */
 public function build_elis_field_data($inputarray)
 {
     $field = new field((object) $inputarray['field']);
     $field->save();
     $fieldcontext = new field_contextlevel();
     $fieldcontext->fieldid = $field->id;
     $fieldcontext->contextlevel = $inputarray['context'];
     $fieldcontext->save();
     if (isset($inputarray['manual'])) {
         $manual = new field_owner();
         $manual->fieldid = $field->id;
         $manual->plugin = 'manual';
         foreach ($inputarray['manual'] as $key => $val) {
             $manual->{'param_' . $key} = $val;
         }
         $manual->save();
     }
     if (isset($inputarray['moodle_profile'])) {
         $moodleprofile = new field_owner();
         $moodleprofile->fieldid = $field->id;
         $moodleprofile->plugin = 'moodle_profile';
         foreach ($inputarray['moodle_profile'] as $key => $val) {
             $moodleprofile->{$key} = $val;
         }
         $moodleprofile->save();
     }
     $field->load();
     // TDB.
     return $field;
 }
Esempio n. 4
0
/**
 * Appends additional data to query parameters based on existence of theme priority field
 *
 * @param  string  $cluster_id_field  The field to join on for the cluster id
 * @param  string  $select            The current select clause
 * @param  string  $join              The current join clause
 */
function cluster_display_priority_append_sort_data($cluster_id_field, &$select, &$join)
{
    global $CURMAN;
    //make sure we can get the field we need for ordering
    if ($theme_priority_field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_DISPLAY_PRIORITY_FIELD)) and $contextlevel = context_level_base::get_custom_context_level('cluster', 'block_curr_admin')) {
        $field_data_table = $CURMAN->db->prefix_table($theme_priority_field->data_table());
        //use this for easier naming in terms of sorting
        $select .= ', field_data.data AS priority ';
        $join .= "LEFT JOIN ({$CURMAN->db->prefix_table('context')} context\n                  JOIN {$field_data_table} field_data\n                    ON field_data.contextid = context.id\n                    AND field_data.fieldid = {$theme_priority_field->id})\n\n                    ON context.contextlevel = {$contextlevel}\n                    AND context.instanceid = {$cluster_id_field} ";
    }
}
 /**
  * Test successful course update.
  */
 public function test_success()
 {
     global $DB;
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_COURSE;
     $fieldctx->save();
     // Grant permissions.
     $this->give_permissions(array('local/elisprogram:course_edit'));
     // Create test program.
     $datagen = new elis_program_datagenerator($DB);
     $program = $datagen->create_program(array('idnumber' => 'TestProgram'));
     // Create test course to update.
     $crs = new course(array('idnumber' => 'TestCourse', 'name' => 'Test Course', 'syllabus' => ''));
     $crs->save();
     $course = array('idnumber' => 'TestCourse', 'name' => 'Test Course', 'code' => 'CRS1', 'syllabus' => 'Test syllabus', 'lengthdescription' => 'Weeks', 'length' => 2, 'credits' => 1.1, 'completion_grade' => 50, 'cost' => '$100', 'version' => '1.0.0', 'assignment' => $program->idnumber);
     // Update test course.
     $response = local_datahub_elis_course_update::course_update($course);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_course_update_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_course_update_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get course.
     $updatedcourse = new course($response['record']['id']);
     $updatedcourse->load();
     $updatedcourse = $updatedcourse->to_array();
     foreach ($course as $param => $val) {
         if ($param != 'assignment') {
             $this->assertArrayHasKey($param, $updatedcourse);
             $this->assertEquals($val, $updatedcourse[$param]);
         }
     }
     // Check that course was assigned to program.
     $curriculumcourseid = $DB->get_field(curriculumcourse::TABLE, 'id', array('curriculumid' => $program->id, 'courseid' => $response['record']['id']));
     $this->assertNotEmpty($curriculumcourseid);
 }
 /**
  * Helper function for creating a Moodle user profile field
  *
  * @param string $name Profile field shortname
  * @param string $datatype Profile field data type
  * @param int $categoryid Profile field category id
  * @return int The id of the created profile field
  */
 private function create_profile_field($name, $datatype, $categoryid, $contextlevelname = 'user')
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php';
     $file = get_plugin_directory('dhimport', 'version1elis') . '/lib.php';
     require_once $file;
     $field = new field(array('categoryid' => $categoryid, 'shortname' => $name, 'name' => $name));
     $field->save();
     // Field contextlevel.
     $contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevelname);
     $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => $contextlevel));
     $fieldcontextlevel->save();
     return $field->id;
 }
 /**
  * Create a custom field.
  */
 protected function create_custom_field()
 {
     $data = new stdClass();
     $data->shortname = 'testfield';
     $data->name = 'Test Field';
     $data->categoryid = 1;
     $data->description = 'Test Field';
     $data->datatype = 'text';
     $data->forceunique = '0';
     $data->mform_showadvanced_last = 0;
     $data->multivalued = '0';
     $data->defaultdata = '';
     $data->manual_field_enabled = '1';
     $data->manual_field_edit_capability = '';
     $data->manual_field_view_capability = '';
     $data->manual_field_control = 'text';
     $data->manual_field_options_source = '';
     $data->manual_field_options = '';
     $data->manual_field_columns = 30;
     $data->manual_field_rows = 10;
     $data->manual_field_maxlength = 2048;
     $field = new field($data);
     $field->save();
     $fieldcontext = new field_contextlevel();
     $fieldcontext->fieldid = $field->id;
     $fieldcontext->contextlevel = $this->contextlevel;
     $fieldcontext->save();
 }
Esempio n. 8
0
 function codemirror($attrs)
 {
     $url = zotop::module('codemirror', 'url');
     $options = new stdClass();
     $options->path = $url . '/codemirror/js/';
     $options->parserfile = array('parsexml.js');
     $options->stylesheet = array($url . '/codemirror/css/xmlcolors.css');
     $options->height = is_numeric($attrs['height']) ? $attrs['height'] . 'px' : $attrs['height'];
     $options->width = is_numeric($attrs['width']) ? $width . 'px' : $attrs['width'];
     $options->continuousScanning = 500;
     $options->autoMatchParens = true;
     if ($attrs['linenumbers'] !== false) {
         $options->lineNumbers = true;
         $options->textWrapping = false;
     }
     if ($attrs['tabmode'] == '') {
         $options->tabMode = 'shift';
     }
     $html = array();
     $html[] = html::script($url . '/codemirror/js/codemirror.js');
     $html[] = html::stylesheet($url . '/codemirror/css/codemirror.css');
     $html[] = '	' . field::textarea($attrs);
     $html[] = '<script type="text/javascript">';
     $html[] = '	var editor = CodeMirror.fromTextArea("' . $attrs['name'] . '", ' . json_encode($options) . ');';
     $html[] = '$(function(){';
     $html[] = '	$("form").submit(function(){';
     $html[] = '		$("textarea[name=+' . $attrs['name'] . '+]").val(editor.getCode());';
     $html[] = '	});';
     $html[] = '})';
     $html[] = '</script>';
     return implode("\n", $html);
 }
Esempio n. 9
0
 function __construct($name, $caption, $is_required = false, $value, $dir, $prefix = "", $help = "", $help_url = "")
 {
     // Вызываем конструктор базового класса field для
     // инициализации его данных
     parent::__construct($name, "file", $caption, $is_required, $value, "", $help, $help_url);
     $this->dir = $dir;
     $this->prefix = $prefix;
     if (!empty($this->value)) {
         // Проверяем, не является ли файл скриптом PHP
         // или Perl, html, если это так преобразуем его в формат .txt
         $extentions = array("#\\.php#is", "#\\.phtml#is", "#\\.php3#is", "#\\.html#is", "#\\.htm#is", "#\\.hta#is", "#\\.pl#is", "#\\.xml#is", "#\\.inc#is", "#\\.shtml#is", "#\\.xht#is", "#\\.xhtml#is");
         // Заменяем русские символы на транслит
         $this->value[$this->name]['name'] = $this->encodestring($this->value[$this->name]['name']);
         // Извлекаем из имени файла расширение
         $path_parts = pathinfo($this->value[$this->name]['name']);
         $ext = "." . $path_parts['extension'];
         $path = basename(date("y_m_d_h_i_") . $this->value[$this->name]['name'], $ext);
         $add = $ext;
         foreach ($extentions as $exten) {
             if (preg_match($exten, $ext)) {
                 $add = ".txt";
             }
         }
         $path .= $add;
         $path = str_replace("//", "/", $dir . "/" . $prefix . $path);
         // Перемещаем файл из временной директории сервера в
         // директорию /files Web-приложения
         if (copy($this->value[$this->name]['tmp_name'], $path)) {
             // Уничтожаем файл во временной директории
             @unlink($this->value[$this->name]['tmp_name']);
             // Изменяем права доступа к файлу
             @chmod($path, 0644);
         }
     }
 }
Esempio n. 10
0
 public function add($param = "")
 {
     global $myAdmin;
     global $formMaj;
     global $datas_lang;
     global $smarty;
     global $thisSite;
     $this->LANG_DATAS = $myAdmin->LANG_DATAS;
     parent::add();
     $smarty->assign('this', $this);
     $smarty->assign('param', $param);
     $smarty->assign('language', $thisSite->LIST_LANG_COMP[$myAdmin->LANG_INTERFACE]);
     $toolbars = array();
     $toolbars["Default"][1] = "cut copy paste pastetext | undo redo | bold italic underline strikethrough | subscript superscript | removeformat | charmap emoticons hr nonbreaking";
     $toolbars["Default"][2] = "bullist numlist | outdent indent | alignleft aligncenter alignright alignjustify | image | inserttable tableprops deletetable cell row column | link unlink | anchor  | template  | visualblocks | code";
     $toolbars["Default"][3] = "styleselect  fontselect fontsizeselect | forecolor backcolor";
     $toolbars["Basic"][1] = "bold italic underline strikethrough | subscript superscript | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent";
     $toolbars["Basic"][2] = "styleselect | link unlink | image charmap | code";
     $toolbars["Simple"][1] = "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist | link unlink | image charmap | code";
     $toolbars["Image"][1] = "image | code";
     $smarty->assign('toolbar', $toolbars[$this->toolbar]);
     $data = $smarty->fetch($this->pathTemplate . 'inc/fields/class.editortm.tpl');
     addStructure("addJsStructure", DOS_OUTILS_ADMIN . "tinymceJQ/jquery.tinymce.min.js");
     addStructure("addJsStructure", DOS_OUTILS_ADMIN . "tinymceJQ/tinymce.min.js");
     $this->smartAssign($this->field, $data);
     return $data;
 }
Esempio n. 11
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2012 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    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
function xmldb_crlm_cluster_themes_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2010080602) {
        require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
        //theme priority
        $theme_priority_field = new field(field::get_for_context_level_with_name('cluster', 'cluster_themepriority'));
        if (isset($theme_priority_field->owners['manual'])) {
            $theme_priority_owner = new field_owner($theme_priority_field->owners['manual']);
            $theme_priority_owner->param_help_file = 'crlm_cluster_themes/cluster_themepriority';
            $theme_priority_owner->update();
        }
        //theme selection
        $theme_field = new field(field::get_for_context_level_with_name('cluster', 'cluster_theme'));
        if (isset($theme_field->owners['manual'])) {
            $theme_owner = new field_owner($theme_field->owners['manual']);
            $theme_owner->param_help_file = 'crlm_cluster_themes/cluster_theme';
            $theme_owner->update();
        }
    }
    return $result;
}
Esempio n. 12
0
 public function actionEditable()
 {
     $name = yii::$app->request->post('name');
     $value = yii::$app->request->post('value');
     $pk = unserialize(base64_decode(yii::$app->request->post('pk')));
     field::saveEdit($pk, $name, $value);
 }
Esempio n. 13
0
 /**
  * 自定义一个图片控件,该控件只对当前控制器页面有效
  *  
  * @param array 控件参数
  */
 public function image($attrs)
 {
     $html = array();
     $html[] = field::hidden($attrs);
     $html[] = '<div class="textarea" style="margin-top:-1px;height:100px;">';
     $html[] = '	<ul class="zotop-image-list" id="' . $attrs['name'] . '-images">';
     for ($i = 0; $i < 10; $i++) {
         $image = url::theme() . '/image/userface/' . $i . '.gif';
         $class = $attrs['value'] == $image ? 'selected' : 'normal';
         $html[] = '		<li class="' . $class . '"><a href="javascript:void(0);" onfocus="blur()"><img src="' . $image . '" style="width:64px;height:64px;"></a></li>';
     }
     $html[] = '	</ul>';
     $html[] = '</div>';
     $html[] = '
     <script>
     	$(function(){
 			var name = "' . $attrs['name'] . '";
     		var id = "#' . $attrs['name'] . '-images";
     		$(id).find("li").click(function(){
 				var image = $(this).find("img").attr("src");
 				$(this).parents("ul").find("li").removeClass("selected");
 				$(this).addClass("selected");
 				$("#"+name).val(image);
 			})
 		});        
     </script>
     ';
     return implode("\n", $html);
 }
Esempio n. 14
0
/**
 * Sets up the fields necessary for enabling cluster theming
 *
 * @return  boolean  Returns true to indicate success
 */
function cluster_themes_install()
{
    //retrieve the cluster context
    $cluster_context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
    //set up the cluster theme category
    $theme_category = new field_category();
    $theme_category->name = get_string('cluster_theme_category', 'crlm_cluster_themes');
    //set up the theme priority field
    $theme_priority_field = new field();
    $theme_priority_field->shortname = 'cluster_themepriority';
    $theme_priority_field->name = get_string('cluster_theme_priority', 'crlm_cluster_themes');
    $theme_priority_field->datatype = 'int';
    //set up the field and category
    $theme_priority_field = field::ensure_field_exists_for_context_level($theme_priority_field, $cluster_context, $theme_category);
    $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'text', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_themes/cluster_themepriority');
    field_owner::ensure_field_owner_exists($theme_priority_field, 'manual', $owner_options);
    //set up the field for selecting the applicable theme
    $theme_field = new field();
    $theme_field->shortname = 'cluster_theme';
    $theme_field->name = get_string('cluster_theme', 'crlm_cluster_themes');
    $theme_field->datatype = 'char';
    //set up the field and category
    $theme_field = field::ensure_field_exists_for_context_level($theme_field, $cluster_context, $theme_category);
    $owner_options = array('control' => 'menu', 'options_source' => 'themes', 'required' => 0, 'edit_capability' => '', 'view_capability' => '', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_themes/cluster_theme');
    field_owner::ensure_field_owner_exists($theme_field, 'manual', $owner_options);
    return true;
}
Esempio n. 15
0
 public function render()
 {
     $output = '';
     if (!empty($this->field)) {
         $data = array();
         $data += parent::setGeneralData();
         if (isset($this->field['type']['maxlength']) && $this->field['type']['maxlength']) {
             $data['maxlength'] = $this->field['type']['maxlength'];
         } else {
             $data['maxlength'] = 32;
         }
         if ($this->field['code'] == 'captcha') {
             $setting = oc::registry()->config->get('quick_order_pro_setting');
             $data['maxlength'] = $setting['captcha_count_items'];
             $data['text_captcha_reload'] = oc::registry()->load->language->get('text_captcha_reload');
         }
         $data['mask'] = $data['placeholder'] = '';
         if (!empty($this->field['type']['use_mask']) && $this->field['type']['use_mask'] && !empty($this->field['type']['mask'])) {
             $data['mask'] = $this->field['type']['mask'];
             oc::registry()->document->addScript('catalog/view/javascript/quick_order_pro/jquery.maskedinput.min.js');
         }
         if (!empty($this->field['type']['placeholder'])) {
             $data['placeholder'] = $this->field['type']['placeholder'];
         }
         $output = $this->renderField($data);
     }
     return $output;
 }
Esempio n. 16
0
 public function add($param = "")
 {
     global $formMaj;
     global $datas_lang;
     global $smarty;
     global $thisSite;
     parent::add();
     $smarty->assign('this', $this);
     $rangeLg = array();
     foreach ($this->list_lang as $clg => $extlg) {
         $value = $this->getValue($clg);
         $values = explode(",", $value);
         if (count($values) == 2) {
             $range = 1;
         } else {
             if (count($values) == 1) {
                 $range = 0;
             } else {
                 return false;
             }
         }
         $rangeLg[$clg] = $range;
     }
     $smarty->assign('rangeLg', $rangeLg);
     $data = $smarty->fetch($this->pathTemplate . 'inc/fields/class.slider.tpl');
     $this->smartAssign($this->field, $data);
     return $data;
 }
 /**
  * Create the necessary custom field
  *
  * @return int The id of the created field
  */
 private function create_custom_field()
 {
     global $CFG;
     require_once $CFG->dirroot . '/local/eliscore/lib/data/customfield.class.php';
     require_once $CFG->dirroot . '/local/elisprogram/accesslib.php';
     // Field category.
     $fieldcategory = new field_category(array('name' => 'testcategoryname'));
     $fieldcategory->save();
     // Custom field.
     $field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname', 'name' => 'testfieldname', 'datatype' => 'bool'));
     $field->save();
     // Field context level assocation.
     $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER));
     $fieldcontextlevel->save();
     return $field->id;
 }
Esempio n. 18
0
 public function validate($value)
 {
     if (is_array($value) && isset($value['path']) && isset($value['dataURL'])) {
         $fileName = str_replace('..', '', $value['path']);
         /* secure relative path */
         /* find an unused name */
         $fileInfo = pathinfo($fileName);
         $base = $fileInfo['filename'];
         $ext = $fileInfo['extension'];
         $dir = empty($fileInfo['dirname']) ? '' : $fileInfo['dirname'] . '/';
         /*  $fileInfo['dirname'] in case that filename contains a part of dirname */
         $path = PROFILE_PATH . $this->entity->getModule() . '/' . $this->path . '/';
         $nbn = 0;
         while (is_file($path . $fileName)) {
             $fileName = $dir . $base . '_' . $nbn . '.' . $ext;
             $nbn++;
         }
         if (!is_dir($path . $dir)) {
             \tools::createDirectory($path . $fileInfo['dirname'] . '/');
         }
         /* decode dataURL */
         $cut = explode(',', $value['dataURL']);
         $dataURL = $cut[1];
         $dataURL = base64_decode(str_replace(' ', '+', $dataURL));
         /* save and check image */
         if (file_put_contents($path . $fileName, $dataURL)) {
             return $fileName;
         } else {
             return FALSE;
             /* can't write image */
         }
     } else {
         return parent::validate($value);
     }
 }
Esempio n. 19
0
 /**
  * Validate field
  * @param string $value
  * @return string
  */
 public function validate($value)
 {
     if (!empty($value) && strstr($value, '://') === FALSE) {
         $value = 'http://' . $value;
     }
     return parent::validate($value);
 }
 public function render()
 {
     $output = '';
     if (!empty($this->field)) {
         $data = array();
         $data += parent::setGeneralData();
         $data['text_select'] = oc::registry()->load->language->get('text_select');
         $data['multiple'] = $this->field['type']['multiple'];
         if ($data['multiple']) {
             $data['class'] .= ($data['class'] ? ' ' : '') . 'multiple';
         }
         $data['selected'] = array();
         if ($data['value']) {
             if (is_array($data['value'])) {
                 $data['selected'] = $data['value'];
             } else {
                 $data['selected'][] = $data['value'];
             }
         } elseif (!empty($this->field['type']['selected'])) {
             $data['selected'][] = $this->field['type']['selected'];
         }
         if (!empty($this->field['type']['option']) && $this->field['type']['option']) {
             $data['option'] = $this->field['type']['option'];
         } else {
             return $output;
         }
         $output = $this->renderField($data);
     }
     return $output;
 }
Esempio n. 21
0
 /**
  * @param $database
  * @return self
  * @throws \Exception
  */
 public static function create($database)
 {
     $file = core_dir . '/db/structures/' . $database . '.json';
     if (file_exists($file)) {
         $file = file_get_contents($file);
         $file = preg_replace_callback('#//@include \'(.*?)\'#', function ($matches) {
             $sub_file = core_dir . '/db/structures/' . $matches[1];
             return file_get_contents($sub_file);
         }, $file);
         $json = json_decode($file);
         if (is_object($json)) {
             if (!isset($json->fieldset)) {
                 $json->fieldset = [];
             }
             foreach ($json->fieldset as &$field) {
                 $field = field::create($field);
             }
             $module = new self();
             foreach ($json as $key => $value) {
                 $module->{$key} = $value;
             }
             return $module;
         } else {
             throw new \Exception('Stub is not valid JSON: ' . $database);
         }
     } else {
         throw new \Exception('Could not find table stub: ' . $database);
     }
 }
Esempio n. 22
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2012 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    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
function archive_install()
{
    global $CFG;
    require_once $CFG->dirroot . '/curriculum/config.php';
    require_once CURMAN_DIRLOCATION . '/lib/customfield.class.php';
    // setup archive field
    $field = new field();
    $field->shortname = '_elis_curriculum_archive';
    $field->name = get_string('archive_field_name', 'crlm_archive');
    $field->datatype = 'bool';
    $category = new field_category();
    $category->name = get_string('archive_category_name', 'crlm_archive');
    $field = field::ensure_field_exists_for_context_level($field, 'curriculum', $category);
    // make sure 'manual' is an owner
    if (!isset($field->owners['manual'])) {
        $owner = new field_owner();
        $owner->fieldid = $field->id;
        $owner->plugin = 'manual';
        $owner->param_view_capability = '';
        $owner->param_edit_capability = '';
        $owner->param_control = 'menu';
        $owner->param_options_source = '';
        $owner->add();
    }
    $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_archive/archive_curriculum');
    field_owner::ensure_field_owner_exists($field, 'manual', $owner_options);
    return true;
}
Esempio n. 23
0
 function __construct($name, $caption, $time, $begin_year = 1970, $end_year = 2020, $parameters = "", $help = "", $help_url = "")
 {
     // Вызываем конструктор базового класса field для
     // инициализации его данных
     parent::__construct($name, "date", $caption, $is_required, $value, $parameters, $help, $help_url);
     if (empty($time)) {
         $this->time = time();
     } else {
         if (is_array($time)) {
             $this->time = mktime($time['hour'], $time['minute'], 0, $time['month'], $time['day'], $time['year']);
         } else {
             $this->time = $time;
         }
     }
     if (!empty($begin_year)) {
         $this->begin_year = $begin_year;
     } else {
         $this->begin_year = 1970;
     }
     if (!empty($end_year)) {
         $this->end_year = $end_year;
     } else {
         $this->end_year = 2020;
     }
 }
Esempio n. 24
0
 /**
  * Test sync-ing an ELIS User Profile field to a DELETED Moodle User Profile field
  */
 public function test_syncpmuserfieldtodeletedmoodleprofilefield()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/definelib.php';
     $this->load_csv_data();
     // Set PM Custom User field(s) to Sync to Moodle.
     $ctxlvl = CONTEXT_ELIS_USER;
     $fields = field::get_for_context_level($ctxlvl);
     foreach ($fields as $field) {
         $fieldobj = new field($field);
         if (!isset($fieldobj->owners['moodle_profile'])) {
             $fieldobj->owners['moodle_profile'] = new stdClass();
         }
         $owner = new field_owner($fieldobj->owners['moodle_profile']);
         $owner->exclude = pm_moodle_profile::sync_from_moodle;
         $owner->save();
         $fieldobj->save();
     }
     // Read a record.
     $src = new user(103, null, array(), false, array());
     $src->reset_custom_field_list();
     // Modify the data.
     $src->firstname = 'Testuser';
     $src->lastname = 'One';
     $src->field_sometext = 'boo';
     $src->field_sometextfrompm = 'bla';
     $src->save();
     // Delete some custom Moodle Profile field(s) to cause old error (pre ELIS-4499).
     $fields = field::get_for_context_level($ctxlvl);
     foreach ($fields as $field) {
         $fieldobj = new field($field);
         if ($moodlefield = $DB->get_record('user_info_field', array('shortname' => $fieldobj->shortname))) {
             profile_delete_field($moodlefield->id);
         }
     }
     // Run the library sync - throws errors not exceptions :(.
     $CFG->mnet_localhost_id = 1;
     // ???
     $mu = cm_get_moodleuser(103);
     try {
         $result = pm_moodle_user_to_pm($mu);
         $this->assertTrue($result);
     } catch (Exception $ex) {
         $this->assertTrue(false, $ex->message);
     }
 }
Esempio n. 25
0
 protected function renderField($data)
 {
     $tpl = tpl::find(field::prepareFieldId($this->field['field_id']), $this->form_info);
     if (!$tpl) {
         $tpl = tpl::find('field-' . $this->field['type']['type'], $this->form_info);
     }
     return tpl::getInstance($tpl, $data)->render();
 }
 /**
  * Set up necessary data
  *
  * @param int $numfields The number of custom fields used in auto-association
  */
 private function init_required_data($numfields = 1)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elis::file('eliscore/fields/moodleprofile/custom_fields.php');
     require_once elis::lib('data/customfield.class.php');
     require_once elispm::file('accesslib.php');
     require_once elispm::lib('data/userset.class.php');
     require_once $CFG->dirroot . '/user/profile/definelib.php';
     require_once $CFG->dirroot . '/user/profile/field/checkbox/define.class.php';
     // Set up the category only once.
     $fieldcategory = new field_category(array('name' => 'testcategoryname'));
     $fieldcategory->save();
     // Ste up the target userset only once.
     $userset = new userset(array('name' => 'testusersetname'));
     $userset->save();
     for ($i = 1; $i <= $numfields; $i++) {
         // Custom field.
         $field = new field(array('categoryid' => $fieldcategory->id, 'shortname' => 'testfieldshortname' . $i, 'name' => 'testfieldname' . $i, 'datatype' => 'bool'));
         $field->save();
         // Ensure manual field owner exists for syncing.
         field_owner::ensure_field_owner_exists($field, 'manual');
         $ownerid = $DB->get_field(field_owner::TABLE, 'id', array('fieldid' => $field->id, 'plugin' => 'manual'));
         $owner = new field_owner($ownerid);
         $owner->param_control = 'checkbox';
         $owner->save();
         // Ensure moodle profile field owner exists.
         field_owner::ensure_field_owner_exists($field, 'moodle_profile');
         $DB->execute("UPDATE {" . field_owner::TABLE . "} SET exclude = ?", array(pm_moodle_profile::sync_to_moodle));
         // Field context level assocation.
         $fieldcontextlevel = new field_contextlevel(array('fieldid' => $field->id, 'contextlevel' => CONTEXT_ELIS_USER));
         $fieldcontextlevel->save();
         // The associated Moodle user profile field.
         $profiledefinecheckbox = new profile_define_checkbox();
         $data = new stdClass();
         $data->datatype = 'checkbox';
         $data->categoryid = 99999;
         $data->shortname = 'testfieldshortname' . $i;
         $data->name = 'testfieldname' . $i;
         $profiledefinecheckbox->define_save($data);
         $mfield = $DB->get_record('user_info_field', array('shortname' => 'testfieldshortname' . $i));
         // The "cluster-profile" association.
         $usersetprofile = new userset_profile(array('clusterid' => $userset->id, 'fieldid' => $mfield->id, 'value' => 1));
         $usersetprofile->save();
     }
 }
Esempio n. 27
0
 /**
  * Test successful user creation.
  */
 public function test_success()
 {
     global $DB;
     $this->give_permissions(array('local/elisprogram:class_edit'));
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_CLASS;
     $fieldctx->save();
     $course = new course();
     $course->idnumber = 'testcourse1';
     $course->name = 'Test Course 1';
     $course->syllabus = 'Test';
     $course->save();
     $class = new pmclass(array('idnumber' => 'testclass', 'startdate' => 1357016400, 'enddate' => 1359694800, 'courseid' => $course->id, 'assignment' => $course->idnumber, 'field_testfield' => 'Test Field'));
     $class->save();
     $classupdates = array('idnumber' => 'testclass', 'startdate' => 'Feb/04/2013', 'enddate' => 'Mar/01/2013', 'field_testfield' => 'Test Field 2');
     $response = local_datahub_elis_class_update::class_update($classupdates);
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     $this->assertEquals(get_string('ws_class_update_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_class_update_success_msg', 'local_datahub'), $response['message']);
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     // Get class.
     $expectedclass = array('idnumber' => $class->idnumber, 'startdate' => rlip_timestamp(0, 0, 0, 2, 4, 2013), 'enddate' => rlip_timestamp(0, 0, 0, 3, 1, 2013), 'courseid' => $course->id, 'field_testfield' => 'Test Field 2');
     $createdclass = new pmclass($response['record']['id']);
     $createdclass->load();
     $createdclass = $createdclass->to_array();
     foreach ($expectedclass as $param => $val) {
         $this->assertArrayHasKey($param, $createdclass);
         $this->assertEquals($val, $createdclass[$param]);
     }
 }
Esempio n. 28
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2012 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    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
function xmldb_crlm_cluster_classification_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2010080502) {
        /// Define table crlm_cluster_classification to be created
        $table = new XMLDBTable('crlm_cluster_classification');
        /// Adding fields to table crlm_cluster_classification
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
        $table->addFieldInfo('shortname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
        $table->addFieldInfo('params', XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null);
        /// Adding keys to table crlm_cluster_classification
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('shortname_idx', XMLDB_KEY_UNIQUE, array('shortname'));
        /// Launch create table for crlm_cluster_classification
        $result = $result && create_table($table);
    }
    if ($result && $oldversion < 2010080503) {
        require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
        $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD));
        // make sure we're set as owner
        if (!isset($field->owners['cluster_classification'])) {
            $owner = new field_owner();
            $owner->fieldid = $field->id;
            $owner->plugin = 'cluster_classification';
            $owner->add();
        }
        // make sure we have a default value set
        if (!field_data::get_for_context_and_field(NULL, $field)) {
            field_data::set_for_context_and_field(NULL, $field, 'regular');
        }
        $default = new clusterclassification();
        $default->shortname = 'regular';
        $default->name = get_string('cluster', 'block_curr_admin');
        $default->param_autoenrol_curricula = 1;
        $default->param_autoenrol_tracks = 1;
        $default->add();
    }
    // make sure 'manual' is an owner
    if ($result && $oldversion < 2010080504) {
        require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
        $field = new field(field::get_for_context_level_with_name('cluster', CLUSTER_CLASSIFICATION_FIELD));
        $owner = new field_owner();
        $owner->fieldid = $field->id;
        $owner->plugin = 'manual';
        $owner->param_view_capability = '';
        $owner->param_edit_capability = 'moodle/user:update';
        $owner->param_control = 'menu';
        $owner->param_options_source = 'cluster_classifications';
        $owner->add();
    }
    return $result;
}
Esempio n. 29
0
 /**
  * Test successful user edit.
  * @dataProvider dataprovider_success
  * @param array $update Incoming update data.
  */
 public function test_success($update)
 {
     global $DB;
     $this->give_permissions(array('local/elisprogram:user_edit'));
     // Create custom field.
     $fieldcat = new field_category();
     $fieldcat->name = 'Test';
     $fieldcat->save();
     $field = new field();
     $field->categoryid = $fieldcat->id;
     $field->shortname = 'testfield';
     $field->name = 'Test Field';
     $field->datatype = 'text';
     $field->save();
     $fieldctx = new field_contextlevel();
     $fieldctx->fieldid = $field->id;
     $fieldctx->contextlevel = CONTEXT_ELIS_USER;
     $fieldctx->save();
     $user = array('idnumber' => 'testuser', 'username' => 'testuser', 'firstname' => 'testuser', 'lastname' => 'testuser', 'email' => '*****@*****.**', 'country' => 'CA', 'field_testfield' => 'Test Field');
     $user = new user($user);
     $user->save();
     $expecteduser = (array) $DB->get_record(user::TABLE, array('id' => $user->id));
     $expecteduser = array_merge($expecteduser, $update);
     $response = local_datahub_elis_user_update::user_update($update);
     // Verify general response structure.
     $this->assertNotEmpty($response);
     $this->assertInternalType('array', $response);
     $this->assertArrayHasKey('messagecode', $response);
     $this->assertArrayHasKey('message', $response);
     $this->assertArrayHasKey('record', $response);
     // Verify response message/code.
     $this->assertEquals(get_string('ws_user_update_success_code', 'local_datahub'), $response['messagecode']);
     $this->assertEquals(get_string('ws_user_update_success_msg', 'local_datahub'), $response['message']);
     // Verify returned user information.
     $this->assertInternalType('array', $response['record']);
     $this->assertArrayHasKey('id', $response['record']);
     $actualuser = $DB->get_record(user::TABLE, array('id' => $response['record']['id']));
     $this->assertNotEmpty($actualuser);
     $actualuser = (array) $actualuser;
     // Unset timemodified as it's unreliable to test.
     unset($actualuser['timemodified']);
     foreach ($actualuser as $param => $val) {
         $this->assertEquals($expecteduser[$param], $val);
     }
 }
Esempio n. 30
0
 function __construct($name, $caption, $is_required = false, $value = "", $maxlength = 255, $size = 41, $parameters = "", $help = "", $help_url = "")
 {
     // Вызываем конструктор базового класса field для
     // инициализации его данных
     parent::__construct($name, "text", $caption, $is_required, $value, $parameters, $help, $help_url);
     // Инициализируем члены класса
     $this->size = $size;
     $this->maxlength = $maxlength;
 }