public function addNotification($toUser, $message, $action, $type) { $userEmp = new User(); $userEmp->load("employee = ?", array($toUser)); if (!empty($userEmp->employee) && $userEmp->employee == $toUser) { $toUser = $userEmp->id; } else { return; } $noti = new Notification(); $user = $this->baseService->getCurrentUser(); $noti->fromUser = $user->id; $noti->fromEmployee = $user->employee; $noti->toUser = $toUser; $noti->message = $message; if (!empty($noti->fromEmployee)) { $employee = $this->baseService->getElement('Employee', $noti->fromEmployee, null, true); if (!empty($employee)) { $fs = new FileService(); $employee = $fs->updateEmployeeImage($employee); $noti->image = $employee->image; } } if (empty($noti->image)) { $noti->image = BASE_URL . "images/user_male.png"; } $noti->action = $action; $noti->type = $type; $noti->time = date('Y-m-d H:i:s'); $noti->status = 'Unread'; $ok = $noti->Save(); if (!$ok) { error_log("Error adding notification: " . $noti->ErrorMsg()); } }
public function deleteProfileImage($req) { if ($this->user->user_level == 'Admin' || $this->user->employee == $req->id) { $fs = new FileService(); $res = $fs->deleteProfileImage($req->id); return new IceResponse(IceResponse::SUCCESS, $res); } }
public static function getInstance() { if (empty(self::$me)) { self::$me = new FileService(); } return self::$me; }
public function getLatestNotificationsAndCounts($userId) { $notification = new Notification(); $listUnread = $notification->Find("toUser = ? and status = ?", array($userId, 'Unread')); $unreadCount = count($listUnread); $limit = $unreadCount < 10 ? 10 : $unreadCount; $list = $notification->Find("toUser = ? order by time desc limit ?", array($userId, $limit)); $newList = array(); $fs = FileService::getInstance(); foreach ($list as $noti) { if ($noti->fromEmployee > 0) { $employee = $this->baseService->getElement('Employee', $noti->fromEmployee, null, true); if (!empty($employee)) { $employee = $fs->updateProfileImage($employee); $noti->image = $employee->image; if (empty($noti->image)) { if ($employee->gender == 'Male') { $noti->image = BASE_URL . "images/user_male.png"; } else { $noti->image = BASE_URL . "images/user_female.png"; } } $newList[] = $noti; } } else { $noti->image = BASE_URL . "images/icehrm.png"; $newList[] = $noti; } } return array($unreadCount, $list); }
/** * For event in shared context: * Node.@images.add.post * * @param NodeRef $nodeRef NodeRef Being Added * @param Node $node Node Being added * @param null $notUsed Paramater passed in via Events::trigger, but set to null, and not used. * @param bool $asyncRebuild Wether to rebuildThumbnails asyncronously or not (defaults to true) * * @return void */ public function processAdd(NodeRef $nodeRef, Node $node, $notUsed = null, $asyncRebuild = true) { $node = $this->RegulatedNodeService->getByNodeRef($nodeRef, new NodePartials('', '#original.fields')); //----------- // Build CMS thumbnail separately so that it's ready when this action completes. $file = $this->FileService->retrieveFileFromNode($node->getElement(), $node->getOutTag('#original')->TagLinkNodeRef); if ($file === null) { throw new Exception('File cannot be retrieved for Node'); } $cmsThumb = $this->ImageService->createAndStoreThumbnail($node->getElement(), $this->imagesThumbnailCmsSize, $file->getLocalPath(), $this->ImageService->filenameForNode($node)); $tag = new Tag($cmsThumb->getElement()->getSlug(), $cmsThumb->Slug, '#thumbnails', $this->imagesThumbnailCmsSize, $this->imagesThumbnailCmsSize); $node->replaceOutTags('#thumbnails', array($tag)); $this->RegulatedNodeService->edit($node); if ($asyncRebuild) { // commit so the node is ready for the worker $this->TransactionManager->commit()->begin(); //----------- // Rebuild thumbnails asynchronously $workerParams = array('nodeRef' => '' . $node->getNodeRef(), 'forceRebuildExisting' => false); $this->GearmanService->doBackgroundJob('ImagesWorker', 'rebuildThumbnails', $workerParams, 'high'); } else { $this->ImageService->rebuildMissingThumbnails($node->getNodeRef(), false); } // remove storage facility generated temp file @unlink($file->getLocalPath()); }
/** * Get all the files for a given expense * @return ArrayObject */ public function getExpenseFiles(Expense $expense) { $client = $this->clientService->getClient($expense->clientid); if (!$client) { // throw new Exception("Invalid expense for attaching files to"); return array(); } $path = 'Expenses/' . $expense->id; $files = $this->fileService->listDirectory($path); return $files; }
protected function _buildCmsThumbnail($node) { $node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef(), new NodePartials('', '#original.fields')); //----------- // Build CMS thumbnail separately so that it's ready when this action completes. $file = $this->FileService->retrieveFileFromNode($node->getElement(), $node->getOutTag('#original')->TagLinkNodeRef); $cmsThumb = $this->ImageService->createAndStoreThumbnail($node->getElement(), $this->imagesThumbnailCmsSize, $file->getLocalPath(), $this->ImageService->filenameForNode($node)); $tag = new Tag($cmsThumb->getElement()->getSlug(), $cmsThumb->Slug, '#thumbnails', $this->imagesThumbnailCmsSize, $this->imagesThumbnailCmsSize); $node->replaceOutTags('#thumbnails', array($tag)); $this->RegulatedNodeService->edit($node); }
public function deleteProfileImage($req) { $profileId = $this->getCurrentProfileId(); $subordinate = new Employee(); $subordinatesCount = $subordinate->Count("supervisor = ? and id = ?", array($profileId, $req->id)); if ($this->user->user_level == 'Admin' || $this->user->employee == $req->id || $subordinatesCount == 1) { $fs = FileService::getInstance(); $res = $fs->deleteProfileImage($req->id); return new IceResponse(IceResponse::SUCCESS, $res); } return new IceResponse(IceResponse::ERROR, "Not allowed to delete profile image"); }
public function getWithImages($id = null) { $fileService = new FileService(); if ($id == null) { $filesQuery = $fileService->get(); $itemsQuery = $this->get(); $files = new Plinq($filesQuery); $items = new Plinq($itemsQuery); $result = $items->Select(function ($k, $v) use($files) { $v->images = $files->Where(function ($k2, $v2) use($v) { return $v->id == $v2->itemId; })->ToArray(); return $v; })->ToArray(); return $result; } else { $item = $this->get($id); $files = $fileService->getByItem($id); $item->images = $files; return $item; } }
public function addNotification($toUser, $message, $action, $type) { $profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME; $profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME); $userEmp = new User(); $userEmp->load("profile = ?", array($toUser)); if (!empty($userEmp->{$profileVar}) && $userEmp->{$profileVar} == $toUser) { $toUser = $userEmp->id; } else { return; } $noti = new Notification(); $user = $this->baseService->getCurrentUser(); $noti->fromUser = $user->id; $noti->fromProfile = $user->{$profileVar}; $noti->toUser = $toUser; $noti->message = $message; if (!empty($noti->fromProfile)) { $profile = $this->baseService->getElement($profileClass, $noti->fromProfile, null, true); if (!empty($profile)) { $fs = new FileService(); $profile = $fs->updateProfileImage($profile); $noti->image = $profile->image; } } if (empty($noti->image)) { $noti->image = BASE_URL . "images/user_male.png"; } $noti->action = $action; $noti->type = $type; $noti->time = date('Y-m-d H:i:s'); $noti->status = 'Unread'; $ok = $noti->Save(); if (!$ok) { LogManager::getInstance()->info("Error adding notification: " . $noti->ErrorMsg()); } }
/** * Delete a file * */ public function deleteAction() { $id = $this->_getParam('id'); $file = $this->fileService->getFile($id); if ($file) { if ($this->fileService->deleteFile($file)) { $this->flash("Deleted " . $file->getTitle()); } else { $this->flash("Failed deleting " . $file->getTitle()); } } $picker = $this->_getParam('picker'); $returnUrl = $this->_getParam('returnurl'); if (!empty($returnUrl)) { $this->redirect(base64_decode($this->_getParam('returnurl')), '', array('picker' => $picker)); } else { $this->redirect('file', 'index', array('picker' => $picker, 'parent' => base64_encode($parent))); } }
/** * Adds a file attachment to an issue. */ private function addAttachmentToIssue(Issue $issue, RawFile $file, $attnum = 0) { // First we need to make sure we've got the filepath for the // client this issue is attached to. $client = $this->clientService->getClient($issue->clientid); if (!$client) { throw new Exception("Invalid request for attaching files to"); } $path = 'Clients/' . $client->title . '/Issues/' . $issue->id; if (!$this->fileService->createDirectory($path)) { throw new Exception("Failed creating directory {$path} for saving request files"); } $existing = $this->fileService->getFileByPath($path . '/' . $file->filename); if ($attnum && $file->filename == 'Email Attachment') { $file->filename .= " #{$attnum}"; } if (!$existing) { $existing = $this->fileService->createFile($file->filename, $path); } $this->fileService->setFileContent($existing, $file->content, $file->contentType); }
$profileCurrent = null; $profileSwitched = null; $profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME); $profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME; if (!empty($user->{$profileVar})) { $profileCurrent = BaseService::getInstance()->getElement($profileClass, $user->{$profileVar}, null, true); if (!empty($profileCurrent)) { $profileCurrent = FileService::getInstance()->updateProfileImage($profileCurrent); } } if ($user->user_level == 'Admin' || $user->user_level == 'Manager') { $switchedEmpId = BaseService::getInstance()->getCurrentProfileId(); if ($switchedEmpId != $user->{$profileVar} && !empty($switchedEmpId)) { $profileSwitched = BaseService::getInstance()->getElement($profileClass, $switchedEmpId, null, true); if (!empty($profileSwitched)) { $profileSwitched = FileService::getInstance()->updateProfileImage($profileSwitched); } } } $activeProfile = null; if (!empty($profileSwitched)) { $activeProfile = $profileSwitched; } else { $activeProfile = $profileCurrent; } //read field templates $fieldTemplates = array(); $fieldTemplates['hidden'] = file_get_contents(CLIENT_PATH . '/templates/fields/hidden.html'); $fieldTemplates['text'] = file_get_contents(CLIENT_PATH . '/templates/fields/text.html'); $fieldTemplates['textarea'] = file_get_contents(CLIENT_PATH . '/templates/fields/textarea.html'); $fieldTemplates['select'] = file_get_contents(CLIENT_PATH . '/templates/fields/select.html');
public function deleteElement($table, $id) { $fileFields = $this->fileFields; $ele = new $table(); $ele->Load('id = ?', array($id)); $this->checkSecureAccess("delete", $ele); if (isset($this->nonDeletables[$table])) { $nonDeletableTable = $this->nonDeletables[$table]; if (!empty($nonDeletableTable)) { foreach ($nonDeletableTable as $field => $value) { if ($ele->{$field} == $value) { return "This item can not be deleted"; } } } } $ok = $ele->Delete(); if (!$ok) { $error = $ele->ErrorMsg(); LogManager::getInstance()->info($error); return $this->findError($error); } else { //Backup if ($table == "Profile") { $newObj = $this->cleanUpAdoDB($ele); $dataEntryBackup = new DataEntryBackup(); $dataEntryBackup->tableType = $table; $dataEntryBackup->data = json_encode($newObj); $dataEntryBackup->Save(); } $this->audit(IceConstants::AUDIT_DELETE, "Deleted an object in " . $table . " [id:" . $ele->id . "]"); } if (isset($fileFields[$table])) { foreach ($fileFields[$table] as $k => $v) { if (!empty($ele->{$k})) { FileService::getInstance()->deleteFileByField($ele->{$k}, $v); } } } return null; }
public function getCompanyLogoUrl() { $logoFileSet = false; $logoFileName = CLIENT_BASE_PATH . "data/logo.png"; $logoSettings = SettingsManager::getInstance()->getSetting("Company: Logo"); if (!empty($logoSettings)) { $logoFileName = FileService::getInstance()->getFileUrl($logoSettings); $logoFileSet = true; } if (!$logoFileSet && !file_exists($logoFileName)) { return BASE_URL . "images/logo.png"; } return $logoFileName; }
/** * 处理文件 */ private function file() { $service = new FileService(); $result = $service->invoke($this->commonUri); echo json_encode($result); }
public function postProcessGetData($obj) { $obj = FileService::getInstance()->updateSmallProfileImage($obj); return $obj; }