18
18
limitations under the License.
19
19
=========================================================================*/
20
20
21
- /** sizequota main config controller */
21
+ /**
22
+ * This controller is used to manage size quotas on folders.
23
+ * It contains the actions for the main module configuration page as well as for
24
+ * maintaining folder-specific quotas.
25
+ */
22
26
class Sizequota_ConfigController extends Sizequota_AppController
23
27
{
28
+ public $ _models = array ('Folder ' , 'Setting ' );
29
+ public $ _moduleModels = array ('FolderQuota ' );
24
30
public $ _moduleForms = array ('Config ' );
25
31
26
32
/** index action*/
@@ -29,9 +35,8 @@ function indexAction()
29
35
$ this ->requireAdminPrivileges ();
30
36
31
37
$ modelLoader = new MIDAS_ModelLoader ();
32
- $ settingModel = $ modelLoader ->loadModel ('Setting ' );
33
- $ defaultUserQuota = $ settingModel ->getValueByName ('defaultuserquota ' , $ this ->moduleName );
34
- $ defaultCommunityQuota = $ settingModel ->getValueByName ('defaultcommunityquota ' , $ this ->moduleName );
38
+ $ defaultUserQuota = $ this ->Setting ->getValueByName ('defaultuserquota ' , $ this ->moduleName );
39
+ $ defaultCommunityQuota = $ this ->Setting ->getValueByName ('defaultcommunityquota ' , $ this ->moduleName );
35
40
36
41
$ configForm = $ this ->ModuleForm ->Config ->createConfigForm ();
37
42
$ formArray = $ this ->getFormAsArray ($ configForm );
@@ -59,14 +64,94 @@ function indexAction()
59
64
echo JsonComponent::encode (array (false , 'Invalid quota value. Please enter a positive integer. ' ));
60
65
return ;
61
66
}
62
- $ settingModel ->setConfig ('defaultuserquota ' , $ defaultUserQuota , $ this ->moduleName );
63
- $ settingModel ->setConfig ('defaultcommunityquota ' , $ defaultCommunityQuota , $ this ->moduleName );
67
+ $ this -> Setting ->setConfig ('defaultuserquota ' , $ defaultUserQuota , $ this ->moduleName );
68
+ $ this -> Setting ->setConfig ('defaultcommunityquota ' , $ defaultCommunityQuota , $ this ->moduleName );
64
69
echo JsonComponent::encode (array (true , 'Changes saved ' ));
65
70
}
66
71
}
67
72
}
68
73
69
- /** Test whether the provided quota value is legal */
74
+ /** Renders the view for folder-specific quotas */
75
+ public function folderAction ()
76
+ {
77
+ $ this ->disableLayout ();
78
+ if (!$ this ->_getParam ('folderId ' ))
79
+ {
80
+ throw new Zend_Exception ('Invalid parameters ' );
81
+ }
82
+ $ folder = $ this ->Folder ->load ($ this ->_getParam ('folderId ' ));
83
+
84
+ if (!$ folder )
85
+ {
86
+ throw new Zend_Exception ('Invalid folderId parameter ' );
87
+ }
88
+ if (!$ this ->Folder ->policyCheck ($ folder , $ this ->userSession ->Dao , MIDAS_POLICY_READ ))
89
+ {
90
+ throw new Zend_Exception ('Invalid policy ' );
91
+ }
92
+
93
+ if ($ folder ->getParentId () == -1 ) //user folder
94
+ {
95
+ $ defaultQuota = $ this ->Setting ->getValueByName ('defaultuserquota ' , $ this ->moduleName );
96
+ }
97
+ else if ($ folder ->getParentId () == -2 ) //community folder
98
+ {
99
+ $ defaultQuota = $ this ->Setting ->getValueByName ('defaultcommunityquota ' , $ this ->moduleName );
100
+ }
101
+ else
102
+ {
103
+ throw new Zend_Exception ('Must be a community or user root folder ' );
104
+ }
105
+
106
+ $ currentQuota = $ this ->Sizequota_FolderQuota ->getQuota ($ folder );
107
+ $ configForm = $ this ->ModuleForm ->Config ->createFolderForm ($ defaultQuota );
108
+ $ formArray = $ this ->getFormAsArray ($ configForm );
109
+ if ($ currentQuota === false )
110
+ {
111
+ $ formArray ['usedefault ' ]->setValue (MIDAS_USE_DEFAULT_QUOTA );
112
+ $ this ->view ->quota = $ defaultQuota ;
113
+ }
114
+ else
115
+ {
116
+ $ formArray ['usedefault ' ]->setValue (MIDAS_USE_SPECIFIC_QUOTA );
117
+ $ formArray ['quota ' ]->setValue ($ currentQuota ->getQuota ());
118
+ $ this ->view ->quota = $ currentQuota ->getQuota ();
119
+ }
120
+ $ this ->view ->configForm = $ formArray ;
121
+ $ this ->view ->folder = $ folder ;
122
+ $ this ->view ->usedSpace = $ this ->Folder ->getSizeFiltered ($ folder , $ this ->userSession ->Dao );
123
+ }
124
+
125
+ /** Used to manage folder-specific quotas (form handler) */
126
+ public function foldersubmitAction ()
127
+ {
128
+ $ this ->requireAdminPrivileges ();
129
+
130
+ $ this ->disableLayout ();
131
+ $ this ->_helper ->viewRenderer ->setNoRender ();
132
+ $ quota = $ this ->_getParam ('quota ' );
133
+ $ useDefault = $ this ->_getParam ('usedefault ' );
134
+ if ($ useDefault == MIDAS_USE_DEFAULT_QUOTA )
135
+ {
136
+ $ quota = null ;
137
+ }
138
+ $ folder = $ this ->Folder ->load ($ this ->_getParam ('folderId ' ));
139
+ if (!$ folder )
140
+ {
141
+ echo JsonComponent::encode (array (false , 'Invalid folderId parameter ' ));
142
+ return ;
143
+ }
144
+ if ($ quota !== null && !$ this ->_isValidQuota (array ($ quota )))
145
+ {
146
+ echo JsonComponent::encode (array (false , 'Invalid quota value. Please enter a positive integer. ' ));
147
+ return ;
148
+ }
149
+
150
+ $ this ->Sizequota_FolderQuota ->setQuota ($ folder , $ quota );
151
+ echo JsonComponent::encode (array (true , 'Changes saved ' ));
152
+ }
153
+
154
+ /** Test whether the provided quota values are legal */
70
155
private function _isValidQuota ($ quotas )
71
156
{
72
157
foreach ($ quotas as $ quota )
0 commit comments