コード例 #1
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();
 }