CODE STYLE Format

Change format
This commit is contained in:
norahmollo
2012-10-19 18:07:17 +00:00
parent 2906790fe3
commit b17a5eff62
4 changed files with 5129 additions and 5141 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,8 @@
<?php <?php
/** /**
* CalendarDefinition.php * CalendarDefinition.php
* @package workflow.engine.classes.model *
* @package workflow.engine.classes.model
*/ */
require_once 'classes/model/om/BaseCalendarDefinition.php'; require_once 'classes/model/om/BaseCalendarDefinition.php';
@@ -15,453 +16,440 @@ require_once 'classes/model/CalendarAssignments.php';
* *
* *
* You should add additional methods to this class to meet the * You should add additional methods to this class to meet the
* application requirements. This class will only be generated as * application requirements. This class will only be generated as
* long as it does not already exist in the output directory. * long as it does not already exist in the output directory.
* *
* @package workflow.engine.classes.model * @package workflow.engine.classes.model
*/ */
class CalendarDefinition extends BaseCalendarDefinition { class CalendarDefinition extends BaseCalendarDefinition
public $calendarLog = ''; {
function getCalendarList($onlyActive = false, $arrayMode = false) { public $calendarLog = '';
$Criteria = new Criteria ( 'workflow' );
$Criteria->clearSelectColumns ();
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UID ); public function getCalendarList ($onlyActive = false, $arrayMode = false)
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_NAME ); {
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_CREATE_DATE ); $Criteria = new Criteria( 'workflow' );
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE ); $Criteria->clearSelectColumns();
$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 ); $Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UID );
$Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_NAME );
if (! $arrayMode) { $Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
return $Criteria; $Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
} else { $Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
$oDataset = calendarDefinitionPeer::doSelectRS ( $Criteria ); $Criteria->addSelectColumn( CalendarDefinitionPeer::CALENDAR_STATUS );
$oDataset->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); // $Criteria->addAsColumn('DELETABLE', "IF (CALENDAR_UID <> '00000000000000000000000000000001', '".G::LoadTranslation('ID_DELETE')."','') ");
$oDataset->next (); $Criteria->addAsColumn( 'DELETABLE', "CASE WHEN CALENDAR_UID <> '00000000000000000000000000000001' THEN '" . G::LoadTranslation( 'ID_DELETE' ) . "' ELSE '' END " );
$calendarA = array (0 => 'dummy' ); // Note: This list doesn't show deleted items (STATUS = DELETED)
$calendarCount = 0; if ($onlyActive) {
while ( is_array ( $aRow = $oDataset->getRow () ) ) { // Show only active. Used on assignment lists
$calendarCount ++; $Criteria->add( calendarDefinitionPeer::CALENDAR_STATUS, "ACTIVE", CRITERIA::EQUAL );
$calendarA [$calendarCount] = $aRow; } else {
$oDataset->next (); // Show Active and Inactive calendars. USed in main list
} $Criteria->add( calendarDefinitionPeer::CALENDAR_STATUS, array ("ACTIVE","INACTIVE"), CRITERIA::IN );
$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' => '');
$Criteria->add( calendarDefinitionPeer::CALENDAR_UID, "xx", CRITERIA::NOT_EQUAL );
//to do: uniform coderror structures for all classes if (! $arrayMode) {
return $Criteria;
} else {
//if ( $res['codError'] < 0 ) { $oDataset = calendarDefinitionPeer::doSelectRS( $Criteria );
// G::SendMessageText ( $res['message'] , 'error' ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
//} $oDataset->next();
$calendarA = array (0 => 'dummy');
$calendarCount = 0;
} while (is_array( $aRow = $oDataset->getRow() )) {
function deleteCalendar($CalendarUid) { $calendarCount ++;
//if exists the row in the database propel will update it, otherwise will insert. $calendarA[$calendarCount] = $aRow;
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid ); $oDataset->next();
}
if (! (is_object ( $tr ) && get_class ( $tr ) == 'CalendarDefinition')) { $return['criteria'] = $Criteria;
// $return['array'] = $calendarA;
return false; return $return;
}
$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 ); }
} //Added by qennix
} else { //Delete record //Gets criteria for listing
if ((is_object ( $tr ) && get_class ( $tr ) == 'CalendarAssignments')) { public function getCalendarCriterias ($filter, $start, $limit)
$tr->delete (); {
} $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)
//Added by Qennix {
//Counts all users,task,process by calendar //if exists the row in the database propel will update it, otherwise will insert.
function getAllCounterByCalendar($type){ $tr = CalendarDefinitionPeer::retrieveByPK( $CalendarUid );
$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) $defaultCalendar['CALENDAR_UID'] = "00000000000000000000000000000001";
{ $defaultCalendar['CALENDAR_NAME'] = "Default";
$Criteria = new Criteria('workflow'); $defaultCalendar['CALENDAR_CREATE_DATE'] = date( "Y-m-d" );
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_UID); $defaultCalendar['CALENDAR_UPDATE_DATE'] = date( "Y-m-d" );
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_NAME); $defaultCalendar['CALENDAR_DESCRIPTION'] = "Default";
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_CREATE_DATE); $defaultCalendar['CALENDAR_STATUS'] = "ACTIVE";
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_UPDATE_DATE); $defaultCalendar['CALENDAR_WORK_DAYS'] = "1|2|3|4|5";
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_DESCRIPTION); $defaultCalendar['CALENDAR_WORK_DAYS'] = explode( "|", "1|2|3|4|5" );
$Criteria->addSelectColumn(CalendarDefinitionPeer::CALENDAR_STATUS); $defaultCalendar['BUSINESS_DAY'][1]['CALENDAR_BUSINESS_DAY'] = 7;
$Criteria->add(calendarDefinitionPeer::CALENDAR_NAME, $calendarName, CRITERIA::EQUAL); $defaultCalendar['BUSINESS_DAY'][1]['CALENDAR_BUSINESS_START'] = "09:00";
$oDataset = calendarDefinitionPeer::doSelectRS ($Criteria); $defaultCalendar['BUSINESS_DAY'][1]['CALENDAR_BUSINESS_END'] = "17:00";
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $defaultCalendar['HOLIDAY'] = array ();
$oDataset->next();
return $oDataset->getRow(); if ((is_object( $tr ) && get_class( $tr ) == 'CalendarDefinition')) {
} $fields['CALENDAR_UID'] = $tr->getCalendarUid();
} // CalendarDefinition $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

View File

@@ -1,7 +1,8 @@
<?php <?php
/** /**
* Content.php * Content.php
* @package workflow.engine.classes.model *
* @package workflow.engine.classes.model
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,11 +14,11 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -32,39 +33,41 @@ require_once 'classes/model/om/BaseContent.php';
* *
* *
* You should add additional methods to this class to meet the * You should add additional methods to this class to meet the
* application requirements. This class will only be generated as * application requirements. This class will only be generated as
* long as it does not already exist in the output directory. * long as it does not already exist in the output directory.
* *
* @package workflow.engine.classes.model * @package workflow.engine.classes.model
*/ */
class Content extends BaseContent { class Content extends BaseContent
{
public $langs; public $langs;
public $rowsProcessed; public $rowsProcessed;
public $rowsInserted; public $rowsInserted;
public $rowsUnchanged; public $rowsUnchanged;
public $rowsClustered; public $rowsClustered;
public $langsAsoc; public $langsAsoc;
/* /*
* Load the content row specified by the parameters: * Load the content row specified by the parameters:
* @param string $sUID * @param string $sUID
* @return variant * @return variant
*/ */
function load($ConCategory, $ConParent, $ConId, $ConLang) { public function load ($ConCategory, $ConParent, $ConId, $ConLang)
$content = ContentPeer::retrieveByPK ( $ConCategory, $ConParent, $ConId, $ConLang ); {
if (is_null ( $content )) { $content = ContentPeer::retrieveByPK( $ConCategory, $ConParent, $ConId, $ConLang );
//we dont find any value for this field and language in CONTENT table if (is_null( $content )) {
$ConValue = Content::autoLoadSave ( $ConCategory, $ConParent, $ConId, $ConLang ); //we dont find any value for this field and language in CONTENT table;
} else { $ConValue = Content::autoLoadSave( $ConCategory, $ConParent, $ConId, $ConLang );
//krumo($content); } else {
$ConValue = $content->getConValue (); //krumo($content);
if ($ConValue == "") { //try to find a valid translation $ConValue = $content->getConValue();
$ConValue = Content::autoLoadSave ( $ConCategory, $ConParent, $ConId, $ConLang ); if ($ConValue == "") {
} //try to find a valid translation
$ConValue = Content::autoLoadSave( $ConCategory, $ConParent, $ConId, $ConLang );
}
}
return $ConValue;
} }
return $ConValue; /*
}
/*
* Find a valid Lang for current Content. The most recent * Find a valid Lang for current Content. The most recent
* @param string $ConCategory * @param string $ConCategory
* @param string $ConParent * @param string $ConParent
@@ -72,123 +75,81 @@ class Content extends BaseContent {
* @return string * @return string
* *
*/ */
function getDefaultContentLang($ConCategory, $ConParent, $ConId, $destConLang) { public function getDefaultContentLang ($ConCategory, $ConParent, $ConId, $destConLang)
$Criteria = new Criteria ( 'workflow' ); {
$Criteria->clearSelectColumns ()->clearOrderByColumns (); $Criteria = new Criteria( 'workflow' );
$Criteria->clearSelectColumns()->clearOrderByColumns();
$Criteria->addSelectColumn ( ContentPeer::CON_CATEGORY ); $Criteria->addSelectColumn( ContentPeer::CON_CATEGORY );
$Criteria->addSelectColumn ( ContentPeer::CON_PARENT ); $Criteria->addSelectColumn( ContentPeer::CON_PARENT );
$Criteria->addSelectColumn ( ContentPeer::CON_ID ); $Criteria->addSelectColumn( ContentPeer::CON_ID );
$Criteria->addSelectColumn ( ContentPeer::CON_LANG ); $Criteria->addSelectColumn( ContentPeer::CON_LANG );
$Criteria->addSelectColumn ( ContentPeer::CON_VALUE ); $Criteria->addSelectColumn( ContentPeer::CON_VALUE );
$Criteria->add ( ContentPeer::CON_CATEGORY, $ConCategory, CRITERIA::EQUAL ); $Criteria->add( ContentPeer::CON_CATEGORY, $ConCategory, CRITERIA::EQUAL );
$Criteria->add ( ContentPeer::CON_PARENT, $ConParent, CRITERIA::EQUAL ); $Criteria->add( ContentPeer::CON_PARENT, $ConParent, CRITERIA::EQUAL );
$Criteria->add ( ContentPeer::CON_ID, $ConId, CRITERIA::EQUAL ); $Criteria->add( ContentPeer::CON_ID, $ConId, CRITERIA::EQUAL );
$Criteria->add( ContentPeer::CON_LANG, $destConLang, CRITERIA::NOT_EQUAL );
$Criteria->add ( ContentPeer::CON_LANG, $destConLang, CRITERIA::NOT_EQUAL ); $rs = ContentPeer::doSelectRS( $Criteria );
$rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$rs->next();
$rs = ContentPeer::doSelectRS ( $Criteria ); if (is_array( $row = $rs->getRow() )) {
$rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); $defaultLang = $row['CON_LANG'];
$rs->next (); } else {
$defaultLang = "";
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
* @param string $ConCategory
* @param string $ConParent
* @param string $ConId
* @param string $ConLang
* @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);
} }
} return ($defaultLang);
$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);
} }
} /*
* 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 * Insert a content row
* @param string $ConCategory * @param string $ConCategory
* @param string $ConParent * @param string $ConParent
@@ -197,27 +158,75 @@ class Content extends BaseContent {
* @param string $ConValue * @param string $ConValue
* @return variant * @return variant
*/ */
function insertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue) { public function addContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
try { {
$con = new Content ( ); try {
$con->setConCategory ( $ConCategory ); if ($ConLang != 'en') {
$con->setConParent ( $ConParent ); $baseLangContent = ContentPeer::retrieveByPk( $ConCategory, $ConParent, $ConId, 'en' );
$con->setConId ( $ConId ); if ($baseLangContent === null) {
$con->setConLang ( $ConLang ); Content::addContent( $ConCategory, $ConParent, $ConId, 'en', $ConValue );
$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);
}
}
/* $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
* @return variant
*/
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 * remove a content row
* @param string $ConCategory * @param string $ConCategory
* @param string $ConParent * @param string $ConParent
@@ -226,27 +235,28 @@ class Content extends BaseContent {
* @param string $ConValue * @param string $ConValue
* @return variant * @return variant
*/ */
function removeContent($ConCategory, $ConParent, $ConId) { public function removeContent ($ConCategory, $ConParent, $ConId)
try { {
$c = new Criteria ( ); try {
$c->add ( ContentPeer::CON_CATEGORY, $ConCategory ); $c = new Criteria();
$c->add ( ContentPeer::CON_PARENT, $ConParent ); $c->add( ContentPeer::CON_CATEGORY, $ConCategory );
$c->add ( ContentPeer::CON_ID, $ConId ); $c->add( ContentPeer::CON_PARENT, $ConParent );
$result = ContentPeer::doSelectRS ( $c ); $c->add( ContentPeer::CON_ID, $ConId );
$result->next (); $result = ContentPeer::doSelectRS( $c );
$row = $result->getRow (); $result->next();
while ( is_array ( $row ) ) { $row = $result->getRow();
ContentPeer::doDelete ( array ($ConCategory, $ConParent, $ConId, $row [3] ) ); while (is_array( $row )) {
$result->next (); ContentPeer::doDelete( array ($ConCategory,$ConParent,$ConId,$row[3]) );
$row = $result->getRow (); $result->next();
} $row = $result->getRow();
} catch ( Exception $e ) { }
throw ($e); } catch (Exception $e) {
throw ($e);
}
} }
} /*
/*
* Reasons if the record already exists * Reasons if the record already exists
* *
* @param string $ConCategory * @param string $ConCategory
@@ -256,69 +266,68 @@ class Content extends BaseContent {
* @param string $ConValue * @param string $ConValue
* @return boolean true or false * @return boolean true or false
*/ */
function Exists ($ConCategory, $ConParent, $ConId, $ConLang) public function Exists ($ConCategory, $ConParent, $ConId, $ConLang)
{ {
try { try {
$oPro = ContentPeer::retrieveByPk($ConCategory, $ConParent, $ConId, $ConLang); $oPro = ContentPeer::retrieveByPk( $ConCategory, $ConParent, $ConId, $ConLang );
if (is_object($oPro) && get_class ($oPro) == 'Content' ) { if (is_object( $oPro ) && get_class( $oPro ) == 'Content') {
return true; return true;
} else { } else {
return false; return false;
} }
} catch (Exception $oError) {
throw ($oError);
}
} }
catch (Exception $oError) {
throw($oError);
}
}
/* /*
* Regenerate Table Content * Regenerate Table Content
* *
* @param array $langs * @param array $langs
*/ */
function regenerateContent($langs, $workSpace=SYS_SYS) public function regenerateContent ($langs, $workSpace = SYS_SYS)
{ {
//Search the language //Search the language
$key = array_search('en',$langs); $key = array_search( 'en', $langs );
if ($key === false) { if ($key === false) {
$key = array_search(SYS_LANG,$langs); $key = array_search( SYS_LANG, $langs );
if ($key === false) { if ($key === false) {
$key = '0'; $key = '0';
} }
} }
$this->langsAsoc = array(); $this->langsAsoc = array ();
foreach ($langs as $key=>$value) { foreach ($langs as $key => $value) {
$this->langsAsoc[$value] = $value; $this->langsAsoc[$value] = $value;
} }
$this->langs = $langs; $this->langs = $langs;
$this->rowsProcessed = 0; $this->rowsProcessed = 0;
$this->rowsInserted = 0; $this->rowsInserted = 0;
$this->rowsUnchanged = 0; $this->rowsUnchanged = 0;
$this->rowsClustered = 0; $this->rowsClustered = 0;
//Creating table CONTENT_BACKUP //Creating table CONTENT_BACKUP
$oConnection = Propel::getConnection('workflow'); $oConnection = Propel::getConnection( 'workflow' );
$oStatement = $oConnection->prepareStatement("CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` ( $oStatement = $oConnection->prepareStatement( "CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` (
`CON_CATEGORY` VARCHAR(30) default '' NOT NULL, `CON_CATEGORY` VARCHAR(30) default '' NOT NULL,
`CON_PARENT` VARCHAR(32) default '' NOT NULL, `CON_PARENT` VARCHAR(32) default '' NOT NULL,
`CON_ID` VARCHAR(100) default '' NOT NULL, `CON_ID` VARCHAR(100) default '' NOT NULL,
`CON_LANG` VARCHAR(10) default '' NOT NULL, `CON_LANG` VARCHAR(10) default '' NOT NULL,
`CON_VALUE` MEDIUMTEXT NOT NULL, `CON_VALUE` MEDIUMTEXT NOT NULL,
CONSTRAINT CONTENT_BACKUP_PK PRIMARY KEY (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG) CONSTRAINT CONTENT_BACKUP_PK PRIMARY KEY (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG)
)Engine=MyISAM DEFAULT CHARSET='utf8' COMMENT='Table for add content';"); )Engine=MyISAM DEFAULT CHARSET='utf8' COMMENT='Table for add content';" );
$oStatement->executeQuery(); $oStatement->executeQuery();
$con = Propel::getConnection('workflow'); $con = Propel::getConnection( 'workflow' );
$sql = " SELECT DISTINCT CON_LANG $sql = " SELECT DISTINCT CON_LANG
FROM CONTENT "; FROM CONTENT ";
$stmt = $con->createStatement(); $stmt = $con->createStatement();
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC); $rs = $stmt->executeQuery( $sql, ResultSet::FETCHMODE_ASSOC );
while ($rs->next()) { while ($rs->next()) {
$row = $rs->getRow(); $row = $rs->getRow();
$language = $row['CON_LANG']; $language = $row['CON_LANG'];
if (array_search($row['CON_LANG'],$langs) === false) { if (array_search( $row['CON_LANG'], $langs ) === false) {
Content::removeLanguageContent($row['CON_LANG']); Content::removeLanguageContent( $row['CON_LANG'] );
} }
} }
@@ -326,154 +335,151 @@ class Content extends BaseContent {
FROM CONTENT FROM CONTENT
ORDER BY CON_ID, CON_CATEGORY, CON_PARENT, CON_LANG"; ORDER BY CON_ID, CON_CATEGORY, CON_PARENT, CON_LANG";
G::LoadClass("wsTools"); G::LoadClass( "wsTools" );
$workSpace = new workspaceTools($workSpace); $workSpace = new workspaceTools( $workSpace );
$workSpace->getDBInfo(); $workSpace->getDBInfo();
$link = mysql_pconnect($workSpace->dbHost, $workSpace->dbUser, $workSpace->dbPass) $link = mysql_pconnect( $workSpace->dbHost, $workSpace->dbUser, $workSpace->dbPass ) or die( "Could not connect" );
or die ("Could not connect");
mysql_select_db($workSpace->dbName, $link); mysql_select_db( $workSpace->dbName, $link );
mysql_query("SET NAMES 'utf8';"); mysql_query( "SET NAMES 'utf8';" );
mysql_query('SET OPTION SQL_BIG_SELECTS=1'); mysql_query( 'SET OPTION SQL_BIG_SELECTS=1' );
$result = mysql_unbuffered_query($sql, $link); $result = mysql_unbuffered_query( $sql, $link );
$list = array(); $list = array ();
$default = array(); $default = array ();
$sw = array('CON_ID'=>'','CON_CATEGORY'=>'','CON_PARENT'=>''); $sw = array ('CON_ID' => '','CON_CATEGORY' => '','CON_PARENT' => ''
while ($row = mysql_fetch_assoc($result)) { );
if ($sw['CON_ID'] == $row['CON_ID'] && while ($row = mysql_fetch_assoc( $result )) {
$sw['CON_CATEGORY'] == $row['CON_CATEGORY'] && if ($sw['CON_ID'] == $row['CON_ID'] && $sw['CON_CATEGORY'] == $row['CON_CATEGORY'] && $sw['CON_PARENT'] == $row['CON_PARENT']) {
$sw['CON_PARENT'] == $row['CON_PARENT']) {
$list[] = $row; $list[] = $row;
} else { } else {
$this->rowsClustered++; $this->rowsClustered ++;
if (count($langs) != count($list)) { if (count( $langs ) != count( $list )) {
$this->checkLanguage($list, $default); $this->checkLanguage( $list, $default );
} else { } else {
$this->rowsUnchanged = $this->rowsUnchanged + count($langs); $this->rowsUnchanged = $this->rowsUnchanged + count( $langs );
} }
$sw = array(); $sw = array ();
$sw['CON_ID'] = $row['CON_ID']; $sw['CON_ID'] = $row['CON_ID'];
$sw['CON_CATEGORY'] = $row['CON_CATEGORY']; $sw['CON_CATEGORY'] = $row['CON_CATEGORY'];
$sw['CON_LANG'] = $row['CON_LANG']; $sw['CON_LANG'] = $row['CON_LANG'];
$sw['CON_PARENT'] = $row['CON_PARENT']; $sw['CON_PARENT'] = $row['CON_PARENT'];
unset($list); unset( $list );
unset($default); unset( $default );
$list = array(); $list = array ();
$default = array(); $default = array ();
$list[] = $row; $list[] = $row;
} }
if ($sw['CON_LANG'] == $langs[$key]) { if ($sw['CON_LANG'] == $langs[$key]) {
$default = $row; $default = $row;
} }
$this->rowsProcessed++; $this->rowsProcessed ++;
} }
if (count($langs) != count($list)) { if (count( $langs ) != count( $list )) {
$this->checkLanguage($list, $default); $this->checkLanguage( $list, $default );
} else { } else {
$this->rowsUnchanged = $this->rowsUnchanged + count($langs); $this->rowsUnchanged = $this->rowsUnchanged + count( $langs );
} }
mysql_free_result($result); mysql_free_result( $result );
$total = $this->rowsProcessed + $this->rowsInserted; $total = $this->rowsProcessed + $this->rowsInserted;
$connection = Propel::getConnection( 'workflow' );
$connection = Propel::getConnection('workflow'); $statement = $connection->prepareStatement( "INSERT INTO CONTENT
$statement = $connection->prepareStatement("INSERT INTO CONTENT
SELECT CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE SELECT CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE
FROM CONTENT_BACKUP"); FROM CONTENT_BACKUP" );
$statement->executeQuery(); $statement->executeQuery();
$statement = $connection->prepareStatement("DROP TABLE CONTENT_BACKUP"); $statement = $connection->prepareStatement( "DROP TABLE CONTENT_BACKUP" );
$statement->executeQuery(); $statement->executeQuery();
if (!isset($_SERVER['SERVER_NAME'])) { if (! isset( $_SERVER['SERVER_NAME'] )) {
CLI::logging("Rows Processed ---> $this->rowsProcessed ..... \n"); CLI::logging( "Rows Processed ---> $this->rowsProcessed ..... \n" );
CLI::logging("Rows Clustered ---> $this->rowsClustered ..... \n"); CLI::logging( "Rows Clustered ---> $this->rowsClustered ..... \n" );
CLI::logging("Rows Unchanged ---> $this->rowsUnchanged ..... \n"); CLI::logging( "Rows Unchanged ---> $this->rowsUnchanged ..... \n" );
CLI::logging("Rows Inserted ---> $this->rowsInserted ..... \n"); CLI::logging( "Rows Inserted ---> $this->rowsInserted ..... \n" );
CLI::logging("Rows Total ---> $total ..... \n"); CLI::logging( "Rows Total ---> $total ..... \n" );
} }
} }
function checkLanguage($content, $default) public function checkLanguage ($content, $default)
{ {
if (count($content)>0) { if (count( $content ) > 0) {
$langs = $this->langs; $langs = $this->langs;
$langsAsoc = $this->langsAsoc; $langsAsoc = $this->langsAsoc;
//Element default //Element default
$default = (count($default)>0) ? $default : $content[0]; $default = (count( $default ) > 0) ? $default : $content[0];
foreach ($content as $key => $value) { foreach ($content as $key => $value) {
unset($langsAsoc[$value['CON_LANG']]); unset( $langsAsoc[$value['CON_LANG']] );
} }
foreach ($langsAsoc as $key => $value) { foreach ($langsAsoc as $key => $value) {
$this->rowsInserted++; $this->rowsInserted ++;
$this->fastInsertContent( $this->fastInsertContent( $default['CON_CATEGORY'], $default['CON_PARENT'], $default['CON_ID'], $value, $default['CON_VALUE'] );
$default['CON_CATEGORY'],
$default['CON_PARENT'],
$default['CON_ID'],
$value,
$default['CON_VALUE']
);
} }
} }
} }
function fastInsertContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue) { public function fastInsertContent ($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
$ConValue = mysql_real_escape_string($ConValue); {
$connection = Propel::getConnection('workflow'); $ConValue = mysql_real_escape_string( $ConValue );
$statement = $connection->prepareStatement("INSERT INTO CONTENT_BACKUP ( $connection = Propel::getConnection( 'workflow' );
$statement = $connection->prepareStatement( "INSERT INTO CONTENT_BACKUP (
CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE) CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE)
VALUES ('$ConCategory', '$ConParent', '$ConId', '$ConLang', '$ConValue');"); VALUES ('$ConCategory', '$ConParent', '$ConId', '$ConLang', '$ConValue');" );
$statement->executeQuery(); $statement->executeQuery();
} }
function removeLanguageContent($lanId) { public function removeLanguageContent ($lanId)
try { {
$c = new Criteria ( ); try {
$c->addSelectColumn(ContentPeer::CON_CATEGORY); $c = new Criteria();
$c->addSelectColumn(ContentPeer::CON_PARENT); $c->addSelectColumn( ContentPeer::CON_CATEGORY );
$c->addSelectColumn(ContentPeer::CON_ID); $c->addSelectColumn( ContentPeer::CON_PARENT );
$c->addSelectColumn(ContentPeer::CON_LANG); $c->addSelectColumn( ContentPeer::CON_ID );
$c->addSelectColumn( ContentPeer::CON_LANG );
$c->add ( ContentPeer::CON_LANG, $lanId ); $c->add( ContentPeer::CON_LANG, $lanId );
$result = ContentPeer::doSelectRS ( $c ); $result = ContentPeer::doSelectRS( $c );
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC); $result->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$result->next (); $result->next();
$row = $result->getRow (); $row = $result->getRow();
while ( is_array ( $row ) ) { while (is_array( $row )) {
$content = ContentPeer::retrieveByPK( $row['CON_CATEGORY'], $row['CON_PARENT'], $row['CON_ID'], $lanId); $content = ContentPeer::retrieveByPK( $row['CON_CATEGORY'], $row['CON_PARENT'], $row['CON_ID'], $lanId );
if( $content !== null ) if ($content !== null) {
$content->delete(); $content->delete();
}
$result->next();
$row = $result->getRow();
}
$result->next (); } catch (Exception $e) {
$row = $result->getRow (); throw ($e);
} }
} catch ( Exception $e ) {
throw ($e);
} }
} //Added by Enrique at Feb 9th,2011
//Added by Enrique at Feb 9th,2011 //Gets all Role Names by Role
//Gets all Role Names by Role public function getAllContentsByRole ($sys_lang = SYS_LANG)
function getAllContentsByRole($sys_lang=SYS_LANG){ {
if (!isset($sys_lang)) $sys_lang = 'en'; if (! isset( $sys_lang )) {
$oCriteria = new Criteria('workflow'); $sys_lang = 'en';
$oCriteria->clearSelectColumns(); }
$oCriteria->addSelectColumn(ContentPeer::CON_ID); $oCriteria = new Criteria( 'workflow' );
$oCriteria->addAsColumn('ROL_NAME', ContentPeer::CON_VALUE); $oCriteria->clearSelectColumns();
//$oCriteria->addAsColumn('ROL_UID', ContentPeer::CON_ID); $oCriteria->addSelectColumn( ContentPeer::CON_ID );
$oCriteria->add(ContentPeer::CON_CATEGORY,'ROL_NAME'); $oCriteria->addAsColumn( 'ROL_NAME', ContentPeer::CON_VALUE );
$oCriteria->add(ContentPeer::CON_LANG, $sys_lang); //$oCriteria->addAsColumn('ROL_UID', ContentPeer::CON_ID);
$oDataset = ContentPeer::doSelectRS($oCriteria); $oCriteria->add( ContentPeer::CON_CATEGORY, 'ROL_NAME' );
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oCriteria->add( ContentPeer::CON_LANG, $sys_lang );
$aRoles = Array(); $oDataset = ContentPeer::doSelectRS( $oCriteria );
while ($oDataset->next()){ $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$xRow = $oDataset->getRow(); $aRoles = Array ();
$aRoles[$xRow['CON_ID']] = $xRow['ROL_NAME']; while ($oDataset->next()) {
} $xRow = $oDataset->getRow();
return $aRoles; $aRoles[$xRow['CON_ID']] = $xRow['ROL_NAME'];
} }
return $aRoles;
}
}
// Content
} // Content

View File

@@ -1,7 +1,8 @@
<?php <?php
/** /**
* Translation.php * Translation.php
* @package workflow.engine.classes.model *
* @package workflow.engine.classes.model
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2011 Colosa Inc. * Copyright (C) 2004 - 2011 Colosa Inc.
@@ -13,11 +14,11 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
@@ -26,436 +27,429 @@
require_once 'classes/model/om/BaseTranslation.php'; require_once 'classes/model/om/BaseTranslation.php';
/** /**
* Skeleton subclass for representing a row from the 'TRANSLATION' table. * Skeleton subclass for representing a row from the 'TRANSLATION' table.
* *
* *
* *
* You should add additional methods to this class to meet the * You should add additional methods to this class to meet the
* application requirements. This class will only be generated as * application requirements. This class will only be generated as
* long as it does not already exist in the output directory. * long as it does not already exist in the output directory.
* *
* @package workflow.engine.classes.model * @package workflow.engine.classes.model
*/ */
class Translation extends BaseTranslation { class Translation extends BaseTranslation
{
public static $meta; public static $meta;
public static $localeSeparator = '-'; public static $localeSeparator = '-';
private $envFilePath; private $envFilePath;
function __construct(){ public function __construct ()
$this->envFilePath = PATH_DATA . "META-INF" . PATH_SEP . "translations.env"; {
} $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; public function getAllCriteria ()
$result->totalCount = $totalCount; {
return $result; //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');
/* Load strings from a Database . 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> * @author Fernando Ontiveros <fernando@colosa.com>
* @parameter $languageId (es|en|...). * @parameter $languageId (es|en|...).
*/ */
function generateFileTranslation ($languageId = '') { public function generateFileTranslation ($languageId = '')
$translation = Array(); {
$translationJS = Array(); $translation = Array ();
$translationJS = Array ();
if ($languageId === '') if ($languageId === '') {
$languageId = defined('SYS_LANG') ? SYS_LANG : 'en'; $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 );
$c = new Criteria(); $cacheFile = PATH_LANGUAGECONT . "translation." . $languageId;
$c->add(TranslationPeer::TRN_LANG, $languageId ); $cacheFileJS = PATH_CORE . 'js' . PATH_SEP . 'labels' . PATH_SEP . $languageId . ".js";
$c->addAscendingOrderByColumn ( 'TRN_CATEGORY' );
$c->addAscendingOrderByColumn ( 'TRN_ID' );
$tranlations = TranslationPeer::doSelect($c);
$cacheFile = PATH_LANGUAGECONT . "translation." . $languageId; foreach ($tranlations as $key => $row) {
$cacheFileJS = PATH_CORE . 'js' . PATH_SEP . 'labels' . PATH_SEP . $languageId.".js"; if ($row->getTrnCategory() === 'LABEL') {
$translation[$row->getTrnId()] = $row->getTrnValue();
}
if ($row->getTrnCategory() === 'JAVASCRIPT') {
$translationJS[$row->getTrnId()] = $row->getTrnValue();
}
}
foreach ( $tranlations as $key => $row ) { try {
if ( $row->getTrnCategory() === 'LABEL' ) {
$translation[ $row->getTrnId() ] = $row->getTrnValue(); if (! is_dir( dirname( $cacheFile ) )) {
} G::mk_dir( dirname( $cacheFile ) );
if ( $row->getTrnCategory() === 'JAVASCRIPT') { }
$translationJS[ $row->getTrnId() ] = $row->getTrnValue(); 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();
}
} }
try { /**
* 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( ! is_dir(dirname($cacheFile)) ) if ($tr->validate()) {
G::mk_dir(dirname($cacheFile)); // we save it, since we get no validation errors, or do whatever else you like.
$res = $tr->save();
if( ! is_dir(dirname($cacheFileJS)) ) } else {
G::mk_dir(dirname($cacheFileJS)); // Something went wrong. We can now get the validationFailures and handle them.
$msg = '';
$f = fopen( $cacheFile , 'w+'); $validationFailuresArray = $tr->getValidationFailures();
fwrite( $f , "<?php\n" ); foreach ($validationFailuresArray as $objValidationFailure) {
fwrite( $f , '$translation =' . 'unserialize(\'' . addcslashes( serialize ( $translation ), '\\\'' ) . "');\n"); $msg .= $objValidationFailure->getMessage() . "\n";
fwrite( $f , "?>" ); }
fclose( $f ); return array ('codError' => - 100,'rowsAffected' => 0,'message' => $msg);
}
$json=new Services_JSON(); return array ('codError' => 0,'rowsAffected' => $res,'message' => '');
//to do: uniform coderror structures for all classes
$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; public function remove ($sCategory, $sId, $sLang)
$environment['HEADERS'] = $headers; {
$environment['DATE'] = date('Y-m-d H:i:s'); $oTranslation = TranslationPeer::retrieveByPK( $sCategory, $sId, $sLang );
$environment['NUM_RECORDS'] = $numRecords; if ((is_object( $oTranslation ) && get_class( $oTranslation ) == 'Translation')) {
$environment['LANGUAGE'] = $headers['X-Poedit-Language']; $oTranslation->delete();
$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;
} }
public function addTranslationEnvironment ($locale, $headers, $numRecords)
file_put_contents($filePath, serialize($environments));
}
function removeTranslationEnvironment($locale)
{ {
$filePath = $this->envFilePath; $filePath = $this->envFilePath;
if (strpos($locale, self::$localeSeparator) !== false) { $environments = Array ();
list($LAN_ID, $IC_UID) = explode('-', strtoupper($locale));
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 { } else {
$LAN_ID = $locale; $LAN_ID = $locale;
$IC_UID = '__INTERNATIONAL__'; $IC_UID = '__INTERNATIONAL__';
} }
if (file_exists($filePath)) { if (file_exists( $filePath )) {
$environments = unserialize(file_get_contents($filePath)); $environments = unserialize( file_get_contents( $filePath ) );
if (!isset($environments[$LAN_ID][$IC_UID])) { if (! isset( $environments[$LAN_ID][$IC_UID] )) {
return NULL; return null;
} }
unset($environments[$LAN_ID][$IC_UID]); unset( $environments[$LAN_ID][$IC_UID] );
file_put_contents($filePath, serialize($environments)); file_put_contents( $filePath, serialize( $environments ) );
if (file_exists(PATH_CORE . "META-INF" . PATH_SEP . "translation.".$locale)) { if (file_exists( PATH_CORE . "META-INF" . PATH_SEP . "translation." . $locale )) {
G::rm_dir(PATH_DATA . "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')) { 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'); G::rm_dir( PATH_CORE . PATH_SEP . 'content' . PATH_SEP . 'translations' . PATH_SEP . 'processmaker' . $locale . '.po' );
} }
} }
} }
function getTranslationEnvironments(){ public function getTranslationEnvironments ()
$filePath = $this->envFilePath; {
$envs = Array(); $filePath = $this->envFilePath;
$envs = Array ();
if( ! file_exists($filePath) ) { if (! file_exists( $filePath )) {
//the transaltions table file doesn't exist, then build it //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; if (! is_dir( dirname( $this->envFilePath ) )) {
$basePOFile = $translationsPath . 'english' . PATH_SEP . 'processmaker.en.po'; 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); $params = self::getInfoFromPOFile( $basePOFile );
$this->addTranslationEnvironment($params['LOCALE'], $params['HEADERS'], $params['COUNT']); $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 ) );
//getting more lanuguage translations $environments = Array ();
$files = glob($translationsPath . "*.po"); foreach ($envs as $LAN_ID => $rec1) {
foreach( $files as $file ){ foreach ($rec1 as $IC_UID => $rec2) {
$params = self::getInfoFromPOFile($file); $environments[] = $rec2;
$this->addTranslationEnvironment($params['LOCALE'], $params['HEADERS'], $params['COUNT']); }
} }
}
$envs = unserialize(file_get_contents($filePath));
$environments = Array(); return $environments;
foreach($envs as $LAN_ID => $rec1 ){
foreach($rec1 as $IC_UID => $rec2 ){ /*
$environments[] = $rec2; 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));
*/
} }
return $environments; public function getInfoFromPOFile ($file)
{
G::loadClass( 'i18n_po' );
$POFile = new i18n_PO( $file );
$POFile->readInit();
$POHeaders = $POFile->getHeaders();
/*G::LoadSystem('dbMaintenance'); if ($POHeaders['X-Poedit-Country'] != '.') {
$o = new DataBaseMaintenance('localhost', 'root', 'atopml2005'); $country = self::getTranslationMetaByCountryName( $POHeaders['X-Poedit-Country'] );
$o->connect('wf_os'); } else {
$r = $o->query('select * from ISO_COUNTRY'); $country = '.';
foreach($r as $i=>$v){ }
$r[$i]['IC_NAME'] = utf8_encode($r[$i]['IC_NAME']); $language = self::getTranslationMetaByLanguageName( $POHeaders['X-Poedit-Language'] );
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){ if ($language !== false) {
G::loadClass('i18n_po'); if ($country !== false) {
$POFile = new i18n_PO($file); if ($country != '.') {
$POFile->readInit(); $LOCALE = $language['LAN_ID'] . '-' . $country['IC_UID'];
$POHeaders = $POFile->getHeaders(); } else if ($country == '.') {
//this a trsnlation file with a language international, no country name was set
if( $POHeaders['X-Poedit-Country'] != '.' ) { $LOCALE = $language['LAN_ID'];
$country = self::getTranslationMetaByCountryName($POHeaders['X-Poedit-Country']); } else
} else { throw new Exception( 'PO File Error: "' . $file . '" has a invalid country definition!' );
$country = '.'; } else
} throw new Exception( 'PO File Error: "' . $file . '" has a invalid country definition!' );
$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 } else
throw new Exception('PO File Error: "'.$file.'" has a invalid country definition!'); throw new Exception( 'PO File Error: "' . $file . '" has a invalid language 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; $countItems = 0;
try { try {
while( $rowTranslation = $POFile->getTranslation() ) { while ($rowTranslation = $POFile->getTranslation()) {
$countItems++; $countItems ++;
} }
} catch(Exception $e) { } catch (Exception $e) {
$countItems = '-'; $countItems = '-';
}
return Array ('LOCALE' => $LOCALE,'HEADERS' => $POHeaders,'COUNT' => $countItems);
} }
return Array('LOCALE'=>$LOCALE, 'HEADERS'=>$POHeaders , 'COUNT'=>$countItems); public function getTranslationEnvironment ($locale)
} {
$filePath = $this->envFilePath;
$environments = Array ();
function getTranslationEnvironment($locale){ if (! file_exists( $filePath )) {
$filePath = $this->envFilePath; throw new Exception( "The file $filePath doesn't exist" );
$environments = Array(); }
if( ! file_exists($filePath) ) { $environments = unserialize( file_get_contents( $filePath ) );
throw new Exception("The file $filePath doesn't exist"); 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;
}
} }
$environments = unserialize(file_get_contents($filePath)); public function saveTranslationEnvironment ($locale, $data)
if( strpos($locale, self::$localeSeparator) !== false ) { {
list($LAN_ID, $IC_UID) = explode(self::localeSeparator, strtoupper($locale)); $filePath = $this->envFilePath;
} else { $environments = Array ();
$LAN_ID = $locale;
$IC_UID = '__INTERNATIONAL__'; 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 ) );
} }
if( isset($environments[$LAN_ID][$IC_UID]) ) public function getTranslationMeta ()
return $environments[$LAN_ID][$IC_UID]; {
else $translationsPath = PATH_CORE . "content" . PATH_SEP . 'translations' . PATH_SEP;
return false; $translationsTable = unserialize( file_get_contents( $translationsPath . 'pmos-translations.meta' ) );
} return $translationsTable;
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)); public function getTranslationMetaByCountryName ($IC_NAME)
if( strpos($locale, self::$localeSeparator) !== false ) { {
list($LAN_ID, $IC_UID) = explode(self::localeSeparator, strtoupper($locale)); $translationsTable = self::getTranslationMeta();
} else {
$LAN_ID = $locale; foreach ($translationsTable['ISO_COUNTRY'] as $row) {
$IC_UID = '__INTERNATIONAL__'; if ($row['IC_NAME'] == $IC_NAME) {
return $row;
}
}
return false;
} }
$environments[$LAN_ID][$IC_UID] = $data; public function getTranslationMetaByLanguageName ($LAN_NAME)
file_put_contents($filePath, serialize($environments)); {
} $translationsTable = self::getTranslationMeta();
function getTranslationMeta(){ foreach ($translationsTable['LANGUAGE'] as $row) {
$translationsPath = PATH_CORE . "content" . PATH_SEP . 'translations' . PATH_SEP; if ($row['LAN_NAME'] == $LAN_NAME) {
$translationsTable = unserialize(file_get_contents($translationsPath . 'pmos-translations.meta')); return $row;
return $translationsTable; }
} }
return false;
function getTranslationMetaByCountryName($IC_NAME){
$translationsTable = self::getTranslationMeta();
foreach ($translationsTable['ISO_COUNTRY'] as $row) {
if( $row['IC_NAME'] == $IC_NAME )
return $row;
} }
return false; }
} // Translation
function getTranslationMetaByLanguageName($LAN_NAME){
$translationsTable = self::getTranslationMeta();
foreach ($translationsTable['LANGUAGE'] as $row) {
if( $row['LAN_NAME'] == $LAN_NAME )
return $row;
}
return false;
}
} // Translation