Răsfoiți Sursa

Use custom diagnostic UI

jmontoyaa 8 ani în urmă
părinte
comite
4c5c48ffab
2 a modificat fișierele cu 234 adăugiri și 83 ștergeri
  1. 172 81
      main/inc/lib/extra_field.lib.php
  2. 62 2
      search.php

+ 172 - 81
main/inc/lib/extra_field.lib.php

@@ -452,7 +452,8 @@ class ExtraField extends Model
         $specialUrlList = [],
         $orderDependingDefaults = false,
         $forceShowFields = false,
-        $separateExtraMultipleSelect = 0
+        $separateExtraMultipleSelect = [],
+        $customLabelsExtraMultipleSelect = []
     ) {
         if (empty($form)) {
             return false;
@@ -489,7 +490,8 @@ class ExtraField extends Model
             $orderFields,
             $specialUrlList,
             $orderDependingDefaults,
-            $separateExtraMultipleSelect
+            $separateExtraMultipleSelect,
+            $customLabelsExtraMultipleSelect
         );
 
         return $extra;
@@ -815,7 +817,8 @@ class ExtraField extends Model
         $orderFields = [],
         $specialUrlList = [],
         $orderDependingDefaults = false,
-        $separateExtraMultipleSelect = 0
+        $separateExtraMultipleSelect = [],
+        $customLabelsExtraMultipleSelect = []
     ) {
         $type = $this->type;
         $jquery_ready_content = '';
@@ -1167,17 +1170,24 @@ class ExtraField extends Model
                             }
                         }
 
