Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit c9bcfe5

Browse files
committed
ENH: refs #231. Respond to QA feedback
Removed trailing spaces; fixed the wrong URL to config.agreementtab.css Use $ instead of jQuery; Added block documentation for php and js function and classes
1 parent 28aa36e commit c9bcfe5

25 files changed

+244
-161
lines changed

modules/communityagreement/AppController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13-
13+
/**
14+
* Communityagreement_AppController
15+
*
16+
* @category Midas modules
17+
* @package communityagreement
18+
*/
1419
class Communityagreement_AppController extends MIDAS_GlobalModule
1520
{
1621
public $moduleName='communityagreement';
@@ -21,5 +26,4 @@ class Communityagreement_AppController extends MIDAS_GlobalModule
2126
*/
2227
var $Communityagreement_Agreement;
2328
} //end class
24-
?>
25-
29+
?>

modules/communityagreement/Notification.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
11
<?php
2-
/** notification manager*/
2+
/**
3+
* Communityagreement_Notification
4+
*
5+
* notification manager
6+
*
7+
* @category Midas modules
8+
* @package communityagreement
9+
*/
310
class Communityagreement_Notification extends MIDAS_Notification
411
{
512
public $_models = array('Community');
6-
7-
/** init notification process*/
13+
14+
/**
15+
* init notification process
16+
*/
817
public function init()
918
{
1019
$this->addCallBack('CALLBACK_CORE_GET_COMMUNITY_MANAGE_TABS', 'getCommunityManageTabs');
1120
$this->addCallBack('CALLBACK_CORE_GET_COMMUNITY_VIEW_JSS', 'getCommunityViewJSs');
1221
$this->addCallBack('CALLBACK_CORE_GET_COMMUNITY_VIEW_CSSS', 'getCommunityViewCSSs');
1322
}//end init
14-
15-
/** get tabs */
23+
24+
/**
25+
* callback function to get 'community agreement' tab
26+
*
27+
* @return array
28+
*/
1629
public function getCommunityManageTabs()
1730
{
1831
$fc = Zend_Controller_Front::getInstance();
1932
$moduleWebroot = $fc->getBaseUrl().'/communityagreement';
2033
return array('Community Agreement' => $moduleWebroot.'/config/agreementtab');
2134
}
22-
23-
/** get Java scripts */
35+
36+
/**
37+
* callback function to get java script
38+
*
39+
* @return array
40+
*/
2441
public function getCommunityViewJSs()
2542
{
2643
$fc = Zend_Controller_Front::getInstance();
2744
$moduleUriroot = $fc->getBaseUrl().'/modules/communityagreement';
2845
return array($moduleUriroot.'/public/js/config/config.agreementcheckbox.js');
2946
}
30-
31-
/** get CSS */
47+
48+
/**
49+
* callback function to get CSS
50+
*
51+
* @return array
52+
*/
3253
public function getCommunityViewCSSs()
3354
{
3455
$fc = Zend_Controller_Front::getInstance();
@@ -38,4 +59,3 @@ public function getCommunityViewCSSs()
3859

3960
} //end class
4061
?>
41-

modules/communityagreement/configs/module.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ fullname= Community Agreement
66
; description
77
description= "Enables community agreement"
88
;Category
9-
category= Core
10-
9+
category= Core

modules/communityagreement/constant/module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
define("MIDAS_COMMUNITYAGREEMENT_AGREEMENT_IS_EMPTY", 0);
1414
define("MIDAS_COMMUNITYAGREEMENT_AGREEMENT_NOT_EMPTY", 1);
15-
?>
15+
?>

modules/communityagreement/controllers/ConfigController.php

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,70 @@
99
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
12-
/** community agreement config controller*/
12+
/**
13+
* Communityagreement_ConfigController
14+
*
15+
* @category Midas modules
16+
* @package communityagreement
17+
*/
1318
class Communityagreement_ConfigController extends Communityagreement_AppController
1419
{
1520
public $_models = array('Community');
1621
public $_moduleModels = array('Agreement');
1722
public $_moduleForms = array('Config');
18-
19-
/** index */
23+
24+
/**
25+
* @method indexAction()
26+
* @throws Zend_Exception on invalid userSession
27+
*/
2028
function indexAction()
2129
{
2230
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
2331
{
2432
throw new Zend_Exception("You should be an administrator");
2533
}
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+
*/
3243
function agreementtabAction()
3344
{
34-
35-
if(!$this->logged)
45+
46+
if(!$this->logged)
3647
{
3748
$this->haveToBeLogged();
3849
return false;
3950
}
40-
if($this->_helper->hasHelper('layout'))
51+
if($this->_helper->hasHelper('layout'))
4152
{
4253
$this->_helper->layout->disableLayout();
4354
}
44-
55+
4556
$communityId = $this->_getParam("communityId");
4657
if(!isset($communityId) || (!is_numeric($communityId) && strlen($communityId) != 32)) // This is tricky! and for Cassandra for now
4758
{
4859
throw new Zend_Exception("Community ID should be a number");
4960
}
50-
61+
5162
$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
5466
if($agreementDao == false)
5567
{
5668
$agreement = '';
5769
$agreementDao = $this->Communityagreement_Agreement->createAgreement($communityId, $agreement);
5870
}
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()))
6274
{
63-
if($this->_helper->hasHelper('layout'))
75+
if($this->_helper->hasHelper('layout'))
6476
{
6577
$this->_helper->layout->disableLayout();
6678
}
@@ -75,32 +87,38 @@ function agreementtabAction()
7587
echo JsonComponent::encode(array(false, $this->t('Error')));
7688
}
7789
}
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
8093
$chopped_agreement = chop($agreementDao->getAgreement());
81-
if($chopped_agreement != '' )
94+
if($chopped_agreement != '' )
8295
{
8396
$this->Communityagreement_Agreement->save($agreementDao);
8497
}
8598
else if($this->Communityagreement_Agreement->getByCommunityId($communityId) != false)
8699
{
87100
$this->Communityagreement_Agreement->delete($agreementDao);
88101
}
89-
90-
//init form
102+
103+
// init form
91104
$agreement = $formAgreement->getElement('agreement');
92105
$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;
95108
}
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+
*/
101119
function agreementdialogAction()
102120
{
103-
if($this->_helper->hasHelper('layout'))
121+
if($this->_helper->hasHelper('layout'))
104122
{
105123
$this->_helper->layout->disableLayout();
106124
}
@@ -110,21 +128,22 @@ function agreementdialogAction()
110128
{
111129
throw new Zend_Exception("Community ID should be a number");
112130
}
113-
114-
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
131+
132+
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
115133
if($agreementDao == false)
116134
{
117135
$agreement = '';
118136
$agreementDao = $this->Communityagreement_Agreement->createAgreement($communityId, $agreement);
119137
}
120-
$this->view->agreementDao = $agreementDao;
138+
$this->view->agreementDao = $agreementDao;
121139
}
122-
123-
140+
124141
/**
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+
*/
128147
public function checkagreementAction()
129148
{
130149
if(!$this->getRequest()->isXmlHttpRequest())
@@ -135,15 +154,15 @@ public function checkagreementAction()
135154
$this->_helper->viewRenderer->setNoRender();
136155

137156
$communityId = $this->_getParam("communityId");
138-
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
157+
$agreementDao = $this->Communityagreement_Agreement->getByCommunityId($communityId);
139158
if($agreementDao != false)
140159
{
141160
echo JsonComponent::encode(MIDAS_COMMUNITYAGREEMENT_AGREEMENT_NOT_EMPTY);
142161
}
143162
else
144163
{
145164
echo JsonComponent::encode(MIDAS_COMMUNITYAGREEMENT_AGREEMENT_IS_EMPTY);
146-
}
165+
}
147166
}
148-
167+
149168
}//end class

