コード例 #1
0
 public function downloadAction()
 {
     $type = $this->getRequest()->getQuery('type');
     $f = $this->getRequest()->getQuery('f');
     if (!$type || !$f) {
         return $this->page404();
     }
     $file = '';
     $fileName = '';
     switch ($type) {
         case Media::TYPE_CRM_LEAD_TEMPLATE_EXCEL:
             $file = BASE_PATH . '/public/media/leads/' . $f;
             $fileName = $f;
             break;
         case Media::TYPE_CRM_CONTRACT_FILE:
             $fileContract = new \Crm\Model\Contract\File();
             $fileContract->setId($f);
             $fileMapper = $this->getServiceLocator()->get('\\Crm\\Model\\Contract\\FileMapper');
             if (!$fileMapper->get($fileContract)) {
                 return $this->page404();
             }
             $file = BASE_PATH . '/public/media/contracts/' . $fileContract->getContractId() . '/' . $fileContract->getFileName();
             $fileName = $fileContract->getFileName();
             break;
         case Media::TYPE_WORK_PROJECT_FILE:
             $d = $this->getRequest()->getQuery('d');
             $document = new \Work\Model\Document();
             $documentFile = new \Work\Model\DocumentFile();
             $documentFile->setId($f);
             $document->setId($d);
             $documentMapper = $this->getServiceLocator()->get('\\Work\\Model\\DocumentMapper');
             $documentFileMapper = $this->getServiceLocator()->get('\\Work\\Model\\DocumentFileMapper');
             if (!$documentMapper->get($document) || !$documentFileMapper->get($documentFile)) {
                 return $this->page404();
             }
             $createdDate = $documentFileMapper->get($documentFile)->getCreatedDateTime();
             $createdDateFolder = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $createdDate)->format('Ymd');
             $file = MEDIA_PATH . '/projects/documents/' . $createdDateFolder . '/' . $documentFile->getFileName();
             $fileName = $documentFile->getFileName();
             break;
         case Media::TYPE_CRM_ACITITY_PHONECALL:
             $phoneCall = new \Crm\Model\Activity();
             $phoneCall->setId($f);
             $activityMapper = $this->getServiceLocator()->get('\\Crm\\Model\\ActivityMapper');
             if (!$activityMapper->get($phoneCall) || $phoneCall->getType() != \Crm\Model\Activity::TYPE_PHONECALL || !$phoneCall->getFileName()) {
                 return $this->page404();
             }
             $file = BASE_PATH . '/public/media/phonecall/' . $phoneCall->getFilePath() . '/' . $phoneCall->getFileName();
             $fileName = $phoneCall->getFileName();
             break;
         case Media::TYPE_WORK_TASK_FILE:
             $attachFile = new \Work\Model\TaskFile();
             $attachFile->setId($f);
             $attachFileMapper = $this->getServiceLocator()->get('\\Work\\Model\\TaskFileMapper');
             if (!$attachFileMapper->get($attachFile)) {
                 return $this->page404();
             }
             //Check oldfile
             $file = Uri::getSavePath($attachFile) . '/' . $attachFile->getFileName();
             $fileName = $attachFile->getFileName();
             break;
         case Media::TYPE_DOCUMENT_DOCUMENT_FILE:
             $documentFile = new \Document\Model\DocumentFile();
             $documentFile->setId($f);
             $documentFileMapper = $this->getServiceLocator()->get('\\Document\\Model\\DocumentFileMapper');
             if (!$documentFile->getId() || !$documentFileMapper->get($documentFile)) {
                 return $this->page404();
             }
             $file = Uri::getSavePath($documentFile) . '/' . $documentFile->getFileName();
             $fileName = $documentFile->getFileName();
             break;
         case Media::TYPE_COMPANY_ANNOUNCEMENT_FILE:
             $d = $this->getRequest()->getQuery('d');
             $announcementFile = new \Company\Model\AnnouncementFile();
             $announcement = new \Company\Model\Announcement();
             $announcementFile->setId($f);
             $announcement->setId($d);
             $announcementMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementMapper');
             $announcementFileMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementFileMapper');
             if (!$announcementMapper->get($announcement) || !$announcementFileMapper->get($announcementFile)) {
                 return null;
             }
             $createdDate = $announcementFileMapper->get($announcementFile)->getCreatedDateTime();
             $createdDateFolder = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $createdDate)->format('Ymd');
             $file = Uri::getSavePath($announcementFile) . '/' . $announcementFile->getFileName();
             $fileName = $announcementFile->getFileName();
             break;
         case Media::TYPE_WORK_MEETING_FILE:
             $d = $this->getRequest()->getQuery('d');
             $meeting = new \Work\Model\Meeting();
             $meetingFile = new \Work\Model\MeetingFile();
             $meetingFile->setId($f);
             $meeting->setId($d);
             $meetingMapper = $this->getServiceLocator()->get('\\Work\\Model\\MeetingMapper');
             $meetingFileMapper = $this->getServiceLocator()->get('\\Work\\Model\\MeetingFileMapper');
             if (!$meetingMapper->get($meeting) || !$meetingFileMapper->get($meetingFile)) {
                 return $this->page404();
             }
             $meetingFile->setMeetingId($meeting->getId());
             $createdDate = $meetingFileMapper->get($meetingFile)->getCreatedDateTime();
             $createdDateFolder = DateBase::createFromFormat(DateBase::COMMON_DATETIME_FORMAT, $createdDate)->format('Ymd');
             $file = Uri::getSavePath($meetingFile) . '/' . $meetingFile->getFileName();
             $fileName = $meetingFile->getFileName();
             break;
         case Media::TYPE_HRM_TEST_TEMPLATE_EXCEL:
             $file = BASE_PATH . '/public/media/test/' . $f;
             $fileName = $f;
             break;
         case Media::TYPE_IDEA_FILE:
             $fileModel = new \Idea\Model\File();
             $fileModel->setId($f);
             $fileMapper = $this->getServiceLocator()->get('\\Idea\\Model\\FileMapper');
             if (!$fileMapper->get($fileModel)) {
                 return $this->page404();
             }
             $file = \Home\Service\Uri::getSavePath($fileModel);
             $fileName = $fileModel->getFileName();
             break;
     }
     if ($file && !file_exists($file)) {
         die("File not found.");
     }
     $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
     switch ($ext) {
         case "pdf":
             $ctype = "application/pdf";
             break;
         case "exe":
             $ctype = "application/octet-stream";
             break;
         case "zip":
             $ctype = "application/zip";
             break;
         case "doc":
         case "docx":
             $ctype = "application/msword";
             break;
         case "xls":
             $ctype = "application/vnd.ms-excel";
             break;
         case "xlsx":
             $ctype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
             break;
         case "ppt":
         case "pptx":
             $ctype = "application/vnd.ms-powerpoint";
             break;
         case "gif":
             $ctype = "image/gif";
             break;
         case "png":
             $ctype = "image/png";
             break;
         case "jpe":
         case "jpeg":
         case "jpg":
             $ctype = "image/jpg";
             break;
         default:
             $ctype = "application/force-download";
     }
     header("Pragma: public");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Cache-Control: private", false);
     header("Content-Type: {$ctype}");
     //echo $file;die;
     header("Content-Disposition: attachment; filename=\"" . $fileName . "\";");
     header("Content-Transfer-Encoding: binary");
     header("Content-Length: " . filesize($file));
     readfile("{$file}") or die("File not found!");
     exit;
 }
