diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index b6d10eeac8..0012d941ef 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -1715,21 +1715,6 @@ class ExtraField extends Model $hideGeoLocalizationDetails ); - /*$form->addElement( - 'text', - 'extra_'.$field_details['variable'], - $field_details['display_text'], - ['id' => 'extra_'.$field_details['variable']] - ); - $form->addHidden( - 'extra_'.$field_details['variable'].'_coordinates', - '', - ['id' => 'extra_'.$field_details['variable'].'_coordinates'] - ); - - $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); - $form->applyFilter('extra_'.$field_details['variable'], 'trim');*/ - if ($freezeElement) { $form->freeze('extra_'.$field_details['variable']); } @@ -1759,1842 +1744,1793 @@ class ExtraField extends Model return $return; } + + /** - * @param \FormValidator $form - * @param int $defaultValueId - * @param bool $freezeElement + * @param array $options + * + * @return array */ - private function addSelectElement(FormValidator $form, array $fieldDetails, $defaultValueId, $freezeElement = false) + public static function extra_field_double_select_convert_array_to_ordered_array($options) { - $get_lang_variables = false; - if (in_array( - $fieldDetails['variable'], - ['mail_notify_message', 'mail_notify_invitation', 'mail_notify_group_message'] - )) { - $get_lang_variables = true; - } - - // Get extra field workflow - $addOptions = []; - $optionsExists = false; - $options = []; - - $optionList = []; - if (!empty($fieldDetails['options'])) { - foreach ($fieldDetails['options'] as $option_details) { - $optionList[$option_details['id']] = $option_details; - if ($get_lang_variables) { - $options[$option_details['option_value']] = $option_details['display_text']; + $optionsParsed = []; + if (!empty($options)) { + foreach ($options as $option) { + if (0 == $option['option_value']) { + $optionsParsed[$option['id']][] = $option; } else { - if ($optionsExists) { - // Adding always the default value - if ($option_details['id'] == $defaultValueId) { - $options[$option_details['option_value']] = $option_details['display_text']; - } else { - if (isset($addOptions) && !empty($addOptions)) { - // Parsing filters - if (in_array($option_details['id'], $addOptions)) { - $options[$option_details['option_value']] = $option_details['display_text']; - } - } - } - } else { - // Normal behaviour - $options[$option_details['option_value']] = $option_details['display_text']; - } - } - } - - // Setting priority message - if (isset($optionList[$defaultValueId]) - && isset($optionList[$defaultValueId]['priority']) - ) { - if (!empty($optionList[$defaultValueId]['priority'])) { - $priorityId = $optionList[$defaultValueId]['priority']; - $option = new ExtraFieldOption($this->type); - $messageType = $option->getPriorityMessageType($priorityId); - $form->addElement( - 'label', - null, - Display::return_message( - $optionList[$defaultValueId]['priority_message'], - $messageType - ) - ); + $optionsParsed[$option['option_value']][] = $option; } } } - /** @var \HTML_QuickForm_select $slct */ - $slct = $form->addElement( - 'select', - 'extra_'.$fieldDetails['variable'], - $fieldDetails['display_text'], - [], - ['id' => 'extra_'.$fieldDetails['variable']] - ); - - if (empty($defaultValueId)) { - $slct->addOption(get_lang('SelectAnOption'), ''); - } + return $optionsParsed; + } - foreach ($options as $value => $text) { - if (empty($value)) { - $slct->addOption($text, $value); - continue; - } - $valueParts = explode('#', $text); - $dataValue = count($valueParts) > 1 ? array_shift($valueParts) : ''; + /** + * @return array + */ + public static function tripleSelectConvertArrayToOrderedArray(array $options) + { + $level1 = self::getOptionsFromTripleSelect($options, 0); + $level2 = []; + $level3 = []; - $slct->addOption(implode('', $valueParts), $value, ['data-value' => $dataValue]); + foreach ($level1 as $item1) { + $level2 += self::getOptionsFromTripleSelect($options, $item1['id']); } - /* Enable this when field_loggeable is introduced as a table field (2.0) - if ($optionsExists && $field_details['field_loggeable'] && !empty($defaultValueId)) { - - $form->addElement( - 'textarea', - 'extra_' . $field_details['variable'] . '_comment', - $field_details['display_text'] . ' ' . get_lang('Comment') - ); - - $extraFieldValue = new ExtraFieldValue($this->type); - $repo = $app['orm.em']->getRepository($extraFieldValue->entityName); - $repoLog = $app['orm.em']->getRepository('Gedmo\Loggable\Entity\LogEntry'); - $newEntity = $repo->findOneBy( - array( - $this->handlerEntityId => $itemId, - 'fieldId' => $field_details['id'] - ) - ); - // @todo move this in a function inside the class - if ($newEntity) { - $logs = $repoLog->getLogEntries($newEntity); - if (!empty($logs)) { - $html = '' . get_lang('LatestChanges') . '

'; - - $table = new HTML_Table(array('class' => 'data_table')); - $table->setHeaderContents(0, 0, get_lang('Value')); - $table->setHeaderContents(0, 1, get_lang('Comment')); - $table->setHeaderContents(0, 2, get_lang('ModifyDate')); - $table->setHeaderContents(0, 3, get_lang('Username')); - $row = 1; - foreach ($logs as $log) { - $column = 0; - $data = $log->getData(); - $fieldValue = isset($data['fieldValue']) ? $data['fieldValue'] : null; - $comment = isset($data['comment']) ? $data['comment'] : null; - - $table->setCellContents($row, $column, $fieldValue); - $column++; - $table->setCellContents($row, $column, $comment); - $column++; - $table->setCellContents($row, $column, api_get_local_time($log->getLoggedAt()->format('Y-m-d H:i:s'))); - $column++; - $table->setCellContents($row, $column, $log->getUsername()); - $row++; - } - $form->addElement('label', null, $html.$table->toHtml()); - } - } + foreach ($level2 as $item2) { + $level3 += self::getOptionsFromTripleSelect($options, $item2['id']); } - */ - if ($freezeElement) { - $form->freeze('extra_'.$fieldDetails['variable']); - } + return ['level1' => $level1, 'level2' => $level2, 'level3' => $level3]; } /** - * @param \FormValidator $form - * @param array $fieldDetails - * @param array $extraData - * @param bool $freezeElement + * @param string $type * - * @return string JavaScript code + * @return array */ - private function addDoubleSelectElement(FormValidator $form, $fieldDetails, $extraData, $freezeElement = false) + public function get_all_extra_field_by_type($type) { - $firstSelectId = 'first_extra_'.$fieldDetails['variable']; - $secondSelectId = 'second_extra_'.$fieldDetails['variable']; - - $jqueryReadyContent = " - $('#$firstSelectId').on('change', function() { - var id = $(this).val(); - - if (!id) { - $('#$secondSelectId').empty().selectpicker('refresh'); - - return; - } - - $.getJSON(_p.web_ajax + 'extra_field.ajax.php?1=1&a=get_second_select_options', { - 'type': '{$this->type}', - 'field_id': {$fieldDetails['id']}, - 'option_value_id': id - }) - .done(function(data) { - $('#$secondSelectId').empty(); - $.each(data, function(index, value) { - $('#second_extra_{$fieldDetails['variable']}').append( - $('