wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.TableRDBMapper.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.TableRDBMapper.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/model/mapper/class.RDBMapper.php");
20 require_once(BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE."wcmf/lib/persistence/converter/class.DataConverter.php");
22 require_once(BASE."wcmf/lib/model/class.Table.php");
23 
24 /**
25  * @class TableRDBMapper
26  * @ingroup Mapper
27  * @brief TableRDBMapper maps Table objects to a relational database schema where one
28  * object contains several table rows.
29  *
30  * @author ingo herwig <ingo@wemove.com>
31  */
33 {
34  /**
35  * @see RDBMapper::createObject()
36  */
37  function &createObject($oid=null)
38  {
39  return new Table($this->getType(), $oid);
40  }
41  /**
42  * @see RDBMapper::appendObject()
43  */
44  function appendObject(&$object, &$dependendObject)
45  {
46  // do nothing because tables have no other tables included!
47  }
48  /**
49  * @see RDBMapper::applyDataOnLoad()
50  */
51  function applyDataOnLoad(&$object, $objectData, $attribs)
52  {
53  $persistenceFacade = &PersistenceFacade::getInstance();
54 
55  // set object data
56  foreach($objectData['_datadef'] as $dataItem)
57  {
58  if ($attribs == null || in_array($dataItem['name'], $attribs))
59  {
60  $valueProperties = array();
61  foreach($dataItem as $key => $value)
62  if ($key != 'name')
63  $valueProperties[$key] = $value;
64 
65  // loop over all rows
66  foreach($objectData['_data'] as $row)
67  {
68  $rowId = $row['id'];
69  $value = $this->_dataConverter->convertStorageToApplication($row[$dataItem['name']], $dataItem['db_data_type'], $dataItem['name']);
70  $object->setValue($rowId, $value, $dataItem['name']);
71  $object->setValueProperties($rowId, $valueProperties, $dataItem['name']);
72  }
73  }
74  }
75  $object->reIndex();
76  }
77  /**
78  * @see RDBMapper::applyDataOnCreate()
79  */
80  function applyDataOnCreate(&$object, $objectData, $attribs)
81  {
82  // set object data
83  foreach($objectData['_datadef'] as $dataItem)
84  {
85  if ($attribs == null || in_array($dataItem['name'], $attribs))
86  {
87  $valueProperties = array();
88  foreach($dataItem as $key => $value)
89  if ($key != 'name')
90  $valueProperties[$key] = $value;
91 
92  $value = $this->_dataConverter->convertStorageToApplication($dataItem['default'], $dataItem['db_data_type'], $dataItem['name']);
93  $object->setValue(0, $value, $dataItem['name']);
94  $object->setValueProperties(0, $valueProperties, $dataItem['name']);
95  }
96  }
97  }
98  /**
99  * @see RDBMapper::getObjectDefinition()
100  *
101  * The _datadef key holds the following structure:
102  *
103  * An array of assoziative arrays with the key 'name' plus application specific keys for every data item.
104  * All keys except 'name' will become keys in the objects valueProperties array hold for each data item while 'name'
105  * is used to identify the values types, see PersistentObject::getValue(). 'name' entries correspond to table columns.
106  * (e.g. array('name' => 'title', 'db_data_type' => 'VARCHAR(255)', 'default' => 'Hello World!')) @n
107  * Known keys are:
108  * - @em db_data_type: The database data type of the attribute. This may be used to decide on value conversions in the assoziated DataConverter class
109  * - @em default: The default value (will be set when creating a blank object, see PersistenceMapper::create())
110  * - @em restrictions_match: A regular expression that the value must match (e.g. '[0-3][0-9]\.[0-1][0-9]\.[0-9][0-9][0-9][0-9]' for date values)
111  * - @em restrictions_not_match: A regular expression that the value must NOT match
112  * - @em is_editable: true, false whether the value should be editable, see FormUtil::getInputControl()
113  * - @em input_type: The HTML input type for the value, see FormUtil::getInputControl()
114  *
115  * @note the content of the _children array is ignored by this mapper because tables have no other tables included.
116  */
118  {
119  WCMFException::throwEx("getObjectDefinition() must be implemented by derived class: ".get_class($this), __FILE__, __LINE__);
120  }
121  /**
122  * @see RDBMapper::getChildrenSelectSQL()
123  */
124  function getChildrenSelectSQL($oid, $compositionOnly=false)
125  {
126  // tables have no other tables included!
127  return array();
128  }
129 }
130 ?>
RDBMapper maps objects of one type to a relational database schema. It defines a persistence mechanis...
applyDataOnCreate(&$object, $objectData, $attribs)
TableRDBMapper maps Table objects to a relational database schema where one object contains several t...
appendObject(&$object, &$dependendObject)
throwEx($message, $file='', $line='')
applyDataOnLoad(&$object, $objectData, $attribs)
getChildrenSelectSQL($oid, $compositionOnly=false)
Table is a PersistentObject that holds a table structure. The rows of the table correspond to the val...
Definition: class.Table.php:34
& createObject($oid=null)