コード例 #2
0
 public function officeannoucementAction()
 {
     $mathType = array('NOTICE' => \Company\Model\Announcement::TYPE_ANNOUNCEMENT, 'DIPLOMA' => \Company\Model\Announcement::TYPE_DECISION);
     $officeDirector = BASE_PATH . '/data/oneOfficeFiles';
     list($adapter, $sql) = $this->createOfficeAdapter();
     $select = $sql->select(['sp' => 'social_posts']);
     $select->where(['type' => ['NOTICE', 'DIPLOMA']]);
     $select->order(['ID ASC']);
     $paginatorAdapter = new \Zend\Paginator\Adapter\DbSelect($select, $adapter);
     $paginator = new \Zend\Paginator\Paginator($paginatorAdapter);
     $paginator->setItemCountPerPage(50);
     $page = $this->getRequest()->getQuery('page', 1);
     $totalFile = $this->getRequest()->getQuery('totalFile', 0);
     $totalRecord = $this->getRequest()->getQuery('totalRecord', 0);
     $paginator->setCurrentPageNumber($page);
     $annoucementMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementMapper');
     $annoucementFileMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementFileMapper');
     foreach ($paginator as $row) {
         $row = (array) $row;
         $annoucement = new \Company\Model\Announcement();
         $annoucement->setCompanyId(10);
         $annoucement->setType($mathType[$row['type']]);
         $annoucement->setTitle($row['title']);
         $annoucement->setContent($row['content']);
         $annoucement->setOneofficeId($row['ID']);
         $annoucement->setCreatedDateTime($row['date_created']);
         $annoucement->setCreatedById(1);
         if ($annoucementMapper->isExistedOneofficeCode($annoucement) === false) {
             $annoucementMapper->save($annoucement);
             $totalRecord++;
         }
         $select = $sql->select(['sf' => 'social_files']);
         $select->where(['post_id' => $row['ID']]);
         $query = $sql->buildSqlString($select);
         $rows = $adapter->query($query, $adapter::QUERY_MODE_EXECUTE);
         if ($rows->count()) {
             foreach ($rows->toArray() as $rowFile) {
                 $officeUri = $officeDirector . '/social/group';
                 if (file_exists($officeUri . '/' . $rowFile['filename'])) {
                     $annoucementFile = new \Company\Model\AnnouncementFile();
                     $annoucementFile->setAnnouncementId($annoucement->getId());
                     $annoucementFile->setCreatedDateTime($annoucement->getCreatedDateTime());
                     $filePath = DateBase::toFormat($annoucementFile->getCreatedDateTime(), DateBase::FILEPATH_DATE_FORMAT);
                     $annoucementFile->setFilePath($filePath);
                     $annoucementFile->setFileName($rowFile['filename']);
                     $annoucementFile->setCreatedById(1);
                     if ($annoucementFileMapper->isExisted($annoucementFile) === false) {
                         $targetFolder = Uri::getSavePath($annoucementFile);
                         if (!file_exists($targetFolder)) {
                             $oldmask = umask(0);
                             mkdir($targetFolder, 0777, true);
                             umask($oldmask);
                         }
                         @copy($officeUri . '/' . $rowFile['filename'], $targetFolder . '/' . $annoucementFile->getFileName());
                         $annoucementFileMapper->save($annoucementFile);
                         $totalFile++;
                     }
                 }
             }
         }
     }
     $this->getViewModel()->setTerminal(true);
     $this->getViewModel()->setVariable('page', $page);
     $this->getViewModel()->setVariable('totalPages', $paginator->count() + 1);
     $this->getViewModel()->setVariable('totalRecord', $totalRecord);
     if ($page <= $paginator->count()) {
         $this->getViewModel()->setVariable('redirectUri', Uri::build('/system/tool/officeannoucement', ['page' => $page + 1, 'totalFile' => $totalFile, 'totalRecord' => $totalRecord]));
     }
     $this->getViewModel()->setVariable('totalFile', $totalFile);
     return $this->getViewModel();
 }