Proyectos de Subversion LeadersLinked - Services

Rev

Rev 775 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 775 Rev 776
Línea 96... Línea 96...
96
    
96
    
97
    
97
    
-
 
98
 
-
 
99
    public function viewAction()
-
 
100
    {
-
 
101
        // Validaciones iniciales
-
 
102
        $validationResponse = $this->validateViewRequest();
-
 
103
        if ($validationResponse) {
-
 
104
            return $validationResponse;
-
 
105
        }
-
 
106
        
-
 
107
        $id = $this->params()->fromRoute('id');
-
 
108
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
109
        $currentUser = $currentUserPlugin->getUser();
-
 
110
        
-
 
111
        // Obtener y validar empresa
-
 
112
        $company = $this->getAndValidateCompany($id, $currentUser->network_id);
-
 
113
        if ($company instanceof JsonModel) {
-
 
114
            return $company; // Error response
-
 
115
        }
-
 
116
        
-
 
117
        // Construir datos de respuesta
-
 
118
        $data = $this->buildCompanyResponseData($company, $currentUser);
-
 
119
        
-
 
120
        return new JsonModel([
-
 
121
            'success' => true,
-
 
122
            'data' => $data
-
 
123
        ]); 
-
 
124
    }
-
 
125
 
-
 
126
    /**
-
 
127
     * Valida la petición de visualización
98
 
128
     */
Línea 99... Línea 129...
99
    public function viewAction()
129
    private function validateViewRequest()
