CODE STYLE Format
Change format
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,467 +1,455 @@
|
||||
<?php
|
||||
/**
|
||||
* CalendarDefinition.php
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
|
||||
require_once 'classes/model/om/BaseCalendarDefinition.php';
|
||||
require_once 'classes/model/CalendarBusinessHours.php';
|
||||
require_once 'classes/model/CalendarHolidays.php';
|
||||
require_once 'classes/model/CalendarAssignments.php';
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'CALENDAR_DEFINITION' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
class CalendarDefinition extends BaseCalendarDefinition {
|
||||
public $calendarLog = '';
|
||||
function getCalendarList($onlyActive = false, $arrayMode = false) {
|
||||
$Criteria = new Criteria ( 'workflow' );
|
||||
$Criteria->clearSelectColumns ();
|
||||
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_NAME );
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
|
||||
$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')."','') ");
|
||||
$Criteria->addAsColumn('DELETABLE', "CASE WHEN CALENDAR_UID <> '00000000000000000000000000000001' THEN '".G::LoadTranslation('ID_DELETE')."' ELSE '' END ");
|
||||
// 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 );
|
||||
}
|
||||
|
||||
$Criteria->add ( calendarDefinitionPeer::CALENDAR_UID, "xx", CRITERIA::NOT_EQUAL );
|
||||
|
||||
if (! $arrayMode) {
|
||||
return $Criteria;
|
||||
} else {
|
||||
$oDataset = calendarDefinitionPeer::doSelectRS ( $Criteria );
|
||||
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next ();
|
||||
$calendarA = array (0 => 'dummy' );
|
||||
$calendarCount = 0;
|
||||
while ( is_array ( $aRow = $oDataset->getRow () ) ) {
|
||||
$calendarCount ++;
|
||||
$calendarA [$calendarCount] = $aRow;
|
||||
$oDataset->next ();
|
||||
}
|
||||
$return ['criteria'] = $Criteria;
|
||||
$return ['array'] = $calendarA;
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
//Added by qennix
|
||||
//Gets criteria for listing
|
||||
function getCalendarCriterias($filter, $start, $limit){
|
||||
$Criteria = new Criteria ( 'workflow' );
|
||||
$Criteria->clearSelectColumns ();
|
||||
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
if ($filter !=''){
|
||||
$Criteria->add(
|
||||
$Criteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_NAME,'%'.$filter.'%',Criteria::LIKE)->addOr(
|
||||
$Criteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_DESCRIPTION,'%'.$filter.'%',Criteria::LIKE)));
|
||||
}
|
||||
$Criteria->add(CalendarDefinitionPeer::CALENDAR_STATUS,'DELETED',Criteria::NOT_EQUAL);
|
||||
|
||||
$oCriteria = new Criteria ( 'workflow' );
|
||||
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_NAME );
|
||||
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
|
||||
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
|
||||
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
|
||||
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_STATUS );
|
||||
if ($filter !=''){
|
||||
$oCriteria->add(
|
||||
$oCriteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_NAME,'%'.$filter.'%',Criteria::LIKE)->addOr(
|
||||
$oCriteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_DESCRIPTION,'%'.$filter.'%',Criteria::LIKE)));
|
||||
}
|
||||
$oCriteria->add(CalendarDefinitionPeer::CALENDAR_STATUS,'DELETED',Criteria::NOT_EQUAL);
|
||||
$oCriteria->setLimit($limit);
|
||||
$oCriteria->setOffset($start);
|
||||
|
||||
$criterias = array();
|
||||
$criterias['COUNTER'] = $Criteria;
|
||||
$criterias['LIST'] = $oCriteria;
|
||||
return $criterias;
|
||||
}
|
||||
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 ();
|
||||
$fields ['CALENDAR_NAME'] = $tr->getCalendarName ();
|
||||
$fields ['CALENDAR_CREATE_DATE'] = $tr->getCalendarCreateDate ();
|
||||
$fields ['CALENDAR_UPDATE_DATE'] = $tr->getCalendarUpdateDate ();
|
||||
$fields ['CALENDAR_DESCRIPTION'] = $tr->getCalendarDescription ();
|
||||
$fields ['CALENDAR_STATUS'] = $tr->getCalendarStatus ();
|
||||
$fields ['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays ();
|
||||
$fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", $tr->getCalendarWorkDays () );
|
||||
} else {
|
||||
$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" );
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid );
|
||||
}
|
||||
$CalendarBusinessHoursObj = new CalendarBusinessHours ( );
|
||||
$CalendarBusinessHours = $CalendarBusinessHoursObj->getCalendarBusinessHours ( $CalendarUid );
|
||||
$fields ['BUSINESS_DAY'] = $CalendarBusinessHours;
|
||||
|
||||
$CalendarHolidaysObj = new CalendarHolidays ( );
|
||||
$CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays ( $CalendarUid );
|
||||
$fields ['HOLIDAY'] = $CalendarHolidays;
|
||||
$fields=$this->validateCalendarInfo($fields, $defaultCalendar); //********************
|
||||
|
||||
return $fields;
|
||||
|
||||
}
|
||||
//for edit
|
||||
function getCalendarInfoE($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 ();
|
||||
$fields ['CALENDAR_NAME'] = $tr->getCalendarName ();
|
||||
$fields ['CALENDAR_CREATE_DATE'] = $tr->getCalendarCreateDate ();
|
||||
$fields ['CALENDAR_UPDATE_DATE'] = $tr->getCalendarUpdateDate ();
|
||||
$fields ['CALENDAR_DESCRIPTION'] = $tr->getCalendarDescription ();
|
||||
$fields ['CALENDAR_STATUS'] = $tr->getCalendarStatus ();
|
||||
$fields ['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays ();
|
||||
$fields ['CALENDAR_WORK_DAYS_A'] = explode ( "|", $tr->getCalendarWorkDays () );
|
||||
} else {
|
||||
$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" );
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid );
|
||||
}
|
||||
$CalendarBusinessHoursObj = new CalendarBusinessHours ( );
|
||||
$CalendarBusinessHours = $CalendarBusinessHoursObj->getCalendarBusinessHours ( $CalendarUid );
|
||||
$fields ['BUSINESS_DAY'] = $CalendarBusinessHours;
|
||||
|
||||
$CalendarHolidaysObj = new CalendarHolidays ( );
|
||||
$CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays ( $CalendarUid );
|
||||
$fields ['HOLIDAY'] = $CalendarHolidays;
|
||||
// $fields=$this->validateCalendarInfo($fields, $defaultCalendar); //********************
|
||||
|
||||
return $fields;
|
||||
|
||||
}
|
||||
//end for edit
|
||||
|
||||
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($businessHours['CALENDAR_BUSINESS_DAY'],$workingDays))){
|
||||
$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'];
|
||||
$CalendarName = $aData ['CALENDAR_NAME'];
|
||||
$CalendarDescription = $aData ['CALENDAR_DESCRIPTION'];
|
||||
$CalendarStatus = isset ( $aData ['CALENDAR_STATUS'] ) ? $aData ['CALENDAR_STATUS'] : "INACTIVE";
|
||||
$defaultCalendars [] = '00000000000000000000000000000001';
|
||||
if (in_array ( $aData ['CALENDAR_UID'], $defaultCalendars )) {
|
||||
$CalendarStatus = 'ACTIVE';
|
||||
$CalendarName = 'Default';
|
||||
}
|
||||
$CalendarWorkDays = isset ( $aData ['CALENDAR_WORK_DAYS'] ) ? implode ( "|", $aData ['CALENDAR_WORK_DAYS'] ) : "";
|
||||
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid );
|
||||
if (! (is_object ( $tr ) && get_class ( $tr ) == 'CalendarDefinition')) {
|
||||
$tr = new CalendarDefinition ( );
|
||||
$tr->setCalendarCreateDate ( 'now' );
|
||||
}
|
||||
$tr->setCalendarUid ( $CalendarUid );
|
||||
$tr->setCalendarName ( $CalendarName );
|
||||
|
||||
$tr->setCalendarUpdateDate ( 'now' );
|
||||
$tr->setCalendarDescription ( $CalendarDescription );
|
||||
$tr->setCalendarStatus ( $CalendarStatus );
|
||||
$tr->setCalendarWorkDays ( $CalendarWorkDays );
|
||||
|
||||
if ($tr->validate ()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save ();
|
||||
//Calendar Business Hours Save code.
|
||||
//First Delete all current records
|
||||
$CalendarBusinessHoursObj = new CalendarBusinessHours ( );
|
||||
$CalendarBusinessHoursObj->deleteAllCalendarBusinessHours ( $CalendarUid );
|
||||
//Save all the sent records
|
||||
foreach ( $aData ['BUSINESS_DAY'] as $key => $objData ) {
|
||||
$objData ['CALENDAR_UID'] = $CalendarUid;
|
||||
$CalendarBusinessHoursObj->saveCalendarBusinessHours ( $objData );
|
||||
}
|
||||
|
||||
//Holiday Save code.
|
||||
//First Delete all current records
|
||||
$CalendarHolidayObj = new CalendarHolidays ( );
|
||||
$CalendarHolidayObj->deleteAllCalendarHolidays ( $CalendarUid );
|
||||
//Save all the sent records
|
||||
foreach ( $aData ['HOLIDAY'] as $key => $objData ) {
|
||||
if (($objData ['CALENDAR_HOLIDAY_NAME'] != "") && ($objData ['CALENDAR_HOLIDAY_START'] != "") && ($objData ['CALENDAR_HOLIDAY_END'] != "")) {
|
||||
$objData ['CALENDAR_UID'] = $CalendarUid;
|
||||
$CalendarHolidayObj->saveCalendarHolidays ( $objData );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures ();
|
||||
foreach ( $validationFailuresArray as $objValidationFailure ) {
|
||||
$msg .= $objValidationFailure->getMessage () . "<br/>";
|
||||
}
|
||||
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
|
||||
|
||||
//to do: uniform coderror structures for all classes
|
||||
|
||||
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
function deleteCalendar($CalendarUid) {
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid );
|
||||
|
||||
if (! (is_object ( $tr ) && get_class ( $tr ) == 'CalendarDefinition')) {
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
$defaultCalendars [] = '00000000000000000000000000000001';
|
||||
if (in_array ( $tr->getCalendarUid(), $defaultCalendars )) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tr->setCalendarStatus ( 'DELETED' );
|
||||
$tr->setCalendarUpdateDate ( 'now' );
|
||||
if ($tr->validate ()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save ();
|
||||
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures ();
|
||||
foreach ( $validationFailuresArray as $objValidationFailure ) {
|
||||
$msg .= $objValidationFailure->getMessage () . "<br/>";
|
||||
}
|
||||
G::SendMessage ( "ERROR", $msg );
|
||||
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
|
||||
|
||||
//to do: uniform coderror structures for all classes
|
||||
|
||||
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
function getCalendarFor($userUid, $proUid, $tasUid, $sw_validate=true) {
|
||||
$Criteria = new Criteria ( 'workflow' );
|
||||
|
||||
//Default Calendar
|
||||
$calendarUid = "00000000000000000000000000000001";
|
||||
$calendarOwner = "DEFAULT";
|
||||
|
||||
//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, 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'];
|
||||
}
|
||||
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>";
|
||||
if($sw_validate){
|
||||
$calendarDefinition = $this->getCalendarInfo ( $calendarUid );
|
||||
}else{
|
||||
$calendarDefinition = $this->getCalendarInfoE ( $calendarUid );
|
||||
}
|
||||
$calendarDefinition ['CALENDAR_APPLIED'] = $calendarOwner;
|
||||
$this->addCalendarLog ( "--=== Calendar Applied: " . $calendarDefinition ['CALENDAR_NAME'] . " -> $calendarOwner" );
|
||||
return $calendarDefinition;
|
||||
}
|
||||
|
||||
function assignCalendarTo($objectUid, $calendarUid, $objectType) {
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarAssignmentsPeer::retrieveByPK ( $objectUid );
|
||||
if ($calendarUid != "") {
|
||||
if (! (is_object ( $tr ) && get_class ( $tr ) == 'CalendarAssignments')) {
|
||||
$tr = new CalendarAssignments ( );
|
||||
|
||||
}
|
||||
$tr->setObjectUid ( $objectUid );
|
||||
$tr->setCalendarUid ( $calendarUid );
|
||||
$tr->setObjectType ( $objectType );
|
||||
|
||||
if ($tr->validate ()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save ();
|
||||
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures ();
|
||||
foreach ( $validationFailuresArray as $objValidationFailure ) {
|
||||
$msg .= $objValidationFailure->getMessage () . "<br/>";
|
||||
}
|
||||
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
} else { //Delete record
|
||||
if ((is_object ( $tr ) && get_class ( $tr ) == 'CalendarAssignments')) {
|
||||
$tr->delete ();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//Added by Qennix
|
||||
//Counts all users,task,process by calendar
|
||||
function getAllCounterByCalendar($type){
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(CalendarAssignmentsPeer::CALENDAR_UID);
|
||||
$oCriteria->addSelectColumn('COUNT(*) AS CNT');
|
||||
$oCriteria->addGroupByColumn(CalendarAssignmentsPeer::CALENDAR_UID);
|
||||
$oCriteria->add(CalendarAssignmentsPeer::OBJECT_TYPE,$type);
|
||||
$oDataset = CalendarAssignmentsPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$aCounter = Array();
|
||||
while($oDataset->next()){
|
||||
$row = $oDataset->getRow();
|
||||
$aCounter[$row['CALENDAR_UID']] = $row['CNT'];
|
||||
}
|
||||
return $aCounter;
|
||||
}
|
||||
|
||||
function loadByCalendarName($calendarName)
|
||||
{
|
||||
$Criteria = new Criteria('workflow');
|
||||
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_UID);
|
||||
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_NAME);
|
||||
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_CREATE_DATE);
|
||||
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_UPDATE_DATE);
|
||||
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_DESCRIPTION);
|
||||
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_STATUS);
|
||||
$Criteria->add(calendarDefinitionPeer::CALENDAR_NAME, $calendarName, CRITERIA::EQUAL);
|
||||
$oDataset = calendarDefinitionPeer::doSelectRS ($Criteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$oDataset->next();
|
||||
|
||||
return $oDataset->getRow();
|
||||
}
|
||||
} // CalendarDefinition
|
||||
|
||||
|
||||
<?php
|
||||
/**
|
||||
* CalendarDefinition.php
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
|
||||
require_once 'classes/model/om/BaseCalendarDefinition.php';
|
||||
require_once 'classes/model/CalendarBusinessHours.php';
|
||||
require_once 'classes/model/CalendarHolidays.php';
|
||||
require_once 'classes/model/CalendarAssignments.php';
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'CALENDAR_DEFINITION' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
class CalendarDefinition extends BaseCalendarDefinition
|
||||
{
|
||||
public $calendarLog = '';
|
||||
|
||||
public function getCalendarList ($onlyActive = false, $arrayMode = false)
|
||||
{
|
||||
$Criteria = new Criteria( 'workflow' );
|
||||
$Criteria->clearSelectColumns();
|
||||
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_NAME );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
|
||||
$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')."','') ");
|
||||
$Criteria->addAsColumn( 'DELETABLE', "CASE WHEN CALENDAR_UID <> '00000000000000000000000000000001' THEN '" . G::LoadTranslation( 'ID_DELETE' ) . "' ELSE '' END " );
|
||||
// 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 );
|
||||
}
|
||||
|
||||
$Criteria->add( calendarDefinitionPeer::CALENDAR_UID, "xx", CRITERIA::NOT_EQUAL );
|
||||
|
||||
if (! $arrayMode) {
|
||||
return $Criteria;
|
||||
} else {
|
||||
$oDataset = calendarDefinitionPeer::doSelectRS( $Criteria );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
$calendarA = array (0 => 'dummy');
|
||||
$calendarCount = 0;
|
||||
while (is_array( $aRow = $oDataset->getRow() )) {
|
||||
$calendarCount ++;
|
||||
$calendarA[$calendarCount] = $aRow;
|
||||
$oDataset->next();
|
||||
}
|
||||
$return['criteria'] = $Criteria;
|
||||
$return['array'] = $calendarA;
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
//Added by qennix
|
||||
//Gets criteria for listing
|
||||
public function getCalendarCriterias ($filter, $start, $limit)
|
||||
{
|
||||
$Criteria = new Criteria( 'workflow' );
|
||||
$Criteria->clearSelectColumns();
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
if ($filter != '') {
|
||||
$Criteria->add( $Criteria->getNewCriterion( CalendarDefinitionPeer::CALENDAR_NAME, '%' . $filter . '%', Criteria::LIKE )->addOr( $Criteria->getNewCriterion( CalendarDefinitionPeer::CALENDAR_DESCRIPTION, '%' . $filter . '%', Criteria::LIKE ) ) );
|
||||
}
|
||||
$Criteria->add( CalendarDefinitionPeer::CALENDAR_STATUS, 'DELETED', Criteria::NOT_EQUAL );
|
||||
|
||||
$oCriteria = new Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
$oCriteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_NAME );
|
||||
$oCriteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
|
||||
$oCriteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
|
||||
$oCriteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
|
||||
$oCriteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_STATUS );
|
||||
if ($filter != '') {
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( CalendarDefinitionPeer::CALENDAR_NAME, '%' . $filter . '%', Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( CalendarDefinitionPeer::CALENDAR_DESCRIPTION, '%' . $filter . '%', Criteria::LIKE ) ) );
|
||||
}
|
||||
$oCriteria->add( CalendarDefinitionPeer::CALENDAR_STATUS, 'DELETED', Criteria::NOT_EQUAL );
|
||||
$oCriteria->setLimit( $limit );
|
||||
$oCriteria->setOffset( $start );
|
||||
|
||||
$criterias = array ();
|
||||
$criterias['COUNTER'] = $Criteria;
|
||||
$criterias['LIST'] = $oCriteria;
|
||||
return $criterias;
|
||||
}
|
||||
|
||||
public 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();
|
||||
$fields['CALENDAR_NAME'] = $tr->getCalendarName();
|
||||
$fields['CALENDAR_CREATE_DATE'] = $tr->getCalendarCreateDate();
|
||||
$fields['CALENDAR_UPDATE_DATE'] = $tr->getCalendarUpdateDate();
|
||||
$fields['CALENDAR_DESCRIPTION'] = $tr->getCalendarDescription();
|
||||
$fields['CALENDAR_STATUS'] = $tr->getCalendarStatus();
|
||||
$fields['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays();
|
||||
$fields['CALENDAR_WORK_DAYS_A'] = explode( "|", $tr->getCalendarWorkDays() );
|
||||
} else {
|
||||
$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" );
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK( $CalendarUid );
|
||||
}
|
||||
$CalendarBusinessHoursObj = new CalendarBusinessHours();
|
||||
$CalendarBusinessHours = $CalendarBusinessHoursObj->getCalendarBusinessHours( $CalendarUid );
|
||||
$fields['BUSINESS_DAY'] = $CalendarBusinessHours;
|
||||
$CalendarHolidaysObj = new CalendarHolidays();
|
||||
$CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays( $CalendarUid );
|
||||
$fields['HOLIDAY'] = $CalendarHolidays;
|
||||
$fields = $this->validateCalendarInfo( $fields, $defaultCalendar );
|
||||
//********************
|
||||
return $fields;
|
||||
}
|
||||
//for edit
|
||||
public function getCalendarInfoE ($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();
|
||||
$fields['CALENDAR_NAME'] = $tr->getCalendarName();
|
||||
$fields['CALENDAR_CREATE_DATE'] = $tr->getCalendarCreateDate();
|
||||
$fields['CALENDAR_UPDATE_DATE'] = $tr->getCalendarUpdateDate();
|
||||
$fields['CALENDAR_DESCRIPTION'] = $tr->getCalendarDescription();
|
||||
$fields['CALENDAR_STATUS'] = $tr->getCalendarStatus();
|
||||
$fields['CALENDAR_WORK_DAYS'] = $tr->getCalendarWorkDays();
|
||||
$fields['CALENDAR_WORK_DAYS_A'] = explode( "|", $tr->getCalendarWorkDays() );
|
||||
} else {
|
||||
$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" );
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK( $CalendarUid );
|
||||
}
|
||||
$CalendarBusinessHoursObj = new CalendarBusinessHours();
|
||||
$CalendarBusinessHours = $CalendarBusinessHoursObj->getCalendarBusinessHours( $CalendarUid );
|
||||
$fields['BUSINESS_DAY'] = $CalendarBusinessHours;
|
||||
$CalendarHolidaysObj = new CalendarHolidays();
|
||||
$CalendarHolidays = $CalendarHolidaysObj->getCalendarHolidays( $CalendarUid );
|
||||
$fields['HOLIDAY'] = $CalendarHolidays;
|
||||
// $fields=$this->validateCalendarInfo($fields, $defaultCalendar); //********************
|
||||
return $fields;
|
||||
}
|
||||
//end for edit
|
||||
|
||||
public 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( $businessHours['CALENDAR_BUSINESS_DAY'], $workingDays ))) {
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function saveCalendarInfo ($aData)
|
||||
{
|
||||
$CalendarUid = $aData['CALENDAR_UID'];
|
||||
$CalendarName = $aData['CALENDAR_NAME'];
|
||||
$CalendarDescription = $aData['CALENDAR_DESCRIPTION'];
|
||||
$CalendarStatus = isset( $aData['CALENDAR_STATUS'] ) ? $aData['CALENDAR_STATUS'] : "INACTIVE";
|
||||
$defaultCalendars[] = '00000000000000000000000000000001';
|
||||
if (in_array( $aData['CALENDAR_UID'], $defaultCalendars )) {
|
||||
$CalendarStatus = 'ACTIVE';
|
||||
$CalendarName = 'Default';
|
||||
}
|
||||
$CalendarWorkDays = isset( $aData['CALENDAR_WORK_DAYS'] ) ? implode( "|", $aData['CALENDAR_WORK_DAYS'] ) : "";
|
||||
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK( $CalendarUid );
|
||||
if (! (is_object( $tr ) && get_class( $tr ) == 'CalendarDefinition')) {
|
||||
$tr = new CalendarDefinition();
|
||||
$tr->setCalendarCreateDate( 'now' );
|
||||
}
|
||||
$tr->setCalendarUid( $CalendarUid );
|
||||
$tr->setCalendarName( $CalendarName );
|
||||
$tr->setCalendarUpdateDate( 'now' );
|
||||
$tr->setCalendarDescription( $CalendarDescription );
|
||||
$tr->setCalendarStatus( $CalendarStatus );
|
||||
$tr->setCalendarWorkDays( $CalendarWorkDays );
|
||||
|
||||
if ($tr->validate()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save();
|
||||
//Calendar Business Hours Save code.
|
||||
//First Delete all current records
|
||||
$CalendarBusinessHoursObj = new CalendarBusinessHours();
|
||||
$CalendarBusinessHoursObj->deleteAllCalendarBusinessHours( $CalendarUid );
|
||||
//Save all the sent records
|
||||
foreach ($aData['BUSINESS_DAY'] as $key => $objData) {
|
||||
$objData['CALENDAR_UID'] = $CalendarUid;
|
||||
$CalendarBusinessHoursObj->saveCalendarBusinessHours( $objData );
|
||||
}
|
||||
//Holiday Save code.
|
||||
//First Delete all current records
|
||||
$CalendarHolidayObj = new CalendarHolidays();
|
||||
$CalendarHolidayObj->deleteAllCalendarHolidays( $CalendarUid );
|
||||
//Save all the sent records
|
||||
foreach ($aData['HOLIDAY'] as $key => $objData) {
|
||||
if (($objData['CALENDAR_HOLIDAY_NAME'] != "") && ($objData['CALENDAR_HOLIDAY_START'] != "") && ($objData['CALENDAR_HOLIDAY_END'] != "")) {
|
||||
$objData['CALENDAR_UID'] = $CalendarUid;
|
||||
$CalendarHolidayObj->saveCalendarHolidays( $objData );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures();
|
||||
foreach ($validationFailuresArray as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
||||
}
|
||||
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
//to do: uniform coderror structures for all classes
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
}
|
||||
|
||||
public function deleteCalendar ($CalendarUid)
|
||||
{
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarDefinitionPeer::retrieveByPK( $CalendarUid );
|
||||
|
||||
if (! (is_object( $tr ) && get_class( $tr ) == 'CalendarDefinition')) {
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
$defaultCalendars[] = '00000000000000000000000000000001';
|
||||
if (in_array( $tr->getCalendarUid(), $defaultCalendars )) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tr->setCalendarStatus( 'DELETED' );
|
||||
$tr->setCalendarUpdateDate( 'now' );
|
||||
if ($tr->validate()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save();
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures();
|
||||
foreach ($validationFailuresArray as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
||||
}
|
||||
G::SendMessage( "ERROR", $msg );
|
||||
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
//return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
//to do: uniform coderror structures for all classes
|
||||
//if ( $res['codError'] < 0 ) {
|
||||
// G::SendMessageText ( $res['message'] , 'error' );
|
||||
//}
|
||||
}
|
||||
|
||||
public function getCalendarFor ($userUid, $proUid, $tasUid, $sw_validate = true)
|
||||
{
|
||||
$Criteria = new Criteria( 'workflow' );
|
||||
//Default Calendar
|
||||
$calendarUid = "00000000000000000000000000000001";
|
||||
$calendarOwner = "DEFAULT";
|
||||
//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, 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'];
|
||||
}
|
||||
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>";
|
||||
if ($sw_validate) {
|
||||
$calendarDefinition = $this->getCalendarInfo( $calendarUid );
|
||||
} else {
|
||||
$calendarDefinition = $this->getCalendarInfoE( $calendarUid );
|
||||
}
|
||||
$calendarDefinition['CALENDAR_APPLIED'] = $calendarOwner;
|
||||
$this->addCalendarLog( "--=== Calendar Applied: " . $calendarDefinition['CALENDAR_NAME'] . " -> $calendarOwner" );
|
||||
return $calendarDefinition;
|
||||
}
|
||||
|
||||
public function assignCalendarTo ($objectUid, $calendarUid, $objectType)
|
||||
{
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = CalendarAssignmentsPeer::retrieveByPK( $objectUid );
|
||||
if ($calendarUid != "") {
|
||||
if (! (is_object( $tr ) && get_class( $tr ) == 'CalendarAssignments')) {
|
||||
$tr = new CalendarAssignments();
|
||||
}
|
||||
$tr->setObjectUid( $objectUid );
|
||||
$tr->setCalendarUid( $calendarUid );
|
||||
$tr->setObjectType( $objectType );
|
||||
|
||||
if ($tr->validate()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save();
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures();
|
||||
foreach ($validationFailuresArray as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
||||
}
|
||||
//return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
} else {
|
||||
//Delete record
|
||||
if ((is_object( $tr ) && get_class( $tr ) == 'CalendarAssignments')) {
|
||||
$tr->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
//Added by Qennix
|
||||
//Counts all users,task,process by calendar
|
||||
public function getAllCounterByCalendar ($type)
|
||||
{
|
||||
$oCriteria = new Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( CalendarAssignmentsPeer::CALENDAR_UID );
|
||||
$oCriteria->addSelectColumn( 'COUNT(*) AS CNT' );
|
||||
$oCriteria->addGroupByColumn( CalendarAssignmentsPeer::CALENDAR_UID );
|
||||
$oCriteria->add( CalendarAssignmentsPeer::OBJECT_TYPE, $type );
|
||||
$oDataset = CalendarAssignmentsPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$aCounter = Array ();
|
||||
while ($oDataset->next()) {
|
||||
$row = $oDataset->getRow();
|
||||
$aCounter[$row['CALENDAR_UID']] = $row['CNT'];
|
||||
}
|
||||
return $aCounter;
|
||||
}
|
||||
|
||||
public function loadByCalendarName ($calendarName)
|
||||
{
|
||||
$Criteria = new Criteria( 'workflow' );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UID );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_NAME );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
|
||||
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_STATUS );
|
||||
$Criteria->add( calendarDefinitionPeer::CALENDAR_NAME, $calendarName, CRITERIA::EQUAL );
|
||||
$oDataset = calendarDefinitionPeer::doSelectRS( $Criteria );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$oDataset->next();
|
||||
return $oDataset->getRow();
|
||||
}
|
||||
}
|
||||
// CalendarDefinition
|
||||
|
||||
|
||||
@@ -1,479 +1,485 @@
|
||||
<?php
|
||||
/**
|
||||
* Content.php
|
||||
* @package workflow.engine.classes.model
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'classes/model/om/BaseContent.php';
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'CONTENT' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
class Content extends BaseContent {
|
||||
|
||||
public $langs;
|
||||
public $rowsProcessed;
|
||||
public $rowsInserted;
|
||||
public $rowsUnchanged;
|
||||
public $rowsClustered;
|
||||
public $langsAsoc;
|
||||
/*
|
||||
* Load the content row specified by the parameters:
|
||||
<?php
|
||||
/**
|
||||
* Content.php
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'classes/model/om/BaseContent.php';
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'CONTENT' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
class Content extends BaseContent
|
||||
{
|
||||
public $langs;
|
||||
public $rowsProcessed;
|
||||
public $rowsInserted;
|
||||
public $rowsUnchanged;
|
||||
public $rowsClustered;
|
||||
public $langsAsoc;
|
||||
/*
|
||||
* Load the content row specified by the parameters:
|
||||
* @param string $sUID
|
||||
* @return variant
|
||||
*/
|
||||
function load($ConCategory, $ConParent, $ConId, $ConLang) {
|
||||
$content = ContentPeer::retrieveByPK ( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
if (is_null ( $content )) {
|
||||
//we dont find any value for this field and language in CONTENT table
|
||||
$ConValue = Content::autoLoadSave ( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
} else {
|
||||
//krumo($content);
|
||||
$ConValue = $content->getConValue ();
|
||||
if ($ConValue == "") { //try to find a valid translation
|
||||
$ConValue = Content::autoLoadSave ( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
}
|
||||
}
|
||||
return $ConValue;
|
||||
}
|
||||
/*
|
||||
* Find a valid Lang for current Content. The most recent
|
||||
*/
|
||||
public function load ($ConCategory, $ConParent, $ConId, $ConLang)
|
||||
{
|
||||
$content = ContentPeer::retrieveByPK( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
if (is_null( $content )) {
|
||||
//we dont find any value for this field and language in CONTENT table;
|
||||
$ConValue = Content::autoLoadSave( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
} else {
|
||||
//krumo($content);
|
||||
$ConValue = $content->getConValue();
|
||||
if ($ConValue == "") {
|
||||
//try to find a valid translation
|
||||
$ConValue = Content::autoLoadSave( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
}
|
||||
}
|
||||
return $ConValue;
|
||||
}
|
||||
/*
|
||||
* Find a valid Lang for current Content. The most recent
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $ConId
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
function getDefaultContentLang($ConCategory, $ConParent, $ConId, $destConLang) {
|
||||
$Criteria = new Criteria ( 'workflow' );
|
||||
$Criteria->clearSelectColumns ()->clearOrderByColumns ();
|
||||
|
||||
$Criteria->addSelectColumn ( ContentPeer::CON_CATEGORY );
|
||||
$Criteria->addSelectColumn ( ContentPeer::CON_PARENT );
|
||||
$Criteria->addSelectColumn ( ContentPeer::CON_ID );
|
||||
$Criteria->addSelectColumn ( ContentPeer::CON_LANG );
|
||||
$Criteria->addSelectColumn ( ContentPeer::CON_VALUE );
|
||||
|
||||
$Criteria->add ( ContentPeer::CON_CATEGORY, $ConCategory, CRITERIA::EQUAL );
|
||||
$Criteria->add ( ContentPeer::CON_PARENT, $ConParent, CRITERIA::EQUAL );
|
||||
$Criteria->add ( ContentPeer::CON_ID, $ConId, CRITERIA::EQUAL );
|
||||
|
||||
$Criteria->add ( ContentPeer::CON_LANG, $destConLang, CRITERIA::NOT_EQUAL );
|
||||
|
||||
$rs = ContentPeer::doSelectRS ( $Criteria );
|
||||
$rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC );
|
||||
$rs->next ();
|
||||
|
||||
if (is_array ( $row = $rs->getRow () )) {
|
||||
$defaultLang = $row ['CON_LANG'];
|
||||
|
||||
} else {
|
||||
$defaultLang = "";
|
||||
}
|
||||
return ($defaultLang);
|
||||
}
|
||||
/*
|
||||
* Load the content row and the Save automatically the row for the destination language
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $destConLang
|
||||
* @return string
|
||||
* if the row doesn't exist, it will be created automatically, even the default 'en' language
|
||||
*/
|
||||
function autoLoadSave($ConCategory, $ConParent, $ConId, $destConLang) {
|
||||
//search in 'en' language, the default language
|
||||
$content = ContentPeer::retrieveByPK ( $ConCategory, $ConParent, $ConId, 'en' );
|
||||
|
||||
if ((is_null ( $content )) || ($content->getConValue () == "")) {
|
||||
$differentLang = Content::getDefaultContentLang ( $ConCategory, $ConParent, $ConId, $destConLang );
|
||||
$content = ContentPeer::retrieveByPK ( $ConCategory, $ConParent, $ConId, $differentLang );
|
||||
}
|
||||
|
||||
//to do: review if the $destConLang is a valid language/
|
||||
if (is_null ( $content ))
|
||||
$ConValue = ''; //we dont find any value for this field and language in CONTENT table
|
||||
else
|
||||
$ConValue = $content->getConValue ();
|
||||
|
||||
try {
|
||||
$con = ContentPeer::retrieveByPK ( $ConCategory, $ConParent, $ConId, $destConLang );
|
||||
if (is_null ( $con )) {
|
||||
$con = new Content ( );
|
||||
}
|
||||
$con->setConCategory ( $ConCategory );
|
||||
$con->setConParent ( $ConParent );
|
||||
$con->setConId ( $ConId );
|
||||
$con->setConLang ( $destConLang );
|
||||
$con->setConValue ( $ConValue );
|
||||
if ($con->validate ()) {
|
||||
$res = $con->save ();
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
throw ($e);
|
||||
}
|
||||
|
||||
return $ConValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a content row
|
||||
*
|
||||
*/
|
||||
public function getDefaultContentLang ($ConCategory, $ConParent, $ConId, $destConLang)
|
||||
{
|
||||
$Criteria = new Criteria( 'workflow' );
|
||||
$Criteria->clearSelectColumns()->clearOrderByColumns();
|
||||
|
||||
$Criteria->addSelectColumn( ContentPeer::CON_CATEGORY );
|
||||
$Criteria->addSelectColumn( ContentPeer::CON_PARENT );
|
||||
$Criteria->addSelectColumn( ContentPeer::CON_ID );
|
||||
$Criteria->addSelectColumn( ContentPeer::CON_LANG );
|
||||
$Criteria->addSelectColumn( ContentPeer::CON_VALUE );
|
||||
|
||||
$Criteria->add( ContentPeer::CON_CATEGORY, $ConCategory, CRITERIA::EQUAL );
|
||||
$Criteria->add( ContentPeer::CON_PARENT, $ConParent, CRITERIA::EQUAL );
|
||||
$Criteria->add( ContentPeer::CON_ID, $ConId, CRITERIA::EQUAL );
|
||||
$Criteria->add( ContentPeer::CON_LANG, $destConLang, CRITERIA::NOT_EQUAL );
|
||||
|
||||
$rs = ContentPeer::doSelectRS( $Criteria );
|
||||
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$rs->next();
|
||||
|
||||
if (is_array( $row = $rs->getRow() )) {
|
||||
$defaultLang = $row['CON_LANG'];
|
||||
} else {
|
||||
$defaultLang = "";
|
||||
}
|
||||
return ($defaultLang);
|
||||
}
|
||||
/*
|
||||
* Load the content row and the Save automatically the row for the destination language
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $destConLang
|
||||
* @return string
|
||||
* if the row doesn't exist, it will be created automatically, even the default 'en' language
|
||||
*/
|
||||
public function autoLoadSave ($ConCategory, $ConParent, $ConId, $destConLang)
|
||||
{
|
||||
//search in 'en' language, the default language
|
||||
$content = ContentPeer::retrieveByPK( $ConCategory, $ConParent, $ConId, 'en' );
|
||||
|
||||
if ((is_null( $content )) || ($content->getConValue() == "")) {
|
||||
$differentLang = Content::getDefaultContentLang( $ConCategory, $ConParent, $ConId, $destConLang );
|
||||
$content = ContentPeer::retrieveByPK( $ConCategory, $ConParent, $ConId, $differentLang );
|
||||
}
|
||||
|
||||
//to do: review if the $destConLang is a valid language/
|
||||
if (is_null( $content )) {
|
||||
$ConValue = '';
|
||||
//we dont find any value for this field and language in CONTENT table
|
||||
} else {
|
||||
$ConValue = $content->getConValue();
|
||||
}
|
||||
|
||||
try {
|
||||
$con = ContentPeer::retrieveByPK( $ConCategory, $ConParent, $ConId, $destConLang );
|
||||
if (is_null( $con )) {
|
||||
$con = new Content();
|
||||
}
|
||||
$con->setConCategory( $ConCategory );
|
||||
$con->setConParent( $ConParent );
|
||||
$con->setConId( $ConId );
|
||||
$con->setConLang( $destConLang );
|
||||
$con->setConValue( $ConValue );
|
||||
if ($con->validate()) {
|
||||
$res = $con->save();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
|
||||
return $ConValue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a content row
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $ConLang
|
||||
* @param string $ConValue
|
||||
* @param string $ConValue
|
||||
* @return variant
|
||||
*/
|
||||
function addContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue) {
|
||||
try {
|
||||
if ($ConLang != 'en') {
|
||||
$baseLangContent = ContentPeer::retrieveByPk($ConCategory, $ConParent, $ConId, 'en');
|
||||
if ($baseLangContent === null) {
|
||||
Content::addContent($ConCategory, $ConParent, $ConId, 'en', $ConValue);
|
||||
}
|
||||
}
|
||||
|
||||
$con = ContentPeer::retrieveByPK ( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
|
||||
if (is_null ( $con )) {
|
||||
$con = new Content ( );
|
||||
} else {
|
||||
if ($con->getConParent () == $ConParent && $con->getConCategory () == $ConCategory && $con->getConValue () == $ConValue && $con->getConLang () == $ConLang && $con->getConId () == $ConId)
|
||||
return true;
|
||||
}
|
||||
$con->setConCategory ( $ConCategory );
|
||||
if ($con->getConParent () != $ConParent)
|
||||
$con->setConParent ( $ConParent );
|
||||
$con->setConId ( $ConId );
|
||||
$con->setConLang ( $ConLang );
|
||||
$con->setConValue ( $ConValue );
|
||||
if ($con->validate ()) {
|
||||
$res = $con->save ();
|
||||
return $res;
|
||||
} else {
|
||||
$e = new Exception ( "Error in addcontent, the row $ConCategory, $ConParent, $ConId, $ConLang is not Valid" );
|
||||
throw ($e);
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a content row
|
||||
*/
|
||||
public function addContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
||||
{
|
||||
try {
|
||||
if ($ConLang != 'en') {
|
||||
$baseLangContent = ContentPeer::retrieveByPk( $ConCategory, $ConParent, $ConId, 'en' );
|
||||
if ($baseLangContent === null) {
|
||||
Content::addContent( $ConCategory, $ConParent, $ConId, 'en', $ConValue );
|
||||
}
|
||||
}
|
||||
|
||||
$con = ContentPeer::retrieveByPK( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
|
||||
if (is_null( $con )) {
|
||||
$con = new Content();
|
||||
} else {
|
||||
if ($con->getConParent() == $ConParent && $con->getConCategory() == $ConCategory && $con->getConValue() == $ConValue && $con->getConLang() == $ConLang && $con->getConId() == $ConId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$con->setConCategory( $ConCategory );
|
||||
if ($con->getConParent() != $ConParent) {
|
||||
$con->setConParent( $ConParent );
|
||||
}
|
||||
$con->setConId( $ConId );
|
||||
$con->setConLang( $ConLang );
|
||||
$con->setConValue( $ConValue );
|
||||
if ($con->validate()) {
|
||||
$res = $con->save();
|
||||
return $res;
|
||||
} else {
|
||||
$e = new Exception( "Error in addcontent, the row $ConCategory, $ConParent, $ConId, $ConLang is not Valid" );
|
||||
throw ($e);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a content row
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $ConLang
|
||||
* @param string $ConValue
|
||||
* @param string $ConValue
|
||||
* @return variant
|
||||
*/
|
||||
function insertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue) {
|
||||
try {
|
||||
$con = new Content ( );
|
||||
$con->setConCategory ( $ConCategory );
|
||||
$con->setConParent ( $ConParent );
|
||||
$con->setConId ( $ConId );
|
||||
$con->setConLang ( $ConLang );
|
||||
$con->setConValue ( $ConValue );
|
||||
if ($con->validate ()) {
|
||||
$res = $con->save ();
|
||||
return $res;
|
||||
} else {
|
||||
$e = new Exception ( "Error in addcontent, the row $ConCategory, $ConParent, $ConId, $ConLang is not Valid" );
|
||||
throw ($e);
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* remove a content row
|
||||
*/
|
||||
public function insertContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
||||
{
|
||||
try {
|
||||
$con = new Content();
|
||||
$con->setConCategory( $ConCategory );
|
||||
$con->setConParent( $ConParent );
|
||||
$con->setConId( $ConId );
|
||||
$con->setConLang( $ConLang );
|
||||
$con->setConValue( $ConValue );
|
||||
if ($con->validate()) {
|
||||
$res = $con->save();
|
||||
return $res;
|
||||
} else {
|
||||
$e = new Exception( "Error in addcontent, the row $ConCategory, $ConParent, $ConId, $ConLang is not Valid" );
|
||||
throw ($e);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* remove a content row
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $ConLang
|
||||
* @param string $ConValue
|
||||
* @param string $ConValue
|
||||
* @return variant
|
||||
*/
|
||||
function removeContent($ConCategory, $ConParent, $ConId) {
|
||||
try {
|
||||
$c = new Criteria ( );
|
||||
$c->add ( ContentPeer::CON_CATEGORY, $ConCategory );
|
||||
$c->add ( ContentPeer::CON_PARENT, $ConParent );
|
||||
$c->add ( ContentPeer::CON_ID, $ConId );
|
||||
$result = ContentPeer::doSelectRS ( $c );
|
||||
$result->next ();
|
||||
$row = $result->getRow ();
|
||||
while ( is_array ( $row ) ) {
|
||||
ContentPeer::doDelete ( array ($ConCategory, $ConParent, $ConId, $row [3] ) );
|
||||
$result->next ();
|
||||
$row = $result->getRow ();
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
throw ($e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
public function removeContent ($ConCategory, $ConParent, $ConId)
|
||||
{
|
||||
try {
|
||||
$c = new Criteria();
|
||||
$c->add( ContentPeer::CON_CATEGORY, $ConCategory );
|
||||
$c->add( ContentPeer::CON_PARENT, $ConParent );
|
||||
$c->add( ContentPeer::CON_ID, $ConId );
|
||||
$result = ContentPeer::doSelectRS( $c );
|
||||
$result->next();
|
||||
$row = $result->getRow();
|
||||
while (is_array( $row )) {
|
||||
ContentPeer::doDelete( array ($ConCategory,$ConParent,$ConId,$row[3]) );
|
||||
$result->next();
|
||||
$row = $result->getRow();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Reasons if the record already exists
|
||||
*
|
||||
* @param string $ConCategory
|
||||
* @param string $ConParent
|
||||
* @param string $ConId
|
||||
* @param string $ConLang
|
||||
* @param string $ConValue
|
||||
* @param string $ConValue
|
||||
* @return boolean true or false
|
||||
*/
|
||||
function Exists ($ConCategory, $ConParent, $ConId, $ConLang)
|
||||
{
|
||||
try {
|
||||
$oPro = ContentPeer::retrieveByPk($ConCategory, $ConParent, $ConId, $ConLang);
|
||||
if (is_object($oPro) && get_class ($oPro) == 'Content' ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception $oError) {
|
||||
throw($oError);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
public function Exists ($ConCategory, $ConParent, $ConId, $ConLang)
|
||||
{
|
||||
try {
|
||||
$oPro = ContentPeer::retrieveByPk( $ConCategory, $ConParent, $ConId, $ConLang );
|
||||
if (is_object( $oPro ) && get_class( $oPro ) == 'Content') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Regenerate Table Content
|
||||
*
|
||||
* @param array $langs
|
||||
*/
|
||||
function regenerateContent($langs, $workSpace=SYS_SYS)
|
||||
{
|
||||
*/
|
||||
public function regenerateContent ($langs, $workSpace = SYS_SYS)
|
||||
{
|
||||
//Search the language
|
||||
$key = array_search('en',$langs);
|
||||
if ($key === false) {
|
||||
$key = array_search(SYS_LANG,$langs);
|
||||
if ($key === false) {
|
||||
$key = '0';
|
||||
}
|
||||
}
|
||||
$this->langsAsoc = array();
|
||||
foreach ($langs as $key=>$value) {
|
||||
$this->langsAsoc[$value] = $value;
|
||||
}
|
||||
|
||||
$this->langs = $langs;
|
||||
$this->rowsProcessed = 0;
|
||||
$this->rowsInserted = 0;
|
||||
$this->rowsUnchanged = 0;
|
||||
$this->rowsClustered = 0;
|
||||
|
||||
$key = array_search( 'en', $langs );
|
||||
if ($key === false) {
|
||||
$key = array_search( SYS_LANG, $langs );
|
||||
if ($key === false) {
|
||||
$key = '0';
|
||||
}
|
||||
}
|
||||
$this->langsAsoc = array ();
|
||||
foreach ($langs as $key => $value) {
|
||||
$this->langsAsoc[$value] = $value;
|
||||
}
|
||||
|
||||
$this->langs = $langs;
|
||||
$this->rowsProcessed = 0;
|
||||
$this->rowsInserted = 0;
|
||||
$this->rowsUnchanged = 0;
|
||||
$this->rowsClustered = 0;
|
||||
|
||||
//Creating table CONTENT_BACKUP
|
||||
$oConnection = Propel::getConnection('workflow');
|
||||
$oStatement = $oConnection->prepareStatement("CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` (
|
||||
$oConnection = Propel::getConnection( 'workflow' );
|
||||
$oStatement = $oConnection->prepareStatement( "CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` (
|
||||
`CON_CATEGORY` VARCHAR(30) default '' NOT NULL,
|
||||
`CON_PARENT` VARCHAR(32) default '' NOT NULL,
|
||||
`CON_ID` VARCHAR(100) default '' NOT NULL,
|
||||
`CON_LANG` VARCHAR(10) default '' NOT NULL,
|
||||
`CON_VALUE` MEDIUMTEXT NOT NULL,
|
||||
CONSTRAINT CONTENT_BACKUP_PK PRIMARY KEY (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG)
|
||||
)Engine=MyISAM DEFAULT CHARSET='utf8' COMMENT='Table for add content';");
|
||||
$oStatement->executeQuery();
|
||||
|
||||
$con = Propel::getConnection('workflow');
|
||||
)Engine=MyISAM DEFAULT CHARSET='utf8' COMMENT='Table for add content';" );
|
||||
$oStatement->executeQuery();
|
||||
|
||||
$con = Propel::getConnection( 'workflow' );
|
||||
$sql = " SELECT DISTINCT CON_LANG
|
||||
FROM CONTENT ";
|
||||
$stmt = $con->createStatement();
|
||||
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
$language = $row['CON_LANG'];
|
||||
if (array_search($row['CON_LANG'],$langs) === false) {
|
||||
Content::removeLanguageContent($row['CON_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
FROM CONTENT ";
|
||||
$stmt = $con->createStatement();
|
||||
$rs = $stmt->executeQuery( $sql, ResultSet::FETCHMODE_ASSOC );
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
$language = $row['CON_LANG'];
|
||||
if (array_search( $row['CON_LANG'], $langs ) === false) {
|
||||
Content::removeLanguageContent( $row['CON_LANG'] );
|
||||
}
|
||||
}
|
||||
|
||||
$sql = " SELECT CON_ID, CON_CATEGORY, CON_LANG, CON_PARENT, CON_VALUE
|
||||
FROM CONTENT
|
||||
ORDER BY CON_ID, CON_CATEGORY, CON_PARENT, CON_LANG";
|
||||
|
||||
G::LoadClass("wsTools");
|
||||
$workSpace = new workspaceTools($workSpace);
|
||||
$workSpace->getDBInfo();
|
||||
|
||||
$link = mysql_pconnect($workSpace->dbHost, $workSpace->dbUser, $workSpace->dbPass)
|
||||
or die ("Could not connect");
|
||||
|
||||
mysql_select_db($workSpace->dbName, $link);
|
||||
mysql_query("SET NAMES 'utf8';");
|
||||
mysql_query('SET OPTION SQL_BIG_SELECTS=1');
|
||||
$result = mysql_unbuffered_query($sql, $link);
|
||||
$list = array();
|
||||
$default = array();
|
||||
$sw = array('CON_ID'=>'','CON_CATEGORY'=>'','CON_PARENT'=>'');
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
if ($sw['CON_ID'] == $row['CON_ID'] &&
|
||||
$sw['CON_CATEGORY'] == $row['CON_CATEGORY'] &&
|
||||
$sw['CON_PARENT'] == $row['CON_PARENT']) {
|
||||
$list[] = $row;
|
||||
} else {
|
||||
$this->rowsClustered++;
|
||||
if (count($langs) != count($list)) {
|
||||
$this->checkLanguage($list, $default);
|
||||
} else {
|
||||
$this->rowsUnchanged = $this->rowsUnchanged + count($langs);
|
||||
}
|
||||
$sw = array();
|
||||
$sw['CON_ID'] = $row['CON_ID'];
|
||||
$sw['CON_CATEGORY'] = $row['CON_CATEGORY'];
|
||||
$sw['CON_LANG'] = $row['CON_LANG'];
|
||||
$sw['CON_PARENT'] = $row['CON_PARENT'];
|
||||
unset($list);
|
||||
unset($default);
|
||||
$list = array();
|
||||
$default = array();
|
||||
$list[] = $row;
|
||||
}
|
||||
if ($sw['CON_LANG'] == $langs[$key]) {
|
||||
$default = $row;
|
||||
}
|
||||
$this->rowsProcessed++;
|
||||
}
|
||||
if (count($langs) != count($list)) {
|
||||
$this->checkLanguage($list, $default);
|
||||
} else {
|
||||
$this->rowsUnchanged = $this->rowsUnchanged + count($langs);
|
||||
}
|
||||
mysql_free_result($result);
|
||||
$total = $this->rowsProcessed + $this->rowsInserted;
|
||||
|
||||
$connection = Propel::getConnection('workflow');
|
||||
$statement = $connection->prepareStatement("INSERT INTO CONTENT
|
||||
ORDER BY CON_ID, CON_CATEGORY, CON_PARENT, CON_LANG";
|
||||
|
||||
G::LoadClass( "wsTools" );
|
||||
$workSpace = new workspaceTools( $workSpace );
|
||||
$workSpace->getDBInfo();
|
||||
|
||||
$link = mysql_pconnect( $workSpace->dbHost, $workSpace->dbUser, $workSpace->dbPass ) or die( "Could not connect" );
|
||||
|
||||
mysql_select_db( $workSpace->dbName, $link );
|
||||
mysql_query( "SET NAMES 'utf8';" );
|
||||
mysql_query( 'SET OPTION SQL_BIG_SELECTS=1' );
|
||||
$result = mysql_unbuffered_query( $sql, $link );
|
||||
$list = array ();
|
||||
$default = array ();
|
||||
$sw = array ('CON_ID' => '','CON_CATEGORY' => '','CON_PARENT' => ''
|
||||
);
|
||||
while ($row = mysql_fetch_assoc( $result )) {
|
||||
if ($sw['CON_ID'] == $row['CON_ID'] && $sw['CON_CATEGORY'] == $row['CON_CATEGORY'] && $sw['CON_PARENT'] == $row['CON_PARENT']) {
|
||||
$list[] = $row;
|
||||
} else {
|
||||
$this->rowsClustered ++;
|
||||
if (count( $langs ) != count( $list )) {
|
||||
$this->checkLanguage( $list, $default );
|
||||
} else {
|
||||
$this->rowsUnchanged = $this->rowsUnchanged + count( $langs );
|
||||
}
|
||||
$sw = array ();
|
||||
$sw['CON_ID'] = $row['CON_ID'];
|
||||
$sw['CON_CATEGORY'] = $row['CON_CATEGORY'];
|
||||
$sw['CON_LANG'] = $row['CON_LANG'];
|
||||
$sw['CON_PARENT'] = $row['CON_PARENT'];
|
||||
unset( $list );
|
||||
unset( $default );
|
||||
$list = array ();
|
||||
$default = array ();
|
||||
$list[] = $row;
|
||||
}
|
||||
if ($sw['CON_LANG'] == $langs[$key]) {
|
||||
$default = $row;
|
||||
}
|
||||
$this->rowsProcessed ++;
|
||||
}
|
||||
if (count( $langs ) != count( $list )) {
|
||||
$this->checkLanguage( $list, $default );
|
||||
} else {
|
||||
$this->rowsUnchanged = $this->rowsUnchanged + count( $langs );
|
||||
}
|
||||
mysql_free_result( $result );
|
||||
$total = $this->rowsProcessed + $this->rowsInserted;
|
||||
$connection = Propel::getConnection( 'workflow' );
|
||||
$statement = $connection->prepareStatement( "INSERT INTO CONTENT
|
||||
SELECT CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE
|
||||
FROM CONTENT_BACKUP");
|
||||
$statement->executeQuery();
|
||||
|
||||
$statement = $connection->prepareStatement("DROP TABLE CONTENT_BACKUP");
|
||||
$statement->executeQuery();
|
||||
|
||||
if (!isset($_SERVER['SERVER_NAME'])) {
|
||||
CLI::logging("Rows Processed ---> $this->rowsProcessed ..... \n");
|
||||
CLI::logging("Rows Clustered ---> $this->rowsClustered ..... \n");
|
||||
CLI::logging("Rows Unchanged ---> $this->rowsUnchanged ..... \n");
|
||||
CLI::logging("Rows Inserted ---> $this->rowsInserted ..... \n");
|
||||
CLI::logging("Rows Total ---> $total ..... \n");
|
||||
}
|
||||
}
|
||||
|
||||
function checkLanguage($content, $default)
|
||||
{
|
||||
if (count($content)>0) {
|
||||
$langs = $this->langs;
|
||||
$langsAsoc = $this->langsAsoc;
|
||||
FROM CONTENT_BACKUP" );
|
||||
$statement->executeQuery();
|
||||
|
||||
$statement = $connection->prepareStatement( "DROP TABLE CONTENT_BACKUP" );
|
||||
$statement->executeQuery();
|
||||
|
||||
if (! isset( $_SERVER['SERVER_NAME'] )) {
|
||||
CLI::logging( "Rows Processed ---> $this->rowsProcessed ..... \n" );
|
||||
CLI::logging( "Rows Clustered ---> $this->rowsClustered ..... \n" );
|
||||
CLI::logging( "Rows Unchanged ---> $this->rowsUnchanged ..... \n" );
|
||||
CLI::logging( "Rows Inserted ---> $this->rowsInserted ..... \n" );
|
||||
CLI::logging( "Rows Total ---> $total ..... \n" );
|
||||
}
|
||||
}
|
||||
|
||||
public function checkLanguage ($content, $default)
|
||||
{
|
||||
if (count( $content ) > 0) {
|
||||
$langs = $this->langs;
|
||||
$langsAsoc = $this->langsAsoc;
|
||||
//Element default
|
||||
$default = (count($default)>0) ? $default : $content[0];
|
||||
foreach ($content as $key => $value) {
|
||||
unset($langsAsoc[$value['CON_LANG']]);
|
||||
}
|
||||
foreach ($langsAsoc as $key => $value) {
|
||||
$this->rowsInserted++;
|
||||
$this->fastInsertContent(
|
||||
$default['CON_CATEGORY'],
|
||||
$default['CON_PARENT'],
|
||||
$default['CON_ID'],
|
||||
$value,
|
||||
$default['CON_VALUE']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fastInsertContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue) {
|
||||
$ConValue = mysql_real_escape_string($ConValue);
|
||||
$connection = Propel::getConnection('workflow');
|
||||
$statement = $connection->prepareStatement("INSERT INTO CONTENT_BACKUP (
|
||||
$default = (count( $default ) > 0) ? $default : $content[0];
|
||||
foreach ($content as $key => $value) {
|
||||
unset( $langsAsoc[$value['CON_LANG']] );
|
||||
}
|
||||
foreach ($langsAsoc as $key => $value) {
|
||||
$this->rowsInserted ++;
|
||||
$this->fastInsertContent( $default['CON_CATEGORY'], $default['CON_PARENT'], $default['CON_ID'], $value, $default['CON_VALUE'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function fastInsertContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
||||
{
|
||||
$ConValue = mysql_real_escape_string( $ConValue );
|
||||
$connection = Propel::getConnection( 'workflow' );
|
||||
$statement = $connection->prepareStatement( "INSERT INTO CONTENT_BACKUP (
|
||||
CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE)
|
||||
VALUES ('$ConCategory', '$ConParent', '$ConId', '$ConLang', '$ConValue');");
|
||||
$statement->executeQuery();
|
||||
}
|
||||
|
||||
function removeLanguageContent($lanId) {
|
||||
try {
|
||||
$c = new Criteria ( );
|
||||
$c->addSelectColumn(ContentPeer::CON_CATEGORY);
|
||||
$c->addSelectColumn(ContentPeer::CON_PARENT);
|
||||
$c->addSelectColumn(ContentPeer::CON_ID);
|
||||
$c->addSelectColumn(ContentPeer::CON_LANG);
|
||||
|
||||
$c->add ( ContentPeer::CON_LANG, $lanId );
|
||||
|
||||
$result = ContentPeer::doSelectRS ( $c );
|
||||
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$result->next ();
|
||||
$row = $result->getRow ();
|
||||
|
||||
while ( is_array ( $row ) ) {
|
||||
$content = ContentPeer::retrieveByPK( $row['CON_CATEGORY'], $row['CON_PARENT'], $row['CON_ID'], $lanId);
|
||||
|
||||
if( $content !== null )
|
||||
$content->delete();
|
||||
|
||||
$result->next ();
|
||||
$row = $result->getRow ();
|
||||
}
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
//Added by Enrique at Feb 9th,2011
|
||||
//Gets all Role Names by Role
|
||||
function getAllContentsByRole($sys_lang=SYS_LANG){
|
||||
if (!isset($sys_lang)) $sys_lang = 'en';
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->clearSelectColumns();
|
||||
$oCriteria->addSelectColumn(ContentPeer::CON_ID);
|
||||
$oCriteria->addAsColumn('ROL_NAME', ContentPeer::CON_VALUE);
|
||||
//$oCriteria->addAsColumn('ROL_UID', ContentPeer::CON_ID);
|
||||
$oCriteria->add(ContentPeer::CON_CATEGORY,'ROL_NAME');
|
||||
$oCriteria->add(ContentPeer::CON_LANG, $sys_lang);
|
||||
$oDataset = ContentPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$aRoles = Array();
|
||||
while ($oDataset->next()){
|
||||
$xRow = $oDataset->getRow();
|
||||
$aRoles[$xRow['CON_ID']] = $xRow['ROL_NAME'];
|
||||
}
|
||||
return $aRoles;
|
||||
}
|
||||
|
||||
} // Content
|
||||
VALUES ('$ConCategory', '$ConParent', '$ConId', '$ConLang', '$ConValue');" );
|
||||
$statement->executeQuery();
|
||||
}
|
||||
|
||||
public function removeLanguageContent ($lanId)
|
||||
{
|
||||
try {
|
||||
$c = new Criteria();
|
||||
$c->addSelectColumn( ContentPeer::CON_CATEGORY );
|
||||
$c->addSelectColumn( ContentPeer::CON_PARENT );
|
||||
$c->addSelectColumn( ContentPeer::CON_ID );
|
||||
$c->addSelectColumn( ContentPeer::CON_LANG );
|
||||
|
||||
$c->add( ContentPeer::CON_LANG, $lanId );
|
||||
|
||||
$result = ContentPeer::doSelectRS( $c );
|
||||
$result->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$result->next();
|
||||
$row = $result->getRow();
|
||||
|
||||
while (is_array( $row )) {
|
||||
$content = ContentPeer::retrieveByPK( $row['CON_CATEGORY'], $row['CON_PARENT'], $row['CON_ID'], $lanId );
|
||||
|
||||
if ($content !== null) {
|
||||
$content->delete();
|
||||
}
|
||||
$result->next();
|
||||
$row = $result->getRow();
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
//Added by Enrique at Feb 9th,2011
|
||||
//Gets all Role Names by Role
|
||||
public function getAllContentsByRole ($sys_lang = SYS_LANG)
|
||||
{
|
||||
if (! isset( $sys_lang )) {
|
||||
$sys_lang = 'en';
|
||||
}
|
||||
$oCriteria = new Criteria( 'workflow' );
|
||||
$oCriteria->clearSelectColumns();
|
||||
$oCriteria->addSelectColumn( ContentPeer::CON_ID );
|
||||
$oCriteria->addAsColumn( 'ROL_NAME', ContentPeer::CON_VALUE );
|
||||
//$oCriteria->addAsColumn('ROL_UID', ContentPeer::CON_ID);
|
||||
$oCriteria->add( ContentPeer::CON_CATEGORY, 'ROL_NAME' );
|
||||
$oCriteria->add( ContentPeer::CON_LANG, $sys_lang );
|
||||
$oDataset = ContentPeer::doSelectRS( $oCriteria );
|
||||
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$aRoles = Array ();
|
||||
while ($oDataset->next()) {
|
||||
$xRow = $oDataset->getRow();
|
||||
$aRoles[$xRow['CON_ID']] = $xRow['ROL_NAME'];
|
||||
}
|
||||
return $aRoles;
|
||||
}
|
||||
}
|
||||
// Content
|
||||
|
||||
|
||||
@@ -1,461 +1,455 @@
|
||||
<?php
|
||||
/**
|
||||
* Translation.php
|
||||
* @package workflow.engine.classes.model
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'classes/model/om/BaseTranslation.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'TRANSLATION' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
class Translation extends BaseTranslation {
|
||||
|
||||
public static $meta;
|
||||
public static $localeSeparator = '-';
|
||||
|
||||
private $envFilePath;
|
||||
|
||||
function __construct(){
|
||||
$this->envFilePath = PATH_DATA . "META-INF" . PATH_SEP . "translations.env";
|
||||
}
|
||||
|
||||
function getAllCriteria(){
|
||||
|
||||
//SELECT * from TRANSLATION WHERE TRN_LANG = 'en' order by TRN_CATEGORY, TRN_ID
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_ID);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_CATEGORY);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_LANG);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_VALUE);
|
||||
//$c->add(TranslationPeer::TRN_LANG, 'en');
|
||||
|
||||
return $oCriteria;
|
||||
}
|
||||
|
||||
function getAll($lang='en', $start=null, $limit=null, $search=null, $dateFrom=null, $dateTo=null){
|
||||
$totalCount = 0;
|
||||
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_ID);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_CATEGORY);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_LANG);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_VALUE);
|
||||
$oCriteria->addSelectColumn(TranslationPeer::TRN_UPDATE_DATE);
|
||||
$oCriteria->add(TranslationPeer::TRN_LANG, $lang);
|
||||
$oCriteria->add(TranslationPeer::TRN_CATEGORY, 'LABEL');
|
||||
//$oCriteria->addAscendingOrderByColumn ( 'TRN_CATEGORY' );
|
||||
$oCriteria->addAscendingOrderByColumn ( 'TRN_ID' );
|
||||
|
||||
|
||||
if( $search ) {
|
||||
$oCriteria->add(
|
||||
$oCriteria->getNewCriterion(
|
||||
TranslationPeer::TRN_ID,
|
||||
"%$search%", Criteria::LIKE
|
||||
)->addOr($oCriteria->getNewCriterion(
|
||||
TranslationPeer::TRN_VALUE,
|
||||
"%$search%", Criteria::LIKE
|
||||
))
|
||||
);
|
||||
}
|
||||
// for date filter
|
||||
if( ($dateFrom)&&($dateTo) ) {
|
||||
$oCriteria->add(
|
||||
$oCriteria->getNewCriterion(
|
||||
TranslationPeer::TRN_UPDATE_DATE,
|
||||
"$dateFrom", Criteria::GREATER_EQUAL//LESS_EQUAL
|
||||
)->addAnd($oCriteria->getNewCriterion(
|
||||
TranslationPeer::TRN_UPDATE_DATE,
|
||||
"$dateTo", Criteria::LESS_EQUAL//GREATER_EQUAL
|
||||
))
|
||||
);
|
||||
}
|
||||
// end filter
|
||||
$c = clone $oCriteria;
|
||||
$c->clearSelectColumns();
|
||||
$c->addSelectColumn('COUNT(*)');
|
||||
$oDataset = TranslationPeer::doSelectRS($c);
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
|
||||
if( is_array($aRow) )
|
||||
$totalCount = $aRow[0];
|
||||
|
||||
if($start)
|
||||
$oCriteria->setOffset($start);
|
||||
if($limit) //&& !isset($seach) && !isset($search))
|
||||
$oCriteria->setLimit($limit);
|
||||
|
||||
$rs = TranslationPeer::doSelectRS($oCriteria);
|
||||
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
$rows = Array();
|
||||
while( $rs->next() ) {
|
||||
$rows[] = $rs->getRow();
|
||||
}
|
||||
|
||||
$result->data = $rows;
|
||||
$result->totalCount = $totalCount;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Load strings from a Database .
|
||||
<?php
|
||||
/**
|
||||
* Translation.php
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once 'classes/model/om/BaseTranslation.php';
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'TRANSLATION' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package workflow.engine.classes.model
|
||||
*/
|
||||
class Translation extends BaseTranslation
|
||||
{
|
||||
|
||||
public static $meta;
|
||||
public static $localeSeparator = '-';
|
||||
|
||||
private $envFilePath;
|
||||
|
||||
public function __construct ()
|
||||
{
|
||||
$this->envFilePath = PATH_DATA . "META-INF" . PATH_SEP . "translations.env";
|
||||
}
|
||||
|
||||
public function getAllCriteria ()
|
||||
{
|
||||
|
||||
//SELECT * from TRANSLATION WHERE TRN_LANG = 'en' order by TRN_CATEGORY, TRN_ID
|
||||
$oCriteria = new Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_ID );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_CATEGORY );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_LANG );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_VALUE );
|
||||
//$c->add(TranslationPeer::TRN_LANG, 'en');
|
||||
|
||||
|
||||
return $oCriteria;
|
||||
}
|
||||
|
||||
public function getAll ($lang = 'en', $start = null, $limit = null, $search = null, $dateFrom = null, $dateTo = null)
|
||||
{
|
||||
$totalCount = 0;
|
||||
|
||||
$oCriteria = new Criteria( 'workflow' );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_ID );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_CATEGORY );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_LANG );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_VALUE );
|
||||
$oCriteria->addSelectColumn( TranslationPeer::TRN_UPDATE_DATE );
|
||||
$oCriteria->add( TranslationPeer::TRN_LANG, $lang );
|
||||
$oCriteria->add( TranslationPeer::TRN_CATEGORY, 'LABEL' );
|
||||
//$oCriteria->addAscendingOrderByColumn ( 'TRN_CATEGORY' );
|
||||
$oCriteria->addAscendingOrderByColumn( 'TRN_ID' );
|
||||
|
||||
if ($search) {
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( TranslationPeer::TRN_ID, "%$search%", Criteria::LIKE )->addOr( $oCriteria->getNewCriterion( TranslationPeer::TRN_VALUE, "%$search%", Criteria::LIKE ) ) );
|
||||
}
|
||||
// for date filter
|
||||
if (($dateFrom) && ($dateTo)) {
|
||||
$oCriteria->add( $oCriteria->getNewCriterion( TranslationPeer::TRN_UPDATE_DATE, "$dateFrom", Criteria::GREATER_EQUAL ) //LESS_EQUAL
|
||||
->addAnd( $oCriteria->getNewCriterion( TranslationPeer::TRN_UPDATE_DATE, "$dateTo", Criteria::LESS_EQUAL ) //GREATER_EQUAL
|
||||
) );
|
||||
}
|
||||
// end filter
|
||||
$c = clone $oCriteria;
|
||||
$c->clearSelectColumns();
|
||||
$c->addSelectColumn( 'COUNT(*)' );
|
||||
$oDataset = TranslationPeer::doSelectRS( $c );
|
||||
$oDataset->next();
|
||||
$aRow = $oDataset->getRow();
|
||||
|
||||
if (is_array( $aRow )) {
|
||||
$totalCount = $aRow[0];
|
||||
}
|
||||
if ($start) {
|
||||
$oCriteria->setOffset( $start );
|
||||
}
|
||||
if ($limit) {
|
||||
//&& !isset($seach) && !isset($search))
|
||||
$oCriteria->setLimit( $limit );
|
||||
}
|
||||
$rs = TranslationPeer::doSelectRS( $oCriteria );
|
||||
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
|
||||
$rows = Array ();
|
||||
while ($rs->next()) {
|
||||
$rows[] = $rs->getRow();
|
||||
}
|
||||
|
||||
$result->data = $rows;
|
||||
$result->totalCount = $totalCount;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/* Load strings from a Database .
|
||||
* @author Fernando Ontiveros <fernando@colosa.com>
|
||||
* @parameter $languageId (es|en|...).
|
||||
*/
|
||||
|
||||
function generateFileTranslation ($languageId = '') {
|
||||
$translation = Array();
|
||||
$translationJS = Array();
|
||||
|
||||
if ($languageId === '')
|
||||
$languageId = defined('SYS_LANG') ? SYS_LANG : 'en';
|
||||
|
||||
$c = new Criteria();
|
||||
$c->add(TranslationPeer::TRN_LANG, $languageId );
|
||||
$c->addAscendingOrderByColumn ( 'TRN_CATEGORY' );
|
||||
$c->addAscendingOrderByColumn ( 'TRN_ID' );
|
||||
$tranlations = TranslationPeer::doSelect($c);
|
||||
|
||||
$cacheFile = PATH_LANGUAGECONT . "translation." . $languageId;
|
||||
$cacheFileJS = PATH_CORE . 'js' . PATH_SEP . 'labels' . PATH_SEP . $languageId.".js";
|
||||
|
||||
foreach ( $tranlations as $key => $row ) {
|
||||
if ( $row->getTrnCategory() === 'LABEL' ) {
|
||||
$translation[ $row->getTrnId() ] = $row->getTrnValue();
|
||||
}
|
||||
if ( $row->getTrnCategory() === 'JAVASCRIPT') {
|
||||
$translationJS[ $row->getTrnId() ] = $row->getTrnValue();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if( ! is_dir(dirname($cacheFile)) )
|
||||
G::mk_dir(dirname($cacheFile));
|
||||
|
||||
if( ! is_dir(dirname($cacheFileJS)) )
|
||||
G::mk_dir(dirname($cacheFileJS));
|
||||
|
||||
$f = fopen( $cacheFile , 'w+');
|
||||
fwrite( $f , "<?php\n" );
|
||||
fwrite( $f , '$translation =' . 'unserialize(\'' . addcslashes( serialize ( $translation ), '\\\'' ) . "');\n");
|
||||
fwrite( $f , "?>" );
|
||||
fclose( $f );
|
||||
|
||||
$json=new Services_JSON();
|
||||
|
||||
$f = fopen( $cacheFileJS , 'w');
|
||||
fwrite( $f , "var G_STRINGS =". $json->encode( $translationJS ) . ";\n");
|
||||
fclose( $f );
|
||||
|
||||
$res['cacheFile'] = $cacheFile;
|
||||
$res['cacheFileJS'] = $cacheFileJS;
|
||||
$res['rows'] = count ( $translation );
|
||||
$res['rowsJS'] = count ( $translationJS );
|
||||
return $res;
|
||||
} catch( Exception $e ) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array with
|
||||
* codError 0 - no error, < 0 error
|
||||
* rowsAffected 0,1 the number of rows affected
|
||||
* message message error.
|
||||
*/
|
||||
function addTranslation ( $category, $id, $languageId, $value ) {
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = TranslationPeer::retrieveByPK( $category, $id, $languageId );
|
||||
if ( ! ( is_object ( $tr ) && get_class ($tr) == 'Translation' ) ) {
|
||||
$tr = new Translation();
|
||||
}
|
||||
$tr->setTrnCategory( $category );
|
||||
$tr->setTrnId( $id );
|
||||
$tr->setTrnLang( $languageId);
|
||||
$tr->setTrnValue( $value );
|
||||
$tr->setTrnUpdateDate( date('Y-m-d') );
|
||||
|
||||
if ($tr->validate() ) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save();
|
||||
}
|
||||
else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures();
|
||||
foreach($validationFailuresArray as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "\n";
|
||||
}
|
||||
return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
|
||||
}
|
||||
return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');
|
||||
//to do: uniform coderror structures for all classes
|
||||
}
|
||||
|
||||
function remove($sCategory, $sId, $sLang) {
|
||||
$oTranslation = TranslationPeer::retrieveByPK($sCategory, $sId, $sLang);
|
||||
if ( ( is_object ( $oTranslation ) && get_class ($oTranslation) == 'Translation' ) ) {
|
||||
$oTranslation->delete();
|
||||
}
|
||||
}
|
||||
|
||||
function addTranslationEnvironment($locale, $headers, $numRecords)
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
$environments = Array();
|
||||
|
||||
if( file_exists($filePath) ) {
|
||||
$environments = unserialize(file_get_contents($filePath));
|
||||
}
|
||||
|
||||
$environment['LOCALE'] = $locale;
|
||||
$environment['HEADERS'] = $headers;
|
||||
$environment['DATE'] = date('Y-m-d H:i:s');
|
||||
$environment['NUM_RECORDS'] = $numRecords;
|
||||
$environment['LANGUAGE'] = $headers['X-Poedit-Language'];
|
||||
$environment['COUNTRY'] = $headers['X-Poedit-Country'];
|
||||
|
||||
if( strpos($locale, self::$localeSeparator) !== false ) {
|
||||
list($environment['LAN_ID'], $environment['IC_UID']) = explode(self::$localeSeparator, strtoupper($locale));
|
||||
$environments[$environment['LAN_ID']][$environment['IC_UID']] = $environment;
|
||||
} else {
|
||||
$environment['LAN_ID'] = strtoupper($locale);
|
||||
$environment['IC_UID'] = '';
|
||||
$environments[$locale]['__INTERNATIONAL__'] = $environment;
|
||||
}
|
||||
|
||||
|
||||
file_put_contents($filePath, serialize($environments));
|
||||
}
|
||||
|
||||
function removeTranslationEnvironment($locale)
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
if (strpos($locale, self::$localeSeparator) !== false) {
|
||||
list($LAN_ID, $IC_UID) = explode('-', strtoupper($locale));
|
||||
} else {
|
||||
$LAN_ID = $locale;
|
||||
$IC_UID = '__INTERNATIONAL__';
|
||||
*/
|
||||
|
||||
public function generateFileTranslation ($languageId = '')
|
||||
{
|
||||
$translation = Array ();
|
||||
$translationJS = Array ();
|
||||
|
||||
if ($languageId === '') {
|
||||
$languageId = defined( 'SYS_LANG' ) ? SYS_LANG : 'en';
|
||||
}
|
||||
$c = new Criteria();
|
||||
$c->add( TranslationPeer::TRN_LANG, $languageId );
|
||||
$c->addAscendingOrderByColumn( 'TRN_CATEGORY' );
|
||||
$c->addAscendingOrderByColumn( 'TRN_ID' );
|
||||
$tranlations = TranslationPeer::doSelect( $c );
|
||||
|
||||
$cacheFile = PATH_LANGUAGECONT . "translation." . $languageId;
|
||||
$cacheFileJS = PATH_CORE . 'js' . PATH_SEP . 'labels' . PATH_SEP . $languageId . ".js";
|
||||
|
||||
foreach ($tranlations as $key => $row) {
|
||||
if ($row->getTrnCategory() === 'LABEL') {
|
||||
$translation[$row->getTrnId()] = $row->getTrnValue();
|
||||
}
|
||||
if ($row->getTrnCategory() === 'JAVASCRIPT') {
|
||||
$translationJS[$row->getTrnId()] = $row->getTrnValue();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (! is_dir( dirname( $cacheFile ) )) {
|
||||
G::mk_dir( dirname( $cacheFile ) );
|
||||
}
|
||||
if (! is_dir( dirname( $cacheFileJS ) )) {
|
||||
G::mk_dir( dirname( $cacheFileJS ) );
|
||||
}
|
||||
$f = fopen( $cacheFile, 'w+' );
|
||||
fwrite( $f, "<?php\n" );
|
||||
fwrite( $f, '$translation =' . 'unserialize(\'' . addcslashes( serialize( $translation ), '\\\'' ) . "');\n" );
|
||||
fwrite( $f, "?>" );
|
||||
fclose( $f );
|
||||
|
||||
$json = new Services_JSON();
|
||||
|
||||
$f = fopen( $cacheFileJS, 'w' );
|
||||
fwrite( $f, "var G_STRINGS =" . $json->encode( $translationJS ) . ";\n" );
|
||||
fclose( $f );
|
||||
|
||||
$res['cacheFile'] = $cacheFile;
|
||||
$res['cacheFileJS'] = $cacheFileJS;
|
||||
$res['rows'] = count( $translation );
|
||||
$res['rowsJS'] = count( $translationJS );
|
||||
return $res;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array with
|
||||
* codError 0 - no error, < 0 error
|
||||
* rowsAffected 0,1 the number of rows affected
|
||||
* message message error.
|
||||
*/
|
||||
public function addTranslation ($category, $id, $languageId, $value)
|
||||
{
|
||||
//if exists the row in the database propel will update it, otherwise will insert.
|
||||
$tr = TranslationPeer::retrieveByPK( $category, $id, $languageId );
|
||||
if (! (is_object( $tr ) && get_class( $tr ) == 'Translation')) {
|
||||
$tr = new Translation();
|
||||
}
|
||||
$tr->setTrnCategory( $category );
|
||||
$tr->setTrnId( $id );
|
||||
$tr->setTrnLang( $languageId );
|
||||
$tr->setTrnValue( $value );
|
||||
$tr->setTrnUpdateDate( date( 'Y-m-d' ) );
|
||||
|
||||
if ($tr->validate()) {
|
||||
// we save it, since we get no validation errors, or do whatever else you like.
|
||||
$res = $tr->save();
|
||||
} else {
|
||||
// Something went wrong. We can now get the validationFailures and handle them.
|
||||
$msg = '';
|
||||
$validationFailuresArray = $tr->getValidationFailures();
|
||||
foreach ($validationFailuresArray as $objValidationFailure) {
|
||||
$msg .= $objValidationFailure->getMessage() . "\n";
|
||||
}
|
||||
return array ('codError' => - 100,'rowsAffected' => 0,'message' => $msg);
|
||||
}
|
||||
return array ('codError' => 0,'rowsAffected' => $res,'message' => '');
|
||||
//to do: uniform coderror structures for all classes
|
||||
}
|
||||
|
||||
public function remove ($sCategory, $sId, $sLang)
|
||||
{
|
||||
$oTranslation = TranslationPeer::retrieveByPK( $sCategory, $sId, $sLang );
|
||||
if ((is_object( $oTranslation ) && get_class( $oTranslation ) == 'Translation')) {
|
||||
$oTranslation->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function addTranslationEnvironment ($locale, $headers, $numRecords)
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
$environments = Array ();
|
||||
|
||||
if (file_exists( $filePath )) {
|
||||
$environments = unserialize( file_get_contents( $filePath ) );
|
||||
}
|
||||
|
||||
$environment['LOCALE'] = $locale;
|
||||
$environment['HEADERS'] = $headers;
|
||||
$environment['DATE'] = date( 'Y-m-d H:i:s' );
|
||||
$environment['NUM_RECORDS'] = $numRecords;
|
||||
$environment['LANGUAGE'] = $headers['X-Poedit-Language'];
|
||||
$environment['COUNTRY'] = $headers['X-Poedit-Country'];
|
||||
|
||||
if (strpos( $locale, self::$localeSeparator ) !== false) {
|
||||
list ($environment['LAN_ID'], $environment['IC_UID']) = explode( self::$localeSeparator, strtoupper( $locale ) );
|
||||
$environments[$environment['LAN_ID']][$environment['IC_UID']] = $environment;
|
||||
} else {
|
||||
$environment['LAN_ID'] = strtoupper( $locale );
|
||||
$environment['IC_UID'] = '';
|
||||
$environments[$locale]['__INTERNATIONAL__'] = $environment;
|
||||
}
|
||||
|
||||
file_put_contents( $filePath, serialize( $environments ) );
|
||||
}
|
||||
|
||||
public function removeTranslationEnvironment ($locale)
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
if (strpos( $locale, self::$localeSeparator ) !== false) {
|
||||
list ($LAN_ID, $IC_UID) = explode( '-', strtoupper( $locale ) );
|
||||
} else {
|
||||
$LAN_ID = $locale;
|
||||
$IC_UID = '__INTERNATIONAL__';
|
||||
}
|
||||
|
||||
if (file_exists( $filePath )) {
|
||||
$environments = unserialize( file_get_contents( $filePath ) );
|
||||
if (! isset( $environments[$LAN_ID][$IC_UID] )) {
|
||||
return null;
|
||||
}
|
||||
|
||||
unset( $environments[$LAN_ID][$IC_UID] );
|
||||
file_put_contents( $filePath, serialize( $environments ) );
|
||||
|
||||
if (file_exists( PATH_CORE . "META-INF" . PATH_SEP . "translation." . $locale )) {
|
||||
G::rm_dir( PATH_DATA . "META-INF" . PATH_SEP . "translation." . $locale );
|
||||
}
|
||||
if (file_exists( PATH_CORE . PATH_SEP . 'content' . PATH_SEP . 'translations' . PATH_SEP . 'processmaker' . $locale . '.po' )) {
|
||||
G::rm_dir( PATH_CORE . PATH_SEP . 'content' . PATH_SEP . 'translations' . PATH_SEP . 'processmaker' . $locale . '.po' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTranslationEnvironments ()
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
$envs = Array ();
|
||||
|
||||
if (! file_exists( $filePath )) {
|
||||
//the transaltions table file doesn't exist, then build it
|
||||
|
||||
|
||||
if (! is_dir( dirname( $this->envFilePath ) )) {
|
||||
G::mk_dir( dirname( $this->envFilePath ) );
|
||||
}
|
||||
$translationsPath = PATH_CORE . "content" . PATH_SEP . 'translations' . PATH_SEP;
|
||||
$basePOFile = $translationsPath . 'english' . PATH_SEP . 'processmaker.en.po';
|
||||
|
||||
$params = self::getInfoFromPOFile( $basePOFile );
|
||||
$this->addTranslationEnvironment( $params['LOCALE'], $params['HEADERS'], $params['COUNT'] );
|
||||
//getting more lanuguage translations
|
||||
$files = glob( $translationsPath . "*.po" );
|
||||
foreach ($files as $file) {
|
||||
$params = self::getInfoFromPOFile( $file );
|
||||
$this->addTranslationEnvironment( $params['LOCALE'], $params['HEADERS'], $params['COUNT'] );
|
||||
}
|
||||
}
|
||||
$envs = unserialize( file_get_contents( $filePath ) );
|
||||
|
||||
$environments = Array ();
|
||||
foreach ($envs as $LAN_ID => $rec1) {
|
||||
foreach ($rec1 as $IC_UID => $rec2) {
|
||||
$environments[] = $rec2;
|
||||
}
|
||||
}
|
||||
|
||||
return $environments;
|
||||
|
||||
/*
|
||||
G::LoadSystem('dbMaintenance');
|
||||
$o = new DataBaseMaintenance('localhost', 'root', 'atopml2005');
|
||||
$o->connect('wf_os');
|
||||
$r = $o->query('select * from ISO_COUNTRY');
|
||||
foreach ($r as $i=>$v) {
|
||||
$r[$i]['IC_NAME'] = utf8_encode($r[$i]['IC_NAME']);
|
||||
unset($r[$i]['IC_SORT_ORDER']);
|
||||
}
|
||||
$r1 = $o->query('select * from LANGUAGE');
|
||||
$r2 = Array();
|
||||
foreach ($r1 as $i=>$v) {
|
||||
$r2[$i]['LAN_NAME'] = utf8_encode($r1[$i]['LAN_NAME']);
|
||||
$r2[$i]['LAN_ID'] = utf8_encode($r1[$i]['LAN_ID']);
|
||||
}
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
$environments = unserialize(file_get_contents($filePath));
|
||||
if (!isset($environments[$LAN_ID][$IC_UID])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unset($environments[$LAN_ID][$IC_UID]);
|
||||
file_put_contents($filePath, serialize($environments));
|
||||
|
||||
if (file_exists(PATH_CORE . "META-INF" . PATH_SEP . "translation.".$locale)) {
|
||||
G::rm_dir(PATH_DATA . "META-INF" . PATH_SEP . "translation.".$locale);
|
||||
}
|
||||
if (file_exists(PATH_CORE . PATH_SEP . 'content' . PATH_SEP . 'translations' . PATH_SEP . 'processmaker' . $locale . '.po')) {
|
||||
G::rm_dir(PATH_CORE . PATH_SEP . 'content' . PATH_SEP . 'translations' . PATH_SEP . 'processmaker' . $locale . '.po');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getTranslationEnvironments(){
|
||||
$filePath = $this->envFilePath;
|
||||
$envs = Array();
|
||||
|
||||
if( ! file_exists($filePath) ) {
|
||||
//the transaltions table file doesn't exist, then build it
|
||||
|
||||
if( ! is_dir(dirname($this->envFilePath)) )
|
||||
G::mk_dir(dirname($this->envFilePath));
|
||||
|
||||
$translationsPath = PATH_CORE . "content" . PATH_SEP . 'translations' . PATH_SEP;
|
||||
$basePOFile = $translationsPath . 'english' . PATH_SEP . 'processmaker.en.po';
|
||||
|
||||
$params = self::getInfoFromPOFile($basePOFile);
|
||||
$this->addTranslationEnvironment($params['LOCALE'], $params['HEADERS'], $params['COUNT']);
|
||||
|
||||
//getting more lanuguage translations
|
||||
$files = glob($translationsPath . "*.po");
|
||||
foreach( $files as $file ){
|
||||
$params = self::getInfoFromPOFile($file);
|
||||
$this->addTranslationEnvironment($params['LOCALE'], $params['HEADERS'], $params['COUNT']);
|
||||
}
|
||||
}
|
||||
$envs = unserialize(file_get_contents($filePath));
|
||||
|
||||
$environments = Array();
|
||||
foreach($envs as $LAN_ID => $rec1 ){
|
||||
foreach($rec1 as $IC_UID => $rec2 ){
|
||||
$environments[] = $rec2;
|
||||
}
|
||||
}
|
||||
|
||||
return $environments;
|
||||
|
||||
/*G::LoadSystem('dbMaintenance');
|
||||
$o = new DataBaseMaintenance('localhost', 'root', 'atopml2005');
|
||||
$o->connect('wf_os');
|
||||
$r = $o->query('select * from ISO_COUNTRY');
|
||||
foreach($r as $i=>$v){
|
||||
$r[$i]['IC_NAME'] = utf8_encode($r[$i]['IC_NAME']);
|
||||
unset($r[$i]['IC_SORT_ORDER']);
|
||||
}
|
||||
$r1 = $o->query('select * from LANGUAGE');
|
||||
$r2 = Array();
|
||||
foreach($r1 as $i=>$v){
|
||||
$r2[$i]['LAN_NAME'] = utf8_encode($r1[$i]['LAN_NAME']);
|
||||
$r2[$i]['LAN_ID'] = utf8_encode($r1[$i]['LAN_ID']);
|
||||
}
|
||||
$s = Array('ISO_COUNTRY'=>$r, 'LANGUAGE'=>$r2);
|
||||
file_put_contents($translationsPath . 'pmos-translations.meta', serialize($s));
|
||||
*/
|
||||
}
|
||||
|
||||
function getInfoFromPOFile($file){
|
||||
G::loadClass('i18n_po');
|
||||
$POFile = new i18n_PO($file);
|
||||
$POFile->readInit();
|
||||
$POHeaders = $POFile->getHeaders();
|
||||
|
||||
if( $POHeaders['X-Poedit-Country'] != '.' ) {
|
||||
$country = self::getTranslationMetaByCountryName($POHeaders['X-Poedit-Country']);
|
||||
} else {
|
||||
$country = '.';
|
||||
}
|
||||
$language = self::getTranslationMetaByLanguageName($POHeaders['X-Poedit-Language']);
|
||||
|
||||
if( $language !== false ) {
|
||||
if( $country !== false ) {
|
||||
if( $country != '.') {
|
||||
$LOCALE = $language['LAN_ID'] . '-' . $country['IC_UID'];
|
||||
} else if( $country == '.' ) {
|
||||
//this a trsnlation file with a language international, no country name was set
|
||||
$LOCALE = $language['LAN_ID'];
|
||||
} else
|
||||
throw new Exception('PO File Error: "'.$file.'" has a invalid country definition!');
|
||||
} else
|
||||
throw new Exception('PO File Error: "'.$file.'" has a invalid country definition!');
|
||||
} else
|
||||
throw new Exception('PO File Error: "'.$file.'" has a invalid language definition!');
|
||||
|
||||
$countItems = 0;
|
||||
try {
|
||||
while( $rowTranslation = $POFile->getTranslation() ) {
|
||||
$countItems++;
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$countItems = '-';
|
||||
}
|
||||
|
||||
return Array('LOCALE'=>$LOCALE, 'HEADERS'=>$POHeaders , 'COUNT'=>$countItems);
|
||||
}
|
||||
|
||||
function getTranslationEnvironment($locale){
|
||||
$filePath = $this->envFilePath;
|
||||
$environments = Array();
|
||||
|
||||
if( ! file_exists($filePath) ) {
|
||||
throw new Exception("The file $filePath doesn't exist");
|
||||
}
|
||||
|
||||
$environments = unserialize(file_get_contents($filePath));
|
||||
if( strpos($locale, self::$localeSeparator) !== false ) {
|
||||
list($LAN_ID, $IC_UID) = explode(self::localeSeparator, strtoupper($locale));
|
||||
} else {
|
||||
$LAN_ID = $locale;
|
||||
$IC_UID = '__INTERNATIONAL__';
|
||||
}
|
||||
|
||||
if( isset($environments[$LAN_ID][$IC_UID]) )
|
||||
return $environments[$LAN_ID][$IC_UID];
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function saveTranslationEnvironment($locale, $data){
|
||||
$filePath = $this->envFilePath;
|
||||
$environments = Array();
|
||||
|
||||
if( ! file_exists($filePath) ) {
|
||||
throw new Exception("The file $filePath doesn't exist");
|
||||
}
|
||||
|
||||
$environments = unserialize(file_get_contents($filePath));
|
||||
if( strpos($locale, self::$localeSeparator) !== false ) {
|
||||
list($LAN_ID, $IC_UID) = explode(self::localeSeparator, strtoupper($locale));
|
||||
} else {
|
||||
$LAN_ID = $locale;
|
||||
$IC_UID = '__INTERNATIONAL__';
|
||||
}
|
||||
|
||||
$environments[$LAN_ID][$IC_UID] = $data;
|
||||
file_put_contents($filePath, serialize($environments));
|
||||
}
|
||||
|
||||
function getTranslationMeta(){
|
||||
$translationsPath = PATH_CORE . "content" . PATH_SEP . 'translations' . PATH_SEP;
|
||||
$translationsTable = unserialize(file_get_contents($translationsPath . 'pmos-translations.meta'));
|
||||
return $translationsTable;
|
||||
}
|
||||
|
||||
function getTranslationMetaByCountryName($IC_NAME){
|
||||
$translationsTable = self::getTranslationMeta();
|
||||
|
||||
foreach ($translationsTable['ISO_COUNTRY'] as $row) {
|
||||
if( $row['IC_NAME'] == $IC_NAME )
|
||||
return $row;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getTranslationMetaByLanguageName($LAN_NAME){
|
||||
$translationsTable = self::getTranslationMeta();
|
||||
|
||||
foreach ($translationsTable['LANGUAGE'] as $row) {
|
||||
if( $row['LAN_NAME'] == $LAN_NAME )
|
||||
return $row;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // Translation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$s = Array('ISO_COUNTRY'=>$r, 'LANGUAGE'=>$r2);
|
||||
file_put_contents($translationsPath . 'pmos-translations.meta', serialize($s));
|
||||
*/
|
||||
}
|
||||
|
||||
public function getInfoFromPOFile ($file)
|
||||
{
|
||||
G::loadClass( 'i18n_po' );
|
||||
$POFile = new i18n_PO( $file );
|
||||
$POFile->readInit();
|
||||
$POHeaders = $POFile->getHeaders();
|
||||
|
||||
if ($POHeaders['X-Poedit-Country'] != '.') {
|
||||
$country = self::getTranslationMetaByCountryName( $POHeaders['X-Poedit-Country'] );
|
||||
} else {
|
||||
$country = '.';
|
||||
}
|
||||
$language = self::getTranslationMetaByLanguageName( $POHeaders['X-Poedit-Language'] );
|
||||
|
||||
if ($language !== false) {
|
||||
if ($country !== false) {
|
||||
if ($country != '.') {
|
||||
$LOCALE = $language['LAN_ID'] . '-' . $country['IC_UID'];
|
||||
} else if ($country == '.') {
|
||||
//this a trsnlation file with a language international, no country name was set
|
||||
$LOCALE = $language['LAN_ID'];
|
||||
} else
|
||||
throw new Exception( 'PO File Error: "' . $file . '" has a invalid country definition!' );
|
||||
} else
|
||||
throw new Exception( 'PO File Error: "' . $file . '" has a invalid country definition!' );
|
||||
} else
|
||||
throw new Exception( 'PO File Error: "' . $file . '" has a invalid language definition!' );
|
||||
|
||||
$countItems = 0;
|
||||
try {
|
||||
while ($rowTranslation = $POFile->getTranslation()) {
|
||||
$countItems ++;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$countItems = '-';
|
||||
}
|
||||
return Array ('LOCALE' => $LOCALE,'HEADERS' => $POHeaders,'COUNT' => $countItems);
|
||||
}
|
||||
|
||||
public function getTranslationEnvironment ($locale)
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
$environments = Array ();
|
||||
|
||||
if (! file_exists( $filePath )) {
|
||||
throw new Exception( "The file $filePath doesn't exist" );
|
||||
}
|
||||
|
||||
$environments = unserialize( file_get_contents( $filePath ) );
|
||||
if (strpos( $locale, self::$localeSeparator ) !== false) {
|
||||
list ($LAN_ID, $IC_UID) = explode( self::localeSeparator, strtoupper( $locale ) );
|
||||
} else {
|
||||
$LAN_ID = $locale;
|
||||
$IC_UID = '__INTERNATIONAL__';
|
||||
}
|
||||
|
||||
if (isset( $environments[$LAN_ID][$IC_UID] )) {
|
||||
return $environments[$LAN_ID][$IC_UID];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function saveTranslationEnvironment ($locale, $data)
|
||||
{
|
||||
$filePath = $this->envFilePath;
|
||||
$environments = Array ();
|
||||
|
||||
if (! file_exists( $filePath )) {
|
||||
throw new Exception( "The file $filePath doesn't exist" );
|
||||
}
|
||||
|
||||
$environments = unserialize( file_get_contents( $filePath ) );
|
||||
if (strpos( $locale, self::$localeSeparator ) !== false) {
|
||||
list ($LAN_ID, $IC_UID) = explode( self::localeSeparator, strtoupper( $locale ) );
|
||||
} else {
|
||||
$LAN_ID = $locale;
|
||||
$IC_UID = '__INTERNATIONAL__';
|
||||
}
|
||||
|
||||
$environments[$LAN_ID][$IC_UID] = $data;
|
||||
file_put_contents( $filePath, serialize( $environments ) );
|
||||
}
|
||||
|
||||
public function getTranslationMeta ()
|
||||
{
|
||||
$translationsPath = PATH_CORE . "content" . PATH_SEP . 'translations' . PATH_SEP;
|
||||
$translationsTable = unserialize( file_get_contents( $translationsPath . 'pmos-translations.meta' ) );
|
||||
return $translationsTable;
|
||||
}
|
||||
|
||||
public function getTranslationMetaByCountryName ($IC_NAME)
|
||||
{
|
||||
$translationsTable = self::getTranslationMeta();
|
||||
|
||||
foreach ($translationsTable['ISO_COUNTRY'] as $row) {
|
||||
if ($row['IC_NAME'] == $IC_NAME) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTranslationMetaByLanguageName ($LAN_NAME)
|
||||
{
|
||||
$translationsTable = self::getTranslationMeta();
|
||||
|
||||
foreach ($translationsTable['LANGUAGE'] as $row) {
|
||||
if ($row['LAN_NAME'] == $LAN_NAME) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Translation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user