Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16769 Rev 16796
Línea 14... Línea 14...
14
use LeadersLinked\Mapper\DailyPulseEmojiMapper;
14
use LeadersLinked\Mapper\DailyPulseEmojiMapper;
15
use LeadersLinked\Form\DailyPulse\DailyPulseAddEmojiForm;
15
use LeadersLinked\Form\DailyPulse\DailyPulseAddEmojiForm;
16
use LeadersLinked\Form\DailyPulse\DailyPulseEditEmojiForm;
16
use LeadersLinked\Form\DailyPulse\DailyPulseEditEmojiForm;
17
use LeadersLinked\Model\DailyPulseEmoji;
17
use LeadersLinked\Model\DailyPulseEmoji;
18
use LeadersLinked\Library\Image;
18
use LeadersLinked\Library\Image;
-
 
19
use LeadersLinked\Form\DailyPulse\DailyPulseSetupForm;
-
 
20
use LeadersLinked\Model\Company;
-
 
21
use LeadersLinked\Model\DailyPulse;
-
 
22
use LeadersLinked\Mapper\DailyPulseMapper;
Línea 19... Línea 23...
19
 
23
 
20
class DailyPulseController extends AbstractActionController
24
class DailyPulseController extends AbstractActionController
21
{
25
{
22
    /**
26
    /**
Línea 76... Línea 80...
76
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
80
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
77
        ]);
81
        ]);
78
    }
82
    }
Línea -... Línea 83...
-
 
83
    
-
 
84
    
-
 
85
    public function setupAction()
-
 
86
    {
-
 
87
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
-
 
88
        $currentUser        = $currentUserPlugin->getUser();
-
 
89
        $currentCompany     = $currentUserPlugin->getCompany();
-
 
90
        
-
 
91
        $request            = $this->getRequest();
-
 
92
        
-
 
93
        
-
 
94
        if($request->isPost()) {
-
 
95
            if( $currentCompany->default_for_network == Company::DEFAULT_FOR_NETWORK_YES) {
-
 
96
                $value_options = [
-
 
97
                    DailyPulse::PRIVACY_COMPANY => 'LABEL_DAILY_PULSE_PRIVACY_COMPANY',
-
 
98
                    DailyPulse::PRIVACY_PUBLIC => 'LABEL_DAILY_PULSE_PRIVACY_PUBLIC',
-
 
99
                ];
-
 
100
            } else {
-
 
101
                $value_options = [
-
 
102
                    DailyPulse::PRIVACY_PUBLIC => 'LABEL_DAILY_PULSE_PRIVACY_PUBLIC',
-
 
103
                ];
-
 
104
            }
-
 
105
            
-
 
106
            $dataPost = $request->getPost()->toArray();
-
 
107
            $form = new DailyPulseSetupForm($value_options);
-
 
108
            $form->setData($dataPost);
-
 
109
            
-
 
110
            if($form->isValid()) {
-
 
111
                $dataPost = (array) $form->getData();
-
 
112
               
-
 
113
                $dailyPulseMapper = DailyPulseMapper::getInstance($this->adapter);
-
 
114
                $dailyPulse = $dailyPulseMapper->fetchOneByCompanyId($currentCompany->id);
-
 
115
                if($dailyPulse) {
-
 
116
                    $result = $dailyPulseMapper->update($dailyPulse);
-
 
117
                } else {
-
 
118
                    $dailyPulse = new DailyPulse();
-
 
119
                    $dailyPulse->company_id = $currentCompany->id;
-
 
120
                    $dailyPulse->privacy = $dataPost['privacy'];
-
 
121
                    
-
 
122
                    $result = $dailyPulseMapper->insert($dailyPulse);
-
 
123
                }
-
 
124
                
-
 
125
                
-
 
126
                if($result) {
-
 
127
                    $this->logger->info('Se actualizo la configuración del Pulso Diario ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
128
                    
-
 
129
                    $data = [
-
 
130
                        'success'   => true,
-
 
131
                        'data'   => 'LABEL_RECORD_UPDATED'
-
 
132
                    ];
-
 
133
                } else {
-
 
134
                    $data = [
-
 
135
                        'success'   => false,
-
 
136
                        'data'      => $dailyPulseMapper->getError()
-
 
137
                    ];
-
 
138
                    
-
 
139
                }
-
 
140
                
-
 
141
                return new JsonModel($data);
-
 
142
                
-
 
143
            } else {
-
 
144
                $messages = [];
-
 
145
                $form_messages = (array) $form->getMessages();
-
 
146
                foreach($form_messages  as $fieldname => $field_messages)
-
 
147
                {
-
 
148
                    
-
 
149
                    $messages[$fieldname] = array_values($field_messages);
-
 
150
                }
-
 
151
                
-
 
152
                return new JsonModel([
-
 
153
                    'success'   => false,
-
 
154
                    'data'   => $messages
-
 
155
                ]);
-
 
156
            }
-
 
157
        } if($request->isGet()) {
-
 
158
            if( $currentCompany->default_for_network == Company::DEFAULT_FOR_NETWORK_YES) {
-
 
159
                $value_options = [
-
 
160
                    DailyPulse::PRIVACY_COMPANY => 'LABEL_DAILY_PULSE_PRIVACY_COMPANY',
-
 
161
                    DailyPulse::PRIVACY_PUBLIC => 'LABEL_DAILY_PULSE_PRIVACY_PUBLIC',
-
 
162
                ]; 
-
 
163
            } else {
-
 
164
                $value_options = [
-
 
165
                    DailyPulse::PRIVACY_PUBLIC => 'LABEL_DAILY_PULSE_PRIVACY_PUBLIC',
-
 
166
                ]; 
-
 
167
            }
-
 
168
            
-
 
169
            $form = new DailyPulseSetupForm($value_options);
-
 
170
 
-
 
171
            $this->layout()->setTemplate('layout/layout-backend');
-
 
172
            $viewModel = new ViewModel();
-
 
173
            $viewModel->setTemplate('leaders-linked/daily-pulse/setup');
-
 
174
            $viewModel->setVariables([
-
 
175
                'form' => $form,
-
 
176
            ]);
-
 
177
            return $viewModel ;
-
 
178
 
-
 
179
        } else {
-
 
180
            $data = [
-
 
181
                'success' => false,
-
 
182
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
183
            ];
-
 
184
            
79
    
185
            return new JsonModel($data);
-
 
186
        }
-
 
187
        
Línea 80... Línea 188...
80
    
188
        return new JsonModel($data);