* @var array
*/
protected $boundVariables = array();
+
+ /**
+ * Backend specific query settings
+ * @var Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface
+ */
+ protected $backendSpecificQuerySettings;
/**
* Constructs this QueryObjectModel instance
* @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint (null if none)
* @param array $orderings
* @param array $columns
+ * @param Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface $backendSpecificQuerySettings Storage backend specific query settings (or NULL)
*/
- public function __construct(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns) {
+ public function __construct(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns, $backendSpecificQuerySettings) {
$this->source = $selectorOrSource;
$this->constraint = $constraint;
$this->orderings = $orderings;
$this->columns = $columns;
+ $this->backendSpecificQuerySettings = $backendSpecificQuerySettings;
if ($this->constraint !== NULL) {
$this->constraint->collectBoundVariableNames($this->boundVariables);
return $this->columns;
}
+ /**
+ * Backend specific query settings
+ *
+ * @return Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface Backend specific query settings
+ */
+ public function getBackendSpecificQuerySettings() {
+ return $this->backendSpecificQuerySettings;
+ }
+
/**
* Binds the given value to the variable named $varName.
*
* @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
* @param array $orderings zero or more orderings; null is equivalent to a zero-length array
* @param array $columns the columns; null is equivalent to a zero-length array
+ * @param Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface $backendSpecificQuerySettings Backend specific query settings (or NULL)
* @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
* @throws \F3\PHPCR\Query\InvalidQueryException if a particular validity test is possible on this method, the implemention chooses to perform that test and the parameters given fail that test. See the individual QOM factory methods for the validity criteria of each query element.
* @throws Tx_Extbase_Persistence_Exception_RepositoryException if another error occurs.
*/
- public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns) {
- $query = new Tx_Extbase_Persistence_QOM_QueryObjectModel($selectorOrSource, $constraint, $orderings, $columns);
+ public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns, $backendSpecificQuerySettings) {
+ $query = new Tx_Extbase_Persistence_QOM_QueryObjectModel($selectorOrSource, $constraint, $orderings, $columns, $backendSpecificQuerySettings);
$query->injectStorageBackend($this->storageBackend);
$query->injectDataMapper($this->dataMapper);
return $query;
* @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint the constraint, or null if none
* @param array $orderings zero or more orderings; null is equivalent to a zero-length array
* @param array $columns the columns; null is equivalent to a zero-length array
+ * @param Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface $backendSpecificQuerySettings Backend specific query settings (or NULL)
* @return Tx_Extbase_Persistence_QOM_QueryObjectModelInterface the query; non-null
*/
- public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns);
+ public function createQuery(Tx_Extbase_Persistence_QOM_SourceInterface $selectorOrSource, $constraint, array $orderings, array $columns, $backendSpecificQuerySettings);
/**
* Selects a subset of the nodes in the repository based on node type.
*/
public function getColumns();
+ /**
+ * Backend specific query settings
+ *
+ * @return Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface Backend specific query settings
+ */
+ public function getBackendSpecificQuerySettings();
+
/**
* Binds the given value to the variable named $varName.
*
* @var int
*/
protected $offset;
-
+
/**
- * Storage page ID. If set, will be automatically added to the query on execute.
- * @var integer
+ * backend specific query settings. Must be instanciated in subclasses.
+ *
+ * @var Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface
*/
- protected $storagePageId = NULL;
+ protected $backendSpecificQuerySettings;
/**
* Constructs a query object working on the given class name
public function injectDataMapper(Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper) {
$this->dataMapper = $dataMapper;
}
-
- /**
- * Sets the storage page ID.
- *
- * Do NOT call this method yourself! It is automatically called in QueryFactory.
- *
- * @param integer $storagePageId Storage page ID to be used.
- * @return void
- * @internal
- */
- public function setStoragePageId($storagePageId) {
- $this->storagePageId = $storagePageId;
- }
/**
* Returns the class name the query handles
* @return Tx_Extbase_Persistence_QueryResultInterface The query result
*/
public function execute() {
- if ($this->storagePageId !== NULL) {
- // storage Page ID has been set, so we have to add this to the query!
- if ($this->constraint !== NULL) {
- $this->matching(
- $this->logicalAnd(
- $this->equals('pid', $this->storagePageId),
- $this->constraint
- )
- );
- } else {
- $this->matching(
- $this->equals('pid', $this->storagePageId)
- );
- }
- }
-
$query = $this->QOMFactory->createQuery(
$this->getSource(),
$this->constraint,
$this->orderings,
- $this->columns // TODO implement selection of columns
+ $this->columns, // TODO implement selection of columns
+ $this->backendSpecificQuerySettings
);
foreach ($this->operands as $name => $value) {
$query->bindValue($name, $this->valueFactory->createValue($value));
* @param boolean $useStoragePageId TRUE if queries should automatically be restricted to the current storage PID, FALSE otherwise.
* @return Tx_Extbase_Persistence_QueryInterface
*/
- public function create($className, $useStoragePageId = TRUE) {
+ public function create($className) {
$persistenceManager = Tx_Extbase_Dispatcher::getPersistenceManager();
$dataMapper = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMapper');
$dataMapper->injectIdentityMap($persistenceManager->getBackend()->getIdentityMap());
$dataMapper->injectPersistenceManager($persistenceManager);
- $query = t3lib_div::makeInstance('Tx_Extbase_Persistence_Query', $className);
+ $query = t3lib_div::makeInstance('Tx_Extbase_Persistence_Typo3Query', $className);
$query->injectPersistenceManager($persistenceManager);
$query->injectDataMapper($dataMapper);
- if ($useStoragePageId) {
- $query->setStoragePageId($this->storagePageId);
- }
+ $query->setStoragePageId($this->storagePageId);
return $query;
}
-
}
?>
\ No newline at end of file
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+* All rights reserved
+*
+* This class is a backport of the corresponding class of FLOW3.
+* All credits go to the v5 team.
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Marker interface for backend specific query options
+ *
+ * @package Extbase
+ * @subpackage Persistence
+ * @version $Id: BackendInterface.php 2120 2009-04-02 10:06:31Z k-fish $
+ */
+interface Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface {
+
+}
+?>
\ No newline at end of file
*/
protected $pageSelectObject;
- /**
- * TRUE if the framework should add the "enable fields" (e.g. checking for hidden or deleted records)
- *
- * @var boolean
- */
- protected $useEnableFields = TRUE;
-
/**
* TRUE if automatic cache clearing in TCEMAIN should be done on insert/update/delete, FALSE otherwise.
*
$sqlString = 'SELECT ' . implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']);
$this->parseConstraint($query->getConstraint(), $sql, $parameters, $query->getBoundVariableValues());
+
if (!empty($sql['where'])) {
$sqlString .= ' WHERE ' . implode('', $sql['where']);
if (!empty($sql['enableFields'])) {
* @param array &$parameters
* @return void
*/
- protected function parseSource(Tx_Extbase_Persistence_QOM_QueryObjectModel $query, array &$sql, array &$parameters) {
+ protected function parseSource(Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query, array &$sql, array &$parameters) {
$source = $query->getSource();
if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
$selectorName = $source->getSelectorName();
$sql['fields'][] = $selectorName . '.*';
$sql['tables'][] = $selectorName;
- // TODO Should we make the usage of enableFields configurable? And how? Because the Query object and even the QOM should be abstracted from the storage backend.
- if ($this->useEnableFields === TRUE) {
+ if ($query->getBackendSpecificQuerySettings()->enableFieldsEnabled()) {
$this->addEnableFieldsStatement($selectorName, $sql);
}
+ if ($query->getBackendSpecificQuerySettings()->storagePageEnabled()) {
+ $sql['enableFields'][] = $selectorName . '.pid=' . intval($query->getBackendSpecificQuerySettings()->getStoragePageId());
+ }
} elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
$this->parseJoin($source, $sql, $parameters);
}
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+* All rights reserved
+*
+* This class is a backport of the corresponding class of FLOW3.
+* All credits go to the v5 team.
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * TYPO3 DB specific query settings like use of a PID
+ *
+ * @package Extbase
+ * @subpackage Persistence
+ * @version $Id: BackendInterface.php 2120 2009-04-02 10:06:31Z k-fish $
+ */
+class Tx_Extbase_Persistence_Storage_Typo3DbSpecificQuerySettings implements Tx_Extbase_Persistence_Storage_BackendSpecificQuerySettingsInterface {
+
+ protected $useStoragePage = TRUE;
+
+ protected $useEnableFields = TRUE;
+
+ protected $storagePageId;
+
+ public function useStoragePage($useStoragePage) {
+ $this->useStoragePage = (boolean)$useStoragePage;
+ }
+
+ public function storagePageEnabled() {
+ return $this->useStoragePage;
+ }
+
+ public function getStoragePageId() {
+ return $this->storagePageId;
+ }
+ public function setStoragePageId($storagePageId) {
+ $this->storagePageId = $storagePageId;
+ }
+ public function enableFieldsEnabled() {
+ return $this->useEnableFields;
+ }
+ public function useEnableFields($useEnableFields) {
+ $this->useEnableFields = $useEnableFields;
+ }
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+* All rights reserved
+*
+* This class is a backport of the corresponding class of FLOW3.
+* All credits go to the v5 team.
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * A persistence query interface
+ *
+ * @package TYPO3
+ * @subpackage Extbase
+ * @version $Id: QueryInterface.php 658 2009-05-16 13:54:16Z jocrau $
+ */
+class Tx_Extbase_Persistence_Typo3Query extends Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_Typo3QueryInterface {
+
+ /**
+ * Constructs a query object working on the given class name
+ *
+ * @param string $className
+ */
+ public function __construct($className) {
+ parent::__construct($className);
+ $this->backendSpecificQuerySettings = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbSpecificQuerySettings');
+ }
+
+ /**
+ * Sets the storage page ID.
+ *
+ * Do NOT call this method yourself! It is automatically called in QueryFactory.
+ *
+ * @param integer $storagePageId Storage page ID to be used.
+ * @return void
+ * @internal
+ */
+ public function setStoragePageId($storagePageId) {
+ $this->backendSpecificQuerySettings->setStoragePageId($storagePageId);
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Classes/Persistence/Tx_Extbase_Persistence_Typo3QueryInterface#useStoragePage($useStoragePage)
+ */
+ public function useStoragePage($useStoragePage) {
+ $this->backendSpecificQuerySettings->useStoragePage($useStoragePage);
+ return this;
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Classes/Persistence/Tx_Extbase_Persistence_Typo3QueryInterface#useEnableFields($useEnableFields)
+ */
+ public function useEnableFields($useEnableFields) {
+ $this->backendSpecificQuerySettings->useEnableFields($useEnableFields);
+ return this;
+ }
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+* All rights reserved
+*
+* This class is a backport of the corresponding class of FLOW3.
+* All credits go to the v5 team.
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * A persistence query interface
+ *
+ * @package TYPO3
+ * @subpackage Extbase
+ * @version $Id: QueryInterface.php 658 2009-05-16 13:54:16Z jocrau $
+ */
+interface Tx_Extbase_Persistence_Typo3QueryInterface extends Tx_Extbase_Persistence_QueryInterface {
+ /**
+ * Sets the storage page ID.
+ *
+ * Do NOT call this method yourself! It is automatically called in QueryFactory.
+ *
+ * @param integer $storagePageId Storage page ID to be used.
+ * @return void
+ * @internal
+ */
+ public function setStoragePageId($storagePageId);
+
+ /**
+ * Use storage page
+ *
+ * @param $useStoragePage if TRUE, should use storage PID. use FALSE to disable the storage Page ID checking
+ * @return void
+ */
+ public function useStoragePage($useStoragePage);
+
+ /**
+ * Use enable fields
+ *
+ * @param $useEnableFields if TRUE, will add enable fields. use FALSE to disable the enable fields checking
+ * @return void
+ */
+ public function useEnableFields($useEnableFields);
+}
+?>
\ No newline at end of file