blob: 0696b3c1b48989f15e407c61b1d0e028954910ae [file] [log] [blame]
<?php
/*
* Releases Rule
*
* This rule validates if any of the Planned, Tentative or Scheduled releases has been Updated.
*
* @author: mparra@openmex.com
*/
class releases_rule {
function releases_rule() {
}
/*
* Process Function
*
* Standar function that runs the rule.
*
* @old_object: Old project-info-object to compare against
* @new_object: New project-info-object to compare against
*/
function process($old_object, $new_object){
$result = "";
//Fetch all the required data from the objects
$old_releases = $old_object->getNumReleases();
$new_releases = $new_object->getNumReleases();
$num_releases = $old_releases;
//Go through all the tentative, planned or scheduled releases of the project (if any)
while($num_releases > 0){
//Fetch all the required data from the releases
$old_release = $old_object->getRelease($num_releases-1);
$new_release = $new_object->getRelease($num_releases-1);
$old_name = $old_release->getName();
$new_name = $new_release->getName();
$old_status = $old_release->getStatus();
$new_status = $new_release->getStatus();
$release_due_date = $old_release->getDate();
if(strcmp($old_name,$new_name)==0){ //Is the same release
if(strcmp($old_status,$new_status)==0){ //The release hadn't change its status
$dates_result = $this->date_compare($release_due_date); //Check if the release has to be up-to-date
if($dates_result == 1){ //If true, the deadline for updating the release information had pass, we attach a message to the email
$result = "\n - Please update your releases information.";
}
}
}
$num_releases = $num_releases - 1;
}
return $result;
}
/*
* Function Date Compare
*
* Takes the $release_due_date argument and compares it against the current date.
*
* @release_due_date: The date to compare against to. In this case will be the date in which the release should be updated.
*
* @return:
* 0: if dates are the same
* 1: if the current date is greater
* 2: if the release_due_date is greater
*/
function date_compare ($release_due_date) {
$result = -1;
//Explode the current date
$current_date = date("j:n:Y"); //D:M:YYYY
$current_date_array = explode(":",$current_date);
$c_day = $current_date_array[0];
$c_month = $current_date_array[1];
$c_year = $current_date_array[2];
//Explode the release date
$release_date_array = explode("/",$release_due_date);
$r_year = 0;
$r_month = 0;
$r_day = 0;
if(count($release_date_array) == 2){ //Release date only specifies month and year
$r_month = $release_date_array[0];
$r_year = $release_date_array[1];
if($c_year == $r_year){ //Same year, lets check the months
if($c_month == $r_month){ //Same month, return 0
$result = 0;
} elseif($c_month > $r_month){ //Current month is greater, return 1
$result = 1;
} else { //Release month is greater, return 2
$result = 2;
}
} elseif($c_year > $r_year){ //Current year is greater, return 1
$result = 1;
} else { //Release year is greater, return 2
$result = 2;
}
} elseif (count($release_date_array) == 3){ //Release date specifies day, month and year
$r_day = $release_date_array[0];
$r_month = $release_date_array[1];
$r_year = $release_date_array[2];
if($c_year == $r_year){ //Same year, lets check the months
if($c_month == $r_month){ //Same month, lets check the days
if($c_day == $r_day){ //Same day, return 0
$result = 0;
} elseif($c_day > $r_day){ //Current day is greater, return 1
$result = 1;
} else { //Release day is greater, return 2
$result = 2;
}
} elseif($c_month > $r_month){ //Current month is greater, return 1
$result = 1;
} else { //Release month is greater, return 2
$result = 2;
}
} elseif($c_year > $r_year){ //Current year is greater, return 1
$result = 1;
} else { //Release year is greater, return 2
$result = 2;
}
}
return $result;
}
}
?>