[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Domain / Model / DatabaseRecord.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Domain\Model;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Database record class
18 *
19 * @author Oliver Hader <oliver.hader@typo3.org>
20 */
21 class DatabaseRecord {
22
23 /**
24 * @var string
25 */
26 protected $table;
27
28 /**
29 * @var integer
30 */
31 protected $uid;
32
33 /**
34 * @var array
35 */
36 protected $row;
37
38 /**
39 * Creates database record object just by id of database record.
40 *
41 * @param string $table Name of the database table
42 * @param integer $uid Id of the datbase record row
43 * @return \TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
44 */
45 static public function create($table, $uid) {
46 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Domain\\Model\\DatabaseRecord', $table, $uid);
47 }
48
49 /**
50 * Creates datbase record object by relevant database record row.
51 *
52 * @param string $table Name of the database table
53 * @param array $row The relevant database record row
54 * @return \TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord
55 */
56 static public function createFromArray($table, array $row) {
57 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Domain\\Model\\DatabaseRecord', $table, $row['uid'], $row);
58 }
59
60 /**
61 * @param string $table Name of the database table
62 * @param integer $uid Id of the datbase record row
63 * @param array|NULL $row The relevant database record row
64 */
65 public function __construct($table, $uid, array $row = NULL) {
66 $this->setTable($table);
67 $this->setUid($uid);
68 if ($row !== NULL) {
69 $this->setRow($row);
70 }
71 }
72
73 /**
74 * Gets the name of the database table.
75 *
76 * @return string
77 */
78 public function getTable() {
79 return $this->table;
80 }
81
82 /**
83 * Sets the name of the database table.
84 *
85 * @param string $table
86 * @return void
87 */
88 public function setTable($table) {
89 $this->table = $table;
90 }
91
92 /**
93 * Gets the id of the database record row.
94 *
95 * @return integer
96 */
97 public function getUid() {
98 return $this->uid;
99 }
100
101 /**
102 * Sets the id of the database record row.
103 *
104 * @param integer $uid
105 * @return void
106 */
107 public function setUid($uid) {
108 $this->uid = $uid;
109 }
110
111 /**
112 * Gets the database record row.
113 *
114 * @return array
115 */
116 public function getRow() {
117 $this->loadRow();
118 return $this->row;
119 }
120
121 /**
122 * Sets the database record row.
123 *
124 * @param array $row
125 * @return void
126 */
127 public function setRow(array $row) {
128 $this->row = $row;
129 }
130
131 /**
132 * Gets the record identifier (table:id).
133 *
134 * @return string
135 */
136 public function getIdentifier() {
137 return implode(':', array($this->getTable(), $this->getUid()));
138 }
139
140 /**
141 * Loads the database record row (if not available yet).
142 *
143 * @return void
144 */
145 protected function loadRow() {
146 if ($this->row === NULL) {
147 $this->row = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($this->getTable(), $this->getUid());
148 }
149 }
150
151 }