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