public function setCurrentUser($user) { if ($user instanceof UserInterface === false) { throw Exception::NotSupported(); } $this->currentUser = $user; }
/** * Find all revisions that were made of entity class with given id. * * @param string $className * @param mixed $id * @return Revision[] */ public function findRevisions($className, $id) { if (!$this->metadataFactory->isAudited($className)) { throw Exception::notAudited($className); } $class = $this->em->getClassMetadata($className); $tableName = $this->config->getTablePrefix() . $class->table['name'] . $this->config->getTableSuffix(); if (!is_array($id)) { $id = array($class->identifier[0] => $id); } $whereSQL = ""; foreach ($class->identifier as $idField) { if (isset($class->fieldMappings[$idField])) { if ($whereSQL) { $whereSQL .= " AND "; } $whereSQL .= "e." . $class->fieldMappings[$idField]['columnName'] . " = ?"; } elseif (isset($class->associationMappings[$idField])) { if ($whereSQL) { $whereSQL .= " AND "; } $whereSQL .= "e." . $class->associationMappings[$idField]['joinColumns'][0] . " = ?"; } } $query = "SELECT r.* FROM " . $this->config->getRevisionTableName() . " r " . "INNER JOIN " . $tableName . " e ON r.id = e." . $this->config->getRevisionFieldName() . " WHERE " . $whereSQL . " ORDER BY r.id DESC"; $revisionsData = $this->em->getConnection()->fetchAll($query, array_values($id)); $revisions = array(); $this->platform = $this->em->getConnection()->getDatabasePlatform(); foreach ($revisionsData as $row) { $revisions[] = new Revision($row['id'], \DateTime::createFromFormat($this->platform->getDateTimeFormatString(), $row['timestamp']), $this->ZfcUserRepository->find($row['user_id']), $row["note"], $row["ipaddress"]); } return $revisions; }