[2010-12-06 15:54:28] Rev:642 | 6 files Modified
hugo: Calednar Improvements and now Multicalendar enabled for community. Flag to save log of calendar calcs per delegation -------------------------------------------------------------------------------- 1. M /trunk/workflow/engine/methods/setup/calendarList.php 2. M /trunk/workflow/public_html/sysGeneric.php 3. M /trunk/workflow/engine/classes/model/AppDelegation.php 4. M /trunk/workflow/engine/classes/model/CalendarDefinition.php 5. M /trunk/workflow/engine/classes/class.dates.php 6. M /trunk/workflow/engine/xmlform/setup/calendarList.xml
This commit is contained in:
@@ -64,7 +64,7 @@ class dates {
|
||||
*/
|
||||
function calculateDate( $sInitDate, $iDuration, $sTimeUnit, $iTypeDay, $UsrUid = NULL, $ProUid = NULL, $TasUid =NULL )
|
||||
{
|
||||
$oldDate=$this->calculateDate_noCalendar( $sInitDate, $iDuration, $sTimeUnit, $iTypeDay, $UsrUid, $ProUid, $TasUid);
|
||||
//$oldDate=$this->calculateDate_noCalendar( $sInitDate, $iDuration, $sTimeUnit, $iTypeDay, $UsrUid, $ProUid, $TasUid);
|
||||
//Set Calendar when the object is instanced in this order/priority (Task, User, Process, Default)
|
||||
G::LoadClass('calendar');
|
||||
$calendarObj=new calendar($UsrUid,$ProUid,$TasUid);
|
||||
@@ -76,6 +76,11 @@ class dates {
|
||||
$dateArray = explode(" ",$sInitDate);
|
||||
$currentDate = $dateArray[0];
|
||||
$currentTime = isset($dateArray[1])? $dateArray[1]: "00:00:00";
|
||||
|
||||
$startTime=(float) array_sum(explode(' ',microtime()));
|
||||
|
||||
|
||||
$calendarObj->addCalendarLog("* Starting at: $startTime");
|
||||
$calendarObj->addCalendarLog(">>>>> Hours to Process: $hoursToProcess");
|
||||
$calendarObj->addCalendarLog(">>>>> Current Date: $currentDate");
|
||||
$calendarObj->addCalendarLog(">>>>> Current Time: $currentTime");
|
||||
@@ -131,8 +136,13 @@ class dates {
|
||||
$calendarObj->addCalendarLog("+++++++++++ Calculated Due Date $currentDate $currentTime");
|
||||
$result['DUE_DATE'] = $currentDate." ".$currentTime;
|
||||
$result['DUE_DATE_SECONDS'] = strtotime($currentDate." ".$currentTime);
|
||||
$result['OLD_DUE_DATE'] = date("Y-m-d H:i:s",$oldDate);
|
||||
$result['OLD_DUE_DATE_SECONDS']= $oldDate;
|
||||
//$result['OLD_DUE_DATE'] = date("Y-m-d H:i:s",$oldDate);
|
||||
//$result['OLD_DUE_DATE_SECONDS']= $oldDate;
|
||||
|
||||
$endTime=(float) array_sum(explode(' ',microtime()));
|
||||
$calendarObj->addCalendarLog("* Ending at: $endTime");
|
||||
$calcTime=round($endTime-$startTime,3);
|
||||
$calendarObj->addCalendarLog("** Processing time: ". sprintf("%.4f", ($endTime-$startTime))." seconds");
|
||||
$result['DUE_DATE_LOG'] = $calendarObj->calendarLog;
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,12 @@ class AppDelegation extends BaseAppDelegation {
|
||||
//The function return an array now. By JHL
|
||||
$delTaskDueDate=$this->calculateDueDate($sNextTasParam);
|
||||
$this->setDelTaskDueDate ( $delTaskDueDate['DUE_DATE'] ); // Due date formatted
|
||||
$this->setDelData ( $delTaskDueDate['DUE_DATE_LOG'] ); // Log of actions made by Calendar Engine
|
||||
|
||||
if((defined("DEBUG_CALENDAR_LOG"))&&(DEBUG_CALENDAR_LOG)){
|
||||
$this->setDelData ($delTaskDueDate['DUE_DATE_LOG'] ); // Log of actions made by Calendar Engine
|
||||
}else{
|
||||
$this->setDelData ( '' );
|
||||
}
|
||||
|
||||
// this condition assures that an internal delegation like a subprocess dont have an initial date setted
|
||||
if ( $delIndex == 1 && !$isSubprocess ) //the first delegation, init date this should be now for draft applications, in other cases, should be null.
|
||||
|
||||
@@ -28,24 +28,16 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_STATUS );
|
||||
$Criteria->addAsColumn('DELETABLE', "IF (CALENDAR_UID <> '00000000000000000000000000000001', '".G::LoadTranslation('ID_DELETE')."','') ");
|
||||
// Note: This list doesn't show deleted items (STATUS = DELETED)
|
||||
if ($onlyActive) { // Show only active. Used on assignment lists
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_STATUS, "ACTIVE", CRITERIA::EQUAL );
|
||||
} else { // Show Active and Inactive calendars. USed in main list
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_STATUS, array ("ACTIVE", "INACTIVE" ), CRITERIA::IN );
|
||||
}
|
||||
if(class_exists('pmLicenseManager')){
|
||||
$pmLicenseManagerO =& pmLicenseManager::getSingleton();
|
||||
$expireIn=$pmLicenseManagerO->getExpireIn();
|
||||
if($expireIn>0){
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_UID, "xx", CRITERIA::NOT_EQUAL );
|
||||
}else{
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_UID, "00000000000000000000000000000001", CRITERIA::EQUAL );
|
||||
}
|
||||
}else{
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_UID, "00000000000000000000000000000001", CRITERIA::EQUAL );
|
||||
|
||||
}
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_UID, "xx", CRITERIA::NOT_EQUAL );
|
||||
|
||||
if (! $arrayMode) {
|
||||
return $Criteria;
|
||||
} else {
|
||||
@@ -67,6 +59,19 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
function getCalendarInfo($CalendarUid) {
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid );
|
||||
|
||||
$defaultCalendar ['CALENDAR_UID'] = "00000000000000000000000000000001";
|
||||
$defaultCalendar ['CALENDAR_NAME'] = "Default";
|
||||
$defaultCalendar ['CALENDAR_CREATE_DATE'] = date ( "Y-m-d" );
|
||||
$defaultCalendar ['CALENDAR_UPDATE_DATE'] = date ( "Y-m-d" );
|
||||
$defaultCalendar ['CALENDAR_DESCRIPTION'] = "Default";
|
||||
$defaultCalendar ['CALENDAR_STATUS'] = "ACTIVE";
|
||||
$defaultCalendar ['CALENDAR_WORK_DAYS'] = "1|2|3|4|5";
|
||||
$defaultCalendar ['CALENDAR_WORK_DAYS'] = explode ( "|", "1|2|3|4|5" );
|
||||
$defaultCalendar ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_DAY'] = 7;
|
||||
$defaultCalendar ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_START'] = "09:00";
|
||||
$defaultCalendar ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_END'] = "17:00";
|
||||
$defaultCalendar ['HOLIDAY'] = array ();
|
||||
|
||||
if ((is_object ( $tr ) && get_class ( $tr ) == 'CalendarDefinition')) {
|
||||
$fields ['CALENDAR_UID'] = $tr->getCalendarUid ();
|
||||
@@ -78,18 +83,7 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
$fields ['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays ();
|
||||
$fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", $tr->getCalendarWorkDays () );
|
||||
} else {
|
||||
$fields ['CALENDAR_UID'] = "00000000000000000000000000000001";
|
||||
$fields ['CALENDAR_NAME'] = "Default";
|
||||
$fields ['CALENDAR_CREATE_DATE'] = date ( "Y-m-d" );
|
||||
$fields ['CALENDAR_UPDATE_DATE'] = date ( "Y-m-d" );
|
||||
$fields ['CALENDAR_DESCRIPTION'] = "Default";
|
||||
$fields ['CALENDAR_STATUS'] = "ACTIVE";
|
||||
$fields ['CALENDAR_WORK_DAYS'] = "1|2|3|4|5";
|
||||
$fields ['CALENDAR_WORK_DAYS'] = explode ( "|", "1|2|3|4|5" );
|
||||
$fields ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_DAY'] = 7;
|
||||
$fields ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_START'] = "09:00";
|
||||
$fields ['BUSINESS_DAY'] [1] ['CALENDAR_BUSINESS_END'] = "17:00";
|
||||
$fields ['HOLIDAY'] = array ();
|
||||
$fields=$defaultCalendar;
|
||||
$this->saveCalendarInfo ( $fields );
|
||||
$fields ['CALENDAR_WORK_DAYS'] = "1|2|3|4|5";
|
||||
$fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", "1|2|3|4|5" );
|
||||
@@ -102,9 +96,56 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
$CalendarHolidaysObj = new CalendarHolidays ( );
|
||||
$CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays ( $CalendarUid );
|
||||
$fields ['HOLIDAY'] = $CalendarHolidays;
|
||||
|
||||
$fields=$this->validateCalendarInfo($fields, $defaultCalendar);
|
||||
|
||||
return $fields;
|
||||
|
||||
}
|
||||
function validateCalendarInfo($fields,$defaultCalendar){
|
||||
try {
|
||||
//Validate if Working days are Correct
|
||||
//Minimun 3 ?
|
||||
$workingDays=explode ( "|", $fields['CALENDAR_WORK_DAYS'] );
|
||||
if(count($workingDays)<3){
|
||||
throw (new Exception ( "You must define at least 3 Working Days!" ));
|
||||
}
|
||||
//Validate that all Working Days have Bussines Hours
|
||||
if(count($fields ['BUSINESS_DAY'])<1){
|
||||
throw (new Exception ( "You must define at least one Business Day for all days" ));
|
||||
}
|
||||
$workingDaysOK=array();
|
||||
foreach($workingDays as $key => $day){
|
||||
$workingDaysOK[$day]=false;
|
||||
}
|
||||
$sw_all=false;
|
||||
foreach($fields ['BUSINESS_DAY'] as $keyB => $businessHours){
|
||||
if(($businessHours['CALENDAR_BUSINESS_DAY']==7)){
|
||||
$sw_all=true;
|
||||
}elseif((in_array($workingDays,$businessHours['CALENDAR_BUSINESS_DAY']))){
|
||||
$workingDaysOK[$businessHours['CALENDAR_BUSINESS_DAY']]=true;
|
||||
}
|
||||
}
|
||||
$sw_days=true;
|
||||
|
||||
foreach($workingDaysOK as $day =>$sw_day){
|
||||
$sw_days=$sw_days && $sw_day;
|
||||
}
|
||||
if(!($sw_all || $sw_days)){
|
||||
throw (new Exception ( "Not all working days have their correspondent business day" ));
|
||||
}
|
||||
//Validate Holidays
|
||||
|
||||
return $fields;
|
||||
} catch (Exception $e) {
|
||||
//print $e->getMessage();
|
||||
$this->addCalendarLog("!!!!!!! BAD CALENDAR DEFINITION. ".$e->getMessage());
|
||||
$defaultCalendar ['CALENDAR_WORK_DAYS'] = "1|2|3|4|5";
|
||||
$defaultCalendar ['CALENDAR_WORK_DAYS_A'] = explode ( "|", "1|2|3|4|5" );
|
||||
return $defaultCalendar;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
function saveCalendarInfo($aData) {
|
||||
$CalendarUid = $aData ['CALENDAR_UID'];
|
||||
@@ -168,12 +209,12 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
|
||||
|
||||
//to do: uniform coderror structures for all classes
|
||||
//to do: uniform coderror structures for all classes
|
||||
|
||||
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
@@ -210,12 +251,12 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
|
||||
|
||||
//to do: uniform coderror structures for all classes
|
||||
//to do: uniform coderror structures for all classes
|
||||
|
||||
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
@@ -226,64 +267,36 @@ class CalendarDefinition extends BaseCalendarDefinition {
|
||||
$calendarUid = "00000000000000000000000000000001";
|
||||
$calendarOwner = "DEFAULT";
|
||||
|
||||
//Try to load a User Calendar if exist
|
||||
$objectID = $userUid;
|
||||
$Criteria->clearSelectColumns ();
|
||||
//Load User,Task and Process calendars (if exist)
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::CALENDAR_UID );
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_UID );
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_TYPE );
|
||||
$Criteria->add ( CalendarAssignmentsPeer::OBJECT_UID, $objectID, CRITERIA::EQUAL );
|
||||
if (CalendarAssignmentsPeer::doCount ( $Criteria ) > 0) {
|
||||
$oDataset = CalendarAssignmentsPeer::doSelectRS ( $Criteria );
|
||||
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next ();
|
||||
$aRow = $oDataset->getRow ();
|
||||
$calendarUid = $aRow ['CALENDAR_UID'];
|
||||
$calendarOwner = "USER";
|
||||
}
|
||||
|
||||
//Try to load a Process Calendar if exist
|
||||
$objectID = $proUid;
|
||||
$Criteria->clearSelectColumns ();
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::CALENDAR_UID );
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_UID );
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_TYPE );
|
||||
$Criteria->add ( CalendarAssignmentsPeer::OBJECT_UID, $objectID, CRITERIA::EQUAL );
|
||||
if (CalendarAssignmentsPeer::doCount ( $Criteria ) > 0) {
|
||||
$oDataset = CalendarAssignmentsPeer::doSelectRS ( $Criteria );
|
||||
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next ();
|
||||
$aRow = $oDataset->getRow ();
|
||||
$calendarUid = $aRow ['CALENDAR_UID'];
|
||||
$calendarOwner = "PROCESS";
|
||||
}
|
||||
|
||||
//Try to load a Task Calendar if exist
|
||||
$objectID = $tasUid;
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::CALENDAR_UID );
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_UID );
|
||||
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_TYPE );
|
||||
$Criteria->add ( CalendarAssignmentsPeer::OBJECT_UID, $objectID, CRITERIA::EQUAL );
|
||||
$Criteria->clearSelectColumns ();
|
||||
if (CalendarAssignmentsPeer::doCount ( $Criteria ) > 0) {
|
||||
$oDataset = CalendarAssignmentsPeer::doSelectRS ( $Criteria );
|
||||
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next ();
|
||||
$aRow = $oDataset->getRow ();
|
||||
$calendarUid = $aRow ['CALENDAR_UID'];
|
||||
$calendarOwner = "TASK";
|
||||
}
|
||||
|
||||
if(class_exists('pmLicenseManager')){
|
||||
$pmLicenseManagerO =& pmLicenseManager::getSingleton();
|
||||
$expireIn=$pmLicenseManagerO->getExpireIn();
|
||||
if($expireIn>0){
|
||||
$calendarUid=$calendarUid;
|
||||
}else{
|
||||
$calendarUid = "00000000000000000000000000000001";
|
||||
$Criteria->add ( CalendarAssignmentsPeer::OBJECT_UID, array($userUid, $proUid, $tasUid), CRITERIA::IN );
|
||||
$oDataset = CalendarAssignmentsPeer::doSelectRS ( $Criteria );
|
||||
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next ();
|
||||
$calendarArray=array();
|
||||
while(is_array($aRow = $oDataset->getRow ())){
|
||||
if($aRow['OBJECT_UID']==$userUid){
|
||||
$calendarArray['USER']=$aRow ['CALENDAR_UID'];
|
||||
}
|
||||
}else{
|
||||
$calendarUid = "00000000000000000000000000000001";
|
||||
if($aRow['OBJECT_UID']==$proUid){
|
||||
$calendarArray['PROCESS']=$aRow ['CALENDAR_UID'];
|
||||
}
|
||||
if($aRow['OBJECT_UID']==$tasUid){
|
||||
$calendarArray['TASK']=$aRow ['CALENDAR_UID'];
|
||||
}
|
||||
$oDataset->next ();
|
||||
}
|
||||
if(isset($calendarArray['USER'])){
|
||||
$calendarUid = $calendarArray['USER'];
|
||||
$calendarOwner = "USER";
|
||||
}elseif (isset($calendarArray['PROCESS'])){
|
||||
$calendarUid = $calendarArray['PROCESS'];
|
||||
$calendarOwner = "PROCESS";
|
||||
}elseif (isset($calendarArray['TASK'])){
|
||||
$calendarUid = $calendarArray['TASK'];
|
||||
$calendarOwner = "TASK";
|
||||
}
|
||||
|
||||
//print "<h1>$calendarUid</h1>";
|
||||
|
||||
Reference in New Issue
Block a user