芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/public_html/mctv/lib/Factory/AuditLogFactory.php
. */ namespace Xibo\Factory; use Xibo\Entity\AuditLog; use Xibo\Helper\SanitizerService; use Xibo\Service\LogServiceInterface; use Xibo\Storage\StorageServiceInterface; /** * Class AuditLogFactory * @package Xibo\Factory */ class AuditLogFactory extends BaseFactory { /** * Construct a factory * @param StorageServiceInterface $store * @param LogServiceInterface $log * @param SanitizerService $sanitizerService */ public function __construct($store, $log, $sanitizerService) { $this->setCommonDependencies($store, $log, $sanitizerService); } /** * @return AuditLog */ public function create() { return new AuditLog($this->getStore(), $this->getLog()); } /** * @param array $sortOrder * @param array $filterBy * @return array */ public function query($sortOrder = null, $filterBy = []) { $this->getLog()->debug(sprintf('AuditLog Factory with filter: %s', var_export($filterBy, true))); $sanitizedFilter = $this->getSanitizer($filterBy); $entries = []; $params = []; $select = ' SELECT logId, logDate, user.userName, message, objectAfter, entity, entityId, auditlog.userId '; $body = 'FROM `auditlog` LEFT OUTER JOIN user ON user.userId = auditlog.userId WHERE 1 = 1 '; if ($sanitizedFilter->getInt('fromTimeStamp') !== null) { $body .= ' AND `auditlog`.logDate >= :fromTimeStamp '; $params['fromTimeStamp'] = $sanitizedFilter->getInt('fromTimeStamp'); } if ($sanitizedFilter->getInt('toTimeStamp') !== null) { $body .= ' AND `auditlog`.logDate < :toTimeStamp '; $params['toTimeStamp'] = $sanitizedFilter->getInt('toTimeStamp'); } if ($sanitizedFilter->getString('entity') != null) { $body .= ' AND `auditlog`.entity LIKE :entity '; $params['entity'] = '%' . $sanitizedFilter->getString('entity') . '%'; } if ($sanitizedFilter->getString('userName') != null) { $body .= ' AND `user`.userName LIKE :userName '; $params['userName'] = '%' . $sanitizedFilter->getString('userName') . '%'; } if ($sanitizedFilter->getString('message') != null) { $body .= ' AND `auditlog`.message LIKE :message '; $params['message'] = '%' . $sanitizedFilter->getString('message') . '%'; } if ($sanitizedFilter->getInt('entityId') !== null) { $body .= ' AND ( `auditlog`.entityId = :entityId ' ; $params['entityId'] = $sanitizedFilter->getInt('entityId'); $entity = $sanitizedFilter->getString('entity'); // if we were supplied with both layout entity and entityId (layoutId), expand the results // we want to get all actions issued on this layout from the moment it was added if (stripos($entity,'layout' ) !== false) { $sqlLayoutHistory = 'SELECT campaign.campaignId FROM layout INNER JOIN lkcampaignlayout on layout.layoutId = lkcampaignlayout.layoutId INNER JOIN campaign ON campaign.campaignId = lkcampaignlayout.campaignId WHERE campaign.isLayoutSpecific = 1 AND layout.layoutId = :layoutId'; $paramsLayoutHistory = ['layoutId' => $params['entityId']]; $results = $this->getStore()->select($sqlLayoutHistory, $paramsLayoutHistory); foreach ($results as $row) { $campaignId = $row['campaignId']; } if (isset($campaignId)) { $body .= ' OR auditlog.entityId IN (SELECT layouthistory.layoutId FROM layouthistory WHERE layouthistory.campaignId = :campaignId) ) '; $params['campaignId'] = $campaignId; } else { $body .= ' ) '; } } else { $body .= ' ) '; } } $order = ''; if (is_array($sortOrder) && count($sortOrder) > 0) { $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]); } // The final statements $sql = $select . $body . $order . $limit; foreach ($this->getStore()->select($sql, $params) as $row) { $entries[] = $this->create()->hydrate($row); } // Paging if ($limit != '' && count($entries) > 0) { $results = $this->getStore()->select('SELECT COUNT(*) AS total ' . $body, $params); $this->_countLast = intval($results[0]['total']); } return $entries; } }