* Copyright 2009-2010, Roland Mas
* Copyright 2010-2011, Franck Villaume - Capgemini
* Copyright 2010-2012, Alain Peyrat - Alcatel-Lucent
- * Copyright 2012, Franck Villaume - TrivialDev
+ * Copyright 2012-2013, Franck Villaume - TrivialDev
* http://fusionforge.org
*
* This file is part of FusionForge. FusionForge is free software;
* IMPORTANT! That db result must contain all fields
* from groups table or you will have problems
*
- * @param int Required
- * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
- * @return object a group object or false on failure
+ * @param int $group_id Required
+ * @param int|bool $res Result set handle ("SELECT * FROM groups WHERE group_id=xx")
+ * @return Group|bool A group object or false on failure
*/
function &group_get_object($group_id, $res = false) {
//create a common set of group objects
/**
* Group - Group object constructor - use group_get_object() to instantiate.
*
- * @param int Required - group_id of the group you want to instantiate.
- * @param int Database result from select query OR associative array of all columns.
- * @return boolean success or not
+ * @param int|bool $id Required - Id of the group you want to instantiate.
+ * @param int|bool $res Database result from select query OR associative array of all columns.
+ * @return boolean Success or not
*/
- function Group($id = false, $res = false) {
+ function __construct($id = false, $res = false) {
$this->Error();
if (!$id) {
//setting up an empty object
/**
* fetchData - May need to refresh database fields if an update occurred.
*
- * @param int The group_id.
- * @return boolean success or not
+ * @param int $group_id The group_id.
+ * @return boolean success or not
*/
function fetchData($group_id) {
$res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
if ($this->getID()!=0) {
$this->setError(_('Group::create: Group object already exists'));
return false;
- } else if (!$this->validateGroupName($group_name)) {
+ } elseif (!$this->validateGroupName($group_name)) {
return false;
- } else if (!account_groupnamevalid($unix_name)) {
+ } elseif (!account_groupnamevalid($unix_name)) {
$this->setError(_('Invalid Unix name'));
return false;
- } else if (!$SYS->sysUseUnixName($unix_name)) {
+ } elseif (!$SYS->sysUseUnixName($unix_name)) {
$this->setError(_('Unix name already taken'));
return false;
- } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
+ } elseif (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
array($unix_name))) > 0) {
$this->setError(_('Unix name already taken'));
return false;
- } else if (strlen($purpose)<10) {
+ } elseif (strlen($purpose)<10) {
$this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
return false;
- } else if (strlen($purpose)>1500) {
+ } elseif (strlen($purpose)>1500) {
$this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
return false;
- } else if (strlen($description)<10) {
+ } elseif (strlen($description)<10) {
$this->setError(_('Describe in a more comprehensive manner your project.'));
return false;
} else {
}
// in the database, these all default to '1',
- // so we have to explicity set 0
+ // so we have to explicitly set 0
if (!$use_mail) {
$use_mail = 0;
}
$homepage = util_make_url('/projects/' . $this->getUnixName() . '/');
}
- if (strlen(htmlspecialchars($short_description))>255) {
- $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
+ if (strlen(htmlspecialchars($short_description))<10) {
+ $this->setError(_('Describe in a more comprehensive manner your project.'));
return false;
}
/* Otherwise, the group is not active, and make sure that
System group is not active either */
- } else if ($SYS->sysCheckGroup($this->getID())) {
+ } elseif ($SYS->sysCheckGroup($this->getID())) {
if (!$SYS->sysRemoveGroup($this->getID())) {
$this->setError($SYS->getErrorMessage());
db_rollback();
/**
* usesPlugin - returns true if the group uses a particular plugin
*
- * @param string name of the plugin
+ * @param string $pluginname name of the plugin
* @return boolean whether plugin is being used or not
*/
function usesPlugin($pluginname) {
}
// unlink roles from this project
- $ra = RoleAnonymous::getInstance();
- $rl = RoleLoggedIn::getInstance();
- $ra->unlinkProject($this);
- $rl->unlinkProject($this);
- // @todo : unlink all the other roles created in the project...
+ foreach ($this->getRoles() as $r) {
+ if ($r->getHomeProject() == NULL
+ || $r->getHomeProject()->getID() != $this->getID()) {
+ $r->unlinkProject($this);
+ }
+ }
//
// Delete Trackers
//
- $atf = new ArtifactTypeFactory($this);
- $at_arr = $atf->getArtifactTypes();
- foreach ($at_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if (!$i->delete(1,1)) {
- $this->setError(_('Could not properly delete the tracker:').' '.$i->getErrorMessage());
- return false;
+ if ($this->usesTracker()) {
+ $atf = new ArtifactTypeFactory($this);
+ $at_arr = $atf->getArtifactTypes();
+ foreach ($at_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if (!$i->delete(1,1)) {
+ $this->setError(_('Could not properly delete the tracker:').' '.$i->getErrorMessage());
+ return false;
+ }
}
}
//
// Delete Forums
//
- $ff = new ForumFactory($this);
- $f_arr = $ff->getForums();
- foreach ($f_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if(!$i->delete(1,1)) {
- $this->setError(_('Could not properly delete the forum:').' '.$i->getErrorMessage());
- return false;
+
+ if ($this->usesForum()) {
+ $ff = new ForumFactory($this);
+ $f_arr = $ff->getForums();
+ foreach ($f_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if(!$i->delete(1,1)) {
+ $this->setError(_('Could not properly delete the forum:').' '.$i->getErrorMessage());
+ return false;
+ }
}
}
//
// Delete Subprojects
//
- $pgf = new ProjectGroupFactory($this);
- $pg_arr = $pgf->getProjectGroups();
- foreach ($pg_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if (!$i->delete(1,1)) {
- $this->setError(_('Could not properly delete the ProjectGroup:').' '.$i->getErrorMessage());
- return false;
+ if ($this->usesPM()) {
+ $pgf = new ProjectGroupFactory($this);
+ $pg_arr = $pgf->getProjectGroups();
+ foreach ($pg_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if (!$i->delete(1,1)) {
+ $this->setError(_('Could not properly delete the ProjectGroup:').' '.$i->getErrorMessage());
+ return false;
+ }
}
}
//
//
// Delete Surveys
//
- $sf = new SurveyFactory($this);
- $s_arr =& $sf->getSurveys();
- foreach ($s_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if (!$i->delete()) {
- $this->setError(_('Could not properly delete the survey'));
- db_rollback();
- return false;
+ if ($this->usesSurvey()) {
+ $sf = new SurveyFactory($this);
+ $s_arr =& $sf->getSurveys();
+ foreach ($s_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if (!$i->delete()) {
+ $this->setError(_('Could not properly delete the survey'));
+ db_rollback();
+ return false;
+ }
}
- }
//
// Delete SurveyQuestions
//
- $sqf = new SurveyQuestionFactory($this);
- $sq_arr =& $sqf->getSurveyQuestions();
- foreach ($sq_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if (!$i->delete()) {
- $this->setError(_('Could not properly delete the survey questions'));
- db_rollback();
- return false;
+ $sqf = new SurveyQuestionFactory($this);
+ $sq_arr = $sqf->getSurveyQuestions();
+ if (is_array($sq_arr)) {
+ foreach ($sq_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if (!$i->delete()) {
+ $this->setError(_('Could not properly delete the survey questions'));
+ db_rollback();
+ return false;
+ }
+ }
}
}
//
// Delete Mailing List Factory
//
- $mlf = new MailingListFactory($this);
- $ml_arr = $mlf->getMailingLists();
- foreach ($ml_arr as $i) {
- if (!is_object($i)) {
- continue;
- }
- if (!$i->delete(1,1)) {
- $this->setError(_('Could not properly delete the mailing list'));
- db_rollback();
- return false;
+ if ($this->usesMail()) {
+ $mlf = new MailingListFactory($this);
+ $ml_arr = $mlf->getMailingLists();
+ foreach ($ml_arr as $i) {
+ if (!is_object($i)) {
+ continue;
+ }
+ if (!$i->delete(1,1)) {
+ $this->setError(_('Could not properly delete the mailing list'));
+ db_rollback();
+ return false;
+ }
}
}
//
if (strlen($group_name)<3) {
$this->setError(_('Group name is too short'));
return false;
- } else if (strlen(htmlspecialchars($group_name))>50) {
+ } elseif (strlen(htmlspecialchars($group_name))>50) {
$this->setError(_('Group name is too long'));
return false;
- } else if (group_get_object_by_publicname($group_name)) {
+ } elseif (group_get_object_by_publicname($group_name)) {
$this->setError(_('Group name already taken'));
return false;
}
// mode: php
// c-file-style: "bsd"
// End:
-
-?>