modules/communityagreement/controllers/forms/ConfigForm.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,35 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13-
/** Community Agreement forms*/
13+
/**
14+
* Communityagreement_ConfigForm
15+
*
16+
* @category Midas modules
17+
* @package communityagreement
18+
* @copyright Copyright (c) Kitware SAS. See Copyright.txt for details.
19+
*/
1420

1521
class Communityagreement_ConfigForm extends AppForm
1622
{
17-
/** create create agreement form */
23+
/**
24+
* Create create_agreement form
25+
*
26+
* @param string $community_id
27+
* @return Zend_Form
28+
*/
1829
public function createCreateAgreementForm($community_id)
1930
{
2031
$form = new Zend_Form;
2132
$form->setAction($this->webroot.'/communityagreement/config/agreementtab?communityId='.$community_id)
2233
->setMethod('post');
2334
$agreement = new Zend_Form_Element_Textarea('agreement');
24-
35+
2536
$submit = new Zend_Form_Element_Submit('submit');
2637
$submit->setLabel($this->t("Save"));
27-
38+
2839
$form->addElements(array($agreement, $submit));
2940
return $form;
3041
}
31-
42+
3243
} // end class
3344
?>
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
2-
-- `communityagreement_agreement` table
3-
ALTER TABLE `community` ENGINE = InnoDB;
4-
51
# DROP TABLE IF EXISTS communityagreement_agreement;
6-
CREATE TABLE communityagreement_agreement (
2+
--
3+
-- Structure of table `communityagreement_agreement`
4+
--
5+
CREATE TABLE IF NOT EXISTS communityagreement_agreement (
76
`agreement_id` bigint(20) NOT NULL AUTO_INCREMENT,
87
`community_id` bigint(20) NOT NULL REFERENCES community.community_id,
98
`agreement` text NOT NULL,
109
PRIMARY KEY (`agreement_id`),
1110
KEY `community_id` (`community_id`)
12-
) ENGINE=InnoDB AUTO_INCREMENT=200;
11+
) AUTO_INCREMENT=200;
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<?php
2-
2+
/**
3+
* Communityagreement_AppDao
4+
*
5+
* @category Midas modules
6+
* @package communityagreement
7+
*/
38
class Communityagreement_AppDao extends MIDAS_GlobalDao
49
{
510
public $moduleName='communityagreement';
611
} //end class
712

8-
?>
13+
?>

modules/communityagreement/models/AppModel.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13+
/**
14+
* Communityagreement_AppModel
15+
*
16+
* @category Midas modules
17+
* @package communityagreement
18+
*/
1319
class Communityagreement_AppModel extends MIDASModel
1420
{
1521
public $moduleName='communityagreement';
1622
}
17-
?>
23+
?>

0 commit comments

Comments
 (0)