| Conditions | 132 |
| Paths | 2 |
| Total Lines | 859 |
| Code Lines | 504 |
| Lines | 233 |
| Ratio | 27.12 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 712 | public function set_extra_fields_in_form( |
||
| 713 | $form, |
||
| 714 | $extraData, |
||
| 715 | $admin_permissions = false, |
||
| 716 | $extra = array(), |
||
| 717 | $itemId = null, |
||
| 718 | $exclude = [] |
||
| 719 | ) { |
||
| 720 | $type = $this->type; |
||
| 721 | |||
| 722 | $jquery_ready_content = null; |
||
| 723 | |||
| 724 | if (!empty($extra)) { |
||
| 725 | foreach ($extra as $field_details) { |
||
| 726 | |||
| 727 | // Getting default value id if is set |
||
| 728 | $defaultValueId = null; |
||
| 729 | if (isset($field_details['options']) && !empty($field_details['options'])) { |
||
| 730 | $valueToFind = null; |
||
| 731 | if (isset($field_details['field_default_value'])) { |
||
| 732 | $valueToFind = $field_details['field_default_value']; |
||
| 733 | } |
||
| 734 | // If a value is found we override the default value |
||
| 735 | if (isset($extraData['extra_'.$field_details['variable']])) { |
||
| 736 | $valueToFind = $extraData['extra_'.$field_details['variable']]; |
||
| 737 | } |
||
| 738 | |||
| 739 | foreach ($field_details['options'] as $option) { |
||
| 740 | if ($option['option_value'] == $valueToFind) { |
||
| 741 | $defaultValueId = $option['id']; |
||
| 742 | } |
||
| 743 | } |
||
| 744 | } |
||
| 745 | |||
| 746 | if (!$admin_permissions) { |
||
| 747 | if ($field_details['visible'] == 0) { |
||
| 748 | continue; |
||
| 749 | } |
||
| 750 | |||
| 751 | if (in_array($field_details['variable'], $exclude)) { |
||
| 752 | continue; |
||
| 753 | } |
||
| 754 | } |
||
| 755 | |||
| 756 | switch ($field_details['field_type']) { |
||
| 757 | case ExtraField::FIELD_TYPE_TEXT: |
||
| 758 | $form->addElement( |
||
| 759 | 'text', |
||
| 760 | 'extra_'.$field_details['variable'], |
||
| 761 | $field_details['display_text'], |
||
| 762 | array() |
||
| 763 | ); |
||
| 764 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 765 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 766 | if (!$admin_permissions) { |
||
| 767 | if ($field_details['visible'] == 0) { |
||
| 768 | $form->freeze( |
||
| 769 | 'extra_'.$field_details['variable'] |
||
| 770 | ); |
||
| 771 | } |
||
| 772 | } |
||
| 773 | break; |
||
| 774 | View Code Duplication | case ExtraField::FIELD_TYPE_TEXTAREA: |
|
| 775 | $form->addHtmlEditor( |
||
| 776 | 'extra_'.$field_details['variable'], |
||
| 777 | $field_details['display_text'], |
||
| 778 | false, |
||
| 779 | false, |
||
| 780 | array('ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130') |
||
| 781 | ); |
||
| 782 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 783 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 784 | if (!$admin_permissions) { |
||
| 785 | if ($field_details['visible'] == 0) { |
||
| 786 | $form->freeze( |
||
| 787 | 'extra_'.$field_details['variable'] |
||
| 788 | ); |
||
| 789 | } |
||
| 790 | } |
||
| 791 | break; |
||
| 792 | case ExtraField::FIELD_TYPE_RADIO: |
||
| 793 | $group = array(); |
||
| 794 | if (isset($field_details['options']) && !empty($field_details['options'])) { |
||
| 795 | View Code Duplication | foreach ($field_details['options'] as $option_details) { |
|
| 796 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 797 | $group[] = $form->createElement( |
||
| 798 | 'radio', |
||
| 799 | 'extra_'.$field_details['variable'], |
||
| 800 | $option_details['option_value'], |
||
| 801 | $option_details['display_text'].'<br />', |
||
| 802 | $option_details['option_value'] |
||
| 803 | ); |
||
| 804 | } |
||
| 805 | } |
||
| 806 | $form->addGroup( |
||
| 807 | $group, |
||
| 808 | 'extra_'.$field_details['variable'], |
||
| 809 | $field_details['display_text'], |
||
| 810 | '' |
||
| 811 | ); |
||
| 812 | if (!$admin_permissions) { |
||
| 813 | if ($field_details['visible'] == 0) { |
||
| 814 | $form->freeze( |
||
| 815 | 'extra_'.$field_details['variable'] |
||
| 816 | ); |
||
| 817 | } |
||
| 818 | } |
||
| 819 | break; |
||
| 820 | case ExtraField::FIELD_TYPE_CHECKBOX: |
||
| 821 | $group = array(); |
||
| 822 | if (isset($field_details['options']) && !empty($field_details['options'])) { |
||
| 823 | View Code Duplication | foreach ($field_details['options'] as $option_details) { |
|
| 824 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 825 | $group[] = $form->createElement( |
||
| 826 | 'checkbox', |
||
| 827 | 'extra_'.$field_details['variable'], |
||
| 828 | $option_details['option_value'], |
||
| 829 | $option_details['display_text'].'<br />', |
||
| 830 | $option_details['option_value'] |
||
| 831 | ); |
||
| 832 | } |
||
| 833 | } else { |
||
| 834 | $fieldVariable = "extra_{$field_details['variable']}"; |
||
| 835 | |||
| 836 | $checkboxAttributes = array(); |
||
| 837 | |||
| 838 | if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) { |
||
| 839 | if (!empty($extraData[$fieldVariable])) { |
||
| 840 | $checkboxAttributes['checked'] = 1; |
||
| 841 | } |
||
| 842 | } |
||
| 843 | |||
| 844 | // We assume that is a switch on/off with 1 and 0 as values |
||
| 845 | $group[] = $form->createElement( |
||
| 846 | 'checkbox', |
||
| 847 | 'extra_'.$field_details['variable'], |
||
| 848 | null, |
||
| 849 | //$field_details['display_text'].'<br />', |
||
| 850 | get_lang('Yes'), |
||
| 851 | $checkboxAttributes |
||
| 852 | ); |
||
| 853 | } |
||
| 854 | |||
| 855 | $form->addGroup( |
||
| 856 | $group, |
||
| 857 | 'extra_'.$field_details['variable'], |
||
| 858 | $field_details['display_text'], |
||
| 859 | '' |
||
| 860 | ); |
||
| 861 | if (!$admin_permissions) { |
||
| 862 | if ($field_details['visible'] == 0) { |
||
| 863 | $form->freeze( |
||
| 864 | 'extra_'.$field_details['variable'] |
||
| 865 | ); |
||
| 866 | } |
||
| 867 | } |
||
| 868 | break; |
||
| 869 | case ExtraField::FIELD_TYPE_SELECT: |
||
| 870 | $get_lang_variables = false; |
||
| 871 | if (in_array( |
||
| 872 | $field_details['variable'], |
||
| 873 | array('mail_notify_message', 'mail_notify_invitation', 'mail_notify_group_message') |
||
| 874 | ) |
||
| 875 | ) { |
||
| 876 | $get_lang_variables = true; |
||
| 877 | } |
||
| 878 | |||
| 879 | // Get extra field workflow |
||
| 880 | $userInfo = api_get_user_info(); |
||
| 881 | |||
| 882 | $addOptions = array(); |
||
| 883 | |||
| 884 | $optionsExists = false; |
||
| 885 | global $app; |
||
| 886 | // Check if exist $app['orm.em'] object |
||
| 887 | if (isset($app['orm.em']) && is_object($app['orm.em'])) { |
||
| 888 | $optionsExists = $app['orm.em'] |
||
| 889 | ->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption') |
||
| 890 | ->findOneBy(array('fieldId' => $field_details['id'])); |
||
| 891 | } |
||
| 892 | |||
| 893 | if ($optionsExists) { |
||
| 894 | if (isset($userInfo['status']) && !empty($userInfo['status'])) { |
||
| 895 | |||
| 896 | $fieldWorkFlow = $app['orm.em']->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption') |
||
| 897 | ->findBy( |
||
| 898 | array( |
||
| 899 | 'fieldId' => $field_details['id'], |
||
| 900 | 'relatedFieldOptionId' => $defaultValueId, |
||
| 901 | 'roleId' => $userInfo['status'] |
||
| 902 | ) |
||
| 903 | ); |
||
| 904 | foreach ($fieldWorkFlow as $item) { |
||
| 905 | $addOptions[] = $item->getFieldOptionId(); |
||
| 906 | } |
||
| 907 | } |
||
| 908 | } |
||
| 909 | |||
| 910 | $options = array(); |
||
| 911 | if (empty($defaultValueId)) { |
||
| 912 | $options[''] = get_lang('SelectAnOption'); |
||
| 913 | } |
||
| 914 | |||
| 915 | $optionList = array(); |
||
| 916 | if (!empty($field_details['options'])) { |
||
| 917 | foreach ($field_details['options'] as $option_details) { |
||
| 918 | $optionList[$option_details['id']] = $option_details; |
||
| 919 | if ($get_lang_variables) { |
||
| 920 | $options[$option_details['option_value']] = get_lang($option_details['display_text']); |
||
| 921 | } else { |
||
| 922 | if ($optionsExists) { |
||
| 923 | // Adding always the default value |
||
| 924 | View Code Duplication | if ($option_details['id'] == $defaultValueId) { |
|
| 925 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 926 | } else { |
||
| 927 | if (isset($addOptions) && !empty($addOptions)) { |
||
| 928 | // Parsing filters |
||
| 929 | if (in_array($option_details['id'], $addOptions)) { |
||
| 930 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 931 | } |
||
| 932 | } |
||
| 933 | } |
||
| 934 | } else { |
||
| 935 | // Normal behaviour |
||
| 936 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 937 | } |
||
| 938 | } |
||
| 939 | } |
||
| 940 | |||
| 941 | if (isset($optionList[$defaultValueId])) { |
||
| 942 | if (isset($optionList[$defaultValueId]['option_value']) && |
||
| 943 | $optionList[$defaultValueId]['option_value'] == 'aprobada' |
||
| 944 | ) { |
||
| 945 | // @todo function don't exists api_is_question_manager |
||
| 946 | /*if (api_is_question_manager() == false) { |
||
| 947 | $form->freeze(); |
||
| 948 | }*/ |
||
| 949 | } |
||
| 950 | } |
||
| 951 | |||
| 952 | // Setting priority message |
||
| 953 | if (isset($optionList[$defaultValueId]) && |
||
| 954 | isset($optionList[$defaultValueId]['priority']) |
||
| 955 | ) { |
||
| 956 | |||
| 957 | if (!empty($optionList[$defaultValueId]['priority'])) { |
||
| 958 | $priorityId = $optionList[$defaultValueId]['priority']; |
||
| 959 | $option = new ExtraFieldOption($this->type); |
||
| 960 | $messageType = $option->getPriorityMessageType($priorityId); |
||
| 961 | $form->addElement( |
||
| 962 | 'label', |
||
| 963 | null, |
||
| 964 | Display::return_message( |
||
| 965 | $optionList[$defaultValueId]['priority_message'], |
||
| 966 | $messageType |
||
| 967 | ) |
||
| 968 | ); |
||
| 969 | } |
||
| 970 | } |
||
| 971 | } |
||
| 972 | |||
| 973 | if ($get_lang_variables) { |
||
| 974 | $field_details['display_text'] = get_lang($field_details['display_text']); |
||
| 975 | } |
||
| 976 | |||
| 977 | // chzn-select doesn't work for sessions?? |
||
| 978 | $form->addElement( |
||
| 979 | 'select', |
||
| 980 | 'extra_' . $field_details['variable'], |
||
| 981 | $field_details['display_text'], |
||
| 982 | $options, |
||
| 983 | array('id' => 'extra_'.$field_details['variable']) |
||
| 984 | ); |
||
| 985 | |||
| 986 | /* Enable this when field_loggeable is introduced as a table field (2.0) |
||
| 987 | if ($optionsExists && $field_details['field_loggeable'] && !empty($defaultValueId)) { |
||
| 988 | |||
| 989 | $form->addElement( |
||
| 990 | 'textarea', |
||
| 991 | 'extra_' . $field_details['variable'] . '_comment', |
||
| 992 | $field_details['display_text'] . ' ' . get_lang('Comment') |
||
| 993 | ); |
||
| 994 | |||
| 995 | $extraFieldValue = new ExtraFieldValue($this->type); |
||
| 996 | $repo = $app['orm.em']->getRepository($extraFieldValue->entityName); |
||
| 997 | $repoLog = $app['orm.em']->getRepository('Gedmo\Loggable\Entity\LogEntry'); |
||
| 998 | $newEntity = $repo->findOneBy( |
||
| 999 | array( |
||
| 1000 | $this->handlerEntityId => $itemId, |
||
| 1001 | 'fieldId' => $field_details['id'] |
||
| 1002 | ) |
||
| 1003 | ); |
||
| 1004 | // @todo move this in a function inside the class |
||
| 1005 | if ($newEntity) { |
||
| 1006 | $logs = $repoLog->getLogEntries($newEntity); |
||
| 1007 | if (!empty($logs)) { |
||
| 1008 | $html = '<b>' . get_lang('LatestChanges') . '</b><br /><br />'; |
||
| 1009 | |||
| 1010 | $table = new HTML_Table(array('class' => 'data_table')); |
||
| 1011 | $table->setHeaderContents(0, 0, get_lang('Value')); |
||
| 1012 | $table->setHeaderContents(0, 1, get_lang('Comment')); |
||
| 1013 | $table->setHeaderContents(0, 2, get_lang('ModifyDate')); |
||
| 1014 | $table->setHeaderContents(0, 3, get_lang('Username')); |
||
| 1015 | $row = 1; |
||
| 1016 | foreach ($logs as $log) { |
||
| 1017 | $column = 0; |
||
| 1018 | $data = $log->getData(); |
||
| 1019 | $fieldValue = isset($data['fieldValue']) ? $data['fieldValue'] : null; |
||
| 1020 | $comment = isset($data['comment']) ? $data['comment'] : null; |
||
| 1021 | |||
| 1022 | $table->setCellContents($row, $column, $fieldValue); |
||
| 1023 | $column++; |
||
| 1024 | $table->setCellContents($row, $column, $comment); |
||
| 1025 | $column++; |
||
| 1026 | $table->setCellContents($row, $column, api_get_local_time($log->getLoggedAt()->format('Y-m-d H:i:s'))); |
||
| 1027 | $column++; |
||
| 1028 | $table->setCellContents($row, $column, $log->getUsername()); |
||
| 1029 | $row++; |
||
| 1030 | } |
||
| 1031 | $form->addElement('label', null, $html.$table->toHtml()); |
||
| 1032 | } |
||
| 1033 | } |
||
| 1034 | } |
||
| 1035 | */ |
||
| 1036 | |||
| 1037 | if (!$admin_permissions) { |
||
| 1038 | if ($field_details['visible'] == 0) { |
||
| 1039 | $form->freeze('extra_' . $field_details['variable']); |
||
| 1040 | } |
||
| 1041 | } |
||
| 1042 | break; |
||
| 1043 | View Code Duplication | case ExtraField::FIELD_TYPE_SELECT_MULTIPLE: |
|
| 1044 | $options = array(); |
||
| 1045 | foreach ($field_details['options'] as $option_id => $option_details) { |
||
| 1046 | $options[$option_details['option_value']] = $option_details['display_text']; |
||
| 1047 | } |
||
| 1048 | $form->addElement( |
||
| 1049 | 'select', |
||
| 1050 | 'extra_'.$field_details['variable'], |
||
| 1051 | $field_details['display_text'], |
||
| 1052 | $options, |
||
| 1053 | array('multiple' => 'multiple') |
||
| 1054 | ); |
||
| 1055 | if (!$admin_permissions) { |
||
| 1056 | if ($field_details['visible'] == 0) { |
||
| 1057 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1058 | } |
||
| 1059 | } |
||
| 1060 | break; |
||
| 1061 | View Code Duplication | case ExtraField::FIELD_TYPE_DATE: |
|
| 1062 | $form->addDatePicker('extra_'.$field_details['variable'], $field_details['display_text']); |
||
| 1063 | if (!$admin_permissions) { |
||
| 1064 | if ($field_details['visible'] == 0) { |
||
| 1065 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1066 | } |
||
| 1067 | } |
||
| 1068 | |||
| 1069 | $form->applyFilter('theme', 'trim'); |
||
| 1070 | break; |
||
| 1071 | case ExtraField::FIELD_TYPE_DATETIME: |
||
| 1072 | $form->addDateTimePicker( |
||
| 1073 | 'extra_'.$field_details['variable'], |
||
| 1074 | $field_details['display_text'] |
||
| 1075 | ); |
||
| 1076 | |||
| 1077 | $defaults['extra_'.$field_details['variable']] = api_get_local_time(); |
||
| 1078 | if (!isset($form->_defaultValues['extra_'.$field_details['variable']])) { |
||
| 1079 | $form->setDefaults($defaults); |
||
| 1080 | } |
||
| 1081 | if (!$admin_permissions) { |
||
| 1082 | if ($field_details['visible'] == 0) { |
||
| 1083 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1084 | } |
||
| 1085 | } |
||
| 1086 | $form->applyFilter('theme', 'trim'); |
||
| 1087 | break; |
||
| 1088 | case ExtraField::FIELD_TYPE_DOUBLE_SELECT: |
||
| 1089 | $first_select_id = 'first_extra_'.$field_details['variable']; |
||
| 1090 | $url = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1'; |
||
| 1091 | |||
| 1092 | $jquery_ready_content .= ' |
||
| 1093 | $("#'.$first_select_id.'").on("change", function() { |
||
| 1094 | var id = $(this).val(); |
||
| 1095 | if (id) { |
||
| 1096 | $.ajax({ |
||
| 1097 | url: "'.$url.'&a=get_second_select_options", |
||
| 1098 | dataType: "json", |
||
| 1099 | data: "type='.$type.'&field_id='.$field_details['id'].'&option_value_id="+id, |
||
| 1100 | success: function(data) { |
||
| 1101 | $("#second_extra_'.$field_details['variable'].'").empty(); |
||
| 1102 | $.each(data, function(index, value) { |
||
| 1103 | $("#second_extra_'.$field_details['variable'].'").append($("<option/>", { |
||
| 1104 | value: index, |
||
| 1105 | text: value |
||
| 1106 | })); |
||
| 1107 | }); |
||
| 1108 | $("#second_extra_'.$field_details['variable'].'").selectpicker("refresh"); |
||
| 1109 | }, |
||
| 1110 | }); |
||
| 1111 | } else { |
||
| 1112 | $("#second_extra_'.$field_details['variable'].'").empty(); |
||
| 1113 | } |
||
| 1114 | });'; |
||
| 1115 | |||
| 1116 | $first_id = null; |
||
| 1117 | $second_id = null; |
||
| 1118 | |||
| 1119 | if (!empty($extraData)) { |
||
| 1120 | $first_id = $extraData['extra_'.$field_details['variable']]['extra_'.$field_details['variable']]; |
||
| 1121 | $second_id = $extraData['extra_'.$field_details['variable']]['extra_'.$field_details['variable'].'_second']; |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | $options = ExtraField::extra_field_double_select_convert_array_to_ordered_array( |
||
| 1125 | $field_details['options'] |
||
| 1126 | ); |
||
| 1127 | $values = array('' => get_lang('Select')); |
||
| 1128 | |||
| 1129 | $second_values = array(); |
||
| 1130 | if (!empty($options)) { |
||
| 1131 | foreach ($options as $option) { |
||
| 1132 | foreach ($option as $sub_option) { |
||
| 1133 | if ($sub_option['option_value'] == '0') { |
||
| 1134 | $values[$sub_option['id']] = $sub_option['display_text']; |
||
| 1135 | } else { |
||
| 1136 | if ($first_id === $sub_option['option_value']) { |
||
| 1137 | $second_values[$sub_option['id']] = $sub_option['display_text']; |
||
| 1138 | } |
||
| 1139 | } |
||
| 1140 | } |
||
| 1141 | } |
||
| 1142 | } |
||
| 1143 | $group = array(); |
||
| 1144 | $group[] = $form->createElement( |
||
| 1145 | 'select', |
||
| 1146 | 'extra_'.$field_details['variable'], |
||
| 1147 | null, |
||
| 1148 | $values, |
||
| 1149 | array('id' => $first_select_id) |
||
| 1150 | ); |
||
| 1151 | $group[] = $form->createElement( |
||
| 1152 | 'select', |
||
| 1153 | 'extra_'.$field_details['variable'].'_second', |
||
| 1154 | null, |
||
| 1155 | $second_values, |
||
| 1156 | array('id' => 'second_extra_'.$field_details['variable']) |
||
| 1157 | ); |
||
| 1158 | $form->addGroup( |
||
| 1159 | $group, |
||
| 1160 | 'extra_'.$field_details['variable'], |
||
| 1161 | $field_details['display_text'], |
||
| 1162 | ' ' |
||
| 1163 | ); |
||
| 1164 | |||
| 1165 | if (!$admin_permissions) { |
||
| 1166 | if ($field_details['visible'] == 0) { |
||
| 1167 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1168 | } |
||
| 1169 | } |
||
| 1170 | break; |
||
| 1171 | case ExtraField::FIELD_TYPE_DIVIDER: |
||
| 1172 | $form->addElement( |
||
| 1173 | 'static', |
||
| 1174 | $field_details['variable'], |
||
| 1175 | '<br /><strong>'.$field_details['display_text'].'</strong>' |
||
| 1176 | ); |
||
| 1177 | break; |
||
| 1178 | case ExtraField::FIELD_TYPE_TAG: |
||
| 1179 | $variable = $field_details['variable']; |
||
| 1180 | $field_id = $field_details['id']; |
||
| 1181 | |||
| 1182 | //Added for correctly translate the extra_field |
||
| 1183 | $get_lang_variables = false; |
||
| 1184 | if (in_array($variable, ['tags'])) { |
||
| 1185 | $get_lang_variables = true; |
||
| 1186 | } |
||
| 1187 | |||
| 1188 | if ($get_lang_variables) { |
||
| 1189 | $field_details['display_text'] = get_lang($field_details['display_text']); |
||
| 1190 | } |
||
| 1191 | |||
| 1192 | $tagsSelect = $form->addSelect( |
||
| 1193 | "extra_{$field_details['variable']}", |
||
| 1194 | $field_details['display_text'] |
||
| 1195 | ); |
||
| 1196 | $tagsSelect->setAttribute('class', null); |
||
| 1197 | $tagsSelect->setAttribute('id', "extra_{$field_details['variable']}"); |
||
| 1198 | $tagsSelect->setMultiple(true); |
||
| 1199 | |||
| 1200 | if ($this->type == 'user') { |
||
| 1201 | |||
| 1202 | /* //the magic should be here |
||
| 1203 | $user_tags = UserManager::get_user_tags($user_id, $field_details[0]); |
||
| 1204 | |||
| 1205 | $tag_list = ''; |
||
| 1206 | if (is_array($user_tags) && count($user_tags) > 0) { |
||
| 1207 | foreach ($user_tags as $tag) { |
||
| 1208 | $tag_list .= '<option value="'.$tag['tag'].'" class="selected">'.$tag['tag'].'</option>'; |
||
| 1209 | } |
||
| 1210 | } |
||
| 1211 | |||
| 1212 | $multi_select = '<select id="extra_'.$field_details[1].'" name="extra_'.$field_details[1].'"> |
||
| 1213 | '.$tag_list.' |
||
| 1214 | </select>'; |
||
| 1215 | |||
| 1216 | $form->addElement('label', $field_details[3], $multi_select); |
||
| 1217 | $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php'; |
||
| 1218 | $complete_text = get_lang('StartToType'); |
||
| 1219 | //if cache is set to true the jquery will be called 1 time |
||
| 1220 | $jquery_ready_content = <<<EOF |
||
| 1221 | $("#extra_$field_details[1]").fcbkcomplete({ |
||
| 1222 | json_url: "$url?a=search_tags&field_id=$field_details[0]", |
||
| 1223 | cache: false, |
||
| 1224 | filter_case: true, |
||
| 1225 | filter_hide: true, |
||
| 1226 | complete_text:"$complete_text", |
||
| 1227 | firstselected: true, |
||
| 1228 | //onremove: "testme", |
||
| 1229 | //onselect: "testme", |
||
| 1230 | filter_selected: true, |
||
| 1231 | newel: true |
||
| 1232 | }); |
||
| 1233 | EOF; |
||
| 1234 | break;*/ |
||
| 1235 | |||
| 1236 | // The magic should be here |
||
| 1237 | $user_tags = UserManager::get_user_tags($itemId, $field_details['id']); |
||
| 1238 | |||
| 1239 | if (is_array($user_tags) && count($user_tags) > 0) { |
||
| 1240 | foreach ($user_tags as $tag) { |
||
| 1241 | $tagsSelect->addOption( |
||
| 1242 | $tag['tag'], |
||
| 1243 | $tag['tag'], |
||
| 1244 | ['selected' => 'selected', 'class' => 'selected'] |
||
| 1245 | ); |
||
| 1246 | } |
||
| 1247 | } |
||
| 1248 | $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php'; |
||
| 1249 | } else { |
||
| 1250 | $em = Database::getManager(); |
||
| 1251 | |||
| 1252 | $fieldTags = $em |
||
| 1253 | ->getRepository('ChamiloCoreBundle:ExtraFieldRelTag') |
||
| 1254 | ->findBy([ |
||
| 1255 | 'fieldId' => $field_id, |
||
| 1256 | 'itemId' => $itemId |
||
| 1257 | ]); |
||
| 1258 | |||
| 1259 | foreach ($fieldTags as $fieldTag) { |
||
| 1260 | $tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId()); |
||
| 1261 | |||
| 1262 | if (empty($tag)) { |
||
| 1263 | continue; |
||
| 1264 | } |
||
| 1265 | |||
| 1266 | $tagsSelect->addOption( |
||
| 1267 | $tag->getTag(), |
||
| 1268 | $tag->getTag(), |
||
| 1269 | ['selected' => 'selected', 'class' => 'selected'] |
||
| 1270 | ); |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | $url = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php'; |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | $complete_text = get_lang('StartToType'); |
||
| 1277 | |||
| 1278 | //if cache is set to true the jquery will be called 1 time |
||
| 1279 | |||
| 1280 | $jquery_ready_content .= <<<EOF |
||
| 1281 | $("#extra_$variable").fcbkcomplete({ |
||
| 1282 | json_url: "$url?a=search_tags&field_id=$field_id&type={$this->type}", |
||
| 1283 | cache: false, |
||
| 1284 | filter_case: true, |
||
| 1285 | filter_hide: true, |
||
| 1286 | complete_text:"$complete_text", |
||
| 1287 | firstselected: false, |
||
| 1288 | filter_selected: true, |
||
| 1289 | newel: true |
||
| 1290 | }); |
||
| 1291 | EOF; |
||
| 1292 | break; |
||
| 1293 | View Code Duplication | case ExtraField::FIELD_TYPE_TIMEZONE: |
|
| 1294 | $form->addElement( |
||
| 1295 | 'select', |
||
| 1296 | 'extra_'.$field_details['variable'], |
||
| 1297 | $field_details['display_text'], |
||
| 1298 | api_get_timezones(), |
||
| 1299 | '' |
||
| 1300 | ); |
||
| 1301 | if ($field_details['visible'] == 0) { |
||
| 1302 | $form->freeze( |
||
| 1303 | 'extra_'.$field_details['variable'] |
||
| 1304 | ); |
||
| 1305 | } |
||
| 1306 | break; |
||
| 1307 | case ExtraField::FIELD_TYPE_SOCIAL_PROFILE: |
||
| 1308 | // get the social network's favicon |
||
| 1309 | $extra_data_variable = isset($extraData['extra_'.$field_details['variable']]) ? $extraData['extra_'.$field_details['variable']] : null; |
||
| 1310 | $field_default_value = isset($field_details['field_default_value']) ? $field_details['field_default_value'] : null; |
||
| 1311 | $icon_path = UserManager::get_favicon_from_url( |
||
| 1312 | $extra_data_variable, |
||
| 1313 | $field_default_value |
||
| 1314 | ); |
||
| 1315 | // special hack for hi5 |
||
| 1316 | $leftpad = '1.7'; |
||
| 1317 | $top = '0.4'; |
||
| 1318 | $domain = parse_url($icon_path, PHP_URL_HOST); |
||
| 1319 | if ($domain == 'www.hi5.com' or $domain == 'hi5.com') { |
||
| 1320 | $leftpad = '3'; |
||
| 1321 | $top = '0'; |
||
| 1322 | } |
||
| 1323 | // print the input field |
||
| 1324 | $form->addElement( |
||
| 1325 | 'text', |
||
| 1326 | 'extra_'.$field_details['variable'], |
||
| 1327 | $field_details['display_text'], |
||
| 1328 | array( |
||
| 1329 | 'size' => 60, |
||
| 1330 | 'style' => 'background-image: url(\''.$icon_path.'\'); background-repeat: no-repeat; background-position: 0.4em '.$top.'em; padding-left: '.$leftpad.'em; ' |
||
| 1331 | ) |
||
| 1332 | ); |
||
| 1333 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1334 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1335 | if ($field_details['visible'] == 0) { |
||
| 1336 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1337 | } |
||
| 1338 | break; |
||
| 1339 | View Code Duplication | case ExtraField::FIELD_TYPE_MOBILE_PHONE_NUMBER: |
|
| 1340 | $form->addElement( |
||
| 1341 | 'text', |
||
| 1342 | 'extra_'.$field_details[1], |
||
| 1343 | $field_details[3]." (".get_lang('CountryDialCode').")", |
||
| 1344 | array('size' => 40, 'placeholder' => '(xx)xxxxxxxxx') |
||
| 1345 | ); |
||
| 1346 | $form->applyFilter('extra_'.$field_details[1], 'stripslashes'); |
||
| 1347 | $form->applyFilter('extra_'.$field_details[1], 'trim'); |
||
| 1348 | $form->applyFilter('extra_'.$field_details[1], 'mobile_phone_number_filter'); |
||
| 1349 | $form->addRule( |
||
| 1350 | 'extra_'.$field_details[1], |
||
| 1351 | get_lang('MobilePhoneNumberWrong'), |
||
| 1352 | 'mobile_phone_number' |
||
| 1353 | ); |
||
| 1354 | if ($field_details['visible'] == 0) { |
||
| 1355 | $form->freeze('extra_'.$field_details['variable']); |
||
| 1356 | } |
||
| 1357 | break; |
||
| 1358 | View Code Duplication | case ExtraField::FIELD_TYPE_INTEGER: |
|
| 1359 | $form->addElement( |
||
| 1360 | 'number', |
||
| 1361 | 'extra_'.$field_details['variable'], |
||
| 1362 | $field_details['display_text'], |
||
| 1363 | array('class' => 'span1', 'step' => 1) |
||
| 1364 | ); |
||
| 1365 | |||
| 1366 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1367 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1368 | $form->applyFilter('extra_'.$field_details['variable'], 'intval'); |
||
| 1369 | |||
| 1370 | if (!$admin_permissions) { |
||
| 1371 | if ($field_details['visible'] == 0) { |
||
| 1372 | $form->freeze( |
||
| 1373 | 'extra_'.$field_details['variable'] |
||
| 1374 | ); |
||
| 1375 | } |
||
| 1376 | } |
||
| 1377 | break; |
||
| 1378 | case ExtraField::FIELD_TYPE_FILE_IMAGE: |
||
| 1379 | $fieldVariable = "extra_{$field_details['variable']}"; |
||
| 1380 | |||
| 1381 | $fieldTexts = array( |
||
| 1382 | $field_details['display_text'] |
||
| 1383 | ); |
||
| 1384 | |||
| 1385 | View Code Duplication | if (is_array($extraData) && array_key_exists($fieldVariable, $extraData)) { |
|
| 1386 | |||
| 1387 | if (file_exists(api_get_path(SYS_UPLOAD_PATH) . $extraData[$fieldVariable])) { |
||
| 1388 | $fieldTexts[] = Display::img( |
||
| 1389 | api_get_path(WEB_UPLOAD_PATH) . $extraData[$fieldVariable], |
||
| 1390 | $field_details['display_text'], |
||
| 1391 | array('width' => '300') |
||
| 1392 | ); |
||
| 1393 | } |
||
| 1394 | } |
||
| 1395 | |||
| 1396 | $form->addElement( |
||
| 1397 | 'file', |
||
| 1398 | $fieldVariable, |
||
| 1399 | $fieldTexts, |
||
| 1400 | array('accept' => 'image/*') |
||
| 1401 | ); |
||
| 1402 | |||
| 1403 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1404 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1405 | |||
| 1406 | $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); |
||
| 1407 | $form->addRule( |
||
| 1408 | 'extra_'.$field_details['variable'], |
||
| 1409 | get_lang('OnlyImagesAllowed') . ' ('.implode(',', $allowed_picture_types).')', |
||
| 1410 | 'filetype', |
||
| 1411 | $allowed_picture_types |
||
| 1412 | ); |
||
| 1413 | |||
| 1414 | if (!$admin_permissions) { |
||
| 1415 | if ($field_details['visible'] == 0) { |
||
| 1416 | $form->freeze( |
||
| 1417 | 'extra_'.$field_details['variable'] |
||
| 1418 | ); |
||
| 1419 | } |
||
| 1420 | } |
||
| 1421 | break; |
||
| 1422 | View Code Duplication | case ExtraField::FIELD_TYPE_FLOAT: |
|
| 1423 | $form->addElement( |
||
| 1424 | 'number', |
||
| 1425 | 'extra_'.$field_details['variable'], |
||
| 1426 | $field_details['display_text'], |
||
| 1427 | array('class' => 'span1', 'step' => '0.01') |
||
| 1428 | ); |
||
| 1429 | |||
| 1430 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1431 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1432 | $form->applyFilter('extra_'.$field_details['variable'], 'floatval'); |
||
| 1433 | |||
| 1434 | if (!$admin_permissions) { |
||
| 1435 | if ($field_details['visible'] == 0) { |
||
| 1436 | $form->freeze( |
||
| 1437 | 'extra_'.$field_details['variable'] |
||
| 1438 | ); |
||
| 1439 | } |
||
| 1440 | } |
||
| 1441 | break; |
||
| 1442 | case ExtraField::FIELD_TYPE_FILE: |
||
| 1443 | $fieldVariable = "extra_{$field_details['variable']}"; |
||
| 1444 | $fieldTexts = array( |
||
| 1445 | $field_details['display_text'] |
||
| 1446 | ); |
||
| 1447 | |||
| 1448 | if (is_array($extraData) && |
||
| 1449 | array_key_exists($fieldVariable, $extraData) |
||
| 1450 | ) { |
||
| 1451 | View Code Duplication | if (file_exists(api_get_path(SYS_UPLOAD_PATH) . $extraData[$fieldVariable])) { |
|
| 1452 | $fieldTexts[] = Display::url( |
||
| 1453 | api_get_path(WEB_UPLOAD_PATH) . $extraData[$fieldVariable], |
||
| 1454 | api_get_path(WEB_UPLOAD_PATH) . $extraData[$fieldVariable], |
||
| 1455 | array( |
||
| 1456 | 'title' => $field_details['display_text'], |
||
| 1457 | 'target' => '_blank' |
||
| 1458 | ) |
||
| 1459 | ); |
||
| 1460 | } |
||
| 1461 | } |
||
| 1462 | |||
| 1463 | $form->addElement( |
||
| 1464 | 'file', |
||
| 1465 | $fieldVariable, |
||
| 1466 | $fieldTexts, |
||
| 1467 | array() |
||
| 1468 | ); |
||
| 1469 | |||
| 1470 | $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); |
||
| 1471 | $form->applyFilter('extra_'.$field_details['variable'], 'trim'); |
||
| 1472 | |||
| 1473 | if (!$admin_permissions) { |
||
| 1474 | if ($field_details['visible'] == 0) { |
||
| 1475 | $form->freeze( |
||
| 1476 | 'extra_'.$field_details['variable'] |
||
| 1477 | ); |
||
| 1478 | } |
||
| 1479 | } |
||
| 1480 | break; |
||
| 1481 | case ExtraField::FIELD_TYPE_VIDEO_URL: |
||
| 1482 | //Added for correctly translate the extra_field |
||
| 1483 | $get_lang_variables = false; |
||
| 1484 | if (in_array($field_details['variable'], ['video_url'])) { |
||
| 1485 | $get_lang_variables = true; |
||
| 1486 | } |
||
| 1487 | |||
| 1488 | if ($get_lang_variables) { |
||
| 1489 | $field_details['display_text'] = get_lang($field_details['display_text']); |
||
| 1490 | } |
||
| 1491 | |||
| 1492 | $form->addUrl( |
||
| 1493 | "extra_{$field_details['variable']}", |
||
| 1494 | $field_details['display_text'], |
||
| 1495 | false, |
||
| 1496 | ['placeholder' => 'https://'] |
||
| 1497 | ); |
||
| 1498 | break; |
||
| 1499 | View Code Duplication | case ExtraField::FIELD_TYPE_LETTERS_ONLY: |
|
| 1500 | $form->addTextLettersOnly( |
||
| 1501 | "extra_{$field_details['variable']}", |
||
| 1502 | $field_details['display_text'] |
||
| 1503 | ); |
||
| 1504 | $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes'); |
||
| 1505 | |||
| 1506 | if (!$admin_permissions) { |
||
| 1507 | if ($field_details['visible'] == 0) { |
||
| 1508 | $form->freeze( |
||
| 1509 | 'extra_' . $field_details['variable'] |
||
| 1510 | ); |
||
| 1511 | } |
||
| 1512 | } |
||
| 1513 | break; |
||
| 1514 | View Code Duplication | case ExtraField::FIELD_TYPE_ALPHANUMERIC: |
|
| 1515 | $form->addTextAlphanumeric( |
||
| 1516 | "extra_{$field_details['variable']}", |
||
| 1517 | $field_details['display_text'] |
||
| 1518 | ); |
||
| 1519 | $form->applyFilter( |
||
| 1520 | 'extra_' . $field_details['variable'], |
||
| 1521 | 'stripslashes' |
||
| 1522 | ); |
||
| 1523 | if (!$admin_permissions) { |
||
| 1524 | if ($field_details['visible'] == 0) { |
||
| 1525 | $form->freeze( |
||
| 1526 | 'extra_' . $field_details['variable'] |
||
| 1527 | ); |
||
| 1528 | } |
||
| 1529 | } |
||
| 1530 | break; |
||
| 1531 | View Code Duplication | case ExtraField::FIELD_TYPE_LETTERS_SPACE: |
|
| 1532 | $form->addTextLettersAndSpaces( |
||
| 1533 | "extra_{$field_details['variable']}", |
||
| 1534 | $field_details['display_text'] |
||
| 1535 | ); |
||
| 1536 | $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes'); |
||
| 1537 | |||
| 1538 | if (!$admin_permissions) { |
||
| 1539 | if ($field_details['visible'] == 0) { |
||
| 1540 | $form->freeze( |
||
| 1541 | 'extra_' . $field_details['variable'] |
||
| 1542 | ); |
||
| 1543 | } |
||
| 1544 | } |
||
| 1545 | break; |
||
| 1546 | View Code Duplication | case ExtraField::FIELD_TYPE_ALPHANUMERIC_SPACE: |
|
| 1547 | $form->addTextAlphanumericAndSpaces( |
||
| 1548 | "extra_{$field_details['variable']}", |
||
| 1549 | $field_details['display_text'] |
||
| 1550 | ); |
||
| 1551 | $form->applyFilter( |
||
| 1552 | 'extra_' . $field_details['variable'], |
||
| 1553 | 'stripslashes' |
||
| 1554 | ); |
||
| 1555 | if (!$admin_permissions) { |
||
| 1556 | if ($field_details['visible'] == 0) { |
||
| 1557 | $form->freeze( |
||
| 1558 | 'extra_' . $field_details['variable'] |
||
| 1559 | ); |
||
| 1560 | } |
||
| 1561 | } |
||
| 1562 | break; |
||
| 1563 | } |
||
| 1564 | } |
||
| 1565 | } |
||
| 1566 | $return = array(); |
||
| 1567 | $return['jquery_ready_content'] = $jquery_ready_content; |
||
| 1568 | |||
| 1569 | return $return; |
||
| 1570 | } |
||
| 1571 | |||
| 2288 |
This check looks for type mismatches where the missing type is
false. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTimeobject or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalsebefore passing on the value to another function or method that may not be able to handle afalse.