1: <?php
2:
3: /**
4: * This file contains the upload meta collection and item class.
5: *
6: * @package Core
7: * @subpackage GenericDB_Model
8: * @author Dominik Ziegler
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: * Upload meta collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiUploadMetaCollection 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']['upl_meta'], 'id_uplmeta');
32: $this->_setItemClass('cApiUploadMeta');
33:
34: // set the join partners so that joins can be used via link() method
35: $this->_setJoinPartner('cApiUploadCollection');
36: }
37:
38: /**
39: * Creates a upload meta entry.
40: *
41: * @param int $idupl
42: * @param int $idlang
43: * @param string $medianame [optional]
44: * @param string $description [optional]
45: * @param string $keywords [optional]
46: * @param string $internal_notice [optional]
47: * @param string $copyright [optional]
48: * @param string $author [optional]
49: * @param string $created [optional]
50: * @param string $modified [optional]
51: * @param string $modifiedby [optional]
52: *
53: * @return cApiUploadMeta
54: * @throws cDbException
55: * @throws cException
56: * @throws cInvalidArgumentException
57: * @global object $auth
58: */
59: public function create($idupl, $idlang, $medianame = '', $description = '',
60: $keywords = '', $internal_notice = '', $copyright = '', $author = '',
61: $created = '', $modified = '', $modifiedby = '') {
62: global $auth;
63:
64: if (empty($author)) {
65: $author = $auth->auth['uname'];
66: }
67: if (empty($created)) {
68: $created = date('Y-m-d H:i:s');
69: }
70: if (empty($modified)) {
71: $modified = date('Y-m-d H:i:s');
72: }
73:
74: $oItem = $this->createNewItem();
75:
76: $oItem->set('idupl', $idupl);
77: $oItem->set('idlang', $idlang);
78: $oItem->set('medianame', $medianame);
79: $oItem->set('description', $description);
80: $oItem->set('keywords', $keywords);
81: $oItem->set('internal_notice', $internal_notice);
82: $oItem->set('author', $author);
83: $oItem->set('created', $created);
84: $oItem->set('modified', $modified);
85: $oItem->set('modifiedby', $modifiedby);
86: $oItem->set('copyright', $copyright);
87: $oItem->store();
88:
89: return $oItem;
90: }
91: }
92:
93: /**
94: * Upload meta item
95: *
96: * @package Core
97: * @subpackage GenericDB_Model
98: */
99: class cApiUploadMeta extends Item
100: {
101: /**
102: * Constructor to create an instance of this class.
103: *
104: * @param mixed $mId [optional]
105: * Specifies the ID of item to load
106: *
107: * @throws cDbException
108: * @throws cException
109: */
110: public function __construct($mId = false) {
111: global $cfg;
112: parent::__construct($cfg['tab']['upl_meta'], 'id_uplmeta');
113: $this->setFilters(array(), array());
114: if ($mId !== false) {
115: $this->loadByPrimaryKey($mId);
116: }
117: }
118:
119: /**
120: * Loads an upload meta entry by upload id and language id
121: *
122: * @param int $idupl
123: * @param int $idlang
124: *
125: * @return bool
126: *
127: * @throws cException
128: */
129: public function loadByUploadIdAndLanguageId($idupl, $idlang) {
130: $aProps = array(
131: 'idupl' => $idupl,
132: 'idlang' => $idlang
133: );
134: $aRecordSet = $this->_oCache->getItemByProperties($aProps);
135: if ($aRecordSet) {
136: // entry in cache found, load entry from cache
137: $this->loadByRecordSet($aRecordSet);
138: return true;
139: } else {
140: $where = $this->db->prepare('idupl = %d AND idlang = %d', $idupl, $idlang);
141: return $this->_loadByWhereClause($where);
142: }
143: }
144:
145: /**
146: * Userdefined setter for upload meta fields.
147: *
148: * @param string $name
149: * @param mixed $value
150: * @param bool $bSafe [optional]
151: * Flag to run defined inFilter on passed value
152: *
153: * @return bool
154: */
155: public function setField($name, $value, $bSafe = true) {
156: switch ($name) {
157: case 'idupl':
158: case 'idlang':
159: $value = (int) $value;
160: break;
161: }
162:
163: return parent::setField($name, $value, $bSafe);
164: }
165: }
166: