芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/mctv/lib/Factory/ReportScheduleFactory.php
. */ namespace Xibo\Factory; use Stash\Interfaces\PoolInterface; use Xibo\Entity\ReportSchedule; use Xibo\Entity\User; use Xibo\Helper\SanitizerService; use Xibo\Service\ConfigServiceInterface; use Xibo\Service\LogServiceInterface; use Xibo\Storage\StorageServiceInterface; use Xibo\Support\Exception\NotFoundException; /** * Class ReportScheduleFactory * @package Xibo\Factory */ class ReportScheduleFactory extends BaseFactory { /** * @var ConfigServiceInterface */ private $config; /** @var PoolInterface */ private $pool; /** * Construct a factory * @param StorageServiceInterface $store * @param LogServiceInterface $log * @param SanitizerService $sanitizerService * @param User $user * @param UserFactory $userFactory * @param ConfigServiceInterface $config * @param PoolInterface $pool */ public function __construct($store, $log, $sanitizerService, $user, $userFactory, $config, $pool) { $this->setCommonDependencies($store, $log, $sanitizerService); $this->setAclDependencies($user, $userFactory); $this->config = $config; $this->pool = $pool; } /** * Create Empty * @return ReportSchedule */ public function createEmpty() { return new ReportSchedule( $this->getStore(), $this->getLog() ); } /** * Loads only the reportSchedule information * @param int $reportScheduleId * @param int $disableUserCheck * @return ReportSchedule * @throws NotFoundException */ public function getById($reportScheduleId, $disableUserCheck = 0) { if ($reportScheduleId == 0) throw new NotFoundException(); $reportSchedules = $this->query(null, ['reportScheduleId' => $reportScheduleId, 'disableUserCheck' => $disableUserCheck]); if (count($reportSchedules) <= 0) { throw new NotFoundException(\__('Report Schedule not found')); } // Set our reportSchedule return $reportSchedules[0]; } /** * @param null $sortOrder * @param array $filterBy * @return ReportSchedule[] * @throws NotFoundException */ public function query($sortOrder = null, $filterBy = []) { if ($sortOrder == null) { $sortOrder = ['name']; } $sanitizedFilter = $this->getSanitizer($filterBy); $entries = []; $params = []; $select = ' SELECT reportschedule.reportScheduleId, reportschedule.name, reportschedule.lastSavedReportId, reportschedule.reportName, reportschedule.filterCriteria, reportschedule.schedule, reportschedule.lastRunDt, reportschedule.previousRunDt, reportschedule.createdDt, reportschedule.userId, reportschedule.fromDt, reportschedule.toDt, reportschedule.isActive, reportschedule.message, `user`.UserName AS owner '; $body = ' FROM `reportschedule` '; $body .= " LEFT OUTER JOIN `user` ON `user`.userId = `reportschedule`.userId "; $body .= " WHERE 1 = 1 "; // Like if ($sanitizedFilter->getString('name') != '') { $terms = explode(',', $sanitizedFilter->getString('name')); $this->nameFilter('reportschedule', 'name', $terms, $body, $params, ($sanitizedFilter->getCheckbox('useRegexForName') == 1)); } if ($sanitizedFilter->getInt('reportScheduleId', ['default' => 0]) != 0) { $params['reportScheduleId'] = $sanitizedFilter->getInt('reportScheduleId', ['default' => 0]); $body .= " AND reportschedule.reportScheduleId = :reportScheduleId "; } // Owner filter if ($sanitizedFilter->getInt('userId', ['default' => 0]) != 0) { $body .= " AND reportschedule.userid = :userId "; $params['userId'] = $sanitizedFilter->getInt('userId', ['default' => 0]); } if ( $sanitizedFilter->getCheckbox('onlyMySchedules') == 1) { $body .= ' AND reportschedule.userid = :currentUserId '; $params['currentUserId'] = $this->getUser()->userId; } // Report Name if ($sanitizedFilter->getString('reportName') != '') { $body .= " AND reportschedule.reportName = :reportName "; $params['reportName'] = $sanitizedFilter->getString('reportName'); } // isActive if ($sanitizedFilter->getInt('isActive') !== null) { $body .= " AND reportschedule.isActive = :isActive "; $params['isActive'] = $sanitizedFilter->getInt('isActive'); } // View Permissions if ($this->getUser()->userTypeId != 1) { $this->viewPermissionSql('Xibo\Entity\ReportSchedule', $body, $params, '`reportschedule`.reportScheduleId', '`reportschedule`.userId', $filterBy); } // Sorting? $order = ''; if (is_array($sortOrder)) $order .= 'ORDER BY ' . implode(',', $sortOrder); $limit = ''; // Paging if ($filterBy !== null && $sanitizedFilter->getInt('start') !== null && $sanitizedFilter->getInt('length') !== null) { $limit = ' LIMIT ' . intval($sanitizedFilter->getInt('start'), 0) . ', ' . $sanitizedFilter->getInt('length', ['default' => 10]); } $sql = $select . $body . $order . $limit; foreach ($this->getStore()->select($sql, $params) as $row) { $entries[] = $this->createEmpty()->hydrate($row, [ 'intProperties' => [ 'reportScheduleId', 'lastRunDt', 'previousRunDt', 'lastSavedReportId', 'isActive', 'fromDt', 'toDt' ] ]); } // Paging if ($limit != '' && count($entries) > 0) { $results = $this->getStore()->select('SELECT COUNT(*) AS total ' . $body, $params); $this->_countLast = intval($results[0]['total']); } return $entries; } }