-                        if ($separateExtraMultipleSelect > 0) {
-                            for($i = 0; $i < $separateExtraMultipleSelect; $i++) {
+                        // OFAJ
+                        $separateValue = 0;
+                        if (isset($separateExtraMultipleSelect[$field_details['variable']])) {
+                            $separateValue = $separateExtraMultipleSelect[$field_details['variable']];
+                        }
+
+                        if ($separateValue > 0) {
+                            for($i = 0; $i < $separateValue; $i++) {
                                 $form->addElement(
                                     'select',
                                     'extra_'.$field_details['variable'].'['.$i.']',
-                                    $field_details['display_text'],
+                                    $customLabelsExtraMultipleSelect[$field_details['variable']][$i], //$field_details['display_text'],
                                     $options,
                                     array('id' => 'extra_'.$field_details['variable'].'_'.$i)
                                 );
                             }
                         } else {
+                            // default behaviour
                             $form->addElement(
                                 'select',
                                 'extra_'.$field_details['variable'],
@@ -1312,35 +1322,16 @@ class ExtraField extends Model
                         $variable = $field_details['variable'];
                         $field_id = $field_details['id'];
 
-                        $tagsSelect = $form->addSelect(
-                            "extra_{$field_details['variable']}",
-                            $field_details['display_text']
-                        );
 
-                        if ($useTagAsSelect === false) {
-                            $tagsSelect->setAttribute('class', null);
+                        $separateValue = 0;
+                        if (isset($separateExtraMultipleSelect[$field_details['variable']])) {
+                            $separateValue = $separateExtraMultipleSelect[$field_details['variable']];
                         }
 
-                        $tagsSelect->setAttribute('id', "extra_{$field_details['variable']}");
-                        $tagsSelect->setMultiple(true);
-
-                        if ($this->type === 'user') {
-                            // The magic should be here
-                            $user_tags = UserManager::get_user_tags($itemId, $field_details['id']);
-
-                            if (is_array($user_tags) && count($user_tags) > 0) {
-                                foreach ($user_tags as $tag) {
-                                    $tagsSelect->addOption(
-                                        $tag['tag'],
-                                        $tag['tag'],
-                                        ['selected' => 'selected', 'class' => 'selected']
-                                    );
-                                }
-                            }
-                            $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php';
-                        } else {
+                        if ($separateValue > 0) {
                             $em = Database::getManager();
-                            $fieldTags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
+                            $fieldTags = $em
+                                ->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
                                 ->findBy(
                                     [
                                         'fieldId' => $field_id,
@@ -1348,20 +1339,8 @@ class ExtraField extends Model
                                     ]
                                 );
 
-                            foreach ($fieldTags as $fieldTag) {
-                                $tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId());
-
-                                if (empty($tag)) {
-                                    continue;
-                                }
-                                $tagsSelect->addOption(
-                                    $tag->getTag(),
-                                    $tag->getTag(),
-                                    ['selected' => 'selected', 'class' => 'selected']
-                                );
-                            }
 
-                            if (!empty($extraData) && isset($extraData['extra_'.$field_details['variable']])) {
+                            /*if (!empty($extraData) && isset($extraData['extra_'.$field_details['variable']])) {
                                 $data = $extraData['extra_'.$field_details['variable']];
                                 foreach ($data as $option) {
                                     $tagsSelect->addOption(
@@ -1370,64 +1349,176 @@ class ExtraField extends Model
                                         ['selected' => 'selected', 'class' => 'selected']
                                     );
                                 }
-                            }
-
-                            if ($useTagAsSelect) {
-
-                                $fieldTags = $em
-                                    ->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
-                                    ->findBy([
-                                        'fieldId' => $field_id
-                                    ]);
-                                $tagsAdded = [];
+                            }*/
+                            // ofaj
+                            for ($i = 0; $i < $separateValue; $i++) {
+                                $tagsSelect = $form->addElement(
+                                    'select',
+                                    'extra_'.$field_details['variable'].'['.$i.']',
+                                    $customLabelsExtraMultipleSelect[$field_details['variable']][$i], //$field_details['display_text'],
+                                    null,
+                                    array('id' => 'extra_'.$field_details['variable'].'_'.$i)
+                                );
                                 foreach ($fieldTags as $fieldTag) {
                                     $tag = $em->find('ChamiloCoreBundle:Tag', $fieldTag->getTagId());
 
                                     if (empty($tag)) {
                                         continue;
                                     }
+                                    $tagsSelect->addOption(
+                                        $tag->getTag(),
+                                        $tag->getTag(),
+                                        ['selected' => 'selected', 'class' => 'selected']
+                                    );
+                                }
+                            }
+                        } else {
+                            $tagsSelect = $form->addSelect(
+                                "extra_{$field_details['variable']}",
+                                $field_details['display_text']
+                            );
+
+                            if ($useTagAsSelect === false) {
+                                $tagsSelect->setAttribute('class', null);
+                            }
+
+                            $tagsSelect->setAttribute(
+                                'id',
+                                "extra_{$field_details['variable']}"
+                            );
+                            $tagsSelect->setMultiple(true);
+
+
+                            if ($this->type === 'user') {
+                                // The magic should be here
+                                $user_tags = UserManager::get_user_tags(
+                                    $itemId,
+                                    $field_details['id']
+                                );
+
+                                if (is_array($user_tags) && count(
+                                        $user_tags
+                                    ) > 0
+                                ) {
+                                    foreach ($user_tags as $tag) {
+                                        $tagsSelect->addOption(
+                                            $tag['tag'],
+                                            $tag['tag'],
+                                            [
+                                                'selected' => 'selected',
+                                                'class' => 'selected'
+                                            ]
+                                        );
+                                    }
+                                }
+                                $url = api_get_path(
+                                        WEB_AJAX_PATH
+                                    ).'user_manager.ajax.php';
+                            } else {
+                                $em = Database::getManager();
+                                $fieldTags = $em->getRepository(
+                                    'ChamiloCoreBundle:ExtraFieldRelTag'
+                                )
+                                    ->findBy(
+                                        [
+                                            'fieldId' => $field_id,
+                                            'itemId' => $itemId,
+                                        ]
+                                    );
 
-                                    $tagText = $tag->getTag();
+                                foreach ($fieldTags as $fieldTag) {
+                                    $tag = $em->find(
+                                        'ChamiloCoreBundle:Tag',
+                                        $fieldTag->getTagId()
+                                    );
 
-                                    if (in_array($tagText, $tagsAdded)) {
+                                    if (empty($tag)) {
                                         continue;
                                     }
                                     $tagsSelect->addOption(
                                         $tag->getTag(),
                                         $tag->getTag(),
-                                        []
+                                        [
+                                            'selected' => 'selected',
+                                            'class' => 'selected'
+                                        ]
                                     );
+                                }
 
-                                    $tagsAdded[] = $tagText;
+                                if (!empty($extraData) && isset($extraData['extra_'.$field_details['variable']])) {
+                                    $data = $extraData['extra_'.$field_details['variable']];
+                                    foreach ($data as $option) {
+                                        $tagsSelect->addOption(
+                                            $option,
+                                            $option,
+                                            [
+                                                'selected' => 'selected',
+                                                'class' => 'selected'
+                                            ]
+                                        );
+                                    }
                                 }
-                            }
 
-                            $url = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php';
-                        }
+                                if ($useTagAsSelect) {
+                                    $fieldTags = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag')
+                                        ->findBy(
+                                            [
+                                                'fieldId' => $field_id
+                                            ]
+                                        );
+                                    $tagsAdded = [];
+                                    foreach ($fieldTags as $fieldTag) {
+                                        $tag = $em->find(
+                                            'ChamiloCoreBundle:Tag',
+                                            $fieldTag->getTagId()
+                                        );
+
+                                        if (empty($tag)) {
+                                            continue;
+                                        }
 
-                        $url = $url."?a=search_tags&field_id=$field_id&type={$this->type}";
+                                        $tagText = $tag->getTag();
 
-                        if (isset($specialUrlList[$field_details['variable']])) {
-                            //$url = $specialUrlList[$field_details['variable']]."&field_id=$field_id&type={$this->type}";
-                        }
+                                        if (in_array($tagText, $tagsAdded)) {
+                                            continue;
+                                        }
+                                        $tagsSelect->addOption(
+                                            $tag->getTag(),
+                                            $tag->getTag(),
+                                            []
+                                        );
 
-                        if ($useTagAsSelect == false) {
-                            $complete_text = get_lang('StartToType');
-
-                            //if cache is set to true the jquery will be called 1 time
-
-                            $jquery_ready_content .= <<<EOF
-                        $("#extra_$variable").fcbkcomplete({
-                            json_url: "$url",
-                            cache: false,
-                            filter_case: true,
-                            filter_hide: true,
-                            complete_text:"$complete_text",
-                            firstselected: false,
-                            filter_selected: true,                        
-                            newel: true
-                        });
+                                        $tagsAdded[] = $tagText;
+                                    }
+                                }
+
+                                $url = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php';
+                            }
+
+                            $url = $url."?a=search_tags&field_id=$field_id&type={$this->type}";
+
+                            if (isset($specialUrlList[$field_details['variable']])) {
+                                //$url = $specialUrlList[$field_details['variable']]."&field_id=$field_id&type={$this->type}";
+                            }
+
+                            if ($useTagAsSelect == false) {
+                                $complete_text = get_lang('StartToType');
+
+                                //if cache is set to true the jquery will be called 1 time
+
+                                $jquery_ready_content .= <<<EOF
+                            $("#extra_$variable").fcbkcomplete({
+                                json_url: "$url",
+                                cache: false,
+                                filter_case: true,
+                                filter_hide: true,
+                                complete_text:"$complete_text",
+                                firstselected: false,
+                                filter_selected: true,                        
+                                newel: true
+                            });
 EOF;
+                            }
                         }
                         break;
                     case ExtraField::FIELD_TYPE_TIMEZONE:

+ 62 - 2
search.php

@@ -239,6 +239,53 @@ $extraField = new ExtraField('user');
 $userForm = new FormValidator('user_form', 'post', api_get_self());
 $jqueryExtra = '';
 
+$htmlHeadXtra[] ='<script>		
+$(document).ready(function() {		
+    /*$("#filiere_panel").hide();			
+    $("#dispo_panel").hide();    		
+    $("#dispo_pendant_panel").hide();		
+    $("#niveau_panel").hide();		
+    $("#methode_panel").hide();		
+    $("#themes_panel").hide();    		
+    $("#objectifs_panel").hide();*/	
+            
+    $("#filiere").on("click", function() {		
+        $("#filiere_panel").toggle();		
+        return false;		
+    });		
+    
+    $("#dispo").on("click", function() {		
+        $("#dispo_panel").toggle();		
+        return false;		
+    });		
+    
+    $("#dispo_pendant").on("click", function() {		
+        $("#dispo_pendant_panel").toggle();		
+        return false;		
+    });			
+    
+    $("#niveau").on("click", function() {		
+        $("#niveau_panel").toggle();		
+        return false;		
+    });		
+    
+    $("#methode").on("click", function() {		
+        $("#methode_panel").toggle();		
+        return false;		
+    });		
+    
+    $("#themes").on("click", function() {		
+        $("#themes_panel").toggle();		
+        return false;		
+    });		
+    
+    $("#objectifs").on("click", function() {		
+        $("#objectifs_panel").toggle();		
+        return false;		
+    });		
+ });		
+ </script>';
+
 $panel = Display::panel(get_lang('FiliereExplanation'), '', '', '',  '', 'filiere_panel');
 $userForm->addHeader(Display::url(get_lang('Filiere'), '#', ['id'=> 'filiere']).''.$panel);
 $fieldsToShow = [
@@ -379,7 +426,21 @@ $extra = $extraFieldSession->addElements(
     null,
     true,
     $forceShowFields, // $forceShowFields
-    3
+    [ 'domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
+    [
+        'domaine' => [
+            get_lang('Domaine').' 1',
+            get_lang('Domaine').' 2',
+            get_lang('Domaine').' 3'
+        ],
+        $theme  => [
+            get_lang('Theme').' 1',
+            get_lang('Theme').' 2',
+            get_lang('Theme').' 3',
+            get_lang('Theme').' 4',
+            get_lang('Theme').' 5'
+        ],
+    ]
 );
 
 $jqueryExtra .= $extra['jquery_ready_content'];
@@ -475,7 +536,6 @@ if ($userForm->validate()) {
     $extraFieldValue = new ExtraFieldValue('user');
     $userData = $userForm->getSubmitValues();
     $userData['extra_diagnosis_completed'] = 1;
-
     $extraFieldValue->saveFieldValues($userData, $forceShowFields);
 
     // Saving to extra_field_saved_search