1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cApiContentVersionCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: parent::__construct(cRegistry::getDbTableName('content_version'), 'idcontentversion');
30: $this->_setItemClass('cApiContentVersion');
31:
32:
33: $this->_setJoinPartner('cApiArticleLanguageCollection');
34: $this->_setJoinPartner('cApiTypeCollection');
35: }
36:
37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
53: public function create(array $parameters) {
54: global $auth;
55:
56: if (empty($author)) {
57: $author = $auth->auth['uname'];
58: }
59: if (empty($created)) {
60: $created = date('Y-m-d H:i:s');
61: }
62: if (empty($lastmodified)) {
63: $lastmodified = date('Y-m-d H:i:s');
64: }
65:
66: $item = $this->createNewItem();
67:
68:
69: foreach (array_keys($parameters) as $key) {
70: $item->set($key, $parameters[$key]);
71: }
72: $item->store();
73:
74: return $item;
75: }
76:
77: 78: 79: 80: 81: 82:
83: public function getIdsByWhereClause($where){
84:
85: $this->select($where);
86:
87: $ids = array();
88: while($item = $this->next()){
89: $ids[] = $item->get('idcontentversion');
90: }
91: return $ids;
92:
93: }
94:
95: }
96:
97: 98: 99: 100: 101: 102:
103: class cApiContentVersion extends Item {
104:
105: 106: 107: 108: 109: 110:
111: public function __construct($id = false) {
112: parent::__construct(cRegistry::getDbTableName('content_version'), 'idcontentversion');
113: $this->setFilters(array(), array());
114: if ($id !== false) {
115: $this->loadByPrimaryKey($id);
116: }
117: }
118:
119: 120: 121: 122: 123: 124: 125: 126: 127:
128: public function setField($name, $value, $safe = true) {
129: parent::setField($name, $value, $safe);
130: }
131:
132: 133: 134:
135: public function markAsCurrent() {
136:
137:
138: $content = new cApiContent();
139: $succ = $content->loadByArticleLanguageIdTypeAndTypeId(
140: $this->get('idartlang'),
141: $this->get('idtype'),
142: $this->get('typeid')
143: );
144:
145:
146: if (!$succ) {
147: $coll = new cApiContentCollection();
148: $content = $coll->createNewItem();
149: }
150:
151:
152: $content->set('idartlang', $this->get('idartlang'));
153: $content->set('idtype', $this->get('idtype'));
154: $content->set('typeid', $this->get('typeid'));
155: $content->set('value', $this->get('value'));
156: $content->set('author', $this->get('author'));
157: $content->set('created', $this->get('created'));
158: $content->set('lastmodified', $this->get('lastmodified'));
159:
160:
161: $content->store();
162:
163: }
164:
165: 166: 167: 168: 169: 170:
171: public function markAsEditable($version, $deleted) {
172:
173:
174: $parameters = $this->toArray();
175: unset($parameters['idcontentversion']);
176: $parameters['version'] = $version;
177:
178:
179: $contentVersionColl = new cApiContentVersionCollection();
180: $contentVersion = $contentVersionColl->create($parameters);
181: if ($deleted == 1) {
182: $contentVersion->set('deleted', $deleted);
183: }
184:
185: $contentVersion->store();
186:
187: }
188:
189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199:
200: public function loadByArticleLanguageIdTypeTypeIdAndVersion(array $contentParameters) {
201:
202: $props = array(
203: 'idartlang' => $contentParameters['idartlang'],
204: 'idtype' => $contentParameters['idtype'],
205: 'typeid' => $contentParameters['typeid'],
206: 'version' => $contentParameters['version']
207: );
208: $recordSet = $this->_oCache->getItemByProperties($props);
209: if ($recordSet) {
210:
211: $this->loadByRecordSet($recordSet);
212: return true;
213: } else {
214: $where = $this->db->prepare('idartlang = %d AND idtype = %d AND typeid = %d AND version <= %d GROUP BY pk desc LIMIT 1', $contentParameters['idartlang'], $contentParameters['idtype'], $contentParameters['typeid'], $contentParameters['version']);
215: return $this->_loadByWhereClause($where);
216: }
217:
218: }
219:
220: }
221: