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 cApiMetaTagVersionCollection extends ItemCollection {
24: 25: 26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['meta_tag_version'], 'idmetatagversion');
32: $this->_setItemClass('cApiMetaTagVersion');
33:
34:
35: $this->_setJoinPartner('cApiArticleLanguageVersionCollection');
36: $this->_setJoinPartner('cApiMetaTypeCollection');
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
53: public function create($idMetaTag, $idArtLang, $idMetaType, $metaValue, $version) {
54:
55:
56: $item = $this->createNewItem();
57:
58: $item->set('idmetatag', $idMetaTag, false);
59: $item->set('idartlang', $idArtLang, false);
60: $item->set('idmetatype', $idMetaType, false);
61: $item->set('metavalue', $metaValue, false);
62: $item->set('version', $version, false);
63: $item->store();
64:
65: return $item;
66: }
67:
68: 69: 70: 71: 72: 73: 74: 75: 76:
77: public function fetchByArtLangMetaTypeAndVersion($idArtLang, $idMetaType, $version) {
78: $sql = 'SELECT idmetatagversion FROM %s
79: WHERE (idmetatype, version)
80: IN (SELECT idmetatype, max(version)
81: FROM %s
82: WHERE idartlang = %d AND version <= %d AND idmetatype = %d group by idmetatype)
83: AND idartlang = %d';
84:
85: $this->db->query(
86: $sql,
87: cRegistry::getDbTableName('meta_tag_version'),
88: cRegistry::getDbTableName('meta_tag_version'),
89: (int) $idArtLang,
90: (int) $version,
91: (int) $idMetaType,
92: (int) $idArtLang
93: );
94:
95: $this->db->nextRecord();
96:
97: return new cApiMetaTagVersion($this->db->f('idmetatagversion'));
98: }
99:
100: 101: 102: 103: 104: 105: 106: 107:
108: public function fetchByArtLangAndMetaType($where) {
109: $metaTagVersionColl = new cApiMetaTagVersionCollection();
110: $metaTagVersionColl->select($where);
111:
112: while($item = $metaTagVersionColl->next()){
113: $ids[] = $item->get('idmetatagversion');
114: }
115: return $ids;
116:
117: }
118:
119: }
120:
121: 122: 123: 124: 125: 126:
127: class cApiMetaTagVersion extends Item
128: {
129: 130: 131: 132: 133: 134: 135: 136: 137:
138: public function __construct($id = false) {
139: global $cfg;
140: parent::__construct($cfg['tab']['meta_tag_version'], 'idmetatagversion');
141: $this->setFilters(array(), array());
142: if ($id !== false) {
143: $this->loadByPrimaryKey($id);
144: }
145: }
146:
147: 148: 149: 150: 151: 152: 153: 154:
155: public function updateMetaValue($metaValue) {
156: $this->set('metavalue', $metaValue, false);
157: return $this->store();
158: }
159:
160: 161: 162: 163: 164: 165: 166: 167:
168: public function markAsCurrent() {
169: $metaTagColl = new cApiMetaTagCollection();
170: $metaTag = $metaTagColl->fetchByArtLangAndMetaType($this->get('idartlang'), $this->get('idmetatype'));
171: if ($metaTag != NULL) {
172: $metaTag->set('metavalue', $this->get('metavalue'), false);
173: return $metaTag->store();
174: } else {
175: $metaTag = new cApiMetaTagCollection();
176: $metaTag->create($this->get('idartlang'), $this->get('idmetatype'), $this->get('metavalue'));
177: }
178: }
179:
180: 181: 182: 183: 184: 185: 186: 187:
188: public function markAsEditable($version) {
189: $metaTagVersionColl = new cApiMetaTagVersionCollection();
190: $metaTagVersionColl->create($this->get('idmetatag'), $this->get('idartlang'), $this->get('idmetatype'), $this->get('metavalue'), $version);
191: }
192:
193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204:
205: public function setField($name, $value, $safe = true) {
206: switch ($name) {
207: case 'idartlang':
208: $value = (int) $value;
209: break;
210: case 'idmetatype':
211: $value = (int) $value;
212: break;
213: }
214:
215: return parent::setField($name, $value, $safe);
216: }
217:
218: }
219: