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:
29: public function __construct() {
30: parent::__construct(cRegistry::getDbTableName('content_version'), 'idcontentversion');
31: $this->_setItemClass('cApiContentVersion');
32:
33:
34: $this->_setJoinPartner('cApiArticleLanguageCollection');
35: $this->_setJoinPartner('cApiTypeCollection');
36: }
37:
38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: public function create(array $parameters) {
49: global $auth;
50:
51: if (empty($author)) {
52: $author = $auth->auth['uname'];
53: }
54: if (empty($created)) {
55: $created = date('Y-m-d H:i:s');
56: }
57: if (empty($lastmodified)) {
58: $lastmodified = date('Y-m-d H:i:s');
59: }
60:
61: $item = $this->createNewItem();
62:
63:
64: foreach (array_keys($parameters) as $key) {
65: $item->set($key, $parameters[$key]);
66: }
67: $item->store();
68:
69: return $item;
70: }
71:
72: 73: 74: 75: 76: 77: 78: 79:
80: public function getIdsByWhereClause($where){
81:
82: $this->select($where);
83:
84: $ids = array();
85: while($item = $this->next()){
86: $ids[] = $item->get('idcontentversion');
87: }
88: return $ids;
89:
90: }
91:
92: }
93:
94: 95: 96: 97: 98: 99:
100: class cApiContentVersion extends Item
101: {
102: 103: 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: 137:
138: public function markAsCurrent() {
139:
140:
141: $content = new cApiContent();
142: $succ = $content->loadByArticleLanguageIdTypeAndTypeId(
143: $this->get('idartlang'),
144: $this->get('idtype'),
145: $this->get('typeid')
146: );
147:
148:
149: if (!$succ) {
150: $coll = new cApiContentCollection();
151: $content = $coll->createNewItem();
152: }
153:
154:
155: $content->set('idartlang', $this->get('idartlang'));
156: $content->set('idtype', $this->get('idtype'));
157: $content->set('typeid', $this->get('typeid'));
158: $content->set('value', $this->get('value'));
159: $content->set('author', $this->get('author'));
160: $content->set('created', $this->get('created'));
161: $content->set('lastmodified', $this->get('lastmodified'));
162:
163:
164: $content->store();
165: }
166:
167: 168: 169: 170: 171: 172: 173: 174: 175:
176: public function markAsEditable($version, $deleted) {
177:
178:
179: $parameters = $this->toArray();
180: unset($parameters['idcontentversion']);
181: $parameters['version'] = $version;
182:
183:
184: $contentVersionColl = new cApiContentVersionCollection();
185: $contentVersion = $contentVersionColl->create($parameters);
186: if ($deleted == 1) {
187: $contentVersion->set('deleted', $deleted);
188: }
189:
190: $contentVersion->store();
191:
192: }
193:
194: 195: 196: 197: 198: 199: 200: 201: 202:
203: public function loadByArticleLanguageIdTypeTypeIdAndVersion(array $contentParameters) {
204: $props = array(
205: 'idartlang' => $contentParameters['idartlang'],
206: 'idtype' => $contentParameters['idtype'],
207: 'typeid' => $contentParameters['typeid'],
208: 'version' => $contentParameters['version']
209: );
210: $recordSet = $this->_oCache->getItemByProperties($props);
211: if ($recordSet) {
212:
213: $this->loadByRecordSet($recordSet);
214: return true;
215: } else {
216: $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']);
217: return $this->_loadByWhereClause($where);
218: }
219:
220: }
221:
222: }
223: