1: <?php
2:
3: /**
4: * This file contains the actionlog 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: * Actionlog collection.
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiActionlogCollection extends ItemCollection {
24: /**
25: * Constructor to create an instance of this class.
26: *
27: * Tables user, client, language, action & category_article
28: * are allowed as join partners.
29: *
30: * @throws cInvalidArgumentException
31: */
32: public function __construct() {
33: global $cfg;
34: parent::__construct($cfg['tab']['actionlog'], 'idlog');
35: $this->_setItemClass('cApiActionlog');
36:
37: // set the join partners so that joins can be used via link() method
38: $this->_setJoinPartner('cApiUserCollection');
39: $this->_setJoinPartner('cApiClientCollection');
40: $this->_setJoinPartner('cApiLanguageCollection');
41: $this->_setJoinPartner('cApiActionCollection');
42: $this->_setJoinPartner('cApiCategoryArticleCollection');
43: }
44:
45: /**
46: * Creates an actionlog item.
47: *
48: * @param string $userId
49: * User id
50: * @param int $idclient
51: * @param int $idlang
52: * @param int $idaction
53: * @param int $idcatart
54: * @param string $logtimestamp [optional]
55: *
56: * @return cApiActionlog
57: *
58: * @throws cDbException
59: * @throws cException
60: * @throws cInvalidArgumentException
61: */
62: public function create($userId, $idclient, $idlang, $idaction, $idcatart, $logtimestamp = '') {
63: $item = $this->createNewItem();
64:
65: if (empty($logtimestamp)) {
66: $logtimestamp = date('Y-m-d H:i:s');
67: }
68:
69: $item->set('user_id', $userId);
70: $item->set('idclient', $idclient);
71: $item->set('idlang', $idlang);
72: $item->set('idaction', $idaction);
73: $item->set('idcatart', $idcatart);
74: $item->set('logtimestamp', $logtimestamp);
75:
76: $item->store();
77:
78: return $item;
79: }
80:
81: }
82:
83: /**
84: * Actionlog item.
85: *
86: * @package Core
87: * @subpackage GenericDB_Model
88: */
89: class cApiActionlog extends Item
90: {
91: /**
92: * Constructor to create an instance of this class.
93: *
94: * @param mixed $mId [optional]
95: * Specifies the ID of item to load
96: *
97: * @throws cDbException
98: * @throws cException
99: */
100: public function __construct($mId = false) {
101: global $cfg;
102: parent::__construct($cfg['tab']['actionlog'], 'idlog');
103: $this->setFilters(array(), array());
104: if ($mId !== false) {
105: $this->loadByPrimaryKey($mId);
106: }
107: }
108:
109: /**
110: * Userdefined setter for action log fields.
111: *
112: * @param string $name
113: * @param mixed $value
114: * @param bool $bSafe [optional]
115: * Flag to run defined inFilter on passed value
116: * @return bool
117: */
118: public function setField($name, $value, $bSafe = true) {
119: switch ($name) {
120: case 'idclient':
121: $value = (int) $value;
122: break;
123: case 'idlang':
124: $value = (int) $value;
125: break;
126: case 'idaction':
127: $value = (int) $value;
128: break;
129: case 'idcatart':
130: $value = (int) $value;
131: break;
132: }
133:
134: return parent::setField($name, $value, $bSafe);
135: }
136:
137: }
138: