allow to copy customfields
[tine20] / tine20 / ExampleApplication / Controller.php
1 <?php
2 /**
3  * Tine 2.0
4  * 
5  * @package     ExampleApplication
6  * @subpackage  Controller
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
8  * @author      Cornelius Weiss <c.weiss@metaways.de>
9  * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
10  *
11  */
12
13 /**
14  * ExampleApplication Controller (composite)
15  * 
16  * The ExampleApplication 2.0 Controller manages access (acl) to the different backends and supports
17  * a common interface to the servers/views
18  * 
19  * @package ExampleApplication
20  * @subpackage  Controller
21  */
22 class ExampleApplication_Controller extends Tinebase_Controller_Event implements Tinebase_Container_Interface
23 {
24     /**
25      * holds the default Model of this application
26      * @var string
27      */
28     protected static $_defaultModel = 'ExampleApplication_Model_ExampleRecord';
29     
30     /**
31      * the constructor
32      *
33      * don't use the constructor. use the singleton 
34      */
35     private function __construct() {
36         $this->_applicationName = 'ExampleApplication';
37     }
38     
39     /**
40      * don't clone. Use the singleton.
41      *
42      */
43     private function __clone() 
44     {
45     }
46     
47     /**
48      * holds self
49      * @var ExampleApplication_Controller
50      */
51     private static $_instance = NULL;
52     
53     /**
54      * singleton
55      *
56      * @return ExampleApplication_Controller
57      */
58     public static function getInstance() 
59     {
60         if (self::$_instance === NULL) {
61             self::$_instance = new ExampleApplication_Controller();
62         }
63         return self::$_instance;
64     }
65
66     /**
67      * creates the initial folder for new accounts
68      *
69      * @param mixed[int|Tinebase_Model_User] $_account   the account object
70      * @return Tinebase_Record_RecordSet  of subtype Tinebase_Model_Container
71      */
72     public function createPersonalFolder($_accountId)
73     {
74         $personalContainer = Tinebase_Container::getInstance()->createDefaultContainer(
75             'ExampleApplication_Model_ExampleRecord',
76             'ExampleApplication',
77             $_accountId
78         );
79
80         $container = new Tinebase_Record_RecordSet('Tinebase_Model_Container', array($personalContainer));
81
82         return $container;
83     }
84
85     /**
86      * event handler function
87      * 
88      * all events get routed through this function
89      *
90      * @param Tinebase_Event_Abstract $_eventObject the eventObject
91      */
92     protected function _handleEvent(Tinebase_Event_Abstract $_eventObject)
93     {
94         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . ' ' . __LINE__
95             . ' handle event of type ' . get_class($_eventObject));
96         
97         switch(get_class($_eventObject)) {
98             case 'Admin_Event_AddAccount':
99                 $this->createPersonalFolder($_eventObject->account);
100                 break;
101             case 'Tinebase_Event_User_DeleteAccount':
102                 /**
103                  * @var Tinebase_Event_User_DeleteAccount $_eventObject
104                  */
105                 if ($_eventObject->deletePersonalContainers()) {
106                     $this->deletePersonalFolder($_eventObject->account);
107                 }
108                 break;
109         }
110     }
111 }