9
9
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
10
PURPOSE. See the above copyright notices for more information.
11
11
=========================================================================*/
12
- /** community agreement config controller*/
12
+ /**
13
+ * Communityagreement_ConfigController
14
+ *
15
+ * @category Midas modules
16
+ * @package communityagreement
17
+ */
13
18
class Communityagreement_ConfigController extends Communityagreement_AppController
14
19
{
15
20
public $ _models = array ('Community ' );
16
21
public $ _moduleModels = array ('Agreement ' );
17
22
public $ _moduleForms = array ('Config ' );
18
-
19
- /** index */
23
+
24
+ /**
25
+ * @method indexAction()
26
+ * @throws Zend_Exception on invalid userSession
27
+ */
20
28
function indexAction ()
21
29
{
22
30
if (!$ this ->logged || !$ this ->userSession ->Dao ->getAdmin () == 1 )
23
31
{
24
32
throw new Zend_Exception ("You should be an administrator " );
25
33
}
26
- }
27
-
28
- /**
29
- * @method agreementtabAction()
30
- * community agreement tab. It is shown in the community manage page when the 'community agreement' module is enabled
31
- */
34
+ }
35
+
36
+ /** community agreement tab
37
+ *
38
+ * Shown in the community manage page when the 'community agreement' module is enabled
39
+ *
40
+ * @method agreementtabAction()
41
+ * @throws Zend_Exception on invalid communityId
42
+ */
32
43
function agreementtabAction ()
33
44
{
34
-
35
- if (!$ this ->logged )
45
+
46
+ if (!$ this ->logged )
36
47
{
37
48
$ this ->haveToBeLogged ();
38
49
return false ;
39
50
}
40
- if ($ this ->_helper ->hasHelper ('layout ' ))
51
+ if ($ this ->_helper ->hasHelper ('layout ' ))
41
52
{
42
53
$ this ->_helper ->layout ->disableLayout ();
43
54
}
44
-
55
+
45
56
$ communityId = $ this ->_getParam ("communityId " );
46
57
if (!isset ($ communityId ) || (!is_numeric ($ communityId ) && strlen ($ communityId ) != 32 )) // This is tricky! and for Cassandra for now
47
58
{
48
59
throw new Zend_Exception ("Community ID should be a number " );
49
60
}
50
-
61
+
51
62
$ agreementDao = $ this ->Communityagreement_Agreement ->getByCommunityId ($ communityId );
52
-
53
- // If community agreement does not exist, show an emtpy string to the cummunity administrator
63
+
64
+ // If cannot find any community agreement using the given communityID,
65
+ // initilize the community agreement using an empty string and then create an agreementDao
54
66
if ($ agreementDao == false )
55
67
{
56
68
$ agreement = '' ;
57
69
$ agreementDao = $ this ->Communityagreement_Agreement ->createAgreement ($ communityId , $ agreement );
58
70
}
59
-
60
- $ formAgreement = $ this ->ModuleForm ->Config ->createCreateAgreementForm ($ communityId );
61
- if ($ this ->_request ->isPost () && $ formAgreement ->isValid ($ this ->getRequest ()->getPost ()))
71
+
72
+ $ formAgreement = $ this ->ModuleForm ->Config ->createCreateAgreementForm ($ communityId );
73
+ if ($ this ->_request ->isPost () && $ formAgreement ->isValid ($ this ->getRequest ()->getPost ()))
62
74
{
63
- if ($ this ->_helper ->hasHelper ('layout ' ))
75
+ if ($ this ->_helper ->hasHelper ('layout ' ))
64
76
{
65
77
$ this ->_helper ->layout ->disableLayout ();
66
78
}
@@ -75,32 +87,38 @@ function agreementtabAction()
75
87
echo JsonComponent::encode (array (false , $ this ->t ('Error ' )));
76
88
}
77
89
}
78
-
79
- // if agreement only contains white spaces, delete it from the database.
90
+
91
+ // If a community agreement only contains white spaces, it is treated as an empty agreement
92
+ // and will be deleted from the database if it exists
80
93
$ chopped_agreement = chop ($ agreementDao ->getAgreement ());
81
- if ($ chopped_agreement != '' )
94
+ if ($ chopped_agreement != '' )
82
95
{
83
96
$ this ->Communityagreement_Agreement ->save ($ agreementDao );
84
97
}
85
98
else if ($ this ->Communityagreement_Agreement ->getByCommunityId ($ communityId ) != false )
86
99
{
87
100
$ this ->Communityagreement_Agreement ->delete ($ agreementDao );
88
101
}
89
-
90
- //init form
102
+
103
+ // init form
91
104
$ agreement = $ formAgreement ->getElement ('agreement ' );
92
105
$ agreement ->setValue ($ agreementDao ->getAgreement ());
93
- $ this ->view ->agreementForm = $ this ->getFormAsArray ($ formAgreement );
94
- $ this ->view ->agreementDao = $ agreementDao ;
106
+ $ this ->view ->agreementForm = $ this ->getFormAsArray ($ formAgreement );
107
+ $ this ->view ->agreementDao = $ agreementDao ;
95
108
}
96
-
97
- /**
98
- * @method agreementdialogAction()
99
- * community agreement dialog, show the community agreements to peaple who want to join the community
100
- */
109
+
110
+ /**
111
+ * community agreement dialog
112
+ *
113
+ * When a user wants to read the community agreement before joining the community, the "agreement" link will be clicked
114
+ * and this dialog will be shown
115
+ *
116
+ * @method agreementdialogAction()
117
+ * @throws Zend_Exception on invalid communityId
118
+ */
101
119
function agreementdialogAction ()
102
120
{
103
- if ($ this ->_helper ->hasHelper ('layout ' ))
121
+ if ($ this ->_helper ->hasHelper ('layout ' ))
104
122
{
105
123
$ this ->_helper ->layout ->disableLayout ();
106
124
}
@@ -110,21 +128,22 @@ function agreementdialogAction()
110
128
{
111
129
throw new Zend_Exception ("Community ID should be a number " );
112
130
}
113
-
114
- $ agreementDao = $ this ->Communityagreement_Agreement ->getByCommunityId ($ communityId );
131
+
132
+ $ agreementDao = $ this ->Communityagreement_Agreement ->getByCommunityId ($ communityId );
115
133
if ($ agreementDao == false )
116
134
{
117
135
$ agreement = '' ;
118
136
$ agreementDao = $ this ->Communityagreement_Agreement ->createAgreement ($ communityId , $ agreement );
119
137
}
120
- $ this ->view ->agreementDao = $ agreementDao ;
138
+ $ this ->view ->agreementDao = $ agreementDao ;
121
139
}
122
-
123
-
140
+
124
141
/**
125
- * @method checkIfAgreementEmptyAction()
126
- * ajax function which checks if the community agreement has been set
127
- */
142
+ * ajax function which checks if the community agreement has been set
143
+ *
144
+ * @method checkagreementAction()
145
+ * @throws Zend_Exception on invalid request
146
+ */
128
147
public function checkagreementAction ()
129
148
{
130
149
if (!$ this ->getRequest ()->isXmlHttpRequest ())
@@ -135,15 +154,15 @@ public function checkagreementAction()
135
154
$ this ->_helper ->viewRenderer ->setNoRender ();
136
155
137
156
$ communityId = $ this ->_getParam ("communityId " );
138
- $ agreementDao = $ this ->Communityagreement_Agreement ->getByCommunityId ($ communityId );
157
+ $ agreementDao = $ this ->Communityagreement_Agreement ->getByCommunityId ($ communityId );
139
158
if ($ agreementDao != false )
140
159
{
141
160
echo JsonComponent::encode (MIDAS_COMMUNITYAGREEMENT_AGREEMENT_NOT_EMPTY );
142
161
}
143
162
else
144
163
{
145
164
echo JsonComponent::encode (MIDAS_COMMUNITYAGREEMENT_AGREEMENT_IS_EMPTY );
146
- }
165
+ }
147
166
}
148
-
167
+
149
168
}//end class
0 commit comments