100
    {
130
    {
101
        $request = $this->getRequest();
131
        $request = $this->getRequest();
102
 
132
 
103
        if(!$request->isGet()) {
133
        if (!$request->isGet()) {
104
            return new JsonModel([
134
            return new JsonModel([
Línea 105... Línea 135...
105
                'success' => false,
135
                'success' => false,
106
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
107
            ]);
136
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
108
        }
137
            ]);
109
        
138
        }
110
        $id = $this->params()->fromRoute('id');
139
        
111
 
140
        $id = $this->params()->fromRoute('id');
112
        if(!$id) {
141
        if (!$id) {
Línea 113... Línea -...
113
            return new JsonModel([
-
 
114
                'success' => false,
142
            return new JsonModel([
-
 
143
                'success' => false,
115
                'data' => 'ERROR_INVALID_PARAMETER'
144
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
145
            ]);
-
 
146
        }
-
 
147
        
-
 
148
        return null; // No error
-
 
149
    }
116
            ]);
150
 
117
        }
151
    /**
Línea 118... Línea 152...
118
        
152
     * Obtiene y valida la empresa
119
        $currentUserPlugin = $this->plugin('currentUserPlugin');
153
     */
120
        $currentUser = $currentUserPlugin->getUser();
154
    private function getAndValidateCompany($id, $networkId)
121
        
155
    {
122
        $companyMapper = CompanyMapper::getInstance($this->adapter);
156
        $companyMapper = CompanyMapper::getInstance($this->adapter);
123
        $company = $companyMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
157
        $company = $companyMapper->fetchOneByUuidAndNetworkId($id, $networkId);
Línea 124... Línea 158...
124
        
158
        
125
        if(!$company) {  
159
        if (!$company) {  
126
            return new JsonModel([
160
            return new JsonModel([
127
                'success' => false,
161
                'success' => false,
128
                'data' => 'ERROR_COMPANY_NOT_FOUND'
162
                'data' => 'ERROR_COMPANY_NOT_FOUND'
129
            ]);
163
            ]);
Línea -... Línea 164...
-
 
164
        }
-
 
165
        
-
 
166
        if ($company->status != Company::STATUS_ACTIVE) {
-
 
167
            return new JsonModel([
-
 
168
                'success' => false,
-
 
169
                'data' => 'ERROR_COMPANY_IS_NOT_ACTIVE'
-
 
170
            ]); 
-
 
171
        }
-
 
172
        
-
 
173
        return $company;
-
 
174
    }
-
 
175
 
-
 
176
    /**
-
 
177
     * Construye todos los datos de respuesta de la empresa
-
 
178
     */
-
 
179
    private function buildCompanyResponseData($company, $currentUser)
-
 
180
    {
-
 
181
        $locations = $this->getCompanyLocations($company->id);
-
 
182
        $industryAndSize = $this->getCompanyIndustryAndSize($company);
-
 
183
        $followerInfo = $this->getFollowerInfo($company->id, $currentUser->id);
-
 
184
        $ownerContactInfo = $this->getOwnerContactInfo($company->id, $currentUser->id);
-
 
185
        
-
 
186
        $storage = Storage::getInstance($this->config, $this->adapter);
-
 
187
        
-
 
188
        // Datos base de la empresa
-
 
189
        $data = [
-
 
190
            'link_follow' => '',
-
 
191
            'link_unfollow' => '',
-
 
192
            'link_request' => '',
-
 
193
            'link_accept' => '',
-
 
194
            'link_cancel' => '',
-
 
195
            'link_reject' => '',
-
 
196
            'link_leave' => '',
-
 
197
            'link_timeline' => $this->url()->fromRoute('feed/timeline', ['id' => $company->uuid, 'type' => 'company']),
-
 
198
            'total_followers' => $followerInfo['total_followers'],
-
 
199
            'company_name' => $company->name,
-
 
200
            'company_uuid' => $company->uuid,
-
 
201
            'name' => trim($company->name),
-
 
202
            'image' => $storage->getCompanyImage($company),
-
 
203
            'cover' => $storage->getCompanyCover($company),
-
 
204
            'overview' => $company->description,
-
 
205
            'website' => $company->website,
-
 
206
            'foundation_year' => $company->foundation_year,
-
 
207
            'facebook' => $company->facebook,
-
 
208
            'instagram' => $company->instagram,
-
 
209
            'twitter' => $company->twitter,
-
 
210
            'locations' => $locations,
-
 
211
            'industry' => $industryAndSize['industry'],
-
 
212
            'company_size' => $industryAndSize['company_size'],
-
 
213
            'is_follower' => $followerInfo['is_follower'],
-
 
214
            'link_inmail' => $ownerContactInfo['link_inmail'],
-
 
215
            'show_contact' => $ownerContactInfo['show_contact'],
-
 
216
        ];
-
 
217
        
-
 
218
        // Agregar enlaces de acciones según relación usuario-empresa
-
 
219
        $this->addUserCompanyActionLinks($data, $company, $currentUser);
-
 
220
        $this->addFollowActionLinks($data, $company, $currentUser);
130
        }
221
        
131
        
222
        return $data;
Línea 132... Línea 223...
132
        if($company->status != Company::STATUS_ACTIVE) {
223
    }
133
            return new JsonModel([
224
 
134
                'success' => false,
-
 
135
                'data' => 'ERROR_COMPANY_IS_NOT_ACTIVE'
225
    /**
136
            ]); 
226
     * Obtiene las ubicaciones de la empresa
137
        }
227
     */
138
        
228
    private function getCompanyLocations($companyId)
139
        $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
229
    {
140
        $records = $companyLocationMapper->fetchAllLocationByCompanyId($company->id);
-
 
141
        
-
 
142
        $locations = [];
230
        $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
Línea -... Línea 231...
-
 
231
        $records = $companyLocationMapper->fetchAllLocationByCompanyId($companyId);
-
 
232
        
-
 
233
        $locations = [];
-
 
234
        foreach ($records as $record) {
-
 
235
            $locations[] = [
-
 
236
                'formatted_address' => $record['formatted_address'],
-
 
237
                'country' => $record['country'],
-
 
238
                'is_main' => $record['is_main'],
143
        foreach($records as $record)
239
            ];
144
        {
240
        }
Línea 145... Línea 241...
145
            $location =  [
241
        
146
                'formatted_address'  => $record['formatted_address'],
242
        return $locations;
Línea -... Línea 243...
-
 
243
    }
-
 
244
 
-
 
245
    /**
-
 
246
     * Obtiene información de industria y tamaño de la empresa
-
 
247
     */
-
 
248
    private function getCompanyIndustryAndSize($company)
-
 
249
    {
-
 
250
        $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
251
        $industry = $industryMapper->fetchOne($company->industry_id);
-
 
252
        
-
 
253
        $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
147
                'country' => $record['country'],
254
        $companySize = $companySizeMapper->fetchOne($company->company_size_id);
148
                'is_main' => $record['is_main'],
255
        
149
            ];
256
        return [
150
            
-
 
151
            array_push($locations, $location);
-
 
Línea -... Línea 257...
-
 
257
            'industry' => $industry->name,
-
 
258
            'company_size' => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee . ')'
-
 
259
        ];
-
 
260
    }
-
 
261
 
-
 
262
    /**
-
 
263
     * Obtiene información de seguimiento de la empresa
-
 
264
     */
-
 
265
    private function getFollowerInfo($companyId, $userId)
-
 
266
    {
-
 
267
        $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
-
 
268
        $totalFollowers = $companyFollowerMapper->getCountFollowers($companyId);
152
        }
269
        $follower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($companyId, $userId);
153
        
270
        
-
 
271
        return [
-
 
272
            'total_followers' => $totalFollowers,
-
 
273
            'is_follower' => $follower ? 1 : 0,
-
 
274
            'follower_record' => $follower
154
        $industryMapper = IndustryMapper::getInstance($this->adapter);
275
        ];
155
        $industry = $industryMapper->fetchOne($company->industry_id);
276
    }
156
        
277
 
-
 
278
    /**
157
        $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
279
     * Obtiene información de contacto del propietario de la empresa
158
        $companySize = $companySizeMapper->fetchOne($company->company_size_id);
280
     */
159
        
281
    private function getOwnerContactInfo($companyId, $currentUserId)
Línea -... Línea 282...
-
 
282
    {
160
        $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
283
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
-
 
284
        $companyUserOwner = $companyUserMapper->fetchOwnerByCompanyId($companyId);
-
 
285
        
-
 
286
        $linkInmail = '';
161
        $total_followers = $companyFollowerMapper->getCountFollowers($company->id);
287
        $showContact = 1;
162
        $follower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
-
 
163
        
-
 
164
        $link_inmail = '';
288
        
165
        
-
 
166
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
-
 
Línea 167... Línea 289...
167
        $companyUserOwner = $companyUserMapper->fetchOwnerByCompanyId($company->id);
289
        if ($companyUserOwner) {
168
        if($companyUserOwner) {
-
 
169
            $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
290
            $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
170
            $userBlocked = $userBlockedMapper->fetchOneByUserIdAndBlockedId($currentUser->id, $companyUserOwner->user_id);
-
 
171
            if(!$userBlocked) {
-
 
172
                $userMapper = UserMapper::getInstance($this->adapter);
291
            $userBlocked = $userBlockedMapper->fetchOneByUserIdAndBlockedId($currentUserId, $companyUserOwner->user_id);
173
                $userOwner = $userMapper->fetchOne($companyUserOwner->user_id);
-
 
174
                
-
 
175
                $link_inmail = $this->url()->fromRoute('inmail/user',['id' => $userOwner->uuid]);
-
 
176
            }
-
 
177
        } else {
-
 
178
            $userBlocked = false;
-
 
179
        }
-
 
180
            
-
 
181
        $storage = Storage::getInstance($this->config, $this->adapter);
-
 
182
        
-
 
183
        $data = [
-
 
184
            'link_follow' => '',
-
 
185
            'link_unfollow' => '',
-
 
186
            'link_request' => '',
-
 
187
            'link_accept' => '',
292
            
188
            'link_cancel' => '',
-
 
189
            'link_reject' =>'',
-
 
190
            'link_leave' => '',
-
 
191
            'link_timeline' => $this->url()->fromRoute('feed/timeline', ['id' => $company->uuid, 'type' => 'company']),
-
 
192
            'total_followers'       => $total_followers,
-
 
193
            'company_name'          => $company->name,
-
 
194
            'company_uuid'          => $company->uuid,
293
            if (!$userBlocked) {
-
 
294
                $userMapper = UserMapper::getInstance($this->adapter);
195
            'name'                  => trim($company->name),
295
                $userOwner = $userMapper->fetchOne($companyUserOwner->user_id);
-
 
296
                
-
 
297
                if ($userOwner) {
-
 
298
                    $linkInmail = $this->url()->fromRoute('inmail/user', ['id' => $userOwner->uuid]);
-
 
299
                }
-
 
300
            } else {
-
 
301
                $showContact = 0;
196
            'image'                 => $storage->getCompanyImage($company),
302
            }
-
 
303
        }
197
            'cover'                 => $storage->getCompanyCover($company),
304
        
-
 
305
        return [
198
            'overview'              => $company->description,
306
            'link_inmail' => $linkInmail,
199
            'website'               => $company->website,
307
            'show_contact' => $showContact,
200
            'foundation_year'       => $company->foundation_year,
308
            'owner_record' => $companyUserOwner
201
            'facebook'              => $company->facebook,
309
        ];
-
 
310
    }
202
            'instagram'             => $company->instagram,
311
 
203
            'twitter'               => $company->twitter,
312
    /**
204
            'locations'             => $locations,
313
     * Agrega enlaces de acciones relacionadas con la membresía de empresa
-
 
314
     */
-
 
315
    private function addUserCompanyActionLinks(&$data, $company, $currentUser)
205
            'industry'              => $industry->name,
316
    {
206
            'company_size'          => $companySize->name . ' (' . $companySize->minimum_no_of_employee . '-'  . $companySize->maximum_no_of_employee . ')',
317
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
207
            'is_follower'           => $follower ? 1 : 0,
318
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
-
 
319
        
-
 
320
        if ($companyUser) {
208
            'link_inmail'           => $link_inmail,
321
            switch ($companyUser->status) {
209
            'show_contact'          => $userBlocked ? 0 : 1,
322
                case CompanyUser::STATUS_ADMIN_WILL_ADD:
-
 
323
                    $data['link_accept'] = $this->url()->fromRoute('company/accept', ['id' => $company->uuid]);
210
        ];
324
                    $data['link_reject'] = $this->url()->fromRoute('company/reject', ['id' => $company->uuid]);
211
        
-
 
212
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
-
 
213
        if($companyUser) {
325
                    break;
214
            if($companyUser->status == CompanyUser::STATUS_ADMIN_WILL_ADD) {
326
                    
215
                $data['link_accept'] = $this->url()->fromRoute('company/accept', ['id' => $company->uuid]);
327
                case CompanyUser::STATUS_SENT:
-
 
328
                    $data['link_cancel'] = $this->url()->fromRoute('company/cancel', ['id' => $company->uuid]);
-
 
329
                    break;
-
 
330
                    
-
 
331
                case CompanyUser::STATUS_ACCEPTED:
-
 
332
                    if ($companyUser->owner == CompanyUser::OWNER_NO && $companyUser->creator == CompanyUser::CREATOR_NO) {
-
 
333
                        $data['link_leave'] = $this->url()->fromRoute('company/leave', ['id' => $company->uuid]);
-
 
334
                    }
-
 
335
                    break;
Línea 216... Línea -...
216
                $data['link_reject'] = $this->url()->fromRoute('company/reject', ['id' => $company->uuid]);
-
 
217
            }
-
 
218
            if($companyUser->status == CompanyUser::STATUS_SENT) {
-
 
219
                $data['link_cancel'] = $this->url()->fromRoute('company/cancel', ['id' => $company->uuid]);
-
 
220
            }
336
                    
221
            if($companyUser->owner == CompanyUser::OWNER_NO && $companyUser->creator == CompanyUser::CREATOR_NO && $companyUser->status == CompanyUser::STATUS_ACCEPTED) {
337
                case CompanyUser::STATUS_CANCELLED:
222
                $data['link_leave'] = $this->url()->fromRoute('company/leave', ['id' => $company->uuid]);;
338
                    $data['link_request'] = $this->url()->fromRoute('company/request', ['id' => $company->uuid]);
223
            }
339
                    break;
224
            if($companyUser->status == CompanyUser::STATUS_CANCELLED) {
-
 
225
                $data['link_request'] = $this->url()->fromRoute('company/request', ['id' => $company->uuid]);;
340
            }
226
            }
-
 
227
            
-
 
228
            
-
 
229
        } else {
-
 
230
            $data['link_request'] = $this->url()->fromRoute('company/request', ['id' => $company->uuid]);;
-
 
231
        }
-
 
232
        
-
 
233
        /* $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
-
 
234
        $data['total_followers'] = $companyFollowerMapper->getCountFollowers($company->id);
-
 
235
        
-
 
236
        $follower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
-
 
237
        if($follower) {
-
 
238
            $data['link_unfollow'] = $this->url()->fromRoute('company/unfollow', ['id' => $company->uuid]);;
-
 
239
        } else {
-
 
240
            $data['link_follow'] = $this->url()->fromRoute('company/follow', ['id' => $company->uuid]);
341
        } else {
Línea 241... Línea 342...
241
            
342
            $data['link_request'] = $this->url()->fromRoute('company/request', ['id' => $company->uuid]);
242
        }
343
        }
243
        
344
    }