protected function addCommonColumns() {
$this->addColumn('uid', Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_INTEGER);
$this->addColumn('pid', Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_INTEGER);
- $this->addColumn('tstamp', Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_DATE);
- $this->addColumn('crdate', Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_DATE);
- $this->addColumn('cruser_id', Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_INTEGER);
- if ($this->getDeletedColumnName() !== NULL) {
+ if ($this->hasTimestampColumn()) {
+ $this->addColumn($this->getTimestampColumnName(), Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_DATE);
+ }
+ if ($this->hasCreationDateColumn()) {
+ $this->addColumn($this->getCreationDateColumnName(), Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_DATE);
+ }
+ if ($this->hasCreatorUidColumn()) {
+ $this->addColumn($this->getCreatorUidColumnName(), Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_INTEGER);
+ }
+ if ($this->hasDeletedColumn()) {
$this->addColumn($this->getDeletedColumnName(), Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_BOOLEAN);
}
- if ($this->getHiddenColumnName() !== NULL) {
+ if ($this->hasHiddenColumn()) {
$this->addColumn($this->getHiddenColumnName(), Tx_ExtBase_Persistence_Mapper_ColumnMap::TYPE_BOOLEAN);
}
}
return $this->columnMaps[$propertyName];
}
- public function getColumnList() {
- $columnList = '';
- foreach ($this->columnMaps as $columnMap) {
- if ($columnList !== '') {
- $columnList .= ',';
- }
- $columnList .= $columnMap->getColumnName();
- }
- return $columnList;
- }
-
/**
* Returns TRUE if the property is persistable (configured in $TCA)
*
return isset($this->columnMaps[$propertyName]);
}
+ /**
+ * Returns TRUE if the table has a pid column holding the id of the page the record is virtually stored on.
+ * Currently we don't support tables without a pid column.
+ *
+ * @return boolean The result
+ */
+ public function hasPidColumn() {
+ // TODO Should we implement a check for having a pid column?
+ return TRUE;
+ }
+
+ /**
+ * Returns the name of a column holding the timestamp the record was modified
+ *
+ * @return string The field name
+ */
+ public function getTimestampColumnName() {
+ return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['tstamp'];
+ }
+
+ /**
+ * Returns TRUE if the table has a column holding the timestamp the record was modified
+ *
+ * @return boolean The result
+ */
+ public function hasTimestampColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['tstamp']);
+ }
+
+ /**
+ * Returns the name of a column holding the creation date timestamp
+ *
+ * @return string The field name
+ */
+ public function getCreationDateColumnName() {
+ return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['crdate'];
+ }
+
+ /**
+ * Returns TRUE if the table has olumn holding the creation date timestamp
+ *
+ * @return boolean The result
+ */
+ public function hasCreationDateColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['crdate']);
+ }
+
+ /**
+ * Returns the name of a column holding the uid of the back-end user who created this record
+ *
+ * @return string The field name
+ */
+ public function getCreatorUidColumnName() {
+ return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['cruser_id'];
+ }
+
+ /**
+ * Returns TRUE if the table has a column holding the uid of the back-end user who created this record
+ *
+ * @return boolean The result
+ */
+ public function hasCreatorUidColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['cruser_id']);
+ }
+
/**
* Returns the name of a column indicating the 'deleted' state of the row
*
- * @return string The class name
+ * @return string The field name
*/
public function getDeletedColumnName() {
return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['delete'];
}
+ /**
+ * Returns TRUE if the table has a column indicating the 'deleted' state of the row
+ *
+ * @return boolean The result
+ */
+ public function hasDeletedColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['delete']);
+ }
+
/**
* Returns the name of a column indicating the 'hidden' state of the row
*
+ * @return string The field name
*/
public function getHiddenColumnName() {
return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['disabled'];
}
+ /**
+ * Returns TRUE if the table has a column indicating the 'hidden' state of the row
+ *
+ * @return boolean The result
+ */
+ public function hasHiddenColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['disabled']);
+ }
+
+ /**
+ * Returns the name of a column holding the timestamp the record should not displayed before
+ *
+ * @return string The field name
+ */
+ public function getStartTimeColumnName() {
+ return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['starttime'];
+ }
+
+ /**
+ * Returns TRUE if the table has a column holding the timestamp the record should not displayed before
+ *
+ * @return boolean The result
+ */
+ public function hasStartTimeColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['starttime']);
+ }
+
+ /**
+ * Returns the name of a column holding the timestamp the record should not displayed afterwards
+ *
+ * @return string The field name
+ */
+ public function getEndTimeColumnName() {
+ return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['endtime'];
+ }
+
+ /**
+ * Returns TRUE if the table has a column holding the timestamp the record should not displayed afterwards
+ *
+ * @return boolean The result
+ */
+ public function hasEndTimeColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['endtime']);
+ }
+
+ /**
+ * Returns the name of a column holding the uid of the front-end user group which is allowed to edit this record
+ *
+ * @return string The field name
+ */
+ public function getFrontEndUserGroupColumnName() {
+ return $GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['fe_group'];
+ }
+
+ /**
+ * Returns TRUE if the table has a column holding the uid of the front-end user group which is allowed to edit this record
+ *
+ * @return boolean The result
+ */
+ public function hasFrontEndUserGroupColumn() {
+ return !empty($GLOBALS['TCA'][$this->getTableName()]['ctrl']['enablecolumns']['fe_group']);
+ }
+
/**
* Converts a value from a database field type to a property type
*
* @return void
*/
public function persistAll() {
- // first, persit all aggregate root objects
+ // first, persist all aggregate root objects
$aggregateRootClassNames = $this->persistenceSession->getAggregateRootClassNames();
foreach ($aggregateRootClassNames as $className) {
$this->persistObjects($className);
}
// persist all remaining objects registered manually
- // $this->persistObjects();
+ $this->persistObjects();
}
/**
foreach ($this->persistenceSession->getAddedObjects($className) as $object) {
$this->insertObject($object);
$this->persistenceSession->unregisterObject($object);
- $this->persistenceSession->registerReconstitutedObject($object);
+ // $this->persistenceSession->registerReconstitutedObject($object);
+ }
+ foreach ($this->persistenceSession->getRemovedObjects($className) as $object) {
+ $this->deleteObject($object);
+ $this->persistenceSession->unregisterObject($object);
}
foreach ($this->persistenceSession->getDirtyObjects($className) as $object) {
$this->updateObject($object);
$this->persistenceSession->unregisterObject($object);
$this->persistenceSession->registerReconstitutedObject($object);
}
- foreach ($this->persistenceSession->getRemovedObjects($className) as $object) {
- $this->deleteObject($object);
- $this->persistenceSession->unregisterObject($object);
- }
}
/**
$row[$parentTableFieldName] = $parentDataMap->getTableName();
}
}
-
+
+ if ($dataMap->hasPidColumn()) {
+ $row['pid'] = !empty($this->cObj->data['pages']) ? $this->cObj->data['pages'] : $GLOBALS['TSFE']->id;
+ }
+ if ($dataMap->hasCreationDateColumn()) {
+ $row[$dataMap->getCreationDateColumnName()] = time();
+ }
+ if ($dataMap->hasTimestampColumn()) {
+ $row[$dataMap->getTimestampColumnName()] = time();
+ }
unset($row['uid']);
-
- $row['pid'] = !empty($this->cObj->data['pages']) ? $this->cObj->data['pages'] : $GLOBALS['TSFE']->id;
- $row['tstamp'] = time();
-
$tableName = $dataMap->getTableName();
$res = $this->database->exec_INSERTquery(
$tableName,
$properties = $object->_getDirtyProperties();
$dataMap = $this->getDataMap(get_class($object));
$row = $this->getRow($dataMap, $properties);
- unset($row['uid']);
- // TODO Check for crdate column
- $row['crdate'] = time();
- if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
- $row['cruser_id'] = $GLOBALS['TSFE']->fe_user->user['uid'];
- }
+
if ($parentObject instanceof Tx_ExtBase_DomainObject_AbstractDomainObject && $parentPropertyName !== NULL) {
$parentDataMap = $this->getDataMap(get_class($parentObject));
$parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
}
}
+ unset($row['uid']);
+ if ($dataMap->hasTimestampColumn()) {
+ $row[$dataMap->getTimestampColumnName()] = time();
+ }
+ if ($dataMap->hasCreatorUidColumn() && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
+ $row[$dataMap->getCreatorUidColumnName()] = $GLOBALS['TSFE']->fe_user->user['uid'];
+ }
$tableName = $dataMap->getTableName();
$res = $this->database->exec_UPDATEquery(
$tableName,
$relations = $this->getRelations($dataMap, $properties);
$tableName = $dataMap->getTableName();
- if ($onlySetDeleted === TRUE && !empty($deletedColumnName)) {
+ if ($onlySetDeleted === TRUE && $dataMap->hasDeletedColumn()) {
$deletedColumnName = $dataMap->getDeletedColumnName();
$res = $this->database->exec_UPDATEquery(
$tableName,
$dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap($className);
$dataMap->initialize();
return $dataMap->isPersistableProperty($propertyName);
- return $dataMap->isPersistableProperty($propertyName);
}
/**
$dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
$dataMap->initialize();
$columnMaps = $dataMap->getColumnMaps();
- $this->assertEquals(12, count($columnMaps), 'The data map was not initialized (wrong number of column maps set).');
+ $this->assertEquals(10, count($columnMaps), 'The data map was not initialized (wrong number of column maps set).');
}
public function test_DeletedColumnNameCanBeResolved() {
$this->assertType('Tx_ExtBase_Persistence_Mapper_ColumnMap', $columnMap, 'The column could not be added.');
}
- public function test_ColumnListCanBeRetrieved() {
- $dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
- $dataMap->addColumn('column1');
- $dataMap->addColumn('column2');
- $dataMap->addColumn('column3');
- $dataMap->addColumn('column4');
- $columnList = $dataMap->getColumnList();
- $this->assertEquals($columnList, 'column1,column2,column3,column4', 'The column list could not be retrieved.');
- }
-
public function test_PersistablePropertyCanBeChecked() {
$dataMap = new Tx_ExtBase_Persistence_Mapper_DataMap('Tx_BlogExample_Domain_Model_Blog');
$dataMap->addColumn('configured_property');