public function applyAction() { /** @var Request $request */ $request = $this->getRequest(); $result = ['status' => 'error', 'msg' => 'Unable to save application. Please try again later.']; try { if ($request->isPost() && $request->isXmlHttpRequest()) { /** @var \DDD\Service\Website\Job $jobService */ $jobService = $this->getServiceLocator()->get('service_website_job'); $form = new JobsForm('announcement-form'); $inputs = $request->getPost()->toArray(); $validateTags = ClassicValidator::checkScriptTags($inputs); if (!$validateTags) { return new JsonModel(['status' => 'error', 'msg' => 'Unable to save application. Please try again later.']); } $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setInputFilter(new JobsFilter()); $form->setData($post); if ($form->isValid()) { $data = $form->getData(); $filesObj = new Files($request->getFiles()->toArray()); $acceptedFileTypes = ['pdf', 'doc', 'docx', 'odt', 'rtf']; $filenames = $filesObj->saveFiles('/ginosi/uploads/hr/applicants/' . date('Y/m/'), $acceptedFileTypes, false, true); if ($filenames['cv']) { $data['cv'] = $filenames['cv']; } else { unset($data['cv']); } $data['date_applied'] = date('Y-m-d H:i:s'); $applicantId = $jobService->saveApplicant($data); if ($applicantId) { /** @var \DDD\Dao\Recruitment\Job\Job $jobDao */ $jobDao = $this->getServiceLocator()->get('dao_recruitment_job_job'); /** @var \DDD\Domain\Recruitment\Job\Job $jobInfo */ $jobInfo = $jobDao->fetchOne(['id' => $data['job_id']]); $hiringManager = $jobInfo->getHiringManagerId(); if ($jobInfo && $jobInfo->getNotifyManager() && $hiringManager && !is_null($hiringManager)) { $notificationService = $this->getServiceLocator()->get('service_notifications'); $sender = NotificationService::$applicants; $message = 'You have a new applicant for ' . $jobInfo->getTitle() . ' position - ' . $data['firstname'] . ' ' . $data['lastname'] . '. Applied on ' . date(Constants::GLOBAL_DATE_FORMAT . ' H:i', strtotime($data['date_applied'])); $url = '/recruitment/applicants/edit/' . $applicantId; $notificationData = ['recipient' => $hiringManager, 'sender' => $sender, 'sender_id' => User::SYSTEM_USER_ID, 'message' => $message, 'url' => $url, 'show_date' => date('Y-m-d')]; $notificationService->createNotification($notificationData); } } $result = ['status' => 'success', 'msg' => 'Application saved']; } } } catch (\Exception $ex) { $this->gr2logException($ex, 'Website: Job application saving process failed'); } return new JsonModel($result); }
/** * @param array $data * @param int $id * @return int */ public function saveParkingLot($data, $id) { /* @var $parkingGeneralDao \DDD\Dao\Parking\General */ $parkingGeneralDao = $this->getServiceLocator()->get('dao_parking_general'); $oldData = $parkingGeneralDao->getParkingById($id); $saveData = ['name' => $data['name'], 'is_virtual' => (int) $data['is_virtual'], 'lock_id' => (int) $data['lock_id']]; if (isset($data['country_id'])) { $saveData['country_id'] = (int) $data['country_id']; } if (isset($data['province_id'])) { $saveData['province_id'] = (int) $data['province_id']; } if (isset($data['city_id'])) { $saveData['city_id'] = (int) $data['city_id']; } if (isset($data['address'])) { $saveData['address'] = $data['address']; } if (isset($data['direction_textline_id'])) { $saveData['direction_textline_id'] = (int) $data['direction_textline_id']; } if (!empty($data['parking_permit'])) { $saveData['parking_permit'] = $data['parking_permit']; } $where = $id ? ['id' => $id] : false; $response = $parkingGeneralDao->save($saveData, $where); if (!$id) { $id = $response; } if (!empty($data['parking_permit'])) { $uploadFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_PARKING_ATTACHMENTS . $id . '/'; $destination = $uploadFolder . $data['parking_permit']; Files::moveFile(DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_TEMP_PATH . $data['parking_permit'], $destination); if ($oldData && $oldData->getParkingPermit()) { @unlink($uploadFolder . $oldData->getParkingPermit()); } } return $id; }
public function taskSave($data, $actionsSet, $isSystemUser = false) { /** * @var \Library\Authentication\BackofficeAuthenticationService $auth * @var Logger $logger * @var \DDD\Domain\Task\Task $oldDataGeneral * @var \DDD\Dao\Task\Staff $taskStaffDao * @var \DDD\Dao\Task\Subtask $taskSubtaskDao * @var \DDD\Dao\Task\Task $taskDao * @var \DDD\Dao\Task\Attachments $attachmentsDao * @var \DDD\Domain\Task\Task $oldDataGeneral * @var \DDD\Domain\Task\Staff[] $oldDataStaff * @var \DDD\Dao\Task\Tag $taskTagDao; * @var \DDD\Dao\Tag\Tag $tagDao; * @var \DDD\Dao\Team\Team $teamsDao; */ $taskDao = $this->getTaskDao(); $taskStaffDao = $this->getTaskStaffDao(); $taskSubtaskDao = $this->getTaskSubtasksDao(); $attachmentsDao = $this->getServiceLocator()->get('dao_task_attachments'); $taskTagDao = $this->getServiceLocator()->get('dao_task_tag'); $tagDao = $this->getServiceLocator()->get('dao_tag_tag'); $teamsDao = $this->getServiceLocator()->get('dao_team_team'); $logger = $this->getServiceLocator()->get('ActionLogger'); if (!$isSystemUser) { $auth = $this->getServiceLocator()->get('library_backoffice_auth'); $authId = $auth->getIdentity()->id; } else { $authId = UserMain::SYSTEM_USER_ID; } if (isset($data['edit_id']) && $data['edit_id'] > 0) { $oldDataGeneral = $taskDao->getTaskById($data['edit_id']); $oldDataStaff = $taskStaffDao->getTaskStaff($data['edit_id']); } $saveData = []; if (isset($data['follower_ids']) && !$data['follower_ids']) { $data['follower_ids'] = []; } if (isset($data['helper_ids']) && !$data['helper_ids']) { $data['helper_ids'] = []; } if (isset($data['tags']) && !$data['tags']) { $data['tags'] = []; } else { if (isset($data['tags'])) { $data['tags'] = explode(',', $data['tags']); } } if (!empty($actionsSet[self::ACTION_CHANGE_STATUS]) && isset($data['task_status'])) { $saveData['task_status'] = (int) ($data['task_status'] ? $data['task_status'] : self::STATUS_NEW); if ((int) $data['task_status'] == self::STATUS_DONE) { $saveData['done_date'] = date('Y-m-d'); if (isset($data['verifier_id']) && ($data['verifier_id'] == User::AUTO_VERIFY_USER_ID || isset($data['responsible_id']) && $authId == $data['verifier_id'] && $authId == $data['responsible_id'])) { $saveData['task_status'] = self::STATUS_VERIFIED; } } elseif (isset($oldDataGeneral) && in_array($oldDataGeneral->getTask_status(), [self::STATUS_DONE, self::STATUS_VERIFIED]) && !in_array($data['task_status'], [self::STATUS_DONE, self::STATUS_VERIFIED])) { $saveData['done_date'] = null; } if ((int) $data['task_status'] == self::STATUS_DONE || (int) $data['task_status'] == self::STATUS_VERIFIED) { if (isset($data['responsible_id']) && $data['responsible_id'] == User::ANY_TEAM_MEMBER_USER_ID || !isset($data['responsible_id']) && $oldDataGeneral->getResponsibleId() == User::ANY_TEAM_MEMBER_USER_ID) { $data['responsible_id'] = $authId; } } } if (!empty($data['last_update_time'])) { $saveData['last_update_time'] = $data['last_update_time']; } else { $data['last_update_time'] = $saveData['last_update_time'] = date('Y:m:d H:i:s'); } if (!empty($actionsSet[self::ACTION_CHANGE_DETAILS])) { if (isset($data['title'])) { $saveData['title'] = $data['title']; } if (isset($data['task_type'])) { $saveData['task_type'] = (int) $data['task_type']; } if (isset($data['task_priority'])) { $saveData['priority'] = (int) $data['task_priority']; } if (isset($data['description'])) { $saveData['description'] = $data['description']; } if (isset($data['start_date'])) { $saveData['start_date'] = $data['start_date'] ? date('Y-m-d H:i:00', strtotime($data['start_date'])) : null; } if (isset($data['end_date'])) { $saveData['end_date'] = $data['end_date'] ? date('Y-m-d H:i:00', strtotime($data['end_date'])) : null; } if (isset($data['property_id'])) { $saveData['property_id'] = (int) $data['property_id']; } if (isset($data['building_id'])) { $saveData['building_id'] = (int) $data['building_id']; } if (isset($data['related_task'])) { $saveData['related_task'] = $data['related_task'] ? (int) $data['related_task'] : null; } if (isset($data['res_id'])) { $saveData['res_id'] = $data['res_id'] ? (int) $data['res_id'] : null; } if (isset($data['team_id'])) { $saveData['team_id'] = (int) $data['team_id']; } if (isset($data['following_team_id'])) { $saveData['following_team_id'] = (int) $data['following_team_id']; } } if (isset($data['team_id']) && ($data['team_id'] == TeamService::TEAM_CONTACT_CENTER || $data['task_type'] == self::TYPE_KEYFOB) && (!isset($data['responsible_id']) || $data['responsible_id'] == '')) { $data['responsible_id'] = User::ANY_TEAM_MEMBER_USER_ID; } if (isset($data['edit_id']) && $data['edit_id'] > 0) { $id = $data['edit_id']; if (isset($data['task_status']) && $data['task_status'] == self::STATUS_DONE && empty($actionsSet[self::ACTION_MANAGE_STAFF]) && $oldDataGeneral->getVerifierId() == User::AUTO_VERIFY_USER_ID) { $saveData['task_status'] = self::STATUS_VERIFIED; } $this->setComment($logger, $oldDataGeneral, $oldDataStaff, $data, $actionsSet); if (count($saveData)) { $taskDao->save($saveData, ['id' => (int) $id]); } } else { $data['creation_date'] = $saveData['creation_date'] = date('Y-m-d H:i:s'); if (isset($data['responsible_id']) && $data['responsible_id'] == $authId) { $saveData['task_status'] = self::STATUS_VIEWED; } if (isset($data['creator_id']) && $data['creator_id'] == UserMain::SYSTEM_USER_ID) { $creatorId = $data['creator_id']; } else { $creatorId = $authId; } if (isset($data['is_hk'])) { $saveData['is_hk'] = $data['is_hk']; } if (isset($data['extra_inspection'])) { $saveData['extra_inspection'] = $data['extra_inspection']; } $id = $taskDao->save($saveData); $taskStaffDao->save(['task_id' => $id, 'type' => self::STAFF_CREATOR, 'user_id' => $creatorId]); } if (!empty($actionsSet[self::ACTION_MANAGE_SUBTASKS]) && isset($data['subtask_description'])) { $existingSubtasks = $taskSubtaskDao->fetchAll(['task_id' => $id]); if (count($existingSubtasks)) { /** @var \DDD\Domain\Task\Subtask[] $existingSubtask */ foreach ($existingSubtasks as $existingSubtask) { // Remove subtask if (empty($data['subtask_description']) || !isset($data['subtask_description'][$existingSubtask->getId()])) { $taskSubtaskDao->delete(['id' => $existingSubtask->getId()]); $logger->save(Logger::MODULE_TASK, $id, Logger::ACTION_TASK_SUBTASK, 'Removed subtask <b>' . $existingSubtask->getDescription() . '</b>'); // Update Subtask } else { if ($data['subtask_description'][$existingSubtask->getId()] != $existingSubtask->getDescription() || (bool) $data['subtask_status'][$existingSubtask->getId()] != (bool) $existingSubtask->getStatus()) { $taskSubtaskDao->save(['description' => $data['subtask_description'][$existingSubtask->getId()], 'status' => $data['subtask_status'][$existingSubtask->getId()]], ['id' => $existingSubtask->getId()]); if ($data['subtask_description'][$existingSubtask->getId()] != $existingSubtask->getDescription()) { $logger->save(Logger::MODULE_TASK, $id, Logger::ACTION_TASK_SUBTASK, 'Changed subtask description from <b>' . $existingSubtask->getDescription() . '</b> to <b>' . $data['subtask_description'][$existingSubtask->getId()] . '</b>'); } if ((bool) $data['subtask_status'][$existingSubtask->getId()] != (bool) $existingSubtask->getStatus()) { $logger->save(Logger::MODULE_TASK, $id, Logger::ACTION_TASK_SUBTASK, 'Marked subtask <b>' . $data['subtask_description'][$existingSubtask->getId()] . '</b> ' . ($data['subtask_status'][$existingSubtask->getId()] ? 'Done' : 'Undone')); } } unset($data['subtask_description'][$existingSubtask->getId()]); unset($data['subtask_status'][$existingSubtask->getId()]); } } } if (!empty($data['subtask_description']) && count($data['subtask_description'])) { foreach ($data['subtask_description'] as $index => $subtaskDescription) { if ($subtaskDescription) { $taskSubtaskDao->save(['task_id' => $id, 'description' => $subtaskDescription, 'status' => !empty($data['subtask_status'][$index]) ? 1 : 0]); if ($id) { $logger->save(Logger::MODULE_TASK, $id, Logger::ACTION_TASK_SUBTASK, 'Added subtask <b>' . $subtaskDescription . '</b>'); } } } } } if (!empty($actionsSet[self::ACTION_COMMENT]) && !empty($data['comments'])) { $logger->save(Logger::MODULE_TASK, $id, Logger::ACTION_COMMENT, $data['comments']); } if (!empty($actionsSet[self::ACTION_MANAGE_STAFF])) { if (isset($data['responsible_id'])) { $taskStaffDao->delete(['task_id' => $id, 'type' => self::STAFF_RESPONSIBLE]); if ($data['responsible_id']) { $taskStaffDao->save(['task_id' => $id, 'type' => self::STAFF_RESPONSIBLE, 'user_id' => $data['responsible_id']]); } } if (isset($data['verifier_id'])) { $taskStaffDao->delete(['task_id' => $id, 'type' => self::STAFF_VERIFIER]); if ((!$data['verifier_id'] || $data['verifier_id'] == UserMain::SYSTEM_USER_ID) && (empty($oldDataGeneral) || isset($data['responsible_id']) && $oldDataGeneral->getResponsibleId() != $data['responsible_id'])) { $taskStaffDao->save(['task_id' => $id, 'type' => self::STAFF_VERIFIER, 'user_id' => $authId]); } else { if ($data['verifier_id']) { $taskStaffDao->save(['task_id' => $id, 'type' => self::STAFF_VERIFIER, 'user_id' => $data['verifier_id']]); } } } if (isset($data['follower_ids'])) { $taskStaffDao->delete(['task_id' => $id, 'type' => self::STAFF_FOLLOWER]); if (count($data['follower_ids'])) { foreach ($data['follower_ids'] as $followerId) { $taskStaffDao->save(['task_id' => $id, 'type' => self::STAFF_FOLLOWER, 'user_id' => $followerId]); } } } if (isset($data['helper_ids'])) { $taskStaffDao->delete(['task_id' => $id, 'type' => self::STAFF_HELPER]); if (count($data['helper_ids'])) { foreach ($data['helper_ids'] as $helperId) { $taskStaffDao->save(['task_id' => $id, 'type' => self::STAFF_HELPER, 'user_id' => $helperId]); } } } } if (isset($data['tags']) && !empty($actionsSet[self::ACTION_TAG])) { $taskTagDao->delete(['task_id' => $id]); if (count($data['tags'])) { foreach ($data['tags'] as $tag) { if (!is_numeric($tag)) { $tagId = $tagDao->save(['name' => $tag, 'style' => 'label-grey']); } else { $tagId = $tag; } $taskTagDao->save(['task_id' => $id, 'tag_id' => $tagId]); } } } if (!empty($actionsSet[self::ACTION_MANAGE_ATTACHMENTS])) { if (!empty($data['attachment_names'])) { $uploadFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_TASK_ATTACHMENTS . date('Y/m/d', strtotime($data['creation_date'])) . '/' . $id . '/'; $attachmentNames = explode('###', $data['attachment_names']); foreach ($attachmentNames as $attachmentName) { if ($attachmentName) { $destination = $uploadFolder . $attachmentName; $response = Files::moveFile(DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_TMP . $attachmentName, $destination); if ($response) { $attachmentsDao->save(['task_id' => $id, 'file' => pathinfo($destination, PATHINFO_BASENAME)]); } } } } } return $id; }
/** * @param Request $request * @param int $buildingId * @return bool */ public function uploadFile($request, $buildingId) { try { /** @var \DDD\Dao\ApartmentGroup\BuildingDetails $buildingDetailsDao */ $buildingDetailsDao = $this->getServiceLocator()->get('dao_apartment_group_building_details'); $files = $request->getFiles(); $file = $files['map_attachment']; $attachmentExtension = pathinfo($file['name'], PATHINFO_EXTENSION); // file attached if ($file['error'] !== 4) { if ($file['error'] !== 0) { throw new \Exception('File upload failed.'); } if ($file['size'] > self::ATTACHMENT_SIZE * 1024 * 1024) { throw new \Exception('File size is too big.'); } if (in_array($attachmentExtension, ['php', 'phtml', 'html', 'js'])) { throw new \Exception('Invalid file format.'); } $folderPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_BUILDING . $buildingId . '/map'; if (!is_dir($folderPath)) { if (!mkdir($folderPath, 0775, true)) { throw new \Exception('Upload failed. Can\'t create directory.'); } } $oldData = $buildingDetailsDao->fetchOne(['apartment_group_id' => $buildingId], ['map_attachment']); $filename = 'ki_map_' . $buildingId . '_' . time(); $filename = $filename . '.' . $attachmentExtension; $fullPath = $folderPath . '/' . $filename; // remove old uploaded file if ($oldData['map_attachment']) { $oldFile = $folderPath . '/' . $oldData['map_attachment']; @unlink($oldFile); } Files::moveFile($file['tmp_name'], $fullPath); $buildingDetailsDao->save(['map_attachment' => $filename], ['apartment_group_id' => $buildingId]); return true; } } catch (\Exception $ex) { return false; } return false; }
/** * Fetch all or a subset of resources * * @param array $params * @return ApiProblem|mixed * * @api {get} API_DOMAIN/warehouse/configs Configs List * @apiVersion 1.0.0 * @apiName GetConfigs * @apiGroup Config * * @apiDescription This method returns the list of all warehouse configurations * * @apiHeader {String} Content-Type application/json * @apiHeader {String} Authorization Bearer ACCESS_TOKEN * * @apiSuccess {Int} assets The update interval for updating assets list. The value is in seconds * @apiSuccess {Int} locations The update interval for updating locations list. The value is in seconds * @apiSuccess {Int} users The update interval for updating users list. The value is in seconds * @apiSuccess {Int} categories The update interval for updating category list. The value is in seconds * @apiSuccess {Int} configs The update interval for updating configurations. The value is in seconds * @apiSuccess {Int} version The current API version * @apiSuccess {Int} requestTTL The value indicating how long should a request stay in the mobile * @apiSuccess {Object} assetTypes All possible values for asset types * @apiSuccess {Object} assetValuableStatuses All possible values for Valuable asset statuses * @apiSuccess {Object} locationTypes All possible values for location types * @apiSuccess {Object} assetChangeTypes All possible values for asset change types * @apiSuccess {Object} attachmentTypes All possible values for attachment types * @apiSuccess {Object} moduleTypes All possible values for module types * @apiSuccess {Object} imageConfigs The maximum width and height for images. Anything larger is compressed on the client to match this criteria. * * @apiSuccessExample {json} Sample Response: * HTTP/1.1 200 OK * { * "updateIntervals": { * "assets": 86400, * "locations": 86400, * "users": 86400, * "categories": 86400, * "configs": 86400 * }, * "requestTTL": 604800, * "version": 1, * "assetTypes": { * "1": "Consumable", * "2": "Valuable" * }, * "assetValuableStatuses": { * "1": "Working", * "2": "Broken", * "3": "Lost", * "4": "Retired", * "5": "Expunged", * "6": "New", * "7": "Repair" * }, * "locationTypes": { * "1": "Apartment", * "2": "Storage", * "3": "Office", * "4": "Building" * }, * "assetChangeTypes" : { * "155": "Status Change", * "156": "Assignee Change", * "157": "Location Change", * "158": "Added Comment" * }, * "attachmentTypes": { * "1": "All", * "2": "Image", * "3": "Document" * }, * "moduleTypes": { * "1": "Incident" * }, * "imageConfigs": { * "maxWidth": 1024, * "maxHeight": 1024 * } * } */ public function fetchAll($params = array()) { try { $config = $this->serviceLocator->get('config'); $requestHandler = $this->serviceLocator->get('Service\\RequestHandler'); $assetService = $this->serviceLocator->get('service_warehouse_asset'); $result = []; if (isset($config['warehouse'])) { $result['updateIntervals']['assets'] = $config['warehouse']['assets']; $result['updateIntervals']['locations'] = $config['warehouse']['locations']; $result['updateIntervals']['users'] = $config['warehouse']['users']; $result['updateIntervals']['categories'] = $config['warehouse']['categories']; $result['updateIntervals']['configs'] = $config['warehouse']['updateTime']; $result['requestTTL'] = $config['warehouse']['apiExpired']; $result['version'] = $config['warehouse']['version']; } $result['assetTypes'] = CategoryService::$categoryTypes; $assetStatuses = $assetService->getValuableAssetsStatusesArray(true); $result['assetValuableStatuses'] = []; if ($assetStatuses && count($assetStatuses)) { $result['assetValuableStatuses'] = $assetStatuses; } $result['locationTypes'] = AssetService::$types; $result['assetChangeTypes'] = AssetService::$assetChangeTypes; $result['attachmentTypes'] = Files::getAttachmentTypes(); $result['moduleTypes'] = TaskService::getModuleTypes(); $result['imageConfigs'] = $config['imageConfigs']; return $result; } catch (\Exception $e) { return $requestHandler->handleException($e); } }
public function ajaxUploadCvAction() { $applicantDao = $this->getServiceLocator()->get('dao_recruitment_applicant_applicant'); $applicantService = $this->getServiceLocator()->get('service_recruitment_applicant'); $request = $this->getRequest(); $result = ['status' => 'error', 'msg' => TextConstants::SERVER_ERROR]; try { if ($request->isPost() && $request->isXmlHttpRequest()) { $data = $request->getPost(); $fileInfo = $request->getFiles()->toArray(); $filename = $fileInfo['cv']['name']; $applicantInfo = $applicantDao->fetchOne(['id' => $data['id']]); $filesObj = new Files($fileInfo); $fileType = $filesObj->getFileType($filename); $acceptedFileTypes = ['pdf', 'doc', 'docx', 'odt', 'rtf']; $cvName = null; if (!in_array($fileType, $acceptedFileTypes)) { $result = ['status' => 'error', 'msg' => TextConstants::FILE_TYPE_NOT_TRUE]; } else { $savedFile = $filesObj->saveFiles(DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_HR_APPLICANT_DOCUMENTS . date('Y/m/', strtotime($applicantInfo->getDateApplied())), $acceptedFileTypes, false, true); if ($savedFile['cv']) { $cvName = $savedFile['cv']; } if (!is_null($cvName)) { $preApplicantInfo = $applicantService->getApplicantById($data['id']); if ($preApplicantInfo->getCvFileName()) { $filePath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_HR_APPLICANT_DOCUMENTS . $preApplicantInfo->getCvFileUrl(); if (is_readable($filePath)) { @unlink($filePath); } } $applicantDao->save(['cv' => $cvName], ['id' => $data['id']]); $result = ['status' => 'success', 'msg' => TextConstants::SUCCESS_UPDATE]; Helper::setFlashMessage(['success' => TextConstants::SUCCESS_UPDATE]); } } } } catch (\Exception $e) { // do nothing } return new JsonModel($result); }
public function officeSave($data, $files, $id, $global) { /** * @var UserManager $userManager */ $officeManagerDao = $this->getOfficeManagerDao(); $officeSectionManagerDao = $this->getOfficeSectionDao(); $userManager = $this->getServiceLocator()->get('dao_user_user_manager'); $data = (array) $data; $staffsId = []; if ($global) { $officeData = ['name' => $data['name'], 'description' => $data['description'], 'address' => $data['address'], 'office_manager_id' => !empty($data['office_manager_id']) ? $data['office_manager_id'] : null, 'it_manager_id' => !empty($data['it_manager_id']) ? $data['it_manager_id'] : null, 'finance_manager_id' => !empty($data['finance_manager_id']) ? $data['finance_manager_id'] : null, 'country_id' => $data['country_id'], 'city_id' => $data['city_id'], 'province_id' => $data['province_id'], 'phone' => $data['phone']]; if ($id) { if ($data['delete_attachment']) { $this->removeAttachment($id); } $officeData['modified_date'] = date('Y-m-d'); $officeManagerDao->save($officeData, ['id' => (int) $id]); $preStaffs = $userManager->fetchAll(['reporting_office_id' => $id]); foreach ($preStaffs as $staffId) { array_push($staffsId, $staffId->getId()); } if (!isset($data['staff']) && !empty($staffsId)) { foreach ($staffsId as $staff) { $userManager->setOfficeUser(0, $staff); } } elseif (empty($staffsId) && isset($data['staff'])) { foreach ($data['staff'] as $staff) { $userManager->setOfficeUser($id, $staff); } } elseif (isset($data['staff']) && !empty($staffsId)) { $sameStaffs = array_intersect($data['staff'], $staffsId); $deleteStaffs = array_diff($staffsId, $sameStaffs); $newStaffs = array_diff($data['staff'], $sameStaffs); foreach ($newStaffs as $staff) { $userManager->setOfficeUser($id, $staff); } foreach ($deleteStaffs as $staff) { $userManager->setOfficeUser(0, $staff); } } if (isset($data['section'])) { $officeSectionList = $this->getOfficeSectionsList($id); if (count($data['section'])) { foreach ($data['section'] as $submittedOfficeSectionId => $submittedOfficeSectionName) { if (empty(trim($submittedOfficeSectionName))) { continue; } // If section id found then it is an update else it is a new office section if (array_key_exists($submittedOfficeSectionId, $officeSectionList)) { if (trim($submittedOfficeSectionName) == $officeSectionList[$submittedOfficeSectionId]) { continue; } // Update name $officeSectionManagerDao->save(['name' => $submittedOfficeSectionName], ['id' => $submittedOfficeSectionId]); } else { // Create office section $officeSectionManagerDao->save(['name' => $submittedOfficeSectionName, 'office_id' => $id, 'disable' => 0]); } } } } } else { $officeData['created_date'] = date('Y-m-d'); $officeData['modified_date'] = null; $id = $officeManagerDao->save($officeData); if ($id > 0) { /** @var \DDD\Dao\Textline\Apartment $productTexlineDao */ $productTexlineDao = $this->getServiceLocator()->get('dao_textline_apartment'); $receptionEntryTextLine = ['entity_id' => $id, 'entity_type' => Translation::PRODUCT_TEXTLINE_TYPE_OFFICE_RECEPTION_ENTRY, 'type' => Translation::PRODUCT_TYPE_OFFICE]; $receptionEntryTextLineId = $productTexlineDao->save($receptionEntryTextLine); $officeManagerDao->save(['textline_id' => $receptionEntryTextLineId], ['id' => $id]); if (isset($data['staff'])) { foreach ($data['staff'] as $staff) { $userManager->setOfficeUser($id, $staff); } } if (isset($data['office_manager_id'])) { $userManager->setOfficeUser($id, $data['office_manager_id']); } if (isset($data['finance_manager_id'])) { $userManager->setOfficeUser($id, $data['finance_manager_id']); } if (isset($data['it_manager_id'])) { $userManager->setOfficeUser($id, $data['it_manager_id']); } if (isset($data['section'])) { foreach ($data['section'] as $section) { if (strlen($section) > 0) { $officeSectionManagerDao->save(['name' => $section, 'office_id' => $id]); } } } } } if (!empty($files) && !empty($files['map_attachment'])) { $file = $files['map_attachment']; $attachmentPath = DirectoryStructure::FS_IMAGES_OFFICE . $id; $fullAttachmentPath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . $attachmentPath; if (!is_dir($fullAttachmentPath)) { mkdir($fullAttachmentPath, 0775, true); } $oldData = $officeManagerDao->fetchOne(['id' => $id], ['map_attachment']); // remove old uploaded file if ($oldData->getMapAttachment()) { $oldFile = $fullAttachmentPath . '/' . $oldData->getMapAttachment(); @unlink($oldFile); } $fileExtention = pathinfo($file['name'], PATHINFO_EXTENSION); if (!in_array(strtolower($fileExtention), ['jpg', 'jpeg', 'png', 'gif'])) { return false; } $fileNewName = 'map_attachment.' . $fileExtention; Files::moveFile($file['tmp_name'], $fullAttachmentPath . '/' . $fileNewName); $officeManagerDao->save(['map_attachment' => $fileNewName], ['id' => $id]); } return $id; } return false; }
private function uploadIncidentPhoto($entityId, $file) { try { $attachmentsDao = $this->getServiceLocator()->get('dao_task_attachments'); $taskDao = new \DDD\Dao\Task\Task($this->getServiceLocator(), 'ArrayObject'); $taskDetails = $taskDao->fetchOne(['id' => $entityId]); if ($taskDetails) { $uploadFolder = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_UPLOADS_ROOT . DirectoryStructure::FS_UPLOADS_TASK_ATTACHMENTS . date('Y/m/d', strtotime($taskDetails['creation_date'])) . '/' . $entityId . '/'; $destination = $uploadFolder . pathinfo($file['name'], PATHINFO_FILENAME) . '_' . round(microtime(true) * 1000) . '.' . pathinfo($file['name'], PATHINFO_EXTENSION); $response = Files::moveFile($file['tmp_name'], $destination); if ($response) { $attachmentsDao->save(['task_id' => $entityId, 'file' => pathinfo($destination, PATHINFO_BASENAME)]); return true; } } return false; } catch (\Exception $e) { return false; } }