1: <?php
2:
3: /**
4: * This file contains the meta tag collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Murat Purc <murat@purc.de>
9: * @copyright four for business AG <www.4fb.de>
10: * @license http://www.contenido.org/license/LIZENZ.txt
11: * @link http://www.4fb.de
12: * @link http://www.contenido.org
13: */
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: /**
18: * Metatag collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiMetaTagCollection extends ItemCollection {
24: /**
25: * Constructor to create an instance of this class.
26: *
27: * @throws cInvalidArgumentException
28: */
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['meta_tag'], 'idmetatag');
32: $this->_setItemClass('cApiMetaTag');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiArticleLanguageCollection');
36: $this->_setJoinPartner('cApiMetaTypeCollection');
37: }
38:
39: /**
40: * Creates a meta tag entry.
41: *
42: * @param int $iIdArtLang
43: * @param int $iIdMetaType
44: * @param string $sMetaValue
45: *
46: * @return cApiMetaTag
47: * @throws cDbException
48: * @throws cException
49: * @throws cInvalidArgumentException
50: */
51: public function create($iIdArtLang, $iIdMetaType, $sMetaValue) {
52: $oItem = $this->createNewItem();
53:
54: $oItem->set('idartlang', $iIdArtLang, false);
55: $oItem->set('idmetatype', $iIdMetaType, false);
56: $oItem->set('metavalue', $sMetaValue, false);
57: $oItem->store();
58:
59: return $oItem;
60: }
61:
62: /**
63: * Returns a meta tag entry by article language and meta type.
64: *
65: * @param int $iIdArtLang
66: * @param int $iIdMetaType
67: * @return cApiMetaTag|NULL
68: * @throws cDbException
69: * @throws cException
70: */
71: public function fetchByArtLangAndMetaType($iIdArtLang, $iIdMetaType) {
72: $this->select('idartlang=' . (int) $iIdArtLang . ' AND idmetatype=' . (int) $iIdMetaType);
73: return $this->next();
74: }
75:
76: }
77:
78: /**
79: * Metatag item
80: *
81: * @package Core
82: * @subpackage GenericDB_Model
83: */
84: class cApiMetaTag extends Item
85: {
86: /**
87: * Constructor to create an instance of this class.
88: *
89: * @param mixed $mId
90: * Specifies the ID of item to load
91: *
92: * @throws cDbException
93: * @throws cException
94: */
95: public function __construct($mId = false) {
96: global $cfg;
97: parent::__construct($cfg['tab']['meta_tag'], 'idmetatag');
98: $this->setFilters(array(), array());
99: if ($mId !== false) {
100: $this->loadByPrimaryKey($mId);
101: }
102: }
103:
104: /**
105: * Updates meta value of an entry.
106: *
107: * @param string $sMetaValue
108: * @return bool
109: * @throws cDbException
110: * @throws cInvalidArgumentException
111: */
112: public function updateMetaValue($sMetaValue) {
113: $this->set('metavalue', $sMetaValue, false);
114: return $this->store();
115: }
116:
117: /**
118: * Userdefined setter for meta tag fields.
119: *
120: * @param string $name
121: * @param mixed $value
122: * @param bool $bSafe [optional]
123: * Flag to run defined inFilter on passed value
124: * @return bool
125: */
126: public function setField($name, $value, $bSafe = true) {
127: switch ($name) {
128: case 'idartlang':
129: $value = (int) $value;
130: break;
131: case 'idmetatype':
132: $value = (int) $value;
133: break;
134: }
135:
136: return parent::setField($name, $value, $bSafe);
137: }
138:
139: /**
140: * Creates a new, editable Version with same properties
141: *
142: * @param string $version
143: * @throws cDbException
144: * @throws cException
145: * @throws cInvalidArgumentException
146: */
147: public function markAsEditable($version) {
148: //var_export($this->values);
149: //$parameters = $this->values;
150: //$parameters['version'] = $version;
151: $metaTagVersionColl = new cApiMetaTagVersionCollection();
152: $metaTagVersionColl->create(
153: $this->getField('idmetatag'),
154: $this->getField('idartlang'),
155: $this->getField('idmetatype'),
156: $this->getField('metavalue'),
157: $version
158: );
159:
160: }
161:
162: }
163: