1: <?php
2:
3: /**
4: * This file contains the communication 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: * Communication collection
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class cApiCommunicationCollection extends ItemCollection {
24:
25: /**
26: * Constructor Function
27: */
28: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['communications'], 'idcommunication');
31: $this->_setItemClass('cApiCommunication');
32:
33: // set the join partners so that joins can be used via link() method
34: $this->_setJoinPartner('cApiClientCollection');
35: }
36:
37: /**
38: * Creates a new communication item.
39: *
40: * @return cApiCommunication
41: */
42: public function create() {
43: global $auth, $client;
44: $item = $this->createNewItem();
45:
46: $item->set('idclient', $client);
47: $item->set('author', $auth->auth['uid']);
48: $item->set('created', date('Y-m-d H:i:s'), false);
49:
50: return $item;
51: }
52:
53: }
54:
55: /**
56: * Communication item
57: *
58: * @package Core
59: * @subpackage GenericDB_Model
60: */
61: class cApiCommunication extends Item {
62:
63: /**
64: * Constructor Function
65: *
66: * @param mixed $mId [optional]
67: * Specifies the ID of item to load
68: */
69: public function __construct($mId = false) {
70: global $cfg;
71: parent::__construct($cfg['tab']['communications'], 'idcommunication');
72: if ($mId !== false) {
73: $this->loadByPrimaryKey($mId);
74: }
75: }
76:
77: /**
78: * Saves a communication item
79: *
80: * @see Item::store()
81: * @return bool
82: */
83: public function store() {
84: global $auth;
85: $this->set('modifiedby', $auth->auth['uid']);
86: $this->set('modified', date('Y-m-d H:i:s'), false);
87:
88: return parent::store();
89: }
90:
91: /**
92: * Userdefined setter for communcation fields.
93: *
94: * @param string $name
95: * @param mixed $value
96: * @param bool $bSafe [optional]
97: * Flag to run defined inFilter on passed value
98: * @return bool
99: */
100: public function setField($name, $value, $bSafe = true) {
101: switch ($name) {
102: case 'idclient':
103: $value = (int) $value;
104: break;
105: }
106:
107: return parent::setField($name, $value, $bSafe);
108: }
109:
110: }
111: