[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:
Erik Amaru Ortiz
2010-12-09 14:00:55 +00:00
parent 4d7bf9dd92
commit f488326d00
6 changed files with 119 additions and 99 deletions

View File

@@ -64,7 +64,7 @@ class dates {
*/ */
function calculateDate( $sInitDate, $iDuration, $sTimeUnit, $iTypeDay, $UsrUid = NULL, $ProUid = NULL, $TasUid =NULL ) 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) //Set Calendar when the object is instanced in this order/priority (Task, User, Process, Default)
G::LoadClass('calendar'); G::LoadClass('calendar');
$calendarObj=new calendar($UsrUid,$ProUid,$TasUid); $calendarObj=new calendar($UsrUid,$ProUid,$TasUid);
@@ -76,6 +76,11 @@ class dates {
$dateArray = explode(" ",$sInitDate); $dateArray = explode(" ",$sInitDate);
$currentDate = $dateArray[0]; $currentDate = $dateArray[0];
$currentTime = isset($dateArray[1])? $dateArray[1]: "00:00:00"; $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(">>>>> Hours to Process: $hoursToProcess");
$calendarObj->addCalendarLog(">>>>> Current Date: $currentDate"); $calendarObj->addCalendarLog(">>>>> Current Date: $currentDate");
$calendarObj->addCalendarLog(">>>>> Current Time: $currentTime"); $calendarObj->addCalendarLog(">>>>> Current Time: $currentTime");
@@ -131,8 +136,13 @@ class dates {
$calendarObj->addCalendarLog("+++++++++++ Calculated Due Date $currentDate $currentTime"); $calendarObj->addCalendarLog("+++++++++++ Calculated Due Date $currentDate $currentTime");
$result['DUE_DATE'] = $currentDate." ".$currentTime; $result['DUE_DATE'] = $currentDate." ".$currentTime;
$result['DUE_DATE_SECONDS'] = strtotime($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'] = date("Y-m-d H:i:s",$oldDate);
$result['OLD_DUE_DATE_SECONDS']= $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; $result['DUE_DATE_LOG'] = $calendarObj->calendarLog;
return $result; return $result;
} }

View File

@@ -98,7 +98,12 @@ class AppDelegation extends BaseAppDelegation {
//The function return an array now. By JHL //The function return an array now. By JHL
$delTaskDueDate=$this->calculateDueDate($sNextTasParam); $delTaskDueDate=$this->calculateDueDate($sNextTasParam);
$this->setDelTaskDueDate ( $delTaskDueDate['DUE_DATE'] ); // Due date formatted $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 // 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. if ( $delIndex == 1 && !$isSubprocess ) //the first delegation, init date this should be now for draft applications, in other cases, should be null.

View File

@@ -28,24 +28,16 @@ class CalendarDefinition extends BaseCalendarDefinition {
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE ); $Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_DESCRIPTION ); $Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_STATUS ); $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) // Note: This list doesn't show deleted items (STATUS = DELETED)
if ($onlyActive) { // Show only active. Used on assignment lists if ($onlyActive) { // Show only active. Used on assignment lists
$Criteria->add ( calendarDefinitionPeer::CALENDAR_STATUS, "ACTIVE", CRITERIA::EQUAL ); $Criteria->add ( calendarDefinitionPeer::CALENDAR_STATUS, "ACTIVE", CRITERIA::EQUAL );
} else { // Show Active and Inactive calendars. USed in main list } else { // Show Active and Inactive calendars. USed in main list
$Criteria->add ( calendarDefinitionPeer::CALENDAR_STATUS, array ("ACTIVE", "INACTIVE" ), CRITERIA::IN ); $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) { if (! $arrayMode) {
return $Criteria; return $Criteria;
} else { } else {
@@ -67,6 +59,19 @@ class CalendarDefinition extends BaseCalendarDefinition {
function getCalendarInfo($CalendarUid) { function getCalendarInfo($CalendarUid) {
//if exists the row in the database propel will update it, otherwise will insert. //if exists the row in the database propel will update it, otherwise will insert.
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid ); $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')) { if ((is_object ( $tr ) && get_class ( $tr ) == 'CalendarDefinition')) {
$fields ['CALENDAR_UID'] = $tr->getCalendarUid (); $fields ['CALENDAR_UID'] = $tr->getCalendarUid ();
@@ -78,18 +83,7 @@ class CalendarDefinition extends BaseCalendarDefinition {
$fields ['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays (); $fields ['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays ();
$fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", $tr->getCalendarWorkDays () ); $fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", $tr->getCalendarWorkDays () );
} else { } else {
$fields ['CALENDAR_UID'] = "00000000000000000000000000000001"; $fields=$defaultCalendar;
$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 ();
$this->saveCalendarInfo ( $fields ); $this->saveCalendarInfo ( $fields );
$fields ['CALENDAR_WORK_DAYS'] = "1|2|3|4|5"; $fields ['CALENDAR_WORK_DAYS'] = "1|2|3|4|5";
$fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", "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 ( ); $CalendarHolidaysObj = new CalendarHolidays ( );
$CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays ( $CalendarUid ); $CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays ( $CalendarUid );
$fields ['HOLIDAY'] = $CalendarHolidays; $fields ['HOLIDAY'] = $CalendarHolidays;
$fields=$this->validateCalendarInfo($fields, $defaultCalendar);
return $fields; 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) { function saveCalendarInfo($aData) {
$CalendarUid = $aData ['CALENDAR_UID']; $CalendarUid = $aData ['CALENDAR_UID'];
@@ -168,12 +209,12 @@ class CalendarDefinition extends BaseCalendarDefinition {
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => ''); //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 ) { //if ( $res['codError'] < 0 ) {
// G::SendMessageText ( $res['message'] , 'error' ); // G::SendMessageText ( $res['message'] , 'error' );
//} //}
} }
@@ -210,12 +251,12 @@ class CalendarDefinition extends BaseCalendarDefinition {
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => ''); //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 ) { //if ( $res['codError'] < 0 ) {
// G::SendMessageText ( $res['message'] , 'error' ); // G::SendMessageText ( $res['message'] , 'error' );
//} //}
} }
@@ -226,64 +267,36 @@ class CalendarDefinition extends BaseCalendarDefinition {
$calendarUid = "00000000000000000000000000000001"; $calendarUid = "00000000000000000000000000000001";
$calendarOwner = "DEFAULT"; $calendarOwner = "DEFAULT";
//Try to load a User Calendar if exist //Load User,Task and Process calendars (if exist)
$objectID = $userUid;
$Criteria->clearSelectColumns ();
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::CALENDAR_UID ); $Criteria->addSelectColumn ( CalendarAssignmentsPeer::CALENDAR_UID );
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_UID ); $Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_UID );
$Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_TYPE ); $Criteria->addSelectColumn ( CalendarAssignmentsPeer::OBJECT_TYPE );
$Criteria->add ( CalendarAssignmentsPeer::OBJECT_UID, $objectID, CRITERIA::EQUAL ); $Criteria->add ( CalendarAssignmentsPeer::OBJECT_UID, array($userUid, $proUid, $tasUid), CRITERIA::IN );
if (CalendarAssignmentsPeer::doCount ( $Criteria ) > 0) { $oDataset = CalendarAssignmentsPeer::doSelectRS ( $Criteria );
$oDataset = CalendarAssignmentsPeer::doSelectRS ( $Criteria ); $oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); $oDataset->next ();
$oDataset->next (); $calendarArray=array();
$aRow = $oDataset->getRow (); while(is_array($aRow = $oDataset->getRow ())){
$calendarUid = $aRow ['CALENDAR_UID']; if($aRow['OBJECT_UID']==$userUid){
$calendarOwner = "USER"; $calendarArray['USER']=$aRow ['CALENDAR_UID'];
}
//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";
} }
}else{ if($aRow['OBJECT_UID']==$proUid){
$calendarUid = "00000000000000000000000000000001"; $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>"; //print "<h1>$calendarUid</h1>";

View File

@@ -29,15 +29,6 @@ if($RBAC->userCanAccess('PM_SETUP') != 1 && $RBAC->userCanAccess('PM_SETUP_ADVAN
die; die;
} }
if(class_exists('pmLicenseManager')){
$pmLicenseManagerO =& pmLicenseManager::getSingleton();
$expireIn=$pmLicenseManagerO->getExpireIn();
if($expireIn<=0){
G::header("location: calendarEdit?id=00000000000000000000000000000001");
}
}else{
G::header("location: calendarEdit?id=00000000000000000000000000000001");
}
$G_MAIN_MENU = 'processmaker'; $G_MAIN_MENU = 'processmaker';
$G_SUB_MENU = 'setup'; $G_SUB_MENU = 'setup';
$G_ID_MENU_SELECTED = 'SETUP'; $G_ID_MENU_SELECTED = 'SETUP';

View File

@@ -22,7 +22,7 @@
<en></en> <en></en>
</LINK1 > </LINK1 >
<LINK2 type="link" colWidth="20" titleAlign="left" value="@G::LoadTranslation(ID_DELETE)" align="left" onclick='return confirm("Sure?")' link='calendarDelete?id=@!CALENDAR_UID' > <LINK2 type="link" colWidth="20" titleAlign="left" value="@!DELETABLE" align="left" onclick='return confirm("Sure?")' link='calendarDelete?id=@!CALENDAR_UID' >
<en></en> <en></en>
</LINK2 > </LINK2 >

View File

@@ -14,6 +14,7 @@ $startingTime = array_sum(explode(' ',microtime()));
define ('DEBUG_SQL_LOG', 0 ); define ('DEBUG_SQL_LOG', 0 );
define ('DEBUG_TIME_LOG', 0 ); define ('DEBUG_TIME_LOG', 0 );
define ('DEBUG_CALENDAR_LOG', 0 );
//*** process the $_POST with magic_quotes enabled //*** process the $_POST with magic_quotes enabled
function strip_slashes(&$vVar) { function strip_slashes(&$vVar) {