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:
129: public function setField($name, $value, $safe = true) {
130: return parent::setField($name, $value, $safe);
131: }
132:
133: 134: 135:
136: public function markAsCurrent() {
137:
138:
139: $content = new cApiContent();
140: $succ = $content->loadByArticleLanguageIdTypeAndTypeId(
141: $this->get('idartlang'),
142: $this->get('idtype'),
143: $this->get('typeid')
144: );
145:
146:
147: if (!$succ) {
148: $coll = new cApiContentCollection();
149: $content = $coll->createNewItem();
150: }
151:
152:
153: $content->set('idartlang', $this->get('idartlang'));
154: $content->set('idtype', $this->get('idtype'));
155: $content->set('typeid', $this->get('typeid'));
156: $content->set('value', $this->get('value'));
157: $content->set('author', $this->get('author'));
158: $content->set('created', $this->get('created'));
159: $content->set('lastmodified', $this->get('lastmodified'));
160:
161:
162: $content->store();
163:
164: }
165:
166: 167: 168: 169: 170: 171:
172: public function markAsEditable($version, $deleted) {
173:
174:
175: $parameters = $this->toArray();
176: unset($parameters['idcontentversion']);
177: $parameters['version'] = $version;
178:
179:
180: $contentVersionColl = new cApiContentVersionCollection();
181: $contentVersion = $contentVersionColl->create($parameters);
182: if ($deleted == 1) {
183: $contentVersion->set('deleted', $deleted);
184: }
185:
186: $contentVersion->store();
187:
188: }
189:
190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200:
201: public function loadByArticleLanguageIdTypeTypeIdAndVersion(array $contentParameters) {
202:
203: $props = array(
204: 'idartlang' => $contentParameters['idartlang'],
205: 'idtype' => $contentParameters['idtype'],
206: 'typeid' => $contentParameters['typeid'],
207: 'version' => $contentParameters['version']
208: );
209: $recordSet = $this->_oCache->getItemByProperties($props);
210: if ($recordSet) {
211:
212: $this->loadByRecordSet($recordSet);
213: return true;
214: } else {
215: $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']);
216: return $this->_loadByWhereClause($where);
217: }
218:
219: }
220:
221: }
222: