Proyectos de Subversion LeadersLinked - Services

Rev

Rev 307 | Rev 322 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 307 Rev 321
Línea 2870... Línea 2870...
2870
    public function habitsAndSkillsAction()
2870
    public function habitsAndSkillsAction()
2871
    {
2871
    {
2872
        $request = $this->getRequest();
2872
        $request = $this->getRequest();
2873
        $request = $this->getRequest();
2873
        $request = $this->getRequest();
2874
        if ($request->isGet()) {
2874
        if ($request->isGet()) {
-
 
2875
            
-
 
2876
            $items = [];
-
 
2877
            $search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
-
 
2878
            if(strlen($search) >= 3) {
-
 
2879
            
-
 
2880
                $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
2881
                $currentUser = $currentUserPlugin->getUser();
-
 
2882
                
-
 
2883
                
-
 
2884
                
-
 
2885
                $company_ids = [];
-
 
2886
                $habitUserMapper = \LeadersLinked\Mapper\HabitUserMapper::getInstance($this->adapter);
-
 
2887
                $records = $habitUserMapper->fetchAllActiveByUserId($currentUser->id);
-
 
2888
                foreach($records as $record)
-
 
2889
                {
-
 
2890
                    if($record->company_id) {
-
 
2891
                    
-
 
2892
                        if(!in_array($record->company_id, $company_ids)) {
-
 
2893
                            array_push($company_ids, $record->company_id);
-
 
2894
                        }
-
 
2895
                    }
-
 
2896
                }
-
 
2897
                
-
 
2898
                
-
 
2899
                if($company_ids) {
-
 
2900
                
-
 
2901
                    $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
-
 
2902
                    $records = $habitSkillMapper->fetchAllTemplateByCompayIds($company_ids);
-
 
2903
                    foreach($records as $record)
-
 
2904
                    {
-
 
2905
                        array_push($items, [
-
 
2906
                            'uuid'  => $record->uuid, 
-
 
2907
                            'name'  => $record->name, 
-
 
2908
                            'link'  =>  $this->url()->fromRoute('helpers/habits-and-skills/get', ['id' => $record->uuid], ['force_canonical' => true]),
-
 
2909
    
-
 
2910
    
-
 
2911
                            
-
 
2912
                        ]);
-
 
2913
                    }
-
 
2914
                }
-
 
2915
            } 
-
 
2916
            
-
 
2917
            
-
 
2918
            return new JsonModel([
-
 
2919
                'success' => true,
-
 
2920
                'data' => $items,
-
 
2921
            ]);
-
 
2922
            
-
 
2923
        }
-
 
2924
        return new JsonModel([
-
 
2925
            'success' => false,
-
 
2926
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
2927
        ]);
-
 
2928
    }
-
 
2929
    
-
 
2930
    public function habitsAndSkillsGetAction()
-
 
2931
    {
-
 
2932
        $request = $this->getRequest();
-
 
2933
        $request = $this->getRequest();
-
 
2934
        if ($request->isGet()) {
-
 
2935
            
2875
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2936
            $currentUserPlugin = $this->plugin('currentUserPlugin');
2876
            $currentUser = $currentUserPlugin->getUser();
2937
            $currentUser = $currentUserPlugin->getUser();
Línea -... Línea 2938...
-
 
2938
            
-
 
2939
           
-
 
2940
            $id = Functions::sanitizeFilterString($this->params()->fromRoute('id'));
-
 
2941
 
-
 
2942
            $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
-
 
2943
            $habitSkill = $habitSkillMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
2944
            
-
 
2945
 
-
 
2946
            if(!$habitSkill) {
-
 
2947
                return new JsonModel([
-
 
2948
                    'success' => true,
-
 
2949
                    'data' => 'ERROR_HABIT_NOT_FOUND'
-
 
2950
                ]);
-
 
2951
            }
-
 
2952
           
2877
            
2953
      
2878
            $company_ids = [];
2954
            $allow = false;
2879
            $habitUserMapper = \LeadersLinked\Mapper\HabitUserMapper::getInstance($this->adapter);
2955
            $habitUserMapper = \LeadersLinked\Mapper\HabitUserMapper::getInstance($this->adapter);
2880
            $records = $habitUserMapper->fetchAllActiveByUserId($currentUser->id);
2956
            $records = $habitUserMapper->fetchAllActiveByUserId($currentUser->id);
2881
            foreach($records as $record)
2957
            foreach($records as $record)
2882
            {
-
 
2883
                if($record->company_id) {
-
 
2884
                
-
 
2885
                    if(!in_array($record->company_id, $company_ids)) {
2958
            {
2886
                        array_push($company_ids, $record->company_id);
-
 
2887
                    }
-
 
2888
                }
-
 
2889
            }
-
 
2890
            
-
 
2891
            $items = [];
-
 
2892
            if($company_ids) {
-
 
2893
            
-
 
2894
                $habitSkillMapper = \LeadersLinked\Mapper\HabitSkillMapper::getInstance($this->adapter);
-
 
2895
                $records = $habitSkillMapper->fetchAllTemplateByCompayIds($company_ids);
-
 
2896
                foreach($records as $record)
-
 
2897
                {
-
 
2898
                    array_push($items, [
-
 
2899
                        'uuid'              => $record->uuid, 
-
 
2900
                        'name'              => $record->name, 
-
 
2901
                        'monday_active'     => $record->monday_active,
-
 
2902
                        'monday_time'       => $record->monday_time,
-
 
2903
                        'tuesday_active'    => $record->tuesday_active,
-
 
2904
                        'tuesday_time'      => $record->tuesday_time,
-
 
2905
                        'wednesday_active'  => $record->wednesday_active,
-
 
2906
                        'wednesday_time'    => $record->wednesday_time,
-
 
2907
                        'thursday_active'   => $record->thursday_active,
-
 
2908
                        'thursday_time'     => $record->thursday_time,
-
 
2909
                        'friday_active'     => $record->friday_active,
-
 
2910
                        'friday_time'       => $record->friday_time,
-
 
2911
                        'saturday_active'   => $record->saturday_active,
-
 
2912
                        'saturday_time'     => $record->saturday_time,
-
 
2913
                        'sunday_active'     => $record->sunday_active,
-
 
Línea -... Línea 2959...
-
 
2959
                if($habitSkill->company_id ==  $record->company_id) {
2914
                        'sunday_time'       => $record->sunday_time,
2960
                        
2915
                        
2961
                    $allow = true;
2916
                    ]);
2962
                    break;
Línea -... Línea 2963...
-
 
2963
                }
-
 
2964
            }
-
 
2965
            
-
 
2966
            if(!$allow) {
-
 
2967
                return new JsonModel([
-
 
2968
                    'success' => true,
2917
                }
2969
                    'data' => 'ERROR_HABIT_YOU_DO_NOT_HAVE_ACCESS_TO_THIS'
2918
            }
2970
                ]);
2919
            
2971
            }
2920
            
2972
                
-
 
2973
            return new JsonModel([
-
 
2974
                'success' => true,
-
 
2975
                'data' =>[
-
 
2976
                    'uuid'              => $habitSkill->uuid,
-
 
2977
                    'name'              => $habitSkill->name,
-
 
2978
                    'description'       => $habitSkill->description,
-
 
2979
                    'intelligence'      => $habitSkill->intelligence,
-
 
2980
                    'monday_active'     => $habitSkill->monday_active,
-
 
2981
                    'monday_time'       => $habitSkill->monday_time,
-
 
2982
                    'tuesday_active'    => $habitSkill->tuesday_active,
-
 
2983
                    'tuesday_time'      => $habitSkill->tuesday_time,
-
 
2984
                    'wednesday_active'  => $habitSkill->wednesday_active,
-
 
2985
                    'wednesday_time'    => $habitSkill->wednesday_time,
-
 
2986
                    'thursday_active'   => $habitSkill->thursday_active,
-
 
2987
                    'thursday_time'     => $habitSkill->thursday_time,
-
 
2988
                    'friday_active'     => $habitSkill->friday_active,
-
 
2989
                    'friday_time'       => $habitSkill->friday_time,
-
 
2990
                    'saturday_active'   => $habitSkill->saturday_active,
-
 
2991
                    'saturday_time'     => $habitSkill->saturday_time,
-
 
2992
                    'sunday_active'     => $habitSkill->sunday_active,
-
 
2993
                    'sunday_time'       => $habitSkill->sunday_time,
-
 
2994
                    
-
 
2995
                    'quantitative_value' => $habitSkill->quantitative_value,
-
 
2996
                    'qualitative_description' => $habitSkill->qualitative_description,
-
 
2997
                    'notification_10min_before' => $habitSkill->notification_10min_before,
-
 
2998
                    'notification_30min_before' => $habitSkill->notification_30min_before,
2921
            return new JsonModel([
2999
                    
Línea 2922... Línea 3000...
2922
                'success' => true,
3000
                    
2923
                'data' => $items,
3001
                ],
2924
            ]);
3002
            ]);