/** * addMobilePhoneNumberField (adds a mobile phone number field if it is not * already created) * @return void */ private function addMobilePhoneNumberField() { $extraField = new ExtraField('user'); $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable('mobile_phone_number'); if (empty($extraFieldInfo)) { $extraField->save(array('field_type' => 1, 'variable' => 'mobile_phone_number', 'display_text' => $this->get_lang('mobile_phone_number'), 'default_value' => null, 'field_order' => 2, 'visible' => 1, 'changeable' => 1, 'filter' => null)); } }
/** * Install the plugin */ public function install() { $this->installHook(); $result = Database::select('variable', Database::get_main_table(TABLE_EXTRA_FIELD), array('where' => array('variable = ?' => array('skype')))); if (empty($result)) { $extraField = new ExtraField('user'); $extraField->save(array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'variable' => 'skype', 'display_text' => 'Skype', 'visible' => 1, 'changeable' => 1)); } }
/** * addAreaField() (adds an area field if it is not already created) * @return void */ private function addAreaField() { $extraField = new ExtraField('user'); $extraFieldHandler = $extraField->get_handler_field_info_by_field_variable('area'); $areaExists = $extraFieldHandler !== false; if (!$areaExists) { $extraField = new ExtraField('user'); $extraField->save(array('field_type' => 1, 'variable' => 'area', 'display_text' => get_plugin_lang('Area', 'AdvancedSubscriptionPlugin'), 'default_value' => null, 'field_order' => null, 'visible' => 1, 'changeable' => 1, 'filter' => null)); } }
/** * Prepares extra fields before the import */ private function prepareImport() { // Create user extra field: extra_external_user_id UserManager::create_extra_field($this->extraFieldIdNameList['user'], 1, 'External user id', null); // Create course extra field: extra_external_course_id CourseManager::create_course_extra_field($this->extraFieldIdNameList['course'], 1, 'External course id'); // Create session extra field extra_external_session_id SessionManager::create_session_extra_field($this->extraFieldIdNameList['session'], 1, 'External session id'); // Create calendar_event extra field extra_external_session_id $extraField = new ExtraField('calendar_event'); $extraField->save(array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_variable' => $this->extraFieldIdNameList['calendar_event'], 'field_display_text' => 'External calendar event id')); }
</script>'; // The header. Display::display_header($tool_name); // Action handling: Add switch ($action) { case 'add': if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { api_not_allowed(); } $url = api_get_self() . '?type=' . $obj->type . '&action=' . Security::remove_XSS($_GET['action']); $form = $obj->return_form($url, 'add'); // The validation or display if ($form->validate()) { //if ($check) { $values = $form->exportValues(); $res = $obj->save($values); if ($res) { Display::display_confirmation_message(get_lang('ItemAdded')); } //} $obj->display(); } else { echo '<div class="actions">'; echo '<a href="' . api_get_self() . '?type=' . $obj->type . '">' . Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; $form->addElement('hidden', 'sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); } break; case 'edit':
$schedule->save(array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'variable' => 'schedule', 'display_text' => get_lang('Schedule'), 'visible' => 1, 'changeable' => 1)); $allowVisitors = new ExtraField('session'); $allowVisitors->save(array('field_type' => ExtraField::FIELD_TYPE_CHECKBOX, 'variable' => 'allow_visitors', 'display_text' => get_lang('AllowVisitors'), 'visible' => 1, 'changeable' => 1)); $modeOptions = array(get_lang('Online'), get_lang('Presencial'), get_lang('B-Learning')); $mode = new ExtraField('session'); $mode->save(array('field_type' => ExtraField::FIELD_TYPE_SELECT, 'variable' => 'mode', 'display_text' => get_lang('Mode'), 'visible' => 1, 'changeable' => 1, 'field_options' => implode('; ', $modeOptions))); $isInductionSession = new ExtraField('session'); $isInductionSession->save(array('field_type' => ExtraField::FIELD_TYPE_CHECKBOX, 'variable' => 'is_induction_session', 'display_text' => get_lang('IsInductionSession'), 'visible' => 1, 'changeable' => 1)); $isOpenSession = new ExtraField('session'); $isOpenSession->save(array('field_type' => ExtraField::FIELD_TYPE_CHECKBOX, 'variable' => 'is_open_session', 'display_text' => get_lang('IsOpenSession'), 'visible' => 1, 'changeable' => 1)); $duration = new ExtraField('session'); $duration->save(array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'variable' => 'human_text_duration', 'display_text' => get_lang('DurationInWords'), 'visible' => 1, 'changeable' => 1)); $showStatusOptions = array(get_lang('Open'), get_lang('InProcess'), get_lang('Closed')); $showStatus = new ExtraField('session'); $showStatus->save(array('field_type' => ExtraField::FIELD_TYPE_SELECT, 'variable' => 'show_status', 'display_text' => get_lang('ShowStatus'), 'visible' => 1, 'changeable' => 1, 'field_options' => implode('; ', $showStatusOptions))); $publicationStartDate = new ExtraField('session'); $publicationStartDate->save(array('field_type' => ExtraField::FIELD_TYPE_DATE, 'variable' => 'publication_start_date', 'display_text' => get_lang('PublicationStartDate'), 'visible' => 1, 'changeable' => 1)); $publicationEndDate = new ExtraField('session'); $publicationEndDate->save(array('field_type' => ExtraField::FIELD_TYPE_DATE, 'variable' => 'publication_end_date', 'display_text' => get_lang('PublicationEndDate'), 'visible' => 1, 'changeable' => 1)); $banner = new ExtraField('session'); $banner->save(array('field_type' => ExtraField::FIELD_TYPE_FILE_IMAGE, 'variable' => 'banner', 'display_text' => get_lang('SessionBanner'), 'visible' => 1, 'changeable' => 1)); $brochure = new ExtraField('session'); $brochure->save(array('field_type' => ExtraField::FIELD_TYPE_FILE, 'variable' => 'brochure', 'display_text' => get_lang('Brochure'), 'visible' => 1, 'changeable' => 1)); $targetOptions = array(get_lang('Minedu'), get_lang('Regiones')); $target = new ExtraField('session'); $target->save(array('field_type' => ExtraField::FIELD_TYPE_SELECT, 'variable' => 'target', 'display_text' => get_lang('TargetAudience'), 'visible' => 1, 'changeable' => 1, 'field_options' => implode('; ', $targetOptions))); $shortDescription = new ExtraField('session'); $shortDescription->save(array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'variable' => 'short_description', 'display_text' => get_lang('ShortDescription'), 'visible' => 1, 'changeable' => 1)); $id = new ExtraField('session'); $id->save(array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'variable' => 'code', 'display_text' => get_lang('Code'), 'visible' => 1, 'changeable' => 1));
/** * Creates a new extra field * @param string $variable Field's internal variable name * @param int $fieldType Field's type * @param string $displayText Field's language var name * @param string $default Field's default value * @return int */ public static function create_extra_field($variable, $fieldType, $displayText, $default) { $extraField = new ExtraField('user'); $params = ['variable' => $variable, 'field_type' => $fieldType, 'display_text' => $displayText, 'default_value' => $default]; return $extraField->save($params); }
/** * Creates a new extra field for a given session * @param string $variable Field's internal variable name * @param int $fieldType Field's type * @param string $displayText Field's language var name * @return int new extra field id */ public static function create_session_extra_field($variable, $fieldType, $displayText) { $extraField = new ExtraField('session'); $params = ['variable' => $variable, 'field_type' => $fieldType, 'display_text' => $displayText]; return $extraField->save($params); }
/** * Helper function to create extra fields in the Chamilo database. If the * extra field aleady exists, then just return the ID of this field. If * options are provided ('options' sub-array), then options are inserted in * the corresponding x_field_options table. * @param Array An array containing an 'extra_fields' entry with details about the required extra fields * @return void */ private function _create_extra_fields(&$table) { $extra_fields = array(); error_log('Inserting (if not exist) extra fields for : ' . $table['dest_table'] . " \n"); foreach ($table['extra_fields'] as $extra_field) { //error_log('Preparing for insertion of extra field ' . $extra_field['field_display_text'] . "\n"); $options = isset($extra_field['options']) ? $extra_field['options'] : null; unset($extra_field['options']); $extra_field_obj = new ExtraField($table['dest_table']); $extra_field_id = $extra_field_obj->save($extra_field); $selected_fields = self::prepare_field_match($options); //Adding options. This is only processed if the corresponding // extra_field has an 'options' sub-aray defined if (!empty($options)) { $extra_field_option_obj = new ExtraFieldOption($table['dest_table']); // use the query defined in the 'query' item as returned in a select by prepare_field_match above $this->select_all($options['orig_table'], $selected_fields); $num_rows = $this->num_rows(); if ($num_rows) { $data_to_insert = array(); $data_to_insert['field_id'] = $extra_field_id; while ($row = $this->fetch_array()) { $data = self::execute_field_match($options, $row); $data_to_insert = array_merge($data_to_insert, $data); $extra_field_option_obj->save_one_item($data_to_insert, false, false); //error_log(print_r($extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']], 1)); $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']]['options'][] = $data_to_insert; $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']]['field_type'] = $extra_field['field_type']; } //$extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']]['selected_option'] = //error_log('$data: ' . print_r($data_to_insert, 1)); } } else { // if there are no pre-defined options, then just return the field_id for this variable $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']] = $extra_field_id; } } return $extra_fields; }
/** * Create the drupal_user_id when it not exists */ private function createExtraField() { $extraFieldExists = $this->getExtraFieldInfo() !== false; if (!$extraFieldExists) { $extraField = new ExtraField('user'); $extraField->save(['field_type' => ExtraField::FIELD_TYPE_INTEGER, 'variable' => self::EXTRAFIELD_VARIABLE_NAME, 'display_text' => get_plugin_lang('DrupalUserId', 'CreateDrupalUser'), 'default_value' => null, 'field_order' => null, 'visible' => false, 'changeable' => false, 'filter' => null]); } }
<?php //Adding extra fields $extra_field = new ExtraField('user'); $params = array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_variable' => 'exam_room', 'field_display_text' => 'Aula', 'field_visible' => false); $extra_field->save($params); $params = array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_variable' => 'exam_schedule', 'field_display_text' => 'Horario', 'field_visible' => false); $extra_field->save($params); $params = array('field_type' => ExtraField::FIELD_TYPE_TEXT, 'field_variable' => 'exam_password', 'field_display_text' => 'Password', 'field_visible' => false); $extra_field->save($params);
/** * Create the user extra field */ public static function init() { $extraField = new ExtraField('user'); $fieldInfo = $extraField->get_handler_field_info_by_field_variable(self::EXTRA_FIELD_GCM_REGISTRATION); if (empty($fieldInfo)) { $extraField->save(['variable' => self::EXTRA_FIELD_GCM_REGISTRATION, 'field_type' => ExtraField::FIELD_TYPE_TEXT, 'display_text' => self::EXTRA_FIELD_GCM_REGISTRATION]); } }