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 cApiContentCollection extends ItemCollection {
24:
25: 26: 27:
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['content'], 'idcontent');
31: $this->_setItemClass('cApiContent');
32:
33:
34: $this->_setJoinPartner('cApiArticleLanguageCollection');
35: $this->_setJoinPartner('cApiTypeCollection');
36: }
37:
38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
51: public function create($idArtLang, $idType, $typeId, $value, $version, $author = '', $created = '', $lastmodified = '') {
52: global $auth;
53:
54: if (empty($author)) {
55: $author = $auth->auth['uname'];
56: }
57: if (empty($created)) {
58: $created = date('Y-m-d H:i:s');
59: }
60: if (empty($lastmodified)) {
61: $lastmodified = date('Y-m-d H:i:s');
62: }
63:
64: $oItem = $this->createNewItem();
65:
66: $oItem->set('idartlang', $idArtLang);
67: $oItem->set('idtype', $idType);
68: $oItem->set('typeid', $typeId);
69: $oItem->set('value', $value);
70: $oItem->set('version', $version);
71: $oItem->set('author', $author);
72: $oItem->set('created', $created);
73: $oItem->set('lastmodified', $lastmodified);
74:
75: $oItem->store();
76:
77: return $oItem;
78: }
79:
80: }
81:
82: 83: 84: 85: 86: 87:
88: class cApiContent extends Item {
89:
90: 91: 92: 93: 94: 95:
96: public function __construct($mId = false) {
97: global $cfg;
98: parent::__construct($cfg['tab']['content'], 'idcontent');
99: $this->setFilters(array(), array());
100: if ($mId !== false) {
101: $this->loadByPrimaryKey($mId);
102: }
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112: 113:
114: public function setField($name, $value, $bSafe = true) {
115: switch ($name) {
116: case 'idartlang':
117: case 'idtype':
118: case 'typeid':
119: case 'version':
120: $value = (int) $value;
121: break;
122: }
123:
124: parent::setField($name, $value, $bSafe);
125: }
126:
127: 128: 129: 130: 131: 132:
133: public function markAsEditable($version, $deleted) {
134: $parameters = $this->values;
135: $parameters['version'] = $version;
136: $contentVersionColl = new cApiContentVersionCollection();
137: $contentVersion = $contentVersionColl->create($parameters);
138: if ($deleted == 1) {
139: $contentVersion->set('deleted', $deleted);
140: }
141: $contentVersion->store();
142: }
143:
144: 145: 146: 147: 148: 149: 150: 151:
152: public function loadByArticleLanguageIdTypeAndTypeId($idartlang, $idtype, $typeid) {
153: $aProps = array(
154: 'idartlang' => $idartlang,
155: 'idtype' => $idtype,
156: 'typeid' => $typeid
157: );
158: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
159: if ($aRecordSet) {
160:
161: $this->loadByRecordSet($aRecordSet);
162: return true;
163: } else {
164: $where = $this->db->prepare("idartlang = %d AND idtype = %d AND typeid = %d", $idartlang, $idtype, $typeid);
165: return $this->_loadByWhereClause($where);
166: }
167: }
168:
169: }
170: