Эх сурвалжийг харах

Merge branch 'ofaj' of github.com:chamilo/chamilo-lms into ofaj

Angel Fernando Quiroz Campos 8 жил өмнө
parent
commit
21a7920bd0

+ 281 - 27
load_search.php

@@ -117,6 +117,114 @@ if ($userToLoadInfo) {
     }
 }
 
+$extraFieldUser = new ExtraField('user');
+
+$userForm = new FormValidator('user_form', 'post', api_get_self());
+$panel = Display::panel(get_lang('FiliereExplanation'), '', '', '',  '', 'filiere_panel');
+$userForm->addHeader(Display::url(get_lang('Filiere'), '#', ['id'=> 'filiere']).''.$panel);
+$fieldsToShow = [
+    'statusocial',
+    'filiere_user',
+    'filiereprecision',
+    'filiere_want_stage',
+];
+$forceShowFields = true;
+$filter = false;
+$extra = $extraFieldUser->addElements(
+    $userForm,
+    $userToLoad,
+    [],
+    $filter,
+    true,
+    $fieldsToShow,
+    $fieldsToShow,
+    [],
+    [],
+    false,
+    $forceShowFields, //$forceShowFields = false
+    [],
+    [],
+    $fieldsToShow
+);
+
+$panel = Display::panel(get_lang('DisponibilitePendantMonStageExplanation'), '', '', '',  '', 'dispo_pendant_panel');
+$userForm->addHeader(Display::url(get_lang('DisponibilitePendantMonStage'), '#', ['id'=> 'dispo_pendant']).''.$panel);
+
+$fieldsToShow = [
+    'datedebutstage',
+    'datefinstage',
+    'poursuiteapprentissagestage',
+    'heures_disponibilite_par_semaine_stage'
+];
+
+$extra = $extraFieldUser->addElements(
+    $userForm,
+    $userToLoad,
+    [],
+    $filter,
+    true,
+    $fieldsToShow,
+    $fieldsToShow,
+    [],
+    [],
+    false,
+    $forceShowFields, //$forceShowFields = false
+    [],
+    [],
+    $fieldsToShow
+);
+
+
+$panel = Display::panel(get_lang('ObjectifsApprentissageExplanation'), '', '', '',  '', 'objectifs_panel');
+$userForm->addHeader(Display::url(get_lang('ObjectifsApprentissage'), '#', ['id'=> 'objectifs']).''.$panel);
+
+$fieldsToShow = [
+    'objectif_apprentissage'
+];
+
+$extra = $extraFieldUser->addElements(
+    $userForm,
+    $userToLoad,
+    [],
+    $filter,
+    false,
+    $fieldsToShow,
+    $fieldsToShow,
+    [],
+    [],
+    false,
+    $forceShowFields,//$forceShowFields = false
+    [],
+    [],
+    $fieldsToShow
+);
+
+
+$panel = Display::panel(get_lang('MethodeTravailExplanation'), '', '', '',  '', 'methode_panel');
+$userForm->addHeader(Display::url(get_lang('MethodeTravail'), '#', ['id'=> 'methode']).''.$panel);
+
+$fieldsToShow = [
+    'methode_de_travaille',
+    'accompagnement'
+];
+
+$extra = $extraFieldUser->addElements(
+    $userForm,
+    $userToLoad,
+    [],
+    $filter,
+    true,
+    $fieldsToShow,
+    $fieldsToShow,
+    [],
+    [],
+    false,
+    $forceShowFields, //$forceShowFields = false
+    [],
+    [],
+    $fieldsToShow
+);
+
 
 // Session fields
 $showOnlyThisFields = [
@@ -132,7 +240,6 @@ $showOnlyThisFields = [
     's_exprimer_oralement_en_continu',
     'ecrire'
 ];
-//$showOnlyThisFields = [];
 
 $extra = $extraField->addElements(
     $form,
@@ -144,11 +251,12 @@ $extra = $extraField->addElements(
     $showOnlyThisFields,
     $defaults,
     [],
-    false,
+    false, //$orderDependingDefaults
     true // force
 );
 
-$form->addButtonSearch(get_lang('Search'), 'save');
+$form->addButtonSearch(get_lang('Search'), 'search');
+$form->addButtonSave(get_lang('Save'), 'save');
 
 $extraFieldsToFilter = $extraField->get_all(array('variable = ?' => 'temps-de-travail'));
 $extraFieldToSearch = array();
@@ -201,39 +309,159 @@ if ($formSearch->validate()) {
 
 if ($form->validate()) {
     $params = $form->getSubmitValues();
+    $save = false;
+    $search = false;
+    if (isset($params['search'])) {
+        unset($params['search']);
+        $search = true;
+    }
+
     if (isset($params['save'])) {
+        $save = true;
         unset($params['save']);
     }
+
     $form->setDefaults($params);
 
-    // Search
     $filters = [];
-    // Parse params.
-    foreach ($params as $key => $value) {
-        if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
-            continue;
+
+    // Search
+    if ($search) {
+        // Parse params.
+        foreach ($params as $key => $value) {
+            if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
+                continue;
+            }
+            if (!empty($value)) {
+                $filters[$key] = $value;
+            }
         }
-        if (!empty($value)) {
-            $filters[$key] = $value;
+
+        $filterToSend = [];
+        if (!empty($filters)) {
+            $filterToSend = ['groupOp' => 'AND'];
+            if ($filters) {
+                $count = 1;
+                $countExtraField = 1;
+                foreach ($result['column_model'] as $column) {
+                    if ($count > 5) {
+                        if (isset($filters[$column['name']])) {
+                            $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
+                            $filterToSend['rules'][] = [
+                                'field' => $column['name'],
+                                'op' => 'cn',
+                                'data' => $filters[$column['name']]
+                            ];
+                        }
+                        $countExtraField++;
+                    }
+                    $count++;
+                }
+            }
         }
     }
-    $filterToSend = [];
-    if (!empty($filters)) {
-        $filterToSend = ['groupOp' => 'AND'];
-        if ($filters) {
-            $count = 1;
-            $countExtraField = 1;
-            foreach ($result['column_model'] as $column) {
-                if ($count > 5) {
-                    if (isset($filters[$column['name']])) {
-                        $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
-                        $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
-                    }
-                    $countExtraField++;
+
+    if ($save) {
+
+        /** @var \Chamilo\UserBundle\Entity\User $user */
+        $user = $em->getRepository('ChamiloUserBundle:User')->find($userToLoad);
+        $extraFieldValueSession = new ExtraFieldValue('session');
+
+        $sessionFields = [
+            'extra_access_start_date',
+            'extra_access_end_date',
+            'extra_filiere',
+            'extra_domaine',
+            'extra_domaine[0]',
+            'extra_domaine[1]',
+            'extra_domaine[3]',
+            'extra_temps-de-travail',
+            //'extra_competenceniveau',
+            'extra_'.$theme,
+            'extra_ecouter',
+            'extra_lire',
+            'extra_participer_a_une_conversation',
+            'extra_s_exprimer_oralement_en_continu',
+            'extra_ecrire'
+        ];
+
+        $userData = $params;
+
+        foreach ($userData as $key => $value) {
+
+
+            $found = strpos($key, '__persist__');
+            if ($found === false) {
+                continue;
+            }
+
+
+        }
+
+        if (isset($userData['extra_filiere_want_stage']) &&
+            isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
+        ) {
+            $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
+
+            if ($wantStage === 'yes') {
+                if (isset($userData['extra_filiere_user'])) {
+                    $userData['extra_filiere'] = [];
+                    $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
                 }
-                $count++;
             }
         }
+
+        // save in ExtraFieldSavedSearch.
+        foreach ($userData as $key => $value) {
+            if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
+                continue;
+            }
+
+            if (!in_array($key, $sessionFields)) {
+                continue;
+            }
+
+            $field_variable = substr($key, 6);
+            $extraFieldInfo = $extraFieldValueSession
+                ->getExtraField()
+                ->get_handler_field_info_by_field_variable($field_variable);
+
+            if (!$extraFieldInfo) {
+                continue;
+            }
+
+            $extraFieldObj = $em->getRepository('ChamiloCoreBundle:ExtraField')->find($extraFieldInfo['id']);
+
+            $search = [
+                'field' => $extraFieldObj,
+                'user' => $user
+            ];
+
+            /** @var ExtraFieldSavedSearch $saved */
+            $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
+
+            if ($saved) {
+                $saved
+                    ->setField($extraFieldObj)
+                    ->setUser($user)
+                    ->setValue($value)
+                ;
+                $em->merge($saved);
+            } else {
+                $saved = new ExtraFieldSavedSearch();
+                $saved
+                    ->setField($extraFieldObj)
+                    ->setUser($user)
+                    ->setValue($value)
+                ;
+                $em->persist($saved);
+            }
+            $em->flush();
+        }
+        Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
+        header('Location: '.api_get_self().'?user_id='.$userToLoad);
+        exit;
+
     }
 }
 
@@ -256,7 +484,25 @@ $(function() {
 });
 </script>';
 
+
+
 if (!empty($filterToSend)) {
+    $userStartDate = $params['extra_access_start_date'];
+    $date = new DateTime($userStartDate);
+    $date->sub(new DateInterval('P3D'));
+    $userStartDateMinus = $date->format('Y-m-d h:i:s');
+
+    $userEndDate = $params['extra_access_end_date'];
+    $date = new DateTime($userEndDate);
+    $date->add(new DateInterval('P2D'));
+    $userEndDatePlus = $date->format('Y-m-d h:i:s');
+
+    $sql = " AND (
+        (s.access_start_date > '$userStartDateMinus' AND s.access_start_date < '$userEndDatePlus') OR
+        (s.access_start_date > '$userStartDateMinus' AND (s.access_start_date = '' OR s.access_start_date IS NULL)) OR 
+        ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
+    )";
+    $filterToSend['custom_dates'] = $sql;
     $filterToSend = json_encode($filterToSend);
     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='.$extraFieldListToString.'&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters2='.$filterToSend;
 } else {
@@ -294,7 +540,16 @@ $action_links = 'function action_formatter(cellvalue, options, rowObject) {
 
 $htmlHeadXtra[] = api_get_jqgrid_js();
 
-$griJs = Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
+$griJs = Display::grid_js(
+    'sessions',
+    $url,
+    $columns,
+    $column_model,
+    $extra_params,
+    array(),
+    $action_links,
+    true
+);
 $grid = '<div id="session-table" class="table-responsive">';
 $grid .= Display::grid_html('sessions');
 $grid .= '</div>';
@@ -307,7 +562,7 @@ if (empty($items)) {
     $griJs = '';
 }
 $tpl->assign('form', $view);
-$tpl->assign('form_search', $formSearch->returnForm());
+$tpl->assign('form_search', $formSearch->returnForm().$userForm->returnForm());
 
 $table = new HTML_Table(array('class' => 'data_table'));
 $column = 0;
@@ -343,7 +598,6 @@ if ($data) {
         if (isset($formData['extra_access_start_date']) && isset($formData['extra_access_end_date'])) {
             $startDate = $formData['extra_access_start_date'];
             $endDate = $formData['extra_access_end_date'];
-
             $numberWeeks = dateDiffInWeeks($startDate, $endDate);
         }
     } else {

+ 5 - 6
main/inc/ajax/model.ajax.php

@@ -159,7 +159,6 @@ if ((isset($_REQUEST['filters2']) && $forceSearch) || ($search || $forceSearch)
                         unset($filters->rules[$key]);
                     }
                 }
-
                 $result = $extraField->getExtraFieldRules($filters, 'extra_');
 
                 $extra_fields = $result['extra_fields'];
@@ -187,8 +186,11 @@ if ((isset($_REQUEST['filters2']) && $forceSearch) || ($search || $forceSearch)
                     // Remove conditions already added
                     $extraQuestionCondition = str_replace($extraCondition, '', $extraQuestionCondition);
                 }
-
                 $whereCondition .= $extraQuestionCondition;
+
+                if (isset($filters->custom_dates)) {
+                    $whereCondition .= $filters->custom_dates;
+                }
             }
         } elseif (!empty($filters->rules)) {
             $whereCondition .= ' AND ( ';
@@ -482,8 +484,6 @@ switch ($action) {
         break;
     case 'get_sessions':
         $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
-
-
         $loadExtraFields = isset($_REQUEST['load_extra_field']) ? $_REQUEST['load_extra_field'] : '';
         if (!empty($loadExtraFields)) {
             $loadExtraFields = explode(',', $loadExtraFields);
@@ -496,7 +496,6 @@ switch ($action) {
         }
 
         if ($list_type === 'simple') {
-
             $count = SessionManager::get_sessions_admin(
                 array('where' => $whereCondition, 'extra' => $extra_fields),
                 true,
@@ -893,7 +892,7 @@ switch ($action) {
         } else {
             $columns = array(
                 //'type',
-                'fullname',               
+                'fullname',
                 'title',
                 'qualification',
                 'sent_date',

+ 17 - 6
main/inc/lib/extra_field.lib.php

@@ -453,7 +453,8 @@ class ExtraField extends Model
         $orderDependingDefaults = false,
         $forceShowFields = false,
         $separateExtraMultipleSelect = [],
-        $customLabelsExtraMultipleSelect = []
+        $customLabelsExtraMultipleSelect = [],
+        $fieldsToFreeze = []
     ) {
         if (empty($form)) {
             return false;
@@ -491,7 +492,8 @@ class ExtraField extends Model
             $specialUrlList,
             $orderDependingDefaults,
             $separateExtraMultipleSelect,
-            $customLabelsExtraMultipleSelect
+            $customLabelsExtraMultipleSelect,
+            $fieldsToFreeze
         );
 
         return $extra;
@@ -818,7 +820,8 @@ class ExtraField extends Model
         $specialUrlList = [],
         $orderDependingDefaults = false,
         $separateExtraMultipleSelect = [],
-        $customLabelsExtraMultipleSelect = []
+        $customLabelsExtraMultipleSelect = [],
+        $fieldsToFreeze = []
     ) {
         $type = $this->type;
         $jquery_ready_content = '';
@@ -922,6 +925,7 @@ class ExtraField extends Model
                                 );
                             }
                         }
+
                         $form->addGroup(
                             $group,
                             'extra_'.$field_details['variable'],
@@ -1925,6 +1929,12 @@ EOF;
                         ');
                         break;
                 }
+
+                if (in_array($field_details['variable'], $fieldsToFreeze)) {
+                    $form->freeze(
+                        'extra_'.$field_details['variable']
+                    );
+                }
             }
         }
 
@@ -2523,8 +2533,10 @@ JAVASCRIPT;
         if ($oper == 'ew' || $oper == 'en') {
             $val = '%'.$val;
         }
+
         if ($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') {
-            if (is_array($val)) {
+            if (is_array($val) || is_object($val)) {
+                $val = (array) $val;
                 $result = '"%'.implode(';', $val).'%"';
                 foreach ($val as $item) {
                     $result .= ' OR '.$col.' LIKE "%'.$item.'%"';
@@ -2562,7 +2574,6 @@ JAVASCRIPT;
         }
 
         $condition_array = array();
-
         foreach ($filters->rules as $rule) {
             if (strpos($rule->field, $stringToSearch) === false) {
                 // normal fields
@@ -2595,7 +2606,7 @@ JAVASCRIPT;
                         }
                     } else {
                         if (isset($rule->data)) {
-                            if ($rule->data == -1) {
+                            if ($rule->data === -1) {
                                 continue;
                             }
                             $condition_array[] = ' ('.$this->get_where_clause($rule->field, $rule->op, $rule->data).') ';

+ 0 - 4
main/inc/lib/sessionmanager.lib.php

@@ -519,7 +519,6 @@ class SessionManager
 
         $query .= $order;
         $query .= $limit;
-
         $result = Database::query($query);
 
         $categories = self::get_all_session_category();
@@ -7599,9 +7598,6 @@ class SessionManager
             $query .= " ORDER BY ".$options['order'];
         }
 
-        //error_log($query);
-        //echo $query;
-
         $result = Database::query($query);
         $formatted_sessions = array();
 

+ 2 - 0
search.php

@@ -605,6 +605,8 @@ if ($userForm->validate()) {
             continue;
         }
 
+
+
         $extraFieldObj = $em->getRepository('ChamiloCoreBundle:ExtraField')->find($extraFieldInfo['id']);
 
         $search = [