blob: fb692dde93a498921c28c500c68acaa32233fa51 [file] [log] [blame]
<?php
require_once "/home/data/httpd/eclipse-php-classes/system/dbconnection.class.php";
class CommittersDB {
var $_dbc;
var $_dbh;
function CommittersDB(){
$this->_dbc = New DBConnection();
$this->_dbh = $this->_dbc->connect();
}
function _CommittersDB(){
$this->_dbc = null;
$this->_dbh = null;
}
/*
* function buildClause($project)
*
* Build a clause to help queries determine if a project
* parameter was passed or if the query should apply to
* all projects.
*
*/
function buildClause($project){
if ($project == "")
return "";
else
return "AND ProjectID = \"".$project."\"";
}
/*
* function getProjects
*
* Get the list of projects available from the Foundations DB.
* Only active projects will be displayed. The results are
* sorted alphabetically.
*
*/
function getProjects(){
$query = "SELECT project_id FROM projects WHERE level >= 1 AND ";
$query .= "is_active = 1 ORDER BY project_id";
$res = mysql_query($query,$this->_dbh) or die("MySQL GP: ".$mysql_error());
while($row = mysql_fetch_array($res, MYSQL_NUM))
$projects[] = $row[0];
return $projects;
}
/*
* function getOrganizations()
*
* Get the list of organizations listed in the Foundations DB.
* The results are sorted alphabetically.
*
*/
function getOrganizations(){
$query = "SELECT OrganizationID, Name1 FROM Organizations ORDER BY Name1";
$res = mysql_query($query,$this->_dbh) or die("MySQL ORG: ".$mysql_error());
while($row = mysql_fetch_array($res, MYSQL_NUM))
$organizations[] = $row;
return $organizations;
}
/*
* function getNameFromOrganization($organization)
*
* Get the company name based on its key in the Foundations DB
*
*/
function getNameFromOrganization($organization){
if ($organization == "")
return "";
$query = "SELECT Name1 FROM Organizations WHERE OrganizationID = ";
$query .= $organization;
$res = mysql_query($query,$this->_dbh) or die("MySQL GNO: ".$mysql_error());
$row = mysql_fetch_row($res);
return $row[0];
}
/*
* function getCommitterCount($project = "")
*
* Get the count per project or across all projects from the Foundations'
* database. The condition to identify a committer is, according to
* Denis Roy (Eclipse webmaster), the following:
*
* Relation = "CM" and InactiveDate IS NULL
*
* If no project is passed to the method then it will get the count for all
* projects. Otherwise only the count for the specified project will be
* returned.
*/
function getCommitterCount($project = ""){
$clause = $this->buildClause($project);
$query = "SELECT COUNT(*) FROM PeopleProjects WHERE Relation = \"CM\" ";
$query .= "AND InactiveDate IS NULL ".$clause;
$res = mysql_query($query,$this->_dbh) or die("MySQL GCC: ".$mysql_error());
$row = mysql_fetch_row($res);
return $row[0];
}
/*
* function getOrganizationCount($organization)
*
* Get the count of people that are committers and are associated
* to $organization. The condition to identify a committer in the,
* PeopleProject table is, according to Denis Roy (Eclipse webmaster),
* the following:
*
* Relation = "CM" AND InactiveDate IS NULL
*
* In the case of the OrganizationContacts table the condition is:
*
* Relation = "CC"
*
*/
function getOrganizationCount($organization){
if ($organization == "")
return 0;
$query = "SELECT count(*) FROM PeopleProjects A, OrganizationContacts B ";
$query .= "WHERE A.PersonID = B.PersonID ";
$query .= "AND A.Relation = \"CM\" AND A.InactiveDate IS NULL ";
$query .= "AND B.Relation = \"CC\" AND B.OrganizationID = $organization ";
$res = mysql_query($query,$this->_dbh) or die("MySQL GOC: ".$mysql_error());
$row = mysql_fetch_row($res);
return $row[0];
}
/*
* function getCommittersByOrganization($project)
*
* Get the name of the organizations and the number of committers
* each of them have associated to a particular project. A project
* must be specified or the method will return an empty set.
*
*/
function getCommittersByOrganization($project){
if ($project == "") // Cannot be empty
return array();
$clause = $this->buildClause($project);
$query = "SELECT A.Name1, Count(*) FROM Organizations AS A, ";
$query .= "OrganizationContacts AS B WHERE A.OrganizationID = ";
$query .= "B.OrganizationID AND B.Relation = \"CC\" AND B.PersonID IN ";
$query .= "(SELECT PersonID FROM PeopleProjects WHERE Relation = \"CM\" ";
$query .= "AND InactiveDate IS NULL ".$clause.") GROUP BY A.OrganizationID";
$res = mysql_query($query,$this->_dbh) or die("MySQL GCO: ".mysql_error());
while($row = mysql_fetch_array($res, MYSQL_NUM))
$committers[] = $row;
return $committers;
}
/*
* function getCommittersByProject($organization)
*
* Get the ProjectIDs and the number of committers an organization
* has committed. An organization must be specified or the method
* will return an empty set.
*
*/
function getCommittersByProject($organization){
if ($organization == "") // Cannot be empty
return array();
$query = "SELECT A.ProjectID, Count(*) FROM PeopleProjects A, ";
$query .= "OrganizationContacts B WHERE A.PersonID = B.PersonID ";
$query .= "AND A.Relation = \"CM\" AND A.InactiveDate IS NULL ";
$query .= "AND B.Relation = \"CC\" AND B.OrganizationID = $organization ";
$query .= "GROUP BY A.ProjectID";
$res = mysql_query($query,$this->_dbh) or die("MySQL GCP: ".mysql_error());
while($row = mysql_fetch_array($res, MYSQL_NUM))
$committers[] = $row;
return $committers;
}
}
?>