diff --git a/workflow/engine/bin/reindex_solr.php b/workflow/engine/bin/reindex_solr.php index 85bb3267c..e5cb8513f 100644 --- a/workflow/engine/bin/reindex_solr.php +++ b/workflow/engine/bin/reindex_solr.php @@ -4,69 +4,67 @@ * @package workflow-engine-bin */ -//check script parameters -//php reindex_solr.php workspacename [reindexall|reindexmissing] -//var_dump($argv); -if(count($argv) != 3 ){ - print "Invalid command line arguments: \n syntax: php reindex_solr.php [workspace_name] [reindexall|reindexmissing] \n". - " Where reindexall : reindex all the database \n". - " reindexmissing: reindex only the missing records stored in database.\n"; - die; +// check script parameters +// php reindex_solr.php workspacename [reindexall|reindexmissing] +// var_dump($argv); +if (count ($argv) != 3) { + print "Invalid command line arguments: \n syntax: php reindex_solr.php [workspace_name] [reindexall|reindexmissing] \n" . " Where reindexall : reindex all the database \n" . " reindexmissing: reindex only the missing records stored in database.\n"; + die (); } -$workspaceName = $argv[1]; -$ScriptAction = $argv[2]; +$workspaceName = $argv [1]; +$ScriptAction = $argv [2]; -ini_set ( 'display_errors', 1 ); -error_reporting ( E_ALL ); -ini_set ( 'memory_limit', '256M' ); // set enough memory for the script +ini_set ('display_errors', 1); +error_reporting (E_ALL); +ini_set ('memory_limit', '256M'); // set enough memory for the script -if (! defined ( 'SYS_LANG' )) { - define ( 'SYS_LANG', 'en' ); +if (! defined ('SYS_LANG')) { + define ('SYS_LANG', 'en'); } -if (! defined ( 'PATH_HOME' )) { - if (! defined ( 'PATH_SEP' )) { - define ( 'PATH_SEP', (substr ( PHP_OS, 0, 3 ) == 'WIN') ? '\\' : '/' ); +if (! defined ('PATH_HOME')) { + if (! defined ('PATH_SEP')) { + define ('PATH_SEP', (substr (PHP_OS, 0, 3) == 'WIN') ? '\\' : '/'); } - $docuroot = explode ( PATH_SEP, str_replace ( 'engine' . PATH_SEP . 'methods' . PATH_SEP . 'services', '', dirname ( __FILE__ ) ) ); - array_pop ( $docuroot ); - array_pop ( $docuroot ); - $pathhome = implode ( PATH_SEP, $docuroot ) . PATH_SEP; + $docuroot = explode (PATH_SEP, str_replace ('engine' . PATH_SEP . 'methods' . PATH_SEP . 'services', '', dirname (__FILE__))); + array_pop ($docuroot); + array_pop ($docuroot); + $pathhome = implode (PATH_SEP, $docuroot) . PATH_SEP; // try to find automatically the trunk directory where are placed the RBAC and // Gulliver directories // in a normal installation you don't need to change it. - array_pop ( $docuroot ); - $pathTrunk = implode ( PATH_SEP, $docuroot ) . PATH_SEP; - array_pop ( $docuroot ); - $pathOutTrunk = implode ( PATH_SEP, $docuroot ) . PATH_SEP; + array_pop ($docuroot); + $pathTrunk = implode (PATH_SEP, $docuroot) . PATH_SEP; + array_pop ($docuroot); + $pathOutTrunk = implode (PATH_SEP, $docuroot) . PATH_SEP; // to do: check previous algorith for Windows $pathTrunk = "c:/home/"; - define ( 'PATH_HOME', $pathhome ); - define ( 'PATH_TRUNK', $pathTrunk ); - define ( 'PATH_OUTTRUNK', $pathOutTrunk ); + define ('PATH_HOME', $pathhome); + define ('PATH_TRUNK', $pathTrunk); + define ('PATH_OUTTRUNK', $pathOutTrunk); require_once (PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php'); - G::LoadThirdParty ( 'pear/json', 'class.json' ); - G::LoadThirdParty ( 'smarty/libs', 'Smarty.class' ); - G::LoadSystem ( 'error' ); - G::LoadSystem ( 'dbconnection' ); - G::LoadSystem ( 'dbsession' ); - G::LoadSystem ( 'dbrecordset' ); - G::LoadSystem ( 'dbtable' ); - G::LoadSystem ( 'rbac' ); - G::LoadSystem ( 'publisher' ); - G::LoadSystem ( 'templatePower' ); - G::LoadSystem ( 'xmlDocument' ); - G::LoadSystem ( 'xmlform' ); - G::LoadSystem ( 'xmlformExtension' ); - G::LoadSystem ( 'form' ); - G::LoadSystem ( 'menu' ); - G::LoadSystem ( "xmlMenu" ); - G::LoadSystem ( 'dvEditor' ); - G::LoadSystem ( 'table' ); - G::LoadSystem ( 'pagedTable' ); - G::LoadClass ( 'system' ); + G::LoadThirdParty ('pear/json', 'class.json'); + G::LoadThirdParty ('smarty/libs', 'Smarty.class'); + G::LoadSystem ('error'); + G::LoadSystem ('dbconnection'); + G::LoadSystem ('dbsession'); + G::LoadSystem ('dbrecordset'); + G::LoadSystem ('dbtable'); + G::LoadSystem ('rbac'); + G::LoadSystem ('publisher'); + G::LoadSystem ('templatePower'); + G::LoadSystem ('xmlDocument'); + G::LoadSystem ('xmlform'); + G::LoadSystem ('xmlformExtension'); + G::LoadSystem ('form'); + G::LoadSystem ('menu'); + G::LoadSystem ("xmlMenu"); + G::LoadSystem ('dvEditor'); + G::LoadSystem ('table'); + G::LoadSystem ('pagedTable'); + G::LoadClass ('system'); require_once ("propel/Propel.php"); require_once ("creole/Creole.php"); } @@ -96,32 +94,32 @@ print "PATH_DB: " . PATH_DB . "\n"; print "PATH_CORE: " . PATH_CORE . "\n"; // define the site name (instance name) -if (! defined ( 'SYS_SYS' )) { +if (! defined ('SYS_SYS')) { $sObject = $workspaceName; $sNow = ''; // $argv[2]; $sFilter = ''; - for($i = 3; $i < count ( $argv ); $i ++) { + for ($i = 3; $i < count ($argv); $i++) { $sFilter .= ' ' . $argv [$i]; } - $oDirectory = dir ( PATH_DB ); + $oDirectory = dir (PATH_DB); - if (is_dir ( PATH_DB . $sObject )) { - saveLog ( 'main', 'action', "checking folder " . PATH_DB . $sObject ); - if (file_exists ( PATH_DB . $sObject . PATH_SEP . 'db.php' )) { + if (is_dir (PATH_DB . $sObject)) { + saveLog ('main', 'action', "checking folder " . PATH_DB . $sObject); + if (file_exists (PATH_DB . $sObject . PATH_SEP . 'db.php')) { - define ( 'SYS_SYS', $sObject ); + define ('SYS_SYS', $sObject); // **************************************** // read initialize file require_once PATH_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP . 'class.system.php'; $config = System::getSystemConfiguration ('', '', SYS_SYS); - define ( 'MEMCACHED_ENABLED', $config ['memcached'] ); - define ( 'MEMCACHED_SERVER', $config ['memcached_server'] ); - define ( 'TIME_ZONE', $config ['time_zone'] ); + define ('MEMCACHED_ENABLED', $config ['memcached']); + define ('MEMCACHED_SERVER', $config ['memcached_server']); + define ('TIME_ZONE', $config ['time_zone']); - date_default_timezone_set ( TIME_ZONE ); + date_default_timezone_set (TIME_ZONE); print "TIME_ZONE: " . TIME_ZONE . "\n"; print "MEMCACHED_ENABLED: " . MEMCACHED_ENABLED . "\n"; print "MEMCACHED_SERVER: " . MEMCACHED_SERVER . "\n"; @@ -131,39 +129,39 @@ if (! defined ( 'SYS_SYS' )) { include_once (PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php'); // ***************** PM Paths DATA ************************** - define ( 'PATH_DATA_SITE', PATH_DATA . 'sites/' . SYS_SYS . '/' ); - define ( 'PATH_DOCUMENT', PATH_DATA_SITE . 'files/' ); - define ( 'PATH_DATA_MAILTEMPLATES', PATH_DATA_SITE . 'mailTemplates/' ); - define ( 'PATH_DATA_PUBLIC', PATH_DATA_SITE . 'public/' ); - define ( 'PATH_DATA_REPORTS', PATH_DATA_SITE . 'reports/' ); - define ( 'PATH_DYNAFORM', PATH_DATA_SITE . 'xmlForms/' ); - define ( 'PATH_IMAGES_ENVIRONMENT_FILES', PATH_DATA_SITE . 'usersFiles' . PATH_SEP ); - define ( 'PATH_IMAGES_ENVIRONMENT_USERS', PATH_DATA_SITE . 'usersPhotographies' . PATH_SEP ); + define ('PATH_DATA_SITE', PATH_DATA . 'sites/' . SYS_SYS . '/'); + define ('PATH_DOCUMENT', PATH_DATA_SITE . 'files/'); + define ('PATH_DATA_MAILTEMPLATES', PATH_DATA_SITE . 'mailTemplates/'); + define ('PATH_DATA_PUBLIC', PATH_DATA_SITE . 'public/'); + define ('PATH_DATA_REPORTS', PATH_DATA_SITE . 'reports/'); + define ('PATH_DYNAFORM', PATH_DATA_SITE . 'xmlForms/'); + define ('PATH_IMAGES_ENVIRONMENT_FILES', PATH_DATA_SITE . 'usersFiles' . PATH_SEP); + define ('PATH_IMAGES_ENVIRONMENT_USERS', PATH_DATA_SITE . 'usersPhotographies' . PATH_SEP); // server info file - if (is_file ( PATH_DATA_SITE . PATH_SEP . '.server_info' )) { - $SERVER_INFO = file_get_contents ( PATH_DATA_SITE . PATH_SEP . '.server_info' ); - $SERVER_INFO = unserialize ( $SERVER_INFO ); + if (is_file (PATH_DATA_SITE . PATH_SEP . '.server_info')) { + $SERVER_INFO = file_get_contents (PATH_DATA_SITE . PATH_SEP . '.server_info'); + $SERVER_INFO = unserialize ($SERVER_INFO); // print_r($SERVER_INFO); - define ( 'SERVER_NAME', $SERVER_INFO ['SERVER_NAME'] ); - define ( 'SERVER_PORT', $SERVER_INFO ['SERVER_PORT'] ); + define ('SERVER_NAME', $SERVER_INFO ['SERVER_NAME']); + define ('SERVER_PORT', $SERVER_INFO ['SERVER_PORT']); } else { - eprintln ( "WARNING! No server info found!", 'red' ); + eprintln ("WARNING! No server info found!", 'red'); } // read db configuration - $sContent = file_get_contents ( PATH_DB . $sObject . PATH_SEP . 'db.php' ); + $sContent = file_get_contents (PATH_DB . $sObject . PATH_SEP . 'db.php'); - $sContent = str_replace ( '', '', $sContent ); - $sContent = str_replace ( 'define', '', $sContent ); - $sContent = str_replace ( "('", "$", $sContent ); - $sContent = str_replace ( "',", '=', $sContent ); - $sContent = str_replace ( ");", ';', $sContent ); + $sContent = str_replace ('', '', $sContent); + $sContent = str_replace ('define', '', $sContent); + $sContent = str_replace ("('", "$", $sContent); + $sContent = str_replace ("',", '=', $sContent); + $sContent = str_replace (");", ';', $sContent); - eval ( $sContent ); + eval ($sContent); $dsn = $DB_ADAPTER . '://' . $DB_USER . ':' . $DB_PASS . '@' . $DB_HOST . '/' . $DB_NAME; $dsnRbac = $DB_ADAPTER . '://' . $DB_RBAC_USER . ':' . $DB_RBAC_PASS . '@' . $DB_RBAC_HOST . '/' . $DB_RBAC_NAME; $dsnRp = $DB_ADAPTER . '://' . $DB_REPORT_USER . ':' . $DB_REPORT_PASS . '@' . $DB_REPORT_HOST . '/' . $DB_REPORT_NAME; @@ -189,22 +187,22 @@ if (! defined ( 'SYS_SYS' )) { // $pro['datasources']['dbarray']['connection'] = // 'dbarray://user:pass@localhost/pm_os'; // $pro['datasources']['dbarray']['adapter'] = 'dbarray'; - $oFile = fopen ( PATH_CORE . 'config/_databases_.php', 'w' ); - fwrite ( $oFile, '' ); - fclose ( $oFile ); - Propel::init ( PATH_CORE . 'config/_databases_.php' ); + $oFile = fopen (PATH_CORE . 'config/_databases_.php', 'w'); + fwrite ($oFile, ''); + fclose ($oFile); + Propel::init (PATH_CORE . 'config/_databases_.php'); // Creole::registerDriver('dbarray', 'creole.contrib.DBArrayConnection'); - eprintln ( "Processing workspace: " . $sObject, 'green' ); + eprintln ("Processing workspace: " . $sObject, 'green'); try { processWorkspace (); } - catch ( Exception $e ) { + catch (Exception $e) { echo $e->getMessage (); - eprintln ( "Probelm in workspace: " . $sObject . ' it was omitted.', 'red' ); + eprintln ("Probelm in workspace: " . $sObject . ' it was omitted.', 'red'); } eprintln (); - unlink ( PATH_CORE . 'config/_databases_.php' ); + unlink (PATH_CORE . 'config/_databases_.php'); } } @@ -217,25 +215,26 @@ else { // @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' => // '0', 'sLastExecution' => date('Y-m-d H:i:s')))); -function processWorkspace() { +function processWorkspace() +{ global $sLastExecution; global $ScriptAction; try { if (($solrConf = System::solrEnv (SYS_SYS)) !== false) { - G::LoadClass ( 'AppSolr' ); + G::LoadClass ('AppSolr'); print "Solr Configuration file: " . PATH_DATA_SITE . "env.ini\n"; print "solr_enabled: " . $solrConf ['solr_enabled'] . "\n"; print "solr_host: " . $solrConf ['solr_host'] . "\n"; print "solr_instance: " . $solrConf ['solr_instance'] . "\n"; - $oAppSolr = new AppSolr ( $solrConf ['solr_enabled'], $solrConf ['solr_host'], $solrConf ['solr_instance'] ); - if($ScriptAction == "reindexall"){ + $oAppSolr = new AppSolr ($solrConf ['solr_enabled'], $solrConf ['solr_host'], $solrConf ['solr_instance']); + if ($ScriptAction == "reindexall") { $oAppSolr->reindexAllApplications (); } - if($ScriptAction == "reindexmissing"){ - $oAppSolr->synchronizePendingApplications(); + if ($ScriptAction == "reindexmissing") { + $oAppSolr->synchronizePendingApplications (); } } else { @@ -243,48 +242,51 @@ function processWorkspace() { } } - catch ( Exception $oError ) { - saveLog ( "main", "error", "Error processing workspace : " . $oError->getMessage () . "\n" ); + catch (Exception $oError) { + saveLog ("main", "error", "Error processing workspace : " . $oError->getMessage () . "\n"); } } -function saveLog($sSource, $sType, $sDescription) { +function saveLog($sSource, $sType, $sDescription) +{ try { global $isDebug; if ($isDebug) - print date ( 'H:i:s' ) . " ($sSource) $sType $sDescription
\n"; - @fwrite ( $oFile, date ( 'Y-m-d H:i:s' ) . '(' . $sSource . ') ' . $sDescription . "\n" ); + print date ('H:i:s') . " ($sSource) $sType $sDescription
\n"; + @fwrite ($oFile, date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n"); - G::verifyPath ( PATH_DATA . 'log' . PATH_SEP, true ); + G::verifyPath (PATH_DATA . 'log' . PATH_SEP, true); if ($sType == 'action') { - $oFile = @fopen ( PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+' ); + $oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cron.log', 'a+'); } else { - $oFile = @fopen ( PATH_DATA . 'log' . PATH_SEP . 'cronError.log', 'a+' ); + $oFile = @fopen (PATH_DATA . 'log' . PATH_SEP . 'cronError.log', 'a+'); } - @fwrite ( $oFile, date ( 'Y-m-d H:i:s' ) . '(' . $sSource . ') ' . $sDescription . "\n" ); - @fclose ( $oFile ); + @fwrite ($oFile, date ('Y-m-d H:i:s') . '(' . $sSource . ') ' . $sDescription . "\n"); + @fclose ($oFile); } - catch ( Exception $oError ) { + catch (Exception $oError) { // CONTINUE } } -function setExecutionMessage($m) { - $len = strlen ( $m ); +function setExecutionMessage($m) +{ + $len = strlen ($m); $linesize = 60; $rOffset = $linesize - $len; - eprint ( "* $m" ); - for($i = 0; $i < $rOffset; $i ++) - eprint ( '.' ); + eprint ("* $m"); + for ($i = 0; $i < $rOffset; $i++) + eprint ('.'); } -function setExecutionResultMessage($m, $t = '') { +function setExecutionResultMessage($m, $t = '') +{ $c = 'green'; if ($t == 'error') $c = 'red'; if ($t == 'info') $c = 'yellow'; - eprintln ( "[$m]", $c ); + eprintln ("[$m]", $c); } diff --git a/workflow/engine/classes/class.AppSolr.php b/workflow/engine/classes/class.AppSolr.php index e598e1074..b361633e0 100644 --- a/workflow/engine/classes/class.AppSolr.php +++ b/workflow/engine/classes/class.AppSolr.php @@ -1,4 +1,27 @@ . + * + * For more information, contact Colosa Inc, 5304 Ventura Drive, + * Delray Beach, FL, 33484, USA, or email info@colosa.com. + * + */ + require_once "classes/model/Application.php"; require_once "classes/model/AppDelegation.php"; require_once "classes/model/AppThread.php"; @@ -13,122 +36,161 @@ require_once "entities/SolrUpdateDocument.php"; require_once "entities/AppSolrQueue.php"; require_once "classes/model/AppSolrQueue.php"; + + /** * Invalid search text for Solr exception - * @author Herbert Saal Gutierrez * + * @author Herbert Saal Gutierrez + * */ -class InvalidIndexSearchTextException extends Exception { +class InvalidIndexSearchTextException extends Exception +{ // Redefine the exception so message isn't optional - public function __construct($message, $code = 0) { + public function __construct($message, $code = 0) + { // some code // make sure everything is assigned properly - parent::__construct ( $message, $code); + parent::__construct ($message, $code); } // custom string representation of object - public function __toString() { + public function __toString() + { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } } /** * Application without Delegations exception - * @author Herbert Saal Gutierrez * + * @author Herbert Saal Gutierrez + * + * @category Colosa + * @copyright Copyright (c) 2005-2011 Colosa Inc. (http://www.colosa.com) */ -class ApplicationWithoutDelegationRecordsException extends Exception { +class ApplicationWithoutDelegationRecordsException extends Exception +{ // Redefine the exception so message isn't optional - public function __construct($message, $code = 0) { + public function __construct($message, $code = 0) + { // some code // make sure everything is assigned properly - parent::__construct ( $message, $code); + parent::__construct ($message, $code); } - + // custom string representation of object - public function __toString() { + public function __toString() + { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } } /** - * Implementation to display application data in the PMOS2 grids using Solr search service - * + * Implementation to display application data in the PMOS2 grids using Solr + * search service + * * @author Herbert Saal Gutierrez + * @category Colosa + * @copyright Copyright (c) 2005-2011 Colosa Inc. (http://www.colosa.com) * */ -class AppSolr { - private $solrIsEnabled = false; - private $solrHost = ""; - private $solrInstance = ""; +class AppSolr +{ + private $_solrIsEnabled = false; + private $_solrHost = ""; + private $_solrInstance = ""; - function __construct($SolrEnabled, $SolrHost, $SolrInstance) { + public function __construct($SolrEnabled, $SolrHost, $SolrInstance) + { // define solr availability - $this->solrIsEnabled = $SolrEnabled; - $this->solrHost = $SolrHost; - $this->solrInstance = $SolrInstance; + $this->_solrIsEnabled = $SolrEnabled; + $this->_solrHost = $SolrHost; + $this->_solrInstance = $SolrInstance; } - public function isSolrEnabled() { - return $this->solrIsEnabled; + /** + * Return if the Solr functionality is enabled. + * @return boolean true:enabled functionality, false:disabled functionality + */ + public function isSolrEnabled() + { + return $this->_solrIsEnabled; } /** * Gets the information of Grids using Solr server. - * - * Returns the list of records for the grid depending of the function conditions - * If doCount is true only the count of records is returned. - * - * @param string $userUid current logged user. - * @param int $start the offset to return the group of records. Used for pagination. - * @param int $limit The number of records to return in the set. - * @param string $action the action: todo, participated, draft, unassigned - * @param string $filter filter the results posible values ('read', 'unread', 'started', 'completed') - * @param string $search search string - * @param string $process PRO_UID to filter results by specified process. - * @param string $user USR_UID to filter results by specified user. - * @param string $status filter by an application Status : TO_DO, COMPLETED, DRAFT - * @param string $type default extjs - * @param string $dateFrom filter by DEL_DELEGATE_DATE, not used - * @param string $dateTo filter by DEL_DELEGATE_DATE, not used - * @param string $callback default stcCallback1001 not used - * @param string $dir sort direction ASC, DESC - * @param string $sort sort field - * @param boolean $doCount default=false, if true only the count of records is returned. + * + * Returns the list of records for the grid depending of the function + * conditions + * If doCount is true only the count of records is returned. + * + * @param string $userUid + * current logged user. + * @param int $start + * the offset to return the group of records. Used for pagination. + * @param int $limit + * The number of records to return in the set. + * @param string $action + * the action: todo, participated, draft, unassigned + * @param string $filter + * filter the results posible values ('read', 'unread', 'started', + * 'completed') + * @param string $search + * search string + * @param string $process + * PRO_UID to filter results by specified process. + * @param string $user + * USR_UID to filter results by specified user. + * @param string $status + * filter by an application Status : TO_DO, COMPLETED, DRAFT + * @param string $type + * default extjs + * @param string $dateFrom + * filter by DEL_DELEGATE_DATE, not used + * @param string $dateTo + * filter by DEL_DELEGATE_DATE, not used + * @param string $callback + * default stcCallback1001 not used + * @param string $dir + * sort direction ASC, DESC + * @param string $sort + * sort field + * @param boolean $doCount + * default=false, if true only the count of records is returned. * @return array return the list of cases */ - public function getAppGridData($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, - $process = null, $user = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, - $dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER', $doCount = false) { + public function getAppGridData($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $user = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER', $doCount = false) + { - $callback = isset ( $callback ) ? $callback : 'stcCallback1001'; - $dir = isset ( $dir ) ? $dir : 'DESC'; // direction of sort column + $callback = isset ($callback) ? $callback : 'stcCallback1001'; + $dir = isset ($dir) ? $dir : 'DESC'; // direction of sort column // (ASC, DESC) - $sort = isset ( $sort ) ? $sort : ''; // sort column (APP_NUMBER, + $sort = isset ($sort) ? $sort : ''; // sort column (APP_NUMBER, // CASE_SUMMARY, // CASE_NOTES_COUNT, APP_TITLE, // APP_PRO_TITLE, APP_TAS_TITLE, // APP_DEL_PREVIOUS_USER, // DEL_TASK_DUE_DATE, // APP_UPDATE_DATE, DEL_PRIORITY) - $start = isset ( $start ) ? $start : '0'; - $limit = isset ( $limit ) ? $limit : '25'; - $filter = isset ( $filter ) ? $filter : ''; // posible values ('read', + $start = isset ($start) ? $start : '0'; + $limit = isset ($limit) ? $limit : '25'; + $filter = isset ($filter) ? $filter : ''; // posible values ('read', // 'unread', 'started', // 'completed') - $search = isset ( $search ) ? $search : ''; // search in fields, plain text - $process = isset ( $process ) ? $process : ''; // filter by an specific + $search = isset ($search) ? $search : ''; // search in fields, plain text + $process = isset ($process) ? $process : ''; // filter by an specific // process // uid - $user = isset ( $user ) ? $user : ''; // filter by an specific user uid - $status = isset ( $status ) ? strtoupper ( $status ) : ''; // filter by an + $user = isset ($user) ? $user : ''; // filter by an specific user uid + $status = isset ($status) ? strtoupper ($status) : ''; // filter by an // specific // app_status - $action = isset ( $action ) ? $action : 'todo'; // todo, paused - $type = isset ( $type ) ? $type : 'extjs'; - $dateFrom = isset ( $dateFrom ) ? $dateFrom : ''; // filter by + $action = isset ($action) ? $action : 'todo'; // todo, paused + $type = isset ($type) ? $type : 'extjs'; + $dateFrom = isset ($dateFrom) ? $dateFrom : ''; // filter by // DEL_DELEGATE_DATE - $dateTo = isset ( $dateTo ) ? $dateTo : ''; // filter by DEL_DELEGATE_DATE + $dateTo = isset ($dateTo) ? $dateTo : ''; // filter by DEL_DELEGATE_DATE $swErrorInSearchText = false; $solrQueryResult = null; @@ -139,7 +201,7 @@ class AppSolr { $result ['success'] = false; $result ['message'] = "Error description."; - G::LoadClass ( 'searchIndex' ); + G::LoadClass ('searchIndex'); try { @@ -183,11 +245,11 @@ class AppSolr { $sortDir = array (); $numSortingCols = 0; - //define sort conditions, default APP_NUMBER, desc + // define sort conditions, default APP_NUMBER, desc // only one column is sorted - $dir = strtolower ( $dir ); + $dir = strtolower ($dir); - if (! empty ( $sort )) { + if (! empty ($sort)) { switch ($sort) { case 'APP_CACHE_VIEW.APP_NUMBER' : case 'APP_NUMBER' : @@ -222,11 +284,11 @@ class AppSolr { // get del_index field $delIndexDynaField = ""; - //process filter + // process filter if ($process != '') { $solrSearchText .= "PRO_UID:" . $process . " AND "; } - //status filter + // status filter if ($status != '') { $solrSearchText .= "APP_STATUS:" . $status . " AND "; } @@ -234,30 +296,30 @@ class AppSolr { if ($userUid != null && $action == 'todo') { if ($filter == 'read') { $solrSearchText .= "APP_ASSIGNED_USERS_READ:" . $userUid . " AND "; - $delIndexDynaField = "APP_ASSIGNED_USER_READ_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_ASSIGNED_USER_READ_DEL_INDEX_" . trim ($userUid) . '_txt'; } elseif ($filter == 'unread') { $solrSearchText .= "APP_ASSIGNED_USERS_UNREAD:" . $userUid . " AND "; - $delIndexDynaField = "APP_ASSIGNED_USER_UNREAD_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_ASSIGNED_USER_UNREAD_DEL_INDEX_" . trim ($userUid) . '_txt'; } else { $solrSearchText .= "APP_ASSIGNED_USERS:" . $userUid . " AND "; - $delIndexDynaField = "APP_ASSIGNED_USER_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_ASSIGNED_USER_DEL_INDEX_" . trim ($userUid) . '_txt'; } } // participated, add condition if ($userUid != null && $action == 'sent') { if ($filter == 'started') { $solrSearchText .= "APP_PARTICIPATED_USERS_STARTED:" . $userUid . " AND "; - $delIndexDynaField = "APP_PARTICIPATED_USER_STARTED_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_PARTICIPATED_USER_STARTED_DEL_INDEX_" . trim ($userUid) . '_txt'; } elseif ($filter == 'completed') { $solrSearchText .= "APP_PARTICIPATED_USERS_COMPLETED:" . $userUid . " AND "; - $delIndexDynaField = "APP_PARTICIPATED_USER_COMPLETED_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_PARTICIPATED_USER_COMPLETED_DEL_INDEX_" . trim ($userUid) . '_txt'; } else { $solrSearchText .= "APP_PARTICIPATED_USERS:" . $userUid . " AND "; - $delIndexDynaField = "APP_PARTICIPATED_USER_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_PARTICIPATED_USER_DEL_INDEX_" . trim ($userUid) . '_txt'; } } // draft, add condition @@ -268,27 +330,27 @@ class AppSolr { // unassigned, add condition if ($userUid != null && $action == 'unassigned') { // get the list of groups to which belongs the user. - $userGroups = $this->getUserGroups ( $userUid ); + $userGroups = $this->getUserGroups ($userUid); $solrSearchText .= "(APP_UNASSIGNED_USERS:" . $userUid; - if(count($userGroups)>0){ + if (count ($userGroups) > 0) { $solrSearchText .= " OR "; - - foreach ( $userGroups as $group ) { + + foreach ($userGroups as $group) { $solrSearchText .= "APP_UNASSIGNED_GROUPS:" . $group ['GRP_UID'] . " OR "; } // remove last OR in condition if ($solrSearchText != '') - $solrSearchText = substr_replace ( $solrSearchText, "", - 4 ); + $solrSearchText = substr_replace ($solrSearchText, "", - 4); } $solrSearchText .= ") AND "; - $delIndexDynaField = "APP_UNASSIGNED_USER_GROUP_DEL_INDEX_" . trim ( $userUid ) . '_txt'; + $delIndexDynaField = "APP_UNASSIGNED_USER_GROUP_DEL_INDEX_" . trim ($userUid) . '_txt'; } // remove last AND in condition if ($solrSearchText != '') - $solrSearchText = substr_replace ( $solrSearchText, "", - 5 ); + $solrSearchText = substr_replace ($solrSearchText, "", - 5); // add parenthesis to Solr search text if ($solrSearchText != "") @@ -298,7 +360,7 @@ class AppSolr { if ($search != '') { // format search string // return exception in case of invalid text - $search = $this->getSearchText ( $search ); + $search = $this->getSearchText ($search); if ($solrSearchText != "" && $search != "") $solrSearchText .= " AND "; @@ -306,22 +368,22 @@ class AppSolr { $solrSearchText .= "(" . $search . ")"; } // add del_index dynamic field to list of resulting columns - $columsToInclude = array_merge ( $columsToInclude, array ( + $columsToInclude = array_merge ($columsToInclude, array ( $delIndexDynaField - ) ); + )); - //if is a counter no records are returned - if($doCount){ + // if is a counter no records are returned + if ($doCount) { $start = 0; $limit = 0; $numSortingCols = 0; - $columsToInclude = array(); + $columsToInclude = array (); } $data = array ( - 'workspace' => $this->solrInstance, // solr instance - 'startAfter' => intval ( $start ), - 'pageSize' => intval ( $limit ), + 'workspace' => $this->_solrInstance, // solr instance + 'startAfter' => intval ($start), + 'pageSize' => intval ($limit), 'searchText' => $solrSearchText, 'filterText' => '', // $filter, //ex:'field1:value1,field2:[value2.1 // TO value2.2],field3:value3' @@ -333,11 +395,11 @@ class AppSolr { 'resultFormat' => 'json' ); - $solrRequestData = Entity_SolrRequestData::CreateForRequestPagination ( $data ); + $solrRequestData = Entity_SolrRequestData::createForRequestPagination ($data); // use search index to return list of cases - $searchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); + $searchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost); // execute query - $solrQueryResult = $searchIndex->getDataTablePaginatedList ( $solrRequestData ); + $solrQueryResult = $searchIndex->getDataTablePaginatedList ($solrRequestData); // complete return data, complete list of columns in grid $resultColumns = array ( @@ -374,41 +436,41 @@ class AppSolr { ); $rows = array (); - //number of found records + // number of found records $result ['totalCount'] = $solrQueryResult->iTotalDisplayRecords; - //complete the missing data to display it in the grid. - foreach ( $solrQueryResult->aaData as $i => $data ) { + // complete the missing data to display it in the grid. + foreach ($solrQueryResult->aaData as $i => $data) { // complete empty values $appUID = $data [11]; $delIndexes = $data [30]; // verify if the delindex is an array // if is not an array all the indexed must be returned - if (! is_array ( $delIndexes )) { + if (! is_array ($delIndexes)) { // if is draft if ($action == 'draft') { $delIndexes [] = 1; // the first default index } elseif ($action == 'search') { // get all the indexes - $delIndexes = $this->getApplicationDelegationsIndex ( $appUID ); + $delIndexes = $this->getApplicationDelegationsIndex ($appUID); } } - foreach ( $delIndexes as $delIndex ) { + foreach ($delIndexes as $delIndex) { $aRow = array (); - foreach ( $resultColumns as $j => $columnName ) { + foreach ($resultColumns as $j => $columnName) { $aRow [$columnName] = $data [$j]; } // convert date from solr format UTC to local time in MySQL format $solrdate = $data [0]; - $localDate = date ( 'Y-m-d H:i:s', strtotime ( $solrdate ) ); + $localDate = date ('Y-m-d H:i:s', strtotime ($solrdate)); $aRow ['APP_CREATE_DATE'] = $localDate; $solrdate = $data [12]; - $localDate = date ( 'Y-m-d H:i:s', strtotime ( $solrdate ) ); + $localDate = date ('Y-m-d H:i:s', strtotime ($solrdate)); $aRow ['APP_UPDATE_DATE'] = $localDate; // get delegation data from DB - $row = $this->getAppDelegationData ( $appUID, $delIndex ); + $row = $this->getAppDelegationData ($appUID, $delIndex); $aRow ['APP_FINISH_DATE'] = null; $aRow ['APP_CURRENT_USER'] = $row ['USR_NAME'] . " " . $row ['USR_LAST']; @@ -420,12 +482,12 @@ class AppSolr { $aRow ['DEL_DELAY_DURATION'] = $row ['DEL_DELAY_DURATION']; $aRow ['DEL_DELEGATE_DATE'] = $row ['DEL_DELEGATE_DATE']; $aRow ['DEL_DURATION'] = $row ['DEL_DURATION']; - $aRow ['DEL_FINISHED'] = (isset ( $row ['DEL_FINISH_DATE'] ) && $row ['DEL_FINISH_DATE'] != '') ? 1 : 0; + $aRow ['DEL_FINISHED'] = (isset ($row ['DEL_FINISH_DATE']) && $row ['DEL_FINISH_DATE'] != '') ? 1 : 0; $aRow ['DEL_FINISH_DATE'] = $row ['DEL_FINISH_DATE']; $aRow ['DEL_INDEX'] = $row ['DEL_INDEX']; $aRow ['DEL_INIT_DATE'] = $row ['DEL_INIT_DATE']; $aRow ['DEL_QUEUE_DURATION'] = $row ['DEL_QUEUE_DURATION']; - $aRow ['DEL_STARTED'] = (isset ( $row ['DEL_INIT_DATE'] ) && $row ['DEL_INIT_DATE'] != '') ? 1 : 0; + $aRow ['DEL_STARTED'] = (isset ($row ['DEL_INIT_DATE']) && $row ['DEL_INIT_DATE'] != '') ? 1 : 0; $aRow ['DEL_TASK_DUE_DATE'] = $row ['DEL_TASK_DUE_DATE']; $aRow ['DEL_THREAD_STATUS'] = $row ['DEL_THREAD_STATUS']; $aRow ['PREVIOUS_USR_UID'] = $row ['PREVIOUS_USR_UID']; @@ -457,85 +519,98 @@ class AppSolr { /** * Get the array of counters of cases - * @param string $userUid the current logged user uid identifier + * + * @param string $userUid + * the current logged user uid identifier */ - function getCasesCount($userUid){ - $casesCount = array(); + public function getCasesCount($userUid) + { + $casesCount = array (); - //get number of records in todo list - $data = $this->getAppGridData($userUid, 0, 0, 'todo', null, null, null, null, null, null, - null, null, null, null, null, true); - $casesCount['to_do'] = $data['totalCount']; - //get number of records in participated list - $data = $this->getAppGridData($userUid, 0, 0, 'sent', null, null, null, null, null, null, - null, null, null, null, null, true); - $casesCount['sent'] = $data['totalCount']; - //get number of records in draft list - $data = $this->getAppGridData($userUid, 0, 0, 'draft', null, null, null, null, null, null, - null, null, null, null, null, true); - $casesCount['draft'] = $data['totalCount']; - //get number of records in unassigned list - $data = $this->getAppGridData($userUid, 0, 0, 'unassigned', null, null, null, null, null, null, - null, null, null, null, null, true); - $casesCount['selfservice'] = $data['totalCount']; + // get number of records in todo list + $data = $this->getAppGridData ($userUid, 0, 0, 'todo', null, null, null, null, null, + null, null, null, null, null, null, true); + $casesCount ['to_do'] = $data ['totalCount']; + // get number of records in participated list + $data = $this->getAppGridData ($userUid, 0, 0, 'sent', null, null, null, null, null, + null, null, null, null, null, null, true); + $casesCount ['sent'] = $data ['totalCount']; + // get number of records in draft list + $data = $this->getAppGridData ($userUid, 0, 0, 'draft', null, null, null, null, null, + null, null, null, null, null, null, true); + $casesCount ['draft'] = $data ['totalCount']; + // get number of records in unassigned list + $data = $this->getAppGridData ($userUid, 0, 0, 'unassigned', null, null, null, null, + null, null, null, null, null, null, null, true); + $casesCount ['selfservice'] = $data ['totalCount']; return $casesCount; } - function getUserGroups($usrUID) { + /** + * Get the user groups + * @param string $usrUID the user identifier + * @return array of user groups + */ + public function getUserGroups($usrUID) + { $gu = new GroupUser (); - $rows = $gu->getAllUserGroups ( $usrUID ); + $rows = $gu->getAllUserGroups ($usrUID); return $rows; } /** * Get the application delegation record from database - * @param string $appUID Application identifier - * @param string $delIndex delegation index + * + * @param string $appUID + * Application identifier + * @param string $delIndex + * delegation index * @return array with delegation record. */ - function getAppDelegationData($appUID, $delIndex) { + public function getAppDelegationData($appUID, $delIndex) + { $c = new Criteria (); - $c->addSelectColumn ( AppDelegationPeer::APP_UID ); - $c->addSelectColumn ( AppDelegationPeer::DEL_INDEX ); + $c->addSelectColumn (AppDelegationPeer::APP_UID); + $c->addSelectColumn (AppDelegationPeer::DEL_INDEX); - $c->addAsColumn ( 'USR_NAME', 'u.USR_FIRSTNAME' ); - $c->addAsColumn ( 'USR_LAST', 'u.USR_LASTNAME' ); + $c->addAsColumn ('USR_NAME', 'u.USR_FIRSTNAME'); + $c->addAsColumn ('USR_LAST', 'u.USR_LASTNAME'); - $c->addAsColumn ( 'USR_PREV_NAME', 'uprev.USR_FIRSTNAME' ); - $c->addAsColumn ( 'USR_PREV_LAST', 'uprev.USR_LASTNAME' ); - $c->addAsColumn ( 'PREVIOUS_USR_UID', 'uprev.USR_UID' ); + $c->addAsColumn ('USR_PREV_NAME', 'uprev.USR_FIRSTNAME'); + $c->addAsColumn ('USR_PREV_LAST', 'uprev.USR_LASTNAME'); + $c->addAsColumn ('PREVIOUS_USR_UID', 'uprev.USR_UID'); - $c->addAsColumn ( 'APP_TAS_TITLE', 'ctastitle.CON_VALUE' ); - $c->addAsColumn ( 'APP_THREAD_STATUS', 'at.APP_THREAD_STATUS' ); + $c->addAsColumn ('APP_TAS_TITLE', 'ctastitle.CON_VALUE'); + $c->addAsColumn ('APP_THREAD_STATUS', 'at.APP_THREAD_STATUS'); - $c->addSelectColumn ( AppDelegationPeer::APP_OVERDUE_PERCENTAGE ); + $c->addSelectColumn (AppDelegationPeer::APP_OVERDUE_PERCENTAGE); - $c->addSelectColumn ( AppDelegationPeer::DEL_DELAYED ); - $c->addSelectColumn ( AppDelegationPeer::DEL_DELAY_DURATION ); - $c->addSelectColumn ( AppDelegationPeer::DEL_DELEGATE_DATE ); - $c->addSelectColumn ( AppDelegationPeer::DEL_DURATION ); - $c->addSelectColumn ( AppDelegationPeer::DEL_FINISH_DATE ); - $c->addSelectColumn ( AppDelegationPeer::DEL_INIT_DATE ); - $c->addSelectColumn ( AppDelegationPeer::DEL_QUEUE_DURATION ); - $c->addSelectColumn ( AppDelegationPeer::DEL_TASK_DUE_DATE ); - $c->addSelectColumn ( AppDelegationPeer::DEL_THREAD_STATUS ); - $c->addSelectColumn ( AppDelegationPeer::TAS_UID ); + $c->addSelectColumn (AppDelegationPeer::DEL_DELAYED); + $c->addSelectColumn (AppDelegationPeer::DEL_DELAY_DURATION); + $c->addSelectColumn (AppDelegationPeer::DEL_DELEGATE_DATE); + $c->addSelectColumn (AppDelegationPeer::DEL_DURATION); + $c->addSelectColumn (AppDelegationPeer::DEL_FINISH_DATE); + $c->addSelectColumn (AppDelegationPeer::DEL_INIT_DATE); + $c->addSelectColumn (AppDelegationPeer::DEL_QUEUE_DURATION); + $c->addSelectColumn (AppDelegationPeer::DEL_TASK_DUE_DATE); + $c->addSelectColumn (AppDelegationPeer::DEL_THREAD_STATUS); + $c->addSelectColumn (AppDelegationPeer::TAS_UID); - $c->addAlias ( 'u', 'USERS' ); - $c->addAlias ( 'uprev', 'USERS' ); - $c->addAlias ( 'adprev', 'APP_DELEGATION' ); - $c->addAlias ( 'ctastitle', 'CONTENT' ); - $c->addAlias ( 'at', 'APP_THREAD' ); + $c->addAlias ('u', 'USERS'); + $c->addAlias ('uprev', 'USERS'); + $c->addAlias ('adprev', 'APP_DELEGATION'); + $c->addAlias ('ctastitle', 'CONTENT'); + $c->addAlias ('at', 'APP_THREAD'); $aConditions = array (); $aConditions [] = array ( AppDelegationPeer::USR_UID, 'u.USR_UID' ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); $aConditions = array (); $aConditions [] = array ( @@ -546,21 +621,21 @@ class AppSolr { AppDelegationPeer::DEL_PREVIOUS, 'adprev.DEL_INDEX' ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); $aConditions = array (); $aConditions [] = array ( AppDelegationPeer::TAS_UID, 'ctastitle.CON_ID' ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); $aConditions = array (); $aConditions [] = array ( 'adprev.USR_UID', 'uprev.USR_UID' ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); $aConditions = array (); $aConditions [] = array ( @@ -571,16 +646,16 @@ class AppSolr { AppDelegationPeer::DEL_THREAD, 'at.APP_THREAD_INDEX' ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); - $c->add ( AppDelegationPeer::APP_UID, $appUID ); - $c->add ( AppDelegationPeer::DEL_INDEX, $delIndex ); + $c->add (AppDelegationPeer::APP_UID, $appUID); + $c->add (AppDelegationPeer::DEL_INDEX, $delIndex); - $c->add ( 'ctastitle.CON_CATEGORY', 'TAS_TITLE' ); - $c->add ( 'ctastitle.CON_LANG', 'en' ); + $c->add ('ctastitle.CON_CATEGORY', 'TAS_TITLE'); + $c->add ('ctastitle.CON_LANG', 'en'); - $rs = AppDelegationPeer::doSelectRS ( $c ); - $rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + $rs = AppDelegationPeer::doSelectRS ($c); + $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); // echo $c->toString(); $rs->next (); $row = $rs->getRow (); @@ -595,7 +670,8 @@ class AppSolr { * @param string $plainSearchText * @return string formated Solr search string. */ - function getSearchText($plainSearchText) { + public function getSearchText($plainSearchText) + { $formattedSearchText = ""; // if an error is found in string null is returned $includeToken = true; @@ -603,13 +679,13 @@ class AppSolr { // prepare string to separate and join parentesis // " " => " " $count = 1; - while ( $count > 0 ) { - $plainSearchText = preg_replace ( '/\s\s+/', ' ', $plainSearchText, - 1, $count ); + while ($count > 0) { + $plainSearchText = preg_replace ('/\s\s+/', ' ', $plainSearchText, - 1, $count); } // "text0( text1" => "text0 (text1"; "text0 )text1" => "text0) text1"; - $plainSearchText = preg_replace ( '/\s\[\s/', '[', $plainSearchText ); - $plainSearchText = preg_replace ( '/\s\]\s/', '] ', $plainSearchText ); - $plainSearchText = preg_replace ( '/\s"\s/', '" ', $plainSearchText ); + $plainSearchText = preg_replace ('/\s\[\s/', '[', $plainSearchText); + $plainSearchText = preg_replace ('/\s\]\s/', '] ', $plainSearchText); + $plainSearchText = preg_replace ('/\s"\s/', '" ', $plainSearchText); // print "format search string: " . $plainSearchText . "\n"; // format @@ -627,26 +703,28 @@ class AppSolr { // search the first // cache the index fields - G::LoadClass ( 'PMmemcached' ); - $oMemcache = PMmemcached::getSingleton ( $this->solrInstance ); - $ListFieldsInfo = $oMemcache->get ( 'Solr_Index_Fields' ); + G::LoadClass ('PMmemcached'); + $oMemcache = PMmemcached::getSingleton ($this->_solrInstance); + $ListFieldsInfo = $oMemcache->get ('Solr_Index_Fields'); if (! $ListFieldsInfo) { - G::LoadClass ( 'searchIndex' ); + G::LoadClass ('searchIndex'); - $searchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); + $searchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost); // execute query - $ListFieldsInfo = $searchIndex->getIndexFields ( $this->solrInstance ); + $ListFieldsInfo = $searchIndex->getIndexFields ($this->_solrInstance); // cache - $oMemcache->set ( 'Solr_Index_Fields', $ListFieldsInfo ); + $oMemcache->set ('Solr_Index_Fields', $ListFieldsInfo); } - $tok = strtok ( $plainSearchText, " " ); + $tok = strtok ($plainSearchText, " "); - while ( $tok !== false ) { - $fieldName = substr($tok, 0, strpos($tok, ":")); //strstr ( $tok, ":", true ); php 5.3 - $searchText = strstr ( $tok, ":" ); + while ($tok !== false) { + $fieldName = substr ($tok, 0, strpos ($tok, ":")); // strstr ( $tok, + // ":", + // true ); php 5.3 + $searchText = strstr ($tok, ":"); // verify if there's a field definition if ($fieldName === false) { @@ -663,13 +741,13 @@ class AppSolr { // verify if is complete if ($fieldName == "" || $searchText == ":") { $includeToken = false; - throw new InvalidIndexSearchTextException ( "Invalid search text, verify the syntax. Expected format = {variable_name}:{search_text}" ); + throw new InvalidIndexSearchTextException ("Invalid search text, verify the syntax. Expected format = {variable_name}:{search_text}"); } // field name found // search index field name $indexFieldName = ""; - if (array_key_exists ( $fieldName, $ListFieldsInfo )) { + if (array_key_exists ($fieldName, $ListFieldsInfo)) { $indexFieldName = $ListFieldsInfo [$fieldName]; } else { @@ -677,7 +755,7 @@ class AppSolr { // don't include field search // return message about it $includeToken = false; - throw new InvalidIndexSearchTextException ( "Invalid search text, variable not found." ); + throw new InvalidIndexSearchTextException ("Invalid search text, variable not found."); } // The token is part of a phrase, date or a word? @@ -692,21 +770,21 @@ class AppSolr { // phrase // the phrase is complete? - if ($searchText [1] == "[" && $searchText [strlen ( $searchText ) - 1] == "]") { + if ($searchText [1] == "[" && $searchText [strlen ($searchText) - 1] == "]") { // complete phrase ok, the date must be validated // throw new InvalidIndexSearchTextException("Invalid search text. // Expected date interval format => // {variable_name}:[YYYY-MM-DDThh:mm:ssZ TO YYYY-MM-DDThh:mm:ssZ]"); } - elseif ($searchText [1] == "\"" && $searchText [strlen ( $searchText ) - 1] == "\"") { + elseif ($searchText [1] == "\"" && $searchText [strlen ($searchText) - 1] == "\"") { // the phrase is complete and is ok. } else { // search end of phrase - $tok = strtok ( " " ); + $tok = strtok (" "); $found = false; - while ( $tok !== false ) { - if ((($searchText [1] == "[") && ($tok [strlen ( $tok ) - 1] == "]")) || (($searchText [1] == "\"") && ($tok [strlen ( $tok ) - 1] == "\""))) { + while ($tok !== false) { + if ((($searchText [1] == "[") && ($tok [strlen ($tok) - 1] == "]")) || (($searchText [1] == "\"") && ($tok [strlen ($tok) - 1] == "\""))) { // end of phrase found $found = true; $searchText .= " " . $tok; @@ -716,11 +794,11 @@ class AppSolr { // continue adding text $searchText .= " " . $tok; } - $tok = strtok ( " " ); + $tok = strtok (" "); } if (! $found) { // error invalid text - throw new InvalidIndexSearchTextException ( "Invalid search text. The date or phase is not completed" ); // Expected + throw new InvalidIndexSearchTextException ("Invalid search text. The date or phase is not completed"); // Expected // date // interval // format @@ -738,7 +816,7 @@ class AppSolr { // use regular expresion to validate it [yyyy-mm-dd TO yyyy-mm-dd] $reg = "/:\[(\d\d\d\d-\d\d-\d\d|\*)\sTO\s(\d\d\d\d-\d\d-\d\d|\*)\]/"; // convert date to utc - $matched = preg_match ( $reg, $searchText, $matches ); + $matched = preg_match ($reg, $searchText, $matches); if ($matched == 1) { // the date interval is valid // convert to SOlr format @@ -749,23 +827,27 @@ class AppSolr { $toDate = $matches [2]; if ($fromDateOriginal != '*') { - //TODO complete date creation - //list($year, $month, $day) = sscanf($fromDateOriginal, '%04d/%02d/%02d'); - //$fromDateDatetime = new DateTime($fromDateOriginal); - //$fromDateDatetime = date_create_from_format ( 'Y-m-d', $fromDateOriginal ); - //$fromDateDatetime->getTimestamp () - $fromDate = gmdate ( "Y-m-d\T00:00:00\Z", strtotime($fromDateOriginal)); + // TODO complete date creation + // list($year, $month, $day) = sscanf($fromDateOriginal, + // '%04d/%02d/%02d'); + // $fromDateDatetime = new DateTime($fromDateOriginal); + // $fromDateDatetime = date_create_from_format ( 'Y-m-d', + // $fromDateOriginal ); + // $fromDateDatetime->getTimestamp () + $fromDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal)); } if ($toDateOriginal != '*') { - //list($year, $month, $day) = sscanf($fromDateOriginal, '%04d/%02d/%02d'); - //$toDateDatetime = new DateTime($toDateOriginal); - //$toDateDatetime = date_create_from_format ( 'Y-m-d', $toDateOriginal ); - $toDate = gmdate ( "Y-m-d\T00:00:00\Z", strtotime($fromDateOriginal) ); + // list($year, $month, $day) = sscanf($fromDateOriginal, + // '%04d/%02d/%02d'); + // $toDateDatetime = new DateTime($toDateOriginal); + // $toDateDatetime = date_create_from_format ( 'Y-m-d', + // $toDateOriginal ); + $toDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal)); } $searchText = ":[" . $fromDate . " TO " . $toDate . "]"; } else { - throw new InvalidIndexSearchTextException ( "Invalid search text. Expected date interval format => {variable_name}:[YYYY-MM-DD TO YYYY-MM-DD]" ); + throw new InvalidIndexSearchTextException ("Invalid search text. Expected date interval format => {variable_name}:[YYYY-MM-DD TO YYYY-MM-DD]"); } } @@ -777,33 +859,36 @@ class AppSolr { $formattedSearchText .= " AND "; // next token - $tok = strtok ( " " ); + $tok = strtok (" "); } // remove last AND - $formattedSearchText = substr_replace ( $formattedSearchText, "", - 5 ); + $formattedSearchText = substr_replace ($formattedSearchText, "", - 5); return $formattedSearchText; } /** - * Get all the application delegation records from database - * @param string $appUID Application identifier + * Get all the application delegation records from database + * + * @param string $appUID + * Application identifier * @return array delegation records */ - function getApplicationDelegationsIndex($appUID) { + public function getApplicationDelegationsIndex($appUID) + { $delIndexes = array (); $c = new Criteria (); - $c->addSelectColumn ( AppDelegationPeer::DEL_INDEX ); - $c->add ( AppDelegationPeer::APP_UID, $appUID ); + $c->addSelectColumn (AppDelegationPeer::DEL_INDEX); + $c->add (AppDelegationPeer::APP_UID, $appUID); - $rs = AppDelegationPeer::doSelectRS ( $c ); - $rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + $rs = AppDelegationPeer::doSelectRS ($c); + $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); $rs->next (); $row = $rs->getRow (); - while ( is_array ( $row ) ) { + while (is_array ($row)) { $delIndexes [] = $row ['DEL_INDEX']; $rs->next (); $row = $rs->getRow (); @@ -815,14 +900,17 @@ class AppSolr { /** * Update the information of the specified applications in Solr - * @param array $aaAPPUIDs Array of arrays of App_UID that must be updated, - * APP_UID is permitted also + * + * @param array $aaAPPUIDs + * Array of arrays of App_UID that must be updated, + * APP_UID is permitted also */ - function updateApplicationSearchIndex($aaAPPUIDs) { - if (empty ( $aaAPPUIDs )) + public function updateApplicationSearchIndex($aaAPPUIDs) + { + if (empty ($aaAPPUIDs)) return; - if (! is_array ( $aaAPPUIDs )) { + if (! is_array ($aaAPPUIDs)) { // convert to array $APPUID = $aaAPPUIDs; $aaAPPUIDs = array (); @@ -833,76 +921,82 @@ class AppSolr { // check if index server is available if (! $this->isSolrEnabled ()) { // store update in table and return - foreach ( $aaAPPUIDs as $aAPPUID ) { - $this->applicationChangedUpdateSolrQueue ( $aAPPUID ['APP_UID'], true ); + foreach ($aaAPPUIDs as $aAPPUID) { + $this->applicationChangedUpdateSolrQueue ($aAPPUID ['APP_UID'], true); } } // create XML document - $xmlDoc = $this->createSolrXMLDocument ( $aaAPPUIDs ); - + $xmlDoc = $this->createSolrXMLDocument ($aaAPPUIDs); + // update document $data = array ( - 'workspace' => $this->solrInstance, + 'workspace' => $this->_solrInstance, 'document' => $xmlDoc ); - $oSolrUpdateDocument = Entity_SolrUpdateDocument::CreateForRequest ( $data ); + $oSolrUpdateDocument = Entity_SolrUpdateDocument::createForRequest ($data); - G::LoadClass ( 'searchIndex' ); + G::LoadClass ('searchIndex'); - $oSearchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); + $oSearchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost); - $oSearchIndex->updateIndexDocument ( $oSolrUpdateDocument ); + $oSearchIndex->updateIndexDocument ($oSolrUpdateDocument); // commit changes - $oSearchIndex->commitIndexChanges ( $this->solrInstance ); + $oSearchIndex->commitIndexChanges ($this->_solrInstance); } /** * Delete the specified application record from Solr - * - * @param string $appUID Application identifier + * + * @param string $appUID + * Application identifier */ - function deleteApplicationSearchIndex($appUID) { - if (empty ( $appUID )) + public function deleteApplicationSearchIndex($appUID) + { + if (empty ($appUID)) return; // check if index server is available if (! $this->isSolrEnabled) { // store update in table and return - $this->applicationChangedUpdateSolrQueue ( $appUID ['APP_UID'], 2 ); // delete + $this->applicationChangedUpdateSolrQueue ($appUID ['APP_UID'], 2); // delete } $idQuery = "APP_UID:" . $appUID; - G::LoadClass ( 'searchIndex' ); + G::LoadClass ('searchIndex'); - $oSearchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); + $oSearchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost); - $oSearchIndex->deleteDocumentFromIndex ( $this->solrInstance, $idQuery ); + $oSearchIndex->deleteDocumentFromIndex ($this->_solrInstance, $idQuery); // commit changes - $oSearchIndex->commitIndexChanges ( $this->solrInstance ); + $oSearchIndex->commitIndexChanges ($this->_solrInstance); } /** - * Create XML data in Solr format of the specified applications - * this function uses the buildSearchIndexDocumentPMOS2 function to create each record - * @param array $aaAPPUIDs array of arrays of application identifiers - * @return string The resulting XML document in Solr format + * Create XML data in Solr format of the specified applications + * this function uses the buildSearchIndexDocumentPMOS2 function to create + * each record + * + * @param array $aaAPPUIDs + * array of arrays of application identifiers + * @return string The resulting XML document in Solr format */ - function createSolrXMLDocument($aaAPPUIDs) { + public function createSolrXMLDocument($aaAPPUIDs) + { // search data from DB $xmlDoc = "\n"; $xmlDoc .= "\n"; // echo "APP Uids to index \n"; - foreach ( $aaAPPUIDs as $aAPPUID ) { + foreach ($aaAPPUIDs as $aAPPUID) { try { - $result = $this->getApplicationIndexData ( $aAPPUID ['APP_UID'] ); + $result = $this->getApplicationIndexData ($aAPPUID ['APP_UID']); } - catch(ApplicationWithoutDelegationRecordsException $e){ - //exception trying to get application information - //skip and continue with the next application + catch ( ApplicationWithoutDelegationRecordsException $e ) { + // exception trying to get application information + // skip and continue with the next application continue; } $documentInformation = $result [0]; @@ -920,7 +1014,10 @@ class AppSolr { $unassignedGroups = $result [12]; // create document - $xmlDoc .= $this->buildSearchIndexDocumentPMOS2 ( $documentInformation, $dynaformFieldTypes, $lastUpdateDate, $maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, $draftUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser, $unassignedUsers, $unassignedGroups ); + $xmlDoc .= $this->buildSearchIndexDocumentPMOS2 ($documentInformation, $dynaformFieldTypes, + $lastUpdateDate, $maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, + $draftUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser, + $unassignedUsers, $unassignedGroups); } @@ -972,230 +1069,231 @@ class AppSolr { * $participatedUsersCompletedByUser, * $unassignedUsers, $unassignedGroups);* */ - function buildSearchIndexDocumentPMOS2($documentData, $dynaformFieldTypes, $lastUpdateDate, + public function buildSearchIndexDocumentPMOS2($documentData, $dynaformFieldTypes, $lastUpdateDate, $maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, $draftUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser, - $unassignedUsers, $unassignedGroups) { + $unassignedUsers, $unassignedGroups) + { // build xml document $writer = new XMLWriter (); $writer->openMemory (); - $writer->setIndent ( 4 ); + $writer->setIndent (4); - $writer->startElement ( "doc" ); + $writer->startElement ("doc"); - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_UID' ); - $writer->text ( $documentData ['APP_UID'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_UID'); + $writer->text ($documentData ['APP_UID']); $writer->endElement (); - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_NUMBER' ); - $writer->text ( $documentData ['APP_NUMBER'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_NUMBER'); + $writer->text ($documentData ['APP_NUMBER']); $writer->endElement (); - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_STATUS' ); - $writer->text ( $documentData ['APP_STATUS'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_STATUS'); + $writer->text ($documentData ['APP_STATUS']); $writer->endElement (); - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'PRO_UID' ); - $writer->text ( $documentData ['PRO_UID'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'PRO_UID'); + $writer->text ($documentData ['PRO_UID']); $writer->endElement (); - if (! empty ( $documentData ['APP_TITLE'] )) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_TITLE' ); - $writer->text ( $documentData ['APP_TITLE'] ); + if (! empty ($documentData ['APP_TITLE'])) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_TITLE'); + $writer->text ($documentData ['APP_TITLE']); $writer->endElement (); } else { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_TITLE' ); - $writer->text ( "" ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_TITLE'); + $writer->text (""); $writer->endElement (); } - if (! empty ( $documentData ['PRO_TITLE'] )) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PRO_TITLE' ); - $writer->text ( $documentData ['PRO_TITLE'] ); + if (! empty ($documentData ['PRO_TITLE'])) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PRO_TITLE'); + $writer->text ($documentData ['PRO_TITLE']); $writer->endElement (); } else { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PRO_TITLE' ); - $writer->text ( "" ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PRO_TITLE'); + $writer->text (""); $writer->endElement (); } - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_CREATE_DATE' ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_CREATE_DATE'); // convert date to UTC with gmdate - $writer->text ( gmdate ( "Y-m-d\TH:i:s\Z", strtotime ( $documentData ['APP_CREATE_DATE'] ) ) ); + $writer->text (gmdate ("Y-m-d\TH:i:s\Z", strtotime ($documentData ['APP_CREATE_DATE']))); $writer->endElement (); - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'DEL_LAST_UPDATE_DATE' ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'DEL_LAST_UPDATE_DATE'); // convert date to UTC with gmdate - $writer->text ( gmdate ( "Y-m-d\TH:i:s\Z", strtotime ( $lastUpdateDate ) ) ); + $writer->text (gmdate ("Y-m-d\TH:i:s\Z", strtotime ($lastUpdateDate))); $writer->endElement (); - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'DEL_MAX_PRIORITY' ); - $writer->text ( $maxPriority ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'DEL_MAX_PRIORITY'); + $writer->text ($maxPriority); $writer->endElement (); - if (is_array ( $assignedUsers ) && ! empty ( $assignedUsers )) { - foreach ( $assignedUsers as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_ASSIGNED_USERS' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($assignedUsers) && ! empty ($assignedUsers)) { + foreach ($assignedUsers as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_ASSIGNED_USERS'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_ASSIGNED_USER_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_ASSIGNED_USER_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (is_array ( $assignedUsersRead ) && ! empty ( $assignedUsersRead )) { - foreach ( $assignedUsersRead as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_ASSIGNED_USERS_READ' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($assignedUsersRead) && ! empty ($assignedUsersRead)) { + foreach ($assignedUsersRead as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_ASSIGNED_USERS_READ'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_ASSIGNED_USER_READ_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_ASSIGNED_USER_READ_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (is_array ( $assignedUsersUnread ) && ! empty ( $assignedUsersUnread )) { - foreach ( $assignedUsersUnread as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_ASSIGNED_USERS_UNREAD' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($assignedUsersUnread) && ! empty ($assignedUsersUnread)) { + foreach ($assignedUsersUnread as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_ASSIGNED_USERS_UNREAD'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_ASSIGNED_USER_UNREAD_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_ASSIGNED_USER_UNREAD_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (! empty ( $draftUser )) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_DRAFT_USER' ); - $writer->text ( $draftUser ['USR_UID'] ); + if (! empty ($draftUser)) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_DRAFT_USER'); + $writer->text ($draftUser ['USR_UID']); $writer->endElement (); } - if (is_array ( $participatedUsers ) && ! empty ( $participatedUsers )) { - foreach ( $participatedUsers as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PARTICIPATED_USERS' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($participatedUsers) && ! empty ($participatedUsers)) { + foreach ($participatedUsers as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PARTICIPATED_USERS'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PARTICIPATED_USER_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PARTICIPATED_USER_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (is_array ( $participatedUsersStartedByUser ) && ! empty ( $participatedUsersStartedByUser )) { - foreach ( $participatedUsersStartedByUser as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PARTICIPATED_USERS_STARTED' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($participatedUsersStartedByUser) && ! empty ($participatedUsersStartedByUser)) { + foreach ($participatedUsersStartedByUser as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PARTICIPATED_USERS_STARTED'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PARTICIPATED_USER_STARTED_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PARTICIPATED_USER_STARTED_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (is_array ( $participatedUsersCompletedByUser ) && ! empty ( $participatedUsersCompletedByUser )) { - foreach ( $participatedUsersCompletedByUser as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PARTICIPATED_USERS_COMPLETED' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($participatedUsersCompletedByUser) && ! empty ($participatedUsersCompletedByUser)) { + foreach ($participatedUsersCompletedByUser as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PARTICIPATED_USERS_COMPLETED'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_PARTICIPATED_USER_COMPLETED_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_PARTICIPATED_USER_COMPLETED_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (is_array ( $unassignedUsers ) && ! empty ( $unassignedUsers )) { - foreach ( $unassignedUsers as $userUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_UNASSIGNED_USERS' ); - $writer->text ( $userUID ['USR_UID'] ); + if (is_array ($unassignedUsers) && ! empty ($unassignedUsers)) { + foreach ($unassignedUsers as $userUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_UNASSIGNED_USERS'); + $writer->text ($userUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_UNASSIGNED_USER_GROUP_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_UNASSIGNED_USER_GROUP_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } - if (is_array ( $unassignedGroups ) && ! empty ( $unassignedGroups )) { - foreach ( $unassignedGroups as $groupUID ) { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_UNASSIGNED_GROUPS' ); - $writer->text ( $groupUID ['USR_UID'] ); + if (is_array ($unassignedGroups) && ! empty ($unassignedGroups)) { + foreach ($unassignedGroups as $groupUID) { + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_UNASSIGNED_GROUPS'); + $writer->text ($groupUID ['USR_UID']); $writer->endElement (); // add dynamic field for del_index information - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', 'APP_UNASSIGNED_USER_GROUP_DEL_INDEX_' . trim ( $userUID ['USR_UID'] ) . '_txt' ); - $writer->text ( $userUID ['DEL_INDEX'] ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', 'APP_UNASSIGNED_USER_GROUP_DEL_INDEX_' . trim ($userUID ['USR_UID']) . '_txt'); + $writer->text ($userUID ['DEL_INDEX']); $writer->endElement (); } } // get the serialized fields - if (! empty ( $documentData ['APP_DATA'] )) { + if (! empty ($documentData ['APP_DATA'])) { - $UnSerializedCaseData = unserialize ( $documentData ['APP_DATA'] ); + $UnSerializedCaseData = unserialize ($documentData ['APP_DATA']); if ($UnSerializedCaseData === false) { - $UnSerializedCaseData = preg_replace ( '!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $documentData ['APP_DATA'] ); // utf8_encode - $UnSerializedCaseData = unserialize ( $UnSerializedCaseData ); + $UnSerializedCaseData = preg_replace ('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $documentData ['APP_DATA']); // utf8_encode + $UnSerializedCaseData = unserialize ($UnSerializedCaseData); } if (! $UnSerializedCaseData) { // error unserializing - throw new Exception ( "Unserialize APP_DATA error. APP_UID: " . $documentData ['APP_UID'] ); + throw new Exception ("Unserialize APP_DATA error. APP_UID: " . $documentData ['APP_UID']); } else { - foreach ( $UnSerializedCaseData as $k => $value ) { - if (!is_array ( $value ) && !is_object($value) && $value != '' && $k != 'SYS_LANG' && $k != 'SYS_SKIN' && $k != 'SYS_SYS') { + foreach ($UnSerializedCaseData as $k => $value) { + if (! is_array ($value) && ! is_object ($value) && $value != '' && $k != 'SYS_LANG' && $k != 'SYS_SKIN' && $k != 'SYS_SYS') { // search the field type in array of dynaform fields - if (! empty ( $dynaformFieldTypes ) && array_key_exists ( trim ( $k ), $dynaformFieldTypes )) { - $type = $dynaformFieldTypes [trim ( $k )]; + if (! empty ($dynaformFieldTypes) && array_key_exists (trim ($k), $dynaformFieldTypes)) { + $type = $dynaformFieldTypes [trim ($k)]; $typeSufix = '_t'; switch ($type) { case 'text' : @@ -1203,46 +1301,39 @@ class AppSolr { break; case 'Int' : $typeSufix = '_ti'; - $value = intval ( $value ); + $value = intval ($value); break; case 'Real' : $typeSufix = '_td'; - $value = floatval ( $value ); + $value = floatval ($value); break; case 'date' : $newdate = false; $withHour = true; // try to convert string to date - //TODO convert to php 5.2 format + // TODO convert to php 5.2 format /* - $newdate = date_create_from_format ( 'Y-m-d H:i:s', $value ); - if (! $newdate) { - $newdate = date_create_from_format ( 'Y-m-d', $value ); - $withHour = false; - } - if (! $newdate) { - $newdate = date_create_from_format ( 'd/m/Y', $value ); - $withHour = false; - } - if (! $newdate) { - $newdate = date_create_from_format ( 'j/m/Y', $value ); - $withHour = false; - } - */ - $newdate = strtotime($value); + * $newdate = date_create_from_format ( 'Y-m-d H:i:s', $value + * ); if (! $newdate) { $newdate = date_create_from_format ( + * 'Y-m-d', $value ); $withHour = false; } if (! $newdate) { + * $newdate = date_create_from_format ( 'd/m/Y', $value ); + * $withHour = false; } if (! $newdate) { $newdate = + * date_create_from_format ( 'j/m/Y', $value ); $withHour = + * false; } + */ + $newdate = strtotime ($value); if (! $newdate) { $typeSufix = '*'; // not store field } else { $typeSufix = '_tdt'; /* - if ($withHour) - //$value = gmdate ( "Y-m-d\TH:i:s\Z", $newdate->getTimestamp () ); - $value = gmdate ( "Y-m-d\TH:i:s\Z", $newdate ); - else { - $value = gmdate ( "Y-m-d\T00:00:00\Z", $newdate ); - }*/ - $value = gmdate ( "Y-m-d\T00:00:00\Z", $newdate ); + * if ($withHour) //$value = gmdate ( "Y-m-d\TH:i:s\Z", + * $newdate->getTimestamp () ); $value = gmdate ( + * "Y-m-d\TH:i:s\Z", $newdate ); else { $value = gmdate ( + * "Y-m-d\T00:00:00\Z", $newdate ); } + */ + $value = gmdate ("Y-m-d\T00:00:00\Z", $newdate); } break; case 'dropdown' : @@ -1283,16 +1374,16 @@ class AppSolr { break; } if ($typeSufix != '*') { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', trim ( $k ) . $typeSufix ); - $writer->text ( $value ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', trim ($k) . $typeSufix); + $writer->text ($value); $writer->endElement (); } } else { - $writer->startElement ( "field" ); - $writer->writeAttribute ( 'name', trim ( $k ) . '_t' ); - $writer->text ( $value ); + $writer->startElement ("field"); + $writer->writeAttribute ('name', trim ($k) . '_t'); + $writer->text ($value); $writer->endElement (); } } @@ -1302,50 +1393,53 @@ class AppSolr { $writer->endElement (); // end /doc - return $writer->outputMemory ( true ); + return $writer->outputMemory (true); } /** * Search records in specified application delegation data - * @param string $AppUID application identifier + * + * @param string $AppUID + * application identifier * @throws ApplicationWithoutDelegationRecordsException - * @return array array of arrays with the following information( - $documentInformation, - $dynaformFieldTypes, - $lastUpdateDate, - $maxPriority, - $assignedUsers, - $assignedUsersRead, - $assignedUsersUnread, - $draftUser, - $participatedUsers, - $participatedUsersStartedByUser, - $participatedUsersCompletedByUser, - $unassignedUsers, - $unassignedGroups + * @return array array of arrays with the following information( + * $documentInformation, + * $dynaformFieldTypes, + * $lastUpdateDate, + * $maxPriority, + * $assignedUsers, + * $assignedUsersRead, + * $assignedUsersUnread, + * $draftUser, + * $participatedUsers, + * $participatedUsersStartedByUser, + * $participatedUsersCompletedByUser, + * $unassignedUsers, + * $unassignedGroups */ - function getApplicationIndexData($AppUID) { - G::LoadClass ( 'memcached' ); + public function getApplicationIndexData($AppUID) + { + G::LoadClass ('memcached'); // get all the application data - $allAppDbData = $this->getApplicationDelegationData ( $AppUID ); + $allAppDbData = $this->getApplicationDelegationData ($AppUID); // check if the application record was found // this case occurs when the application doesn't have related delegation // records. - if (empty ( $allAppDbData ) || ! isset ( $allAppDbData [0] )) { - throw new ApplicationWithoutDelegationRecordsException ( "Application without delegation records. APP_UID: " . $AppUID ); + if (empty ($allAppDbData) || ! isset ($allAppDbData [0])) { + throw new ApplicationWithoutDelegationRecordsException ("Application without delegation records. APP_UID: " . $AppUID); } // copy the application information $documentInformation = $allAppDbData [0]; // get the last delegate date using the del_delegate_date - $index = $this->aaGetMaximun ( $allAppDbData, 'DEL_DELEGATE_DATE', 'DATE' ); + $index = $this->aaGetMaximun ($allAppDbData, 'DEL_DELEGATE_DATE', 'DATE'); $lastUpdateDate = $allAppDbData [$index] ['DEL_DELEGATE_DATE']; // get the delegate with max priority => minimun value - $index2 = $this->aaGetMinimun ( $allAppDbData, 'DEL_PRIORITY', 'NUMBER', 'DEL_THREAD_STATUS', 'OPEN' ); + $index2 = $this->aaGetMinimun ($allAppDbData, 'DEL_PRIORITY', 'NUMBER', 'DEL_THREAD_STATUS', 'OPEN'); if ($index2 == null) { // get the last priority @@ -1356,125 +1450,125 @@ class AppSolr { } $assignedUsers = array (); - $indexes = $this->aaSearchRecords ( $allAppDbData, array ( - 'DEL_THREAD_STATUS' => 'OPEN', - 'DEL_FINISH_DATE' => 'NULL', - 'APP_STATUS' => 'TO_DO', - 'APP_THREAD_STATUS' => 'OPEN' - ) ); - foreach ( $indexes as $index ) { + $indexes = $this->aaSearchRecords ($allAppDbData, array ( + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_FINISH_DATE' => 'NULL', + 'APP_STATUS' => 'TO_DO', + 'APP_THREAD_STATUS' => 'OPEN' + )); + foreach ($indexes as $index) { $assignedUsers [] = array ( - 'USR_UID' => $allAppDbData [$index] ['USR_UID'], + 'USR_UID' => $allAppDbData [$index] ['USR_UID'], 'DEL_INDEX' => $allAppDbData [$index] ['DEL_INDEX'] ); } $assignedUsersRead = array (); - $indexes = $this->aaSearchRecords ( $allAppDbData, array ( - 'DEL_THREAD_STATUS' => 'OPEN', - 'DEL_FINISH_DATE' => 'NULL', - 'APP_STATUS' => 'TO_DO', - 'APP_THREAD_STATUS' => 'OPEN', - 'DEL_INIT_DATE' => 'NOTNULL' - ) ); - foreach ( $indexes as $index ) { + $indexes = $this->aaSearchRecords ($allAppDbData, array ( + 'DEL_THREAD_STATUS' => 'OPEN', + 'DEL_FINISH_DATE' => 'NULL', + 'APP_STATUS' => 'TO_DO', + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INIT_DATE' => 'NOTNULL' + )); + foreach ($indexes as $index) { $assignedUsersRead [] = array ( - 'USR_UID' => $allAppDbData [$index] ['USR_UID'], + 'USR_UID' => $allAppDbData [$index] ['USR_UID'], 'DEL_INDEX' => $allAppDbData [$index] ['DEL_INDEX'] ); } $assignedUsersUnread = array (); - $indexes = $this->aaSearchRecords ( $allAppDbData, array ( + $indexes = $this->aaSearchRecords ($allAppDbData, array ( 'DEL_THREAD_STATUS' => 'OPEN', - 'DEL_FINISH_DATE' => 'NULL', - 'APP_STATUS' => 'TO_DO', + 'DEL_FINISH_DATE' => 'NULL', + 'APP_STATUS' => 'TO_DO', 'APP_THREAD_STATUS' => 'OPEN', - 'DEL_INIT_DATE' => 'NULL' - ) ); - foreach ( $indexes as $index ) { + 'DEL_INIT_DATE' => 'NULL' + )); + foreach ($indexes as $index) { $assignedUsersUnread [] = array ( - 'USR_UID' => $allAppDbData [$index] ['USR_UID'], + 'USR_UID' => $allAppDbData [$index] ['USR_UID'], 'DEL_INDEX' => $allAppDbData [$index] ['DEL_INDEX'] ); } $draftUser = array (); - $indexes = $this->aaSearchRecords ( $allAppDbData, array ( + $indexes = $this->aaSearchRecords ($allAppDbData, array ( 'DEL_THREAD_STATUS' => 'OPEN', - 'DEL_FINISH_DATE' => 'NULL', - 'APP_STATUS' => 'DRAFT', + 'DEL_FINISH_DATE' => 'NULL', + 'APP_STATUS' => 'DRAFT', 'APP_THREAD_STATUS' => 'OPEN' - ) ); - if (! empty ( $indexes )) { + )); + if (! empty ($indexes)) { $draftUser = array ( - 'USR_UID' => $allAppDbData [$indexes [0]] ['USR_UID'], + 'USR_UID' => $allAppDbData [$indexes [0]] ['USR_UID'], 'DEL_INDEX' => $allAppDbData [$indexes [0]] ['DEL_INDEX'] ); } $participatedUsers = array (); - foreach ( $allAppDbData as $row ) { + foreach ($allAppDbData as $row) { $participatedUsers [] = array ( - 'USR_UID' => $row ['USR_UID'], + 'USR_UID' => $row ['USR_UID'], 'DEL_INDEX' => $row ['DEL_INDEX'] ); } $participatedUsersStartedByUser = array (); - $indexes = $this->aaSearchRecords ( $allAppDbData, array ( + $indexes = $this->aaSearchRecords ($allAppDbData, array ( 'DEL_INDEX' => '1' - ) ); - foreach ( $indexes as $index ) { + )); + foreach ($indexes as $index) { $participatedUsersStartedByUser [] = array ( - 'USR_UID' => $allAppDbData [$index] ['USR_UID'], + 'USR_UID' => $allAppDbData [$index] ['USR_UID'], 'DEL_INDEX' => $allAppDbData [$index] ['DEL_INDEX'] ); } $participatedUsersCompletedByUser = array (); - $indexes = $this->aaSearchRecords ( $allAppDbData, array ( + $indexes = $this->aaSearchRecords ($allAppDbData, array ( 'APP_STATUS' => 'COMPLETED' - ) ); - foreach ( $indexes as $index ) { + )); + foreach ($indexes as $index) { $participatedUsersCompletedByUser [] = array ( - 'USR_UID' => $allAppDbData [$index] ['USR_UID'], + 'USR_UID' => $allAppDbData [$index] ['USR_UID'], 'DEL_INDEX' => $allAppDbData [$index] ['DEL_INDEX'] ); } // search information of unassigned users // the unassigned users are the self service users and groups. // the self service users are defined in the TASKs of the PROCESS. - foreach ( $allAppDbData as $row ) { + foreach ($allAppDbData as $row) { $unassignedUsersGroups = array (); // use cache - $oMemcache = PMmemcached::getSingleton ( $this->solrInstance ); - $unassignedUsersGroups = $oMemcache->get ( $row ['PRO_UID'] . "_" . $row ['TAS_UID'] ); + $oMemcache = PMmemcached::getSingleton ($this->_solrInstance); + $unassignedUsersGroups = $oMemcache->get ($row ['PRO_UID'] . "_" . $row ['TAS_UID']); if (! $unassignedUsersGroups) { - $unassignedUsersGroups = $this->getTaskUnassignedUsersGroupsData ( $row ['PRO_UID'], $row ['TAS_UID'] ); + $unassignedUsersGroups = $this->getTaskUnassignedUsersGroupsData ($row ['PRO_UID'], $row ['TAS_UID']); // add del_index - foreach ( $unassignedUsersGroups as $i => $newRow ) { + foreach ($unassignedUsersGroups as $i => $newRow) { $unassignedUsersGroups [$i] ['DEL_INDEX'] = $row ['DEL_INDEX']; } // store in cache - $oMemcache->set ( $row ['PRO_UID'] . "_" . $row ['TAS_UID'], $unassignedUsersGroups ); + $oMemcache->set ($row ['PRO_UID'] . "_" . $row ['TAS_UID'], $unassignedUsersGroups); } // copy list of unassigned users and groups $unassignedUsers = array (); $unassignedGroups = array (); - foreach ( $unassignedUsersGroups as $unassignedUserGroup ) { + foreach ($unassignedUsersGroups as $unassignedUserGroup) { if ($unassignedUserGroup ['TU_RELATION'] == 1) { $unassignedUsers [] = array ( - 'USR_UID' => $unassignedUserGroup ['USR_UID'], + 'USR_UID' => $unassignedUserGroup ['USR_UID'], 'DEL_INDEX' => $unassignedUserGroup ['DEL_INDEX'] ); } elseif ($unassignedUserGroup ['TU_RELATION'] == 2) { $unassignedGroups [] = array ( - 'USR_UID' => $unassignedUserGroup ['USR_UID'], + 'USR_UID' => $unassignedUserGroup ['USR_UID'], 'DEL_INDEX' => $unassignedUserGroup ['DEL_INDEX'] ); } @@ -1488,35 +1582,35 @@ class AppSolr { // process $dynaformFieldTypes = array (); // get cache instance - $oMemcache = PMmemcached::getSingleton ( $this->solrInstance ); - $dynaformFieldTypes = $oMemcache->get ( $documentInformation ['PRO_UID'] ); + $oMemcache = PMmemcached::getSingleton ($this->_solrInstance); + $dynaformFieldTypes = $oMemcache->get ($documentInformation ['PRO_UID']); if (! $dynaformFieldTypes) { - G::LoadClass ( 'dynaformhandler' ); - $dynaformFileNames = $this->getProcessDynaformFileNames ( $documentInformation ['PRO_UID'] ); + G::LoadClass ('dynaformhandler'); + $dynaformFileNames = $this->getProcessDynaformFileNames ($documentInformation ['PRO_UID']); $dynaformFields = array (); - foreach ( $dynaformFileNames as $dynaformFileName ) { - if (file_exists ( PATH_DATA . '/sites/workflow/xmlForms/' . $dynaformFileName ['DYN_FILENAME'] . '.xml' )) { - $dyn = new dynaFormHandler ( PATH_DATA . '/sites/workflow/xmlForms/' . $dynaformFileName ['DYN_FILENAME'] . '.xml' ); + foreach ($dynaformFileNames as $dynaformFileName) { + if (file_exists (PATH_DATA . '/sites/workflow/xmlForms/' . $dynaformFileName ['DYN_FILENAME'] . '.xml')) { + $dyn = new dynaFormHandler (PATH_DATA . '/sites/workflow/xmlForms/' . $dynaformFileName ['DYN_FILENAME'] . '.xml'); $dynaformFields [] = $dyn->getFields (); } } - foreach ( $dynaformFields as $aDynFormFields ) { - foreach ( $aDynFormFields as $field ) { + foreach ($dynaformFields as $aDynFormFields) { + foreach ($aDynFormFields as $field) { // create array of fields and types - if ($field->getAttribute ( 'validate' ) == 'Int') { + if ($field->getAttribute ('validate') == 'Int') { $dynaformFieldTypes [$field->nodeName] = 'Int'; } - elseif ($field->getAttribute ( 'validate' ) == 'Real') { + elseif ($field->getAttribute ('validate') == 'Real') { $dynaformFieldTypes [$field->nodeName] = 'Real'; } else { - $dynaformFieldTypes [$field->nodeName] = $field->getAttribute ( 'type' ); + $dynaformFieldTypes [$field->nodeName] = $field->getAttribute ('type'); } } } // create cache of dynaformfields - $oMemcache->set ( $documentInformation ['PRO_UID'], $dynaformFieldTypes ); + $oMemcache->set ($documentInformation ['PRO_UID'], $dynaformFieldTypes); } // return result values @@ -1542,21 +1636,29 @@ class AppSolr { /** * Find the maximun value of the specified column in the array and return the * row index - * @param array $arr array of arrays with the data - * @param string $column column name to search in - * @param string $columnType column type STRING, NUMBER, DATE - * @param string $columnCondition column condition - * @param string $condition the condition + * + * @param array $arr + * array of arrays with the data + * @param string $column + * column name to search in + * @param string $columnType + * column type STRING, NUMBER, DATE + * @param string $columnCondition + * column condition + * @param string $condition + * the condition * @return integer The index of the maximun record in array */ - function aaGetMaximun($arr, $column, $columnType = 'STRING', $columnCondition = "", $condition = "") { + public function aaGetMaximun($arr, $column, $columnType = 'STRING', + $columnCondition = "", $condition = "") + { // get first value $auxValue = $arr [0] [$column]; $index = null; - foreach ( $arr as $i => $row ) { + foreach ($arr as $i => $row) { switch ($columnType) { case 'STRING' : - if ((strnatcmp ( $row [$column], $auxValue ) >= 0) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { + if ((strnatcmp ($row [$column], $auxValue) >= 0) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { $auxValue = $row [$column]; $index = $i; } @@ -1568,7 +1670,7 @@ class AppSolr { } break; case 'DATE' : - if ((strtotime ( $row [$column] ) >= strtotime ( $auxValue )) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { + if ((strtotime ($row [$column]) >= strtotime ($auxValue)) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { $auxValue = $row [$column]; $index = $i; } @@ -1581,21 +1683,28 @@ class AppSolr { /** * Get minimum of array of arrays * - * @param array $arr array of arrays with the data - * @param string $column the name of the column to search in - * @param string $columnType the column type STRING, NUMBER, DATE - * @param string $columnCondition the column condition - * @param string $condition the condition + * @param array $arr + * array of arrays with the data + * @param string $column + * the name of the column to search in + * @param string $columnType + * the column type STRING, NUMBER, DATE + * @param string $columnCondition + * the column condition + * @param string $condition + * the condition * @return Ambigous Index of the minimun value found */ - function aaGetMinimun($arr, $column, $columnType = 'STRING', $columnCondition = "", $condition = "") { + public function aaGetMinimun($arr, $column, $columnType = 'STRING', + $columnCondition = "", $condition = "") + { // get first value $auxValue = $arr [0] [$column]; $index = null; - foreach ( $arr as $i => $row ) { + foreach ($arr as $i => $row) { switch ($columnType) { case 'STRING' : - if ((strnatcmp ( $row [$column], $auxValue ) <= 0) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { + if ((strnatcmp ($row [$column], $auxValue) <= 0) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { $auxValue = $row [$column]; $index = $i; } @@ -1607,7 +1716,7 @@ class AppSolr { } break; case 'DATE' : - if ((strtotime ( $row [$column] ) <= strtotime ( $auxValue )) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { + if ((strtotime ($row [$column]) <= strtotime ($auxValue)) && (($columnCondition == "") || ($row [$columnCondition] == $condition))) { $auxValue = $row [$column]; $index = $i; @@ -1627,13 +1736,14 @@ class AppSolr { * contain the conditions that must fullfill 'Column'=>'Condition' * @return array array of indexes with the found records */ - function aaSearchRecords($arr, $andColumnsConditions) { + public function aaSearchRecords($arr, $andColumnsConditions) + { $indexes = array (); $isEqual = true; - foreach ( $arr as $i => $row ) { + foreach ($arr as $i => $row) { $evaluateRow = false; // evaluate each row - foreach ( $andColumnsConditions as $column => $valueCondition ) { + foreach ($andColumnsConditions as $column => $valueCondition) { $condition = $valueCondition; $isEqual = true; if ($valueCondition == 'NULL') { @@ -1673,55 +1783,58 @@ class AppSolr { /** * Get application and delegation data from database - * @param string $AppUID the application identifier + * + * @param string $AppUID + * the application identifier * @return array of records from database */ - function getApplicationDelegationData($AppUID) { + public function getApplicationDelegationData($AppUID) + { $allAppDbData = array (); $c = new Criteria (); - $c->addSelectColumn ( ApplicationPeer::APP_UID ); - $c->addSelectColumn ( ApplicationPeer::APP_NUMBER ); - $c->addSelectColumn ( ApplicationPeer::APP_STATUS ); - $c->addSelectColumn ( ApplicationPeer::PRO_UID ); - $c->addSelectColumn ( ApplicationPeer::APP_CREATE_DATE ); - $c->addSelectColumn ( ApplicationPeer::APP_FINISH_DATE ); - $c->addSelectColumn ( ApplicationPeer::APP_UPDATE_DATE ); - $c->addSelectColumn ( ApplicationPeer::APP_DATA ); + $c->addSelectColumn (ApplicationPeer::APP_UID); + $c->addSelectColumn (ApplicationPeer::APP_NUMBER); + $c->addSelectColumn (ApplicationPeer::APP_STATUS); + $c->addSelectColumn (ApplicationPeer::PRO_UID); + $c->addSelectColumn (ApplicationPeer::APP_CREATE_DATE); + $c->addSelectColumn (ApplicationPeer::APP_FINISH_DATE); + $c->addSelectColumn (ApplicationPeer::APP_UPDATE_DATE); + $c->addSelectColumn (ApplicationPeer::APP_DATA); - $c->addAsColumn ( 'APP_TITLE', 'capp.CON_VALUE' ); - $c->addAsColumn ( 'PRO_TITLE', 'cpro.CON_VALUE' ); + $c->addAsColumn ('APP_TITLE', 'capp.CON_VALUE'); + $c->addAsColumn ('PRO_TITLE', 'cpro.CON_VALUE'); - $c->addSelectColumn ( 'ad.DEL_INDEX' ); - $c->addSelectColumn ( 'ad.DEL_PREVIOUS' ); - $c->addSelectColumn ( 'ad.TAS_UID' ); - $c->addSelectColumn ( 'ad.USR_UID' ); - $c->addSelectColumn ( 'ad.DEL_TYPE' ); - $c->addSelectColumn ( 'ad.DEL_THREAD' ); - $c->addSelectColumn ( 'ad.DEL_THREAD_STATUS' ); - $c->addSelectColumn ( 'ad.DEL_PRIORITY' ); - $c->addSelectColumn ( 'ad.DEL_DELEGATE_DATE' ); - $c->addSelectColumn ( 'ad.DEL_INIT_DATE' ); - $c->addSelectColumn ( 'ad.DEL_TASK_DUE_DATE' ); - $c->addSelectColumn ( 'ad.DEL_FINISH_DATE' ); - $c->addSelectColumn ( 'ad.DEL_DURATION' ); - $c->addSelectColumn ( 'ad.DEL_QUEUE_DURATION' ); - $c->addSelectColumn ( 'ad.DEL_DELAY_DURATION' ); - $c->addSelectColumn ( 'ad.DEL_STARTED' ); - $c->addSelectColumn ( 'ad.DEL_FINISHED' ); - $c->addSelectColumn ( 'ad.DEL_DELAYED' ); - $c->addSelectColumn ( 'ad.APP_OVERDUE_PERCENTAGE' ); + $c->addSelectColumn ('ad.DEL_INDEX'); + $c->addSelectColumn ('ad.DEL_PREVIOUS'); + $c->addSelectColumn ('ad.TAS_UID'); + $c->addSelectColumn ('ad.USR_UID'); + $c->addSelectColumn ('ad.DEL_TYPE'); + $c->addSelectColumn ('ad.DEL_THREAD'); + $c->addSelectColumn ('ad.DEL_THREAD_STATUS'); + $c->addSelectColumn ('ad.DEL_PRIORITY'); + $c->addSelectColumn ('ad.DEL_DELEGATE_DATE'); + $c->addSelectColumn ('ad.DEL_INIT_DATE'); + $c->addSelectColumn ('ad.DEL_TASK_DUE_DATE'); + $c->addSelectColumn ('ad.DEL_FINISH_DATE'); + $c->addSelectColumn ('ad.DEL_DURATION'); + $c->addSelectColumn ('ad.DEL_QUEUE_DURATION'); + $c->addSelectColumn ('ad.DEL_DELAY_DURATION'); + $c->addSelectColumn ('ad.DEL_STARTED'); + $c->addSelectColumn ('ad.DEL_FINISHED'); + $c->addSelectColumn ('ad.DEL_DELAYED'); + $c->addSelectColumn ('ad.APP_OVERDUE_PERCENTAGE'); - $c->addSelectColumn ( 'at.APP_THREAD_INDEX' ); - $c->addSelectColumn ( 'at.APP_THREAD_PARENT' ); - $c->addSelectColumn ( 'at.APP_THREAD_STATUS' ); + $c->addSelectColumn ('at.APP_THREAD_INDEX'); + $c->addSelectColumn ('at.APP_THREAD_PARENT'); + $c->addSelectColumn ('at.APP_THREAD_STATUS'); - $c->addAlias ( 'capp', 'CONTENT' ); - $c->addAlias ( 'cpro', 'CONTENT' ); - $c->addAlias ( 'ad', 'APP_DELEGATION' ); - $c->addAlias ( 'at', 'APP_THREAD' ); + $c->addAlias ('capp', 'CONTENT'); + $c->addAlias ('cpro', 'CONTENT'); + $c->addAlias ('ad', 'APP_DELEGATION'); + $c->addAlias ('at', 'APP_THREAD'); $aConditions = array (); $aConditions [] = array ( @@ -1736,7 +1849,7 @@ class AppSolr { 'capp.CON_LANG', DBAdapter::getStringDelimiter () . 'en' . DBAdapter::getStringDelimiter () ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); $aConditions = array (); $aConditions [] = array ( @@ -1751,9 +1864,9 @@ class AppSolr { 'cpro.CON_LANG', DBAdapter::getStringDelimiter () . 'en' . DBAdapter::getStringDelimiter () ); - $c->addJoinMC ( $aConditions, Criteria::LEFT_JOIN ); + $c->addJoinMC ($aConditions, Criteria::LEFT_JOIN); - $c->addJoin ( ApplicationPeer::APP_UID, 'ad.APP_UID', Criteria::JOIN ); + $c->addJoin (ApplicationPeer::APP_UID, 'ad.APP_UID', Criteria::JOIN); $aConditions = array (); $aConditions [] = array ( @@ -1764,17 +1877,17 @@ class AppSolr { 'ad.DEL_THREAD', 'at.APP_THREAD_INDEX' ); - $c->addJoinMC ( $aConditions, Criteria::JOIN ); + $c->addJoinMC ($aConditions, Criteria::JOIN); - $c->add ( ApplicationPeer::APP_UID, $AppUID ); + $c->add (ApplicationPeer::APP_UID, $AppUID); - $rs = ApplicationPeer::doSelectRS ( $c ); - $rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + $rs = ApplicationPeer::doSelectRS ($c); + $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); $rs->next (); $row = $rs->getRow (); - while ( is_array ( $row ) ) { + while (is_array ($row)) { $allAppDbData [] = $row; $rs->next (); $row = $rs->getRow (); @@ -1783,18 +1896,23 @@ class AppSolr { } /** - * Get the list of groups of unassigned users of the specified task from database - * @param string $ProUID Process identifier - * @param string $TaskUID task identifier + * Get the list of groups of unassigned users of the specified task from + * database + * + * @param string $ProUID + * Process identifier + * @param string $TaskUID + * task identifier * @return array of unassigned user groups */ - function getTaskUnassignedUsersGroupsData($ProUID, $TaskUID) { + public function getTaskUnassignedUsersGroupsData($ProUID, $TaskUID) + { $unassignedUsersGroups = array (); $c = new Criteria (); - $c->addSelectColumn ( TaskUserPeer::USR_UID ); - $c->addSelectColumn ( TaskUserPeer::TU_RELATION ); + $c->addSelectColumn (TaskUserPeer::USR_UID); + $c->addSelectColumn (TaskUserPeer::TU_RELATION); $aConditions = array (); $aConditions [] = array ( @@ -1805,18 +1923,18 @@ class AppSolr { TaskPeer::TAS_ASSIGN_TYPE, DBAdapter::getStringDelimiter () . 'SELF_SERVICE' . DBAdapter::getStringDelimiter () ); - $c->addJoinMC ( $aConditions, Criteria::JOIN ); + $c->addJoinMC ($aConditions, Criteria::JOIN); - $c->add ( TaskPeer::PRO_UID, $ProUID ); - $c->add ( TaskPeer::TAS_UID, $TaskUID ); + $c->add (TaskPeer::PRO_UID, $ProUID); + $c->add (TaskPeer::TAS_UID, $TaskUID); - $rs = TaskPeer::doSelectRS ( $c ); - $rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + $rs = TaskPeer::doSelectRS ($c); + $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); // echo $c->toString(); $rs->next (); $row = $rs->getRow (); - while ( is_array ( $row ) ) { + while (is_array ($row)) { $unassignedUsersGroups [] = $row; $rs->next (); $row = $rs->getRow (); @@ -1828,24 +1946,27 @@ class AppSolr { /** * Get the list of dynaform file names associated with the specified process * from database - * @param string $ProUID process identifier + * + * @param string $ProUID + * process identifier * @return array of dynaform file names */ - function getProcessDynaformFileNames($ProUID) { + public function getProcessDynaformFileNames($ProUID) + { $dynaformFileNames = array (); $c = new Criteria (); - $c->addSelectColumn ( DynaformPeer::DYN_FILENAME ); + $c->addSelectColumn (DynaformPeer::DYN_FILENAME); - $c->add ( DynaformPeer::PRO_UID, $ProUID ); + $c->add (DynaformPeer::PRO_UID, $ProUID); - $rs = DynaformPeer::doSelectRS ( $c ); - $rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + $rs = DynaformPeer::doSelectRS ($c); + $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); $rs->next (); $row = $rs->getRow (); - while ( is_array ( $row ) ) { + while (is_array ($row)) { $dynaformFileNames [] = $row; $rs->next (); $row = $rs->getRow (); @@ -1858,67 +1979,76 @@ class AppSolr { * Store a flag indicating if the application was updated in database * table APP_SOLR_QUEUE * - * @param string $AppUid applicatiom identifier + * @param string $AppUid + * applicatiom identifier * @param integer $updated * 0:false, not updated, 1: updated, 2:deleted */ - function applicationChangedUpdateSolrQueue($AppUid, $updated) { + public function applicationChangedUpdateSolrQueue($AppUid, $updated) + { $oAppSolrQueue = new AppSolrQueue (); - $oAppSolrQueue->createUpdate ( $AppUid, $updated ); + $oAppSolrQueue->createUpdate ($AppUid, $updated); } /** - * Update application records in Solr that are stored in APP_SOLR_QUEUE table + * Update application records in Solr that are stored in APP_SOLR_QUEUE table */ - function synchronizePendingApplications() { + public function synchronizePendingApplications() + { // check table of pending updates $oAppSolrQueue = new AppSolrQueue (); $aAppSolrQueue = $oAppSolrQueue->getListUpdatedApplications (); - foreach ( $aAppSolrQueue as $oAppSolrQueueEntity ) { + foreach ($aAppSolrQueue as $oAppSolrQueueEntity) { // call the syncronization function - $this->updateApplicationSearchIndex ( $oAppSolrQueueEntity->appUid ); - $this->applicationChangedUpdateSolrQueue ( $oAppSolrQueueEntity->appUid, 0 ); + $this->updateApplicationSearchIndex ($oAppSolrQueueEntity->appUid); + $this->applicationChangedUpdateSolrQueue ($oAppSolrQueueEntity->appUid, 0); } } /** * Get the total number of application records in database + * * @return application counter */ - function getCountApplicationsPMOS2() { + public function getCountApplicationsPMOS2() + { $c = new Criteria (); - $c->addSelectColumn ( ApplicationPeer::APP_UID ); + $c->addSelectColumn (ApplicationPeer::APP_UID); - $count = ApplicationPeer::doCount ( $c ); + $count = ApplicationPeer::doCount ($c); return $count; } /** * Get a paginated list of application uids from database. - * @param integer $skip the offset from where to return the application records - * @param integer $pagesize the size of the page + * + * @param integer $skip + * the offset from where to return the application records + * @param integer $pagesize + * the size of the page * @return array of application id's in the specified page. */ - function getPagedApplicationUids($skip, $pagesize) { + public function getPagedApplicationUids($skip, $pagesize) + { $c = new Criteria (); - $c->addSelectColumn ( ApplicationPeer::APP_UID ); - $c->setOffset ( $skip ); - $c->setLimit ( $pagesize ); + $c->addSelectColumn (ApplicationPeer::APP_UID); + $c->setOffset ($skip); + $c->setLimit ($pagesize); - $rs = ApplicationPeer::doSelectRS ( $c ); - $rs->setFetchmode ( ResultSet::FETCHMODE_ASSOC ); + $rs = ApplicationPeer::doSelectRS ($c); + $rs->setFetchmode (ResultSet::FETCHMODE_ASSOC); $rs->next (); $row = $rs->getRow (); $appUIds = array (); - while ( is_array ( $row ) ) { + while (is_array ($row)) { $appUIds [] = $row; $rs->next (); $row = $rs->getRow (); @@ -1928,9 +2058,10 @@ class AppSolr { /** * Reindex all the application records in Solr server - * update applications in groups of 1000 + * update applications in groups of 1000 */ - function reindexAllApplications() { + public function reindexAllApplications() + { $trunk = 1000; // delete all documents to begin reindex // deleteAllDocuments(); @@ -1940,22 +2071,22 @@ class AppSolr { $numRows = $this->getCountApplicationsPMOS2 (); print "Total number of records: " . $numRows . "\n"; // - $initTimeAll = microtime ( true ); + $initTimeAll = microtime (true); // $numRows = 15; - for($skip = 0; $skip <= $numRows;) { - $aaAPPUIds = $this->getPagedApplicationUids ( $skip, $trunk ); + for ($skip = 0; $skip <= $numRows;) { + $aaAPPUIds = $this->getPagedApplicationUids ($skip, $trunk); - printf ( "Indexing %d to %d \n", $skip, $skip + $trunk ); - $initTimeDoc = microtime ( true ); - $this->updateApplicationSearchIndex ( $aaAPPUIds ); + printf ("Indexing %d to %d \n", $skip, $skip + $trunk); + $initTimeDoc = microtime (true); + $this->updateApplicationSearchIndex ($aaAPPUIds); - $curTimeDoc = gmdate ( 'H:i:s', (microtime ( true ) - $initTimeDoc) ); - printf ( "Indexing document time: %s \n", $curTimeDoc ); + $curTimeDoc = gmdate ('H:i:s', (microtime (true) - $initTimeDoc)); + printf ("Indexing document time: %s \n", $curTimeDoc); $skip += $trunk; } - $curTimeDoc = gmdate ( 'H:i:s', (microtime ( true ) - $initTimeAll) ); - printf ( "Total reindex time: %s \n", $curTimeDoc ); + $curTimeDoc = gmdate ('H:i:s', (microtime (true) - $initTimeAll)); + printf ("Total reindex time: %s \n", $curTimeDoc); } } diff --git a/workflow/engine/classes/class.searchIndex.php b/workflow/engine/classes/class.searchIndex.php index 255c8632e..a7aa9acaa 100644 --- a/workflow/engine/classes/class.searchIndex.php +++ b/workflow/engine/classes/class.searchIndex.php @@ -1,368 +1,456 @@ -. + * + * For more information, contact Colosa Inc, 5304 Ventura Drive, + * Delray Beach, FL, 33484, USA, or email info@colosa.com. + * + */ + + /** * Class used as interface to have access to the search index services * * @author Herbert Saal Gutierrez * - */ -Class BpmnEngine_Services_SearchIndex -{ - private $solrIsEnabled = false; - private $solrHost = ""; - - function __construct($solrIsEnabled = false, $solrHost = ""){ - //check if Zend Library is available -// if(class_exists("Zend_Registry")){ -// $registry = Zend_Registry::getInstance(); -// //check if configuration is enabled -// $this->solrIsEnabled = $registry->isRegistered('solrEnabled') && $registry->get('solrEnabled') == 1; -// $this->solrHost = $registry->isRegistered('solrHost')?$registry->get('solrHost'):""; -// } -// else{ -// //use the parameters to initialize class - $this->solrIsEnabled = $solrIsEnabled; - $this->solrHost = $solrHost; -// } - } - /** - * Verify if the Solr service is available - * @gearman = false - * @rest = false - * @background = false - * - * no input parameters @param[in] - * @param[out] bool true if index service is enabled false in other case - */ - public function isEnabled() - { - //require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); - require_once ('class.solr.php'); - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - return $solr->isEnabled(); - } - - - /** - * Get the list of facets in base to the specified query and filter - * @gearman = true - * @rest = false - * @background = false - * - * @param[in] Entity_FacetRequest facetRequestEntity Facet request entity - * @param[out] array FacetGroup - */ - function getFacetsList($facetRequestEntity) - { - require_once ('class.solr.php'); - //require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); - require_once ('entities/FacetGroup.php'); - require_once ('entities/FacetItem.php'); - require_once ('entities/SelectedFacetGroupItem.php'); - require_once ('entities/FacetResult.php'); - - /******************************************************************/ - //get array of selected facet groups - $facetRequestEntity->selectedFacetsString = str_replace(',,', ',', $facetRequestEntity->selectedFacetsString); - //remove descriptions of selected facet groups - - $aGroups = explode(',', $facetRequestEntity->selectedFacetsString); - - $aGroups = array_filter($aGroups);//remove empty items - - $aSelectedFacetGroups = array(); - foreach($aGroups as $i => $value) - { - $gi = explode(':::', $value); - $gr = explode('::', $gi[0]); - $it = explode('::', $gi[1]); - - //create string for remove condition - $count = 0; - $removeCondition = str_replace($value . ',', '', $facetRequestEntity->selectedFacetsString, $count); - if($count == 0) - { - $removeCondition = str_replace($value, '', $facetRequestEntity->selectedFacetsString, $count); - } - $selectedFacetGroupData= array( - 'selectedFacetGroupName' => $gr[0], - 'selectedFacetGroupPrintName' => $gr[1], - 'selectedFacetItemName' => $it[0], - 'selectedFacetItemPrintName' => $it[1], - 'selectedFacetRemoveCondition' => $removeCondition - ); - - $aSelectedFacetGroups[] = Entity_SelectedFacetGroupItem::CreateForRequest($selectedFacetGroupData); - } - - /******************************************************************/ - //convert request to index request - //create filters - $filters = array(); - if (!empty($aSelectedFacetGroups)) { - //exclude facetFields and facetDates included in filter from the next list of facets - foreach ($aSelectedFacetGroups as $value) { - $facetRequestEntity->facetFields = array_diff($facetRequestEntity->facetFields, array($value->selectedFacetGroupName)); - $facetRequestEntity->facetDates = array_diff($facetRequestEntity->facetDates, array($value->selectedFacetGroupName)); - } - - //$facetFields = array_diff($facetFields, $facetInterfaceRequestEntity->selectedFacetGroups); - //$facetDates = array_diff($facetDates, $facetInterfaceRequestEntity->selectedFacetGroups); - foreach ($aSelectedFacetGroups as $group) { - $filters[] = $group->selectedFacetGroupName . ':' . urlencode($group->selectedFacetItemName); - } - } - $facetRequestEntity->filters = $filters; - - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - - //create list of facets - $facetsList = $solr->getFacetsList($facetRequestEntity); - - $numFound = $facetsList['response']['numFound']; - - $facetCounts = $facetsList['facet_counts']; - - $facetGroups = array(); - //convert facet fields result to objects - /************************************************************************/ - //include facet field results - $facetFieldsResult = $facetsList['facet_counts']['facet_fields']; - if(!empty($facetFieldsResult)) - { - foreach($facetFieldsResult as $facetGroup => $facetvalues) - { - if(count($facetvalues) > 0) //if the group have facets included - { - $data = array('facetGroupName' => $facetGroup); - $data['facetGroupPrintName'] = $facetGroup; - $data['facetGroupType'] = 'field'; - $facetItems = array(); - for($i = 0; $i < count($facetvalues) ; $i+=2) - { - $dataItem = array(); - $dataItem['facetName'] = $facetvalues[$i]; - $dataItem['facetPrintName'] = $facetvalues[$i]; - $dataItem['facetCount'] = $facetvalues[$i+1]; - $dataItem['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty($facetRequestEntity->selectedFacetsString)?'':',') . $data['facetGroupName'] . '::' . $data['facetGroupPrintName'] .':::' . $dataItem['facetName'] . '::' . $dataItem['facetPrintName']; - $newFacetItem = Entity_FacetItem::CreateForInsert($dataItem); - $facetItems[] =$newFacetItem; - } - $data['facetItems'] = $facetItems; - $newFacetGroup = Entity_FacetGroup::CreateForInsert($data); - - $facetGroups[] = $newFacetGroup; - } - } - } - /************************************************************************/ - //include facet date ranges results - $facetDatesResult = $facetsList['facet_counts']['facet_dates']; - if(!empty($facetDatesResult)) - { - foreach($facetDatesResult as $facetGroup => $facetvalues) - { - if(count($facetvalues) > 3) //if the group have any facets included besides start, end and gap - { - $data = array('facetGroupName' => $facetGroup); - $data['facetGroupPrintName'] = $facetGroup; - $data['facetGroupType'] = 'daterange'; - $facetItems = array(); - $facetvalueskeys = array_keys($facetvalues); - foreach ($facetvalueskeys as $i => $k) - { - if($k != 'gap' && $k != 'start' && $k != 'end') - { - $dataItem = array(); - if($i < count($facetvalueskeys) - 4){ - - $dataItem['facetName'] = '['.$k.'%20TO%20'.$facetvalueskeys[$i+1].']'; - $dataItem['facetPrintName'] = '['.$k.'%20TO%20'.$facetvalueskeys[$i+1].']'; - } - else { - //the last group - $dataItem['facetName'] = '['.$k.'%20TO%20'.$facetvalues['end'].']'; - $dataItem['facetPrintName'] = '['.$k.'%20TO%20'.$facetvalues['end'].']'; - } - - $dataItem['facetCount'] = $facetvalues[$k]; - $dataItem['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty($facetRequestEntity->selectedFacetsString)?'':',') . $data['facetGroupName'] . '::' . $data['facetGroupPrintName'] .':::' . $dataItem['facetName'] . '::' . $dataItem['facetPrintName']; - $newFacetItem = Entity_FacetItem::CreateForInsert($dataItem); - $facetItems[] =$newFacetItem; - } - } - - $data['facetItems'] = $facetItems; - $newFacetGroup = Entity_FacetGroup::CreateForInsert($data); - - $facetGroups[] = $newFacetGroup; - } - } - } - //TODO:convert facet queries - //----- - /******************************************************************/ - //Create a filter string used in the filter of results of a datatable - $filterText = ''; //the list of selected filters used for filtering result, send in ajax - foreach($aSelectedFacetGroups as $selectedFacetGroup) - { - $filterText .= $selectedFacetGroup->selectedFacetGroupName .':'. urlencode($selectedFacetGroup->selectedFacetItemName).','; - } - $filterText = substr_replace($filterText, '', -1); - //$filterText = ($filterText == '')?'':'&filterText='.$filterText; - - /******************************************************************/ - //Create result - $dataFacetResult = array( - 'aFacetGroups' => $facetGroups, - 'aSelectedFacetGroups' => $aSelectedFacetGroups, - 'sFilterText' => $filterText - ); - $facetResult = Entity_FacetResult::CreateForRequest($dataFacetResult); - - return $facetResult; - } - - function getNumberDocuments($workspace){ - require_once ('class.solr.php'); - //require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - - //create list of facets - $numberDocuments = $solr->getNumberDocuments($workspace); - - return $numberDocuments; - } - - function updateIndexDocument($solrUpdateDocumentEntity){ - G::LoadClass('solr'); - - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - - //create list of facets - $solr->updateDocument($solrUpdateDocumentEntity); - } - - function deleteDocumentFromIndex($workspace, $idQuery){ - G::LoadClass('solr'); - - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - - //create list of facets - $solr->deleteDocument($workspace, $idQuery); - } - - function commitIndexChanges($workspace){ - G::LoadClass('solr'); - - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - - //commit - $solr->commitChanges($workspace); - } - - function getDataTablePaginatedList($solrRequestData){ - require_once ('class.solr.php'); - //require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); - require_once ('entities/SolrRequestData.php'); - require_once ('entities/SolrQueryResult.php'); - - //print_r($solrRequestData); - //prepare the list of sorted columns - //verify if the data of sorting is available - if(isset($solrRequestData->sortCols[0])){ - for($i=0; $i<$solrRequestData->numSortingCols; $i++){ - //verify if column is sortable - if($solrRequestData->includeCols[$solrRequestData->sortCols[$i]] != '' && $solrRequestData->sortableCols[$i] == "true"){ - //change sorting column index to column names - $solrRequestData->sortCols[$i] = $solrRequestData->includeCols[$solrRequestData->sortCols[$i]]; - //define the direction of the sorting columns - $solrRequestData->sortDir[$i] = $solrRequestData->sortDir[$i]; - } - } - } - //remove placeholder fields - //the placeholder doesn't affect the the solr's response - //$solrRequestData->includeCols = array_diff($solrRequestData->includeCols, array('')); - - //print_r($solrRequestData); - //execute query - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - $solrPaginatedResult = $solr->executeQuery($solrRequestData); - - //get total number of documents in index - $numTotalDocs = $solr->getNumberDocuments($solrRequestData->workspace); - - //create the Datatable response of the query - $numFound = $solrPaginatedResult['response']['numFound']; - - $docs = $solrPaginatedResult['response']['docs']; - //print_r($docs); - //insert list of names in docs result - $data = array( - "sEcho" => '',//must be completed in response - "iTotalRecords" => intval($numTotalDocs), //we must get the total number of documents - "iTotalDisplayRecords" => $numFound, - "aaData" => array() - ); - //copy result document or add placeholders to result - foreach ($docs as $i => $doc) { - $data['aaData'][$i] = array(); - foreach($solrRequestData->includeCols as $columnName){ - if($columnName == ''){ - $data['aaData'][$i][] = ''; //placeholder - }else{ - if(isset($doc[$columnName])){ - $data['aaData'][$i][] = $doc[$columnName]; - }else{ - $data['aaData'][$i][] = ''; - } - } - } - } - - $solrQueryResponse = Entity_SolrQueryResult::CreateForRequest($data); - // - - return $solrQueryResponse; - } - - function getIndexFields($workspace){ - //global $indexFields; - //cache -// if(!empty($indexFields)) -// return $indexFields; - - require_once ('class.solr.php'); - //require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); - $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - - - //print "SearchIndex!!!!"; - //create list of facets - $solrFieldsData = $solr->getListIndexedStoredFields($workspace); - - //copy list of arrays - $listFields = array(); - foreach($solrFieldsData['fields'] as $key => $fieldData){ - if(array_key_exists('dynamicBase', $fieldData)){ - //remove * - $originalFieldName = substr($key, 0, -strlen($fieldData['dynamicBase'])+1); - //$listFields[strtolower($originalFieldName)] = $key; - //Maintain case sensitive variable names - $listFields[$originalFieldName] = $key; - }else{ - //$listFields[strtolower($key)] = $key; - //Maintain case sensitive variable names - $listFields[$key] = $key; - } - } - - //print_r($listFields); - //$indexFields = $listFields; - - return $listFields; - } - + */ +class BpmnEngine_Services_SearchIndex +{ + private $_solrIsEnabled = false; + private $_solrHost = ""; + + function __construct($solrIsEnabled = false, $solrHost = "") + { + // check if Zend Library is available + // if(class_exists("Zend_Registry")){ + // $registry = Zend_Registry::getInstance(); + // //check if configuration is enabled + // $this->solrIsEnabled = $registry->isRegistered('solrEnabled') && + // $registry->get('solrEnabled') == 1; + // $this->solrHost = + // $registry->isRegistered('solrHost')?$registry->get('solrHost'):""; + // } + // else{ + // //use the parameters to initialize class + $this->_solrIsEnabled = $solrIsEnabled; + $this->_solrHost = $solrHost; + // } + } + /** + * Verify if the Solr service is available + * @gearman = false + * @rest = false + * @background = false + * + * no input parameters @param[in] + * + * @param + * [out] bool true if index service is enabled false in other case + */ + public function isEnabled() + { + // require_once (ROOT_PATH . + // '/businessLogic/modules/SearchIndexAccess/Solr.php'); + require_once ('class.solr.php'); + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + return $solr->isEnabled (); + } + + /** + * Get the list of facets in base to the specified query and filter + * @gearman = true + * @rest = false + * @background = false + * + * @param + * [in] Entity_FacetRequest facetRequestEntity Facet request entity + * @param + * [out] array FacetGroup + */ + public function getFacetsList($facetRequestEntity) + { + require_once ('class.solr.php'); + // require_once (ROOT_PATH . + // '/businessLogic/modules/SearchIndexAccess/Solr.php'); + require_once ('entities/FacetGroup.php'); + require_once ('entities/FacetItem.php'); + require_once ('entities/SelectedFacetGroupItem.php'); + require_once ('entities/FacetResult.php'); + + /** + * *************************************************************** + */ + // get array of selected facet groups + $facetRequestEntity->selectedFacetsString = str_replace (',,', ',', $facetRequestEntity->selectedFacetsString); + // remove descriptions of selected facet groups + + $aGroups = explode (',', $facetRequestEntity->selectedFacetsString); + + $aGroups = array_filter ($aGroups); // remove empty items + + $aSelectedFacetGroups = array (); + foreach ($aGroups as $i => $value) { + $gi = explode (':::', $value); + $gr = explode ('::', $gi [0]); + $it = explode ('::', $gi [1]); + + // create string for remove condition + $count = 0; + $removeCondition = str_replace ($value . ',', '', $facetRequestEntity->selectedFacetsString, $count); + if ($count == 0) { + $removeCondition = str_replace ($value, '', $facetRequestEntity->selectedFacetsString, $count); + } + $selectedFacetGroupData = array ( + 'selectedFacetGroupName' => $gr [0], + 'selectedFacetGroupPrintName' => $gr [1], + 'selectedFacetItemName' => $it [0], + 'selectedFacetItemPrintName' => $it [1], + 'selectedFacetRemoveCondition' => $removeCondition + ); + + $aSelectedFacetGroups [] = Entity_SelectedFacetGroupItem::createForRequest ($selectedFacetGroupData); + } + + /** + * *************************************************************** + */ + // convert request to index request + // create filters + $filters = array (); + if (! empty ($aSelectedFacetGroups)) { + // exclude facetFields and facetDates included in filter from the next + // list of facets + foreach ($aSelectedFacetGroups as $value) { + $facetRequestEntity->facetFields = array_diff ($facetRequestEntity->facetFields, array ( + $value->selectedFacetGroupName + )); + $facetRequestEntity->facetDates = array_diff ($facetRequestEntity->facetDates, array ( + $value->selectedFacetGroupName + )); + } + + // $facetFields = array_diff($facetFields, + // $facetInterfaceRequestEntity->selectedFacetGroups); + // $facetDates = array_diff($facetDates, + // $facetInterfaceRequestEntity->selectedFacetGroups); + foreach ($aSelectedFacetGroups as $group) { + $filters [] = $group->selectedFacetGroupName . ':' . urlencode ($group->selectedFacetItemName); + } + } + $facetRequestEntity->filters = $filters; + + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + + // create list of facets + $facetsList = $solr->getFacetsList ($facetRequestEntity); + + $numFound = $facetsList ['response'] ['numFound']; + + $facetCounts = $facetsList ['facet_counts']; + + $facetGroups = array (); + // convert facet fields result to objects + /** + * ********************************************************************* + */ + // include facet field results + $facetFieldsResult = $facetsList ['facet_counts'] ['facet_fields']; + if (! empty ($facetFieldsResult)) { + foreach ($facetFieldsResult as $facetGroup => $facetvalues) { + if (count ($facetvalues) > 0) // if the group have facets included + { + $data = array ( + 'facetGroupName' => $facetGroup + ); + $data ['facetGroupPrintName'] = $facetGroup; + $data ['facetGroupType'] = 'field'; + $facetItems = array (); + for ($i = 0; $i < count ($facetvalues); $i += 2) { + $dataItem = array (); + $dataItem ['facetName'] = $facetvalues [$i]; + $dataItem ['facetPrintName'] = $facetvalues [$i]; + $dataItem ['facetCount'] = $facetvalues [$i + 1]; + $dataItem ['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty ($facetRequestEntity->selectedFacetsString) ? '' : ',') . $data ['facetGroupName'] . '::' . $data ['facetGroupPrintName'] . ':::' . $dataItem ['facetName'] . '::' . $dataItem ['facetPrintName']; + $newFacetItem = Entity_FacetItem::createForInsert ($dataItem); + $facetItems [] = $newFacetItem; + } + $data ['facetItems'] = $facetItems; + $newFacetGroup = Entity_FacetGroup::createForInsert ($data); + + $facetGroups [] = $newFacetGroup; + } + } + } + /** + * ********************************************************************* + */ + // include facet date ranges results + $facetDatesResult = $facetsList ['facet_counts'] ['facet_dates']; + if (! empty ($facetDatesResult)) { + foreach ($facetDatesResult as $facetGroup => $facetvalues) { + if (count ($facetvalues) > 3) // if the group have any facets included + // besides start, end and gap + { + $data = array ( + 'facetGroupName' => $facetGroup + ); + $data ['facetGroupPrintName'] = $facetGroup; + $data ['facetGroupType'] = 'daterange'; + $facetItems = array (); + $facetvalueskeys = array_keys ($facetvalues); + foreach ($facetvalueskeys as $i => $k) { + if ($k != 'gap' && $k != 'start' && $k != 'end') { + $dataItem = array (); + if ($i < count ($facetvalueskeys) - 4) { + + $dataItem ['facetName'] = '[' . $k . '%20TO%20' . $facetvalueskeys [$i + 1] . ']'; + $dataItem ['facetPrintName'] = '[' . $k . '%20TO%20' . $facetvalueskeys [$i + 1] . ']'; + } + else { + // the last group + $dataItem ['facetName'] = '[' . $k . '%20TO%20' . $facetvalues ['end'] . ']'; + $dataItem ['facetPrintName'] = '[' . $k . '%20TO%20' . $facetvalues ['end'] . ']'; + } + + $dataItem ['facetCount'] = $facetvalues [$k]; + $dataItem ['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty ($facetRequestEntity->selectedFacetsString) ? '' : ',') . $data ['facetGroupName'] . '::' . $data ['facetGroupPrintName'] . ':::' . $dataItem ['facetName'] . '::' . $dataItem ['facetPrintName']; + $newFacetItem = Entity_FacetItem::createForInsert ($dataItem); + $facetItems [] = $newFacetItem; + } + } + + $data ['facetItems'] = $facetItems; + $newFacetGroup = Entity_FacetGroup::createForInsert ($data); + + $facetGroups [] = $newFacetGroup; + } + } + } + // TODO:convert facet queries + // ----- + /** + * *************************************************************** + */ + // Create a filter string used in the filter of results of a datatable + $filterText = ''; // the list of selected filters used for filtering result, + // send in ajax + foreach ($aSelectedFacetGroups as $selectedFacetGroup) { + $filterText .= $selectedFacetGroup->selectedFacetGroupName . ':' . urlencode ($selectedFacetGroup->selectedFacetItemName) . ','; + } + $filterText = substr_replace ($filterText, '', - 1); + // $filterText = ($filterText == '')?'':'&filterText='.$filterText; + + /** + * *************************************************************** + */ + // Create result + $dataFacetResult = array ( + 'aFacetGroups' => $facetGroups, + 'aSelectedFacetGroups' => $aSelectedFacetGroups, + 'sFilterText' => $filterText + ); + $facetResult = Entity_FacetResult::createForRequest ($dataFacetResult); + + return $facetResult; + } + + /** + * Get the total number of documents in search server + * @param string $workspace + * @return integer number of documents + * + */ + public function getNumberDocuments($workspace) + { + require_once ('class.solr.php'); + // require_once (ROOT_PATH . + // '/businessLogic/modules/SearchIndexAccess/Solr.php'); + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + + // create list of facets + $numberDocuments = $solr->getNumberDocuments ($workspace); + + return $numberDocuments; + } + + /** + * Update document Index + * @param SolrUpdateDocumentEntity $solrUpdateDocumentEntity + */ + public function updateIndexDocument($solrUpdateDocumentEntity) + { + G::LoadClass ('solr'); + + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + + // create list of facets + $solr->updateDocument ($solrUpdateDocumentEntity); + } + + /** + * Delete document from index + * @param string $workspace + * @param string $idQuery + */ + public function deleteDocumentFromIndex($workspace, $idQuery) + { + G::LoadClass ('solr'); + + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + + // create list of facets + $solr->deleteDocument ($workspace, $idQuery); + } + + /** + * Commit index changes + * @param string $workspace + */ + public function commitIndexChanges($workspace) + { + G::LoadClass ('solr'); + + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + + // commit + $solr->commitChanges ($workspace); + } + + /** + * Call Solr server to return the list of paginated pages. + * @param FacetRequest $solrRequestData + * @return Entity_SolrQueryResult + */ + public function getDataTablePaginatedList($solrRequestData) + { + require_once ('class.solr.php'); + // require_once (ROOT_PATH . + // '/businessLogic/modules/SearchIndexAccess/Solr.php'); + require_once ('entities/SolrRequestData.php'); + require_once ('entities/SolrQueryResult.php'); + + // print_r($solrRequestData); + // prepare the list of sorted columns + // verify if the data of sorting is available + if (isset ($solrRequestData->sortCols [0])) { + for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { + // verify if column is sortable + if ($solrRequestData->includeCols [$solrRequestData->sortCols [$i]] != '' && $solrRequestData->sortableCols [$i] == "true") { + // change sorting column index to column names + $solrRequestData->sortCols [$i] = $solrRequestData->includeCols [$solrRequestData->sortCols [$i]]; + // define the direction of the sorting columns + $solrRequestData->sortDir [$i] = $solrRequestData->sortDir [$i]; + } + } + } + // remove placeholder fields + // the placeholder doesn't affect the the solr's response + // $solrRequestData->includeCols = array_diff($solrRequestData->includeCols, + // array('')); + + // print_r($solrRequestData); + // execute query + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + $solrPaginatedResult = $solr->executeQuery ($solrRequestData); + + // get total number of documents in index + $numTotalDocs = $solr->getNumberDocuments ($solrRequestData->workspace); + + // create the Datatable response of the query + $numFound = $solrPaginatedResult ['response'] ['numFound']; + + $docs = $solrPaginatedResult ['response'] ['docs']; + // print_r($docs); + // insert list of names in docs result + $data = array ( + "sEcho" => '', // must be completed in response + "iTotalRecords" => intval ($numTotalDocs), // we must get the + // total number of + // documents + "iTotalDisplayRecords" => $numFound, + "aaData" => array () + ); + // copy result document or add placeholders to result + foreach ($docs as $i => $doc) { + $data ['aaData'] [$i] = array (); + foreach ($solrRequestData->includeCols as $columnName) { + if ($columnName == '') { + $data ['aaData'] [$i] [] = ''; // placeholder + } + else { + if (isset ($doc [$columnName])) { + $data ['aaData'] [$i] [] = $doc [$columnName]; + } + else { + $data ['aaData'] [$i] [] = ''; + } + } + } + } + + $solrQueryResponse = Entity_SolrQueryResult::createForRequest ($data); + // + + return $solrQueryResponse; + } + + /** + * Return the list of stored fields in the index. + * @param string $workspace + * @return array of index fields + */ + public function getIndexFields($workspace) + { + // global $indexFields; + // cache + // if(!empty($indexFields)) + // return $indexFields; + + require_once ('class.solr.php'); + // require_once (ROOT_PATH . + // '/businessLogic/modules/SearchIndexAccess/Solr.php'); + $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost); + + // print "SearchIndex!!!!"; + // create list of facets + $solrFieldsData = $solr->getListIndexedStoredFields ($workspace); + + // copy list of arrays + $listFields = array (); + foreach ($solrFieldsData ['fields'] as $key => $fieldData) { + if (array_key_exists ('dynamicBase', $fieldData)) { + // remove * + $originalFieldName = substr ($key, 0, - strlen ($fieldData ['dynamicBase']) + 1); + // $listFields[strtolower($originalFieldName)] = $key; + // Maintain case sensitive variable names + $listFields [$originalFieldName] = $key; + } + else { + // $listFields[strtolower($key)] = $key; + // Maintain case sensitive variable names + $listFields [$key] = $key; + } + } + + // print_r($listFields); + // $indexFields = $listFields; + + return $listFields; + } + } \ No newline at end of file diff --git a/workflow/engine/classes/class.solr.php b/workflow/engine/classes/class.solr.php index c9dfa8745..bf0ed2755 100644 --- a/workflow/engine/classes/class.solr.php +++ b/workflow/engine/classes/class.solr.php @@ -1,19 +1,44 @@ . + * + * For more information, contact Colosa Inc, 5304 Ventura Drive, + * Delray Beach, FL, 33484, USA, or email info@colosa.com. + * + */ + /** * Interface to the Solr Search server * @author Herbert Saal Gutierrez * */ -class BpmnEngine_SearchIndexAccess_Solr { +class BpmnEngine_SearchIndexAccess_Solr +{ const SOLR_VERSION = '&version=2.2'; - private $solrIsEnabled = false; - private $solrHost = ""; + private $_solrIsEnabled = false; + private $_solrHost = ""; - function __construct($solrIsEnabled = false, $solrHost = "") { + public function __construct($solrIsEnabled = false, $solrHost = "") + { // use the parameters to initialize class - $this->solrIsEnabled = $solrIsEnabled; - $this->solrHost = $solrHost; + $this->_solrIsEnabled = $solrIsEnabled; + $this->_solrHost = $solrHost; } /** @@ -21,13 +46,14 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return bool */ - function isEnabled() { + public function isEnabled() + { // verify solr server response - return $this->solrIsEnabled; + return $this->_solrIsEnabled; } /** @@ -35,32 +61,33 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @param * workspace: workspace name * @return total */ - function getNumberDocuments($workspace) { - if (! $this->solrIsEnabled) + public function getNumberDocuments($workspace) + { + if (! $this->_solrIsEnabled) return; // get configuration information in base to workspace parameter // get total number of documents in registry - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/select/?q=*:*"; $solrIntruct .= self::SOLR_VERSION; $solrIntruct .= "&start=0&rows=0&echoParams=none&wt=json"; - $handlerTotal = curl_init ( $solrIntruct ); - curl_setopt ( $handlerTotal, CURLOPT_RETURNTRANSFER, true ); - $responseTotal = curl_exec ( $handlerTotal ); - curl_close ( $handlerTotal ); + $handlerTotal = curl_init ($solrIntruct); + curl_setopt ($handlerTotal, CURLOPT_RETURNTRANSFER, true); + $responseTotal = curl_exec ($handlerTotal); + curl_close ($handlerTotal); // verify the result of solr - $responseSolrTotal = json_decode ( $responseTotal, true ); - if ($responseSolrTotal['responseHeader']['status'] != 0) { - throw new Exception ( "Error returning the total number of documents in Solr." . $solrIntruct); + $responseSolrTotal = G::json_decode ($responseTotal, true); + if ($responseSolrTotal ['responseHeader'] ['status'] != 0) { + throw new Exception ("Error returning the total number of documents in Solr." . $solrIntruct); } $numTotalDocs = $responseSolrTotal ['response'] ['numFound']; return $numTotalDocs; @@ -71,43 +98,44 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function executeQuery($solrRequestData) { - if (! $this->solrIsEnabled) + public function executeQuery($solrRequestData) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; // get configuration information in base to workspace parameter $workspace = $solrRequestData->workspace; // format request - $query = empty ( $solrRequestData->searchText ) ? '*:*' : $solrRequestData->searchText; - $query = rawurlencode ( $query ); + $query = empty ($solrRequestData->searchText) ? '*:*' : $solrRequestData->searchText; + $query = rawurlencode ($query); $start = '&start=' . $solrRequestData->startAfter; $rows = '&rows=' . $solrRequestData->pageSize; $fieldList = ''; $cols = $solrRequestData->includeCols; - if (! empty ( $cols )) { - $fieldList = "&fl=" . implode ( ",", $cols ); + if (! empty ($cols)) { + $fieldList = "&fl=" . implode (",", $cols); } $sort = ''; if ($solrRequestData->numSortingCols > 0) { $sort = '&sort='; - for($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { + for ($i = 0; $i < $solrRequestData->numSortingCols; $i ++) { $sort .= $solrRequestData->sortCols [$i] . "%20" . $solrRequestData->sortDir [$i] . ","; } - $sort = substr_replace ( $sort, "", - 1 ); + $sort = substr_replace ($sort, "", - 1); } - $resultFormat = empty ( $solrRequestData->resultFormat ) ? '' : '&wt=' . $solrRequestData->resultFormat; + $resultFormat = empty ($solrRequestData->resultFormat) ? '' : '&wt=' . $solrRequestData->resultFormat; $filters = ''; - $aFilters = explode ( ',', $solrRequestData->filterText ); - foreach ( $aFilters as $value ) { - $filters .= '&fq=' . urlencode ( $value ); + $aFilters = explode (',', $solrRequestData->filterText); + foreach ($aFilters as $value) { + $filters .= '&fq=' . urlencode ($value); } - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/select/?q=$query"; $solrIntruct .= "&echoParams=none"; @@ -120,15 +148,15 @@ class BpmnEngine_SearchIndexAccess_Solr { $solrIntruct .= $resultFormat; // send query // search the cases in base to datatable parameters - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - $response = curl_exec ( $handler ); - curl_close ( $handler ); - + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec ($handler); + curl_close ($handler); + // decode - $responseSolr = json_decode ( $response, true ); - if ($responseSolr['responseHeader']['status'] != 0) { - throw new Exception ( "Error executing query to Solr." . $solrIntruct); + $responseSolr = G::json_decode ($response, true); + if ($responseSolr ['responseHeader'] ['status'] != 0) { + throw new Exception ("Error executing query to Solr." . $solrIntruct); } return $responseSolr; @@ -139,31 +167,32 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function updateDocument($solrUpdateDocument) { - if (! $this->solrIsEnabled) + public function updateDocument($solrUpdateDocument) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $solrUpdateDocument->workspace; $solrIntruct .= "/update"; - - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( - 'Content-type:application/xml' - ) ); // -H - curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary - curl_setopt ( $handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document ); // data - $response = curl_exec ( $handler ); - curl_close ( $handler ); - $swOk = strpos ( $response, '0' ); + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( + 'Content-type:application/xml' + )); // -H + curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary + curl_setopt ($handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document); // data + $response = curl_exec ($handler); + curl_close ($handler); + + $swOk = strpos ($response, '0'); if (! $swOk) { - throw new Exception ( "Error updating document in Solr." . $solrIntruct); + throw new Exception ("Error updating document in Solr." . $solrIntruct); } } @@ -172,31 +201,32 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function commitChanges($workspace) { - if (! $this->solrIsEnabled) + public function commitChanges($workspace) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( 'Content-type:application/xml' - ) ); // -H - curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary - curl_setopt ( $handler, CURLOPT_POSTFIELDS, "" ); // data - $response = curl_exec ( $handler ); - curl_close ( $handler ); + )); // -H + curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary + curl_setopt ($handler, CURLOPT_POSTFIELDS, ""); // data + $response = curl_exec ($handler); + curl_close ($handler); - $swOk = strpos ( $response, '0' ); + $swOk = strpos ($response, '0'); if (! $swOk) { - throw new Exception ( "Error commiting changes in Solr." . $solrIntruct); + throw new Exception ("Error commiting changes in Solr." . $solrIntruct); } } @@ -205,32 +235,33 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function rollbackChanges($workspace) { - if (! $this->solrIsEnabled) + public function rollbackChanges($workspace) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( 'Content-type:application/xml' - ) ); // -H - curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary - curl_setopt ( $handler, CURLOPT_POSTFIELDS, "" ); // data - $response = curl_exec ( $handler ); - curl_close ( $handler ); + )); // -H + curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary + curl_setopt ($handler, CURLOPT_POSTFIELDS, ""); // data + $response = curl_exec ($handler); + curl_close ($handler); - $swOk = strpos ( $response, '0' ); + $swOk = strpos ($response, '0'); if (! $swOk) { - throw new Exception ( "Error rolling back changes in Solr." . $solrIntruct); + throw new Exception ("Error rolling back changes in Solr." . $solrIntruct); } } @@ -239,59 +270,63 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function optimizeChanges($workspace) { - if (! $this->solrIsEnabled) + public function optimizeChanges($workspace) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( 'Content-type:application/xml' - ) ); // -H - curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary - curl_setopt ( $handler, CURLOPT_POSTFIELDS, "" ); // data - $response = curl_exec ( $handler ); - curl_close ( $handler ); + )); // -H + curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary + curl_setopt ($handler, CURLOPT_POSTFIELDS, ""); // data + $response = curl_exec ($handler); + curl_close ($handler); - $swOk = strpos ( $response, '0' ); + $swOk = strpos ($response, '0'); if (! $swOk) { - throw new Exception ( "Error optimizing changes in Solr." . $solrIntruct); + throw new Exception ("Error optimizing changes in Solr." . $solrIntruct); } } /** - * Return the list of the stored fields in Solr - * @param string $workspace Solr instance name + * Return the list of the stored fields in Solr + * + * @param string $workspace + * Solr instance name * @throws Exception - * @return void|mixed array of field names + * @return void mixed of field names */ - function getListIndexedStoredFields($workspace) { - if (! $this->solrIsEnabled) + public function getListIndexedStoredFields($workspace) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/admin/luke?numTerms=0&wt=json"; - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - $response = curl_exec ( $handler ); - curl_close ( $handler ); + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + $response = curl_exec ($handler); + curl_close ($handler); // decode - $responseSolr = json_decode ( $response, true ); - if ($responseSolr['responseHeader']['status'] != 0) { - throw new Exception ( "Error getting index fields in Solr." . $solrIntruct); + $responseSolr = G::json_decode ($response, true); + if ($responseSolr ['responseHeader'] ['status'] != 0) { + throw new Exception ("Error getting index fields in Solr." . $solrIntruct); } return $responseSolr; } @@ -301,34 +336,35 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function deleteAllDocuments($workspace) { - if (! $this->solrIsEnabled) + public function deleteAllDocuments($workspace) + { + if (! $this->_solrIsEnabled) return; // $registry = Zend_Registry::getInstance(); $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( 'Content-type:application/xml' - ) ); // -H - curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary - curl_setopt ( $handler, CURLOPT_POSTFIELDS, "*:*" ); // data - $response = curl_exec ( $handler ); + )); // -H + curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary + curl_setopt ($handler, CURLOPT_POSTFIELDS, "*:*"); // data + $response = curl_exec ($handler); - curl_close ( $handler ); + curl_close ($handler); - $swOk = strpos ( $response, '0' ); + $swOk = strpos ($response, '0'); if (! $swOk) { - throw new Exception ( "Error deleting all documents in Solr." . $solrIntruct); + throw new Exception ("Error deleting all documents in Solr." . $solrIntruct); } } @@ -337,45 +373,47 @@ class BpmnEngine_SearchIndexAccess_Solr { * @gearman = false * @rest = false * @background = false - * + * * @return solr response */ - function deleteDocument($workspace, $idQuery) { - if (! $this->solrIsEnabled) + public function deleteDocument($workspace, $idQuery) + { + if (! $this->_solrIsEnabled) return; // $registry = Zend_Registry::getInstance(); $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; + $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; - $handler = curl_init ( $solrIntruct ); - curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); - curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( + $handler = curl_init ($solrIntruct); + curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt ($handler, CURLOPT_HTTPHEADER, array ( 'Content-type:application/xml' - ) ); // -H - curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary - curl_setopt ( $handler, CURLOPT_POSTFIELDS, "" . $idQuery . "" ); // data - $response = curl_exec ( $handler ); + )); // -H + curl_setopt ($handler, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary + curl_setopt ($handler, CURLOPT_POSTFIELDS, "" . $idQuery . ""); // data + $response = curl_exec ($handler); - curl_close ( $handler ); + curl_close ($handler); - $swOk = strpos ( $response, '0' ); + $swOk = strpos ($response, '0'); if (! $swOk) { - throw new Exception ( "Error deleting document in Solr." . $solrIntruct); + throw new Exception ("Error deleting document in Solr." . $solrIntruct); } } /** * Execute a query in base to Request data - * + * * @param Entity_FacetRequest $facetRequestEntity * @return solr response: list of facets array */ - function getFacetsList($facetRequest) { - if (! $this->solrIsEnabled) + public function getFacetsList($facetRequest) + { + if (! $this->_solrIsEnabled) return; $solrIntruct = ''; @@ -383,22 +421,22 @@ class BpmnEngine_SearchIndexAccess_Solr { $workspace = $facetRequest->workspace; // format request - $query = empty ( $facetRequest->searchText ) ? '*:*' : $facetRequest->searchText; - $query = rawurlencode ( $query ); + $query = empty ($facetRequest->searchText) ? '*:*' : $facetRequest->searchText; + $query = rawurlencode ($query); $start = '&start=0'; $rows = '&rows=0'; $facets = '&facet=on&facet.mincount=1&facet.limit=20'; // enable facet and // only return facets // with minimun one // instance - foreach ( $facetRequest->facetFields as $value ) { + foreach ($facetRequest->facetFields as $value) { $facets .= '&facet.field=' . $value; } - foreach ( $facetRequest->facetQueries as $value ) { + foreach ($facetRequest->facetQueries as $value) { $facets .= '&facet.query=' . $value; } - if (! empty ( $facetRequest->facetDates )) { - foreach ( $facetRequest->facetDates as $value ) { + if (! empty ($facetRequest->facetDates)) { + foreach ($facetRequest->facetDates as $value) { $facets .= '&facet.date=' . $value; } $facets .= '&facet.date.start=' . $facetRequest->facetDatesStart; @@ -406,14 +444,14 @@ class BpmnEngine_SearchIndexAccess_Solr { $facets .= '&facet.date.gap=' . $facetRequest->facetDateGap; } $filters = ''; - foreach ( $facetRequest->filters as $value ) { + foreach ($facetRequest->filters as $value) { $filters .= '&fq=' . $value; } // echo "
";
     
     $resultFormat = '&wt=json';
     
-    $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/";
+    $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
     $solrIntruct .= $workspace;
     $solrIntruct .= "/select/?q=$query";
     $solrIntruct .= "&echoParams=none";
@@ -426,15 +464,15 @@ class BpmnEngine_SearchIndexAccess_Solr {
     
     // send query
     // search the cases in base to datatable parameters
-    $handler = curl_init ( $solrIntruct );
-    curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true );
-    $response = curl_exec ( $handler );
-    curl_close ( $handler );
+    $handler = curl_init ($solrIntruct);
+    curl_setopt ($handler, CURLOPT_RETURNTRANSFER, true);
+    $response = curl_exec ($handler);
+    curl_close ($handler);
     
     // decode
-    $responseSolr = json_decode ( $response, true );
-    if ($responseSolr['responseHeader']['status'] != 0) {
-      throw new Exception ( "Error getting faceted list from Solr." . $solrIntruct);
+    $responseSolr = G::json_decode ($response, true);
+    if ($responseSolr ['responseHeader'] ['status'] != 0) {
+      throw new Exception ("Error getting faceted list from Solr." . $solrIntruct);
     }
     
     return $responseSolr;
diff --git a/workflow/engine/classes/entities/AppSolrQueue.php b/workflow/engine/classes/entities/AppSolrQueue.php
index 089babac9..fbccce566 100644
--- a/workflow/engine/classes/entities/AppSolrQueue.php
+++ b/workflow/engine/classes/entities/AppSolrQueue.php
@@ -4,30 +4,34 @@ require_once ('Base.php');
 /**
  * Application Solr Queue
  */
-class Entity_AppSolrQueue extends Entity_Base {
+class Entity_AppSolrQueue extends Entity_Base
+{
   public $appUid = '';
   public $appUpdated = 0;
   
-  private function __construct() {
+  private function __construct()
+  {
   
   }
   
-  static function CreateEmpty() {
+  static function createEmpty()
+  {
     $obj = new Entity_AppSolrQueue ();
     return $obj;
   }
   
-  static function CreateForRequest($data) {
+  static function createForRequest($data)
+  {
     $obj = new Entity_AppSolrQueue ();
     
-    $obj->initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "appUid",
         "appUpdated" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/Base.php b/workflow/engine/classes/entities/Base.php
index 39046d3ef..5aa927469 100644
--- a/workflow/engine/classes/entities/Base.php
+++ b/workflow/engine/classes/entities/Base.php
@@ -1,17 +1,19 @@
  $f ) {
-      if (isset ( $this->temp [$f] )) {
+    foreach ($fields as $k => $f) {
+      if (isset ($this->temp [$f])) {
         $fieldIsEmpty = false;
         return $this->temp [$f];
       }
@@ -37,16 +39,18 @@ class Entity_Base {
     }
   }
   
-  protected function validateRequiredFields($requiredFields = array()) {
-    foreach ( $requiredFields as $k => $field ) {
+  protected function validateRequiredFields($requiredFields = array())
+  {
+    foreach ($requiredFields as $k => $field) {
       if ($this->{$field} === NULL) {
-        throw (new Exception ( "Field $field is required in " . get_class ( $this ) ));
+        throw (new Exception ("Field $field is required in " . get_class ($this)));
         die ();
       }
     }
   }
   
   /**
+   *
    *
    *
    * Copy the values of the Entity to the array of aliases
@@ -54,15 +58,19 @@ class Entity_Base {
    *
    * @return Array of alias with the Entity values
    */
-  public function getAliasDataArray() {
+  public function getAliasDataArray()
+  {
     $aAlias = array ();
     // get aliases from class
-    $className = get_class ( $this );
-    if (method_exists ( $className, 'GetAliases' )) {
-      $aliases = call_user_func(array($className, 'GetAliases'));
-      //$aliases = $className::GetAliases ();
-      foreach ( $this as $field => $value )
-        if (isset ( $aliases [$field] )) {
+    $className = get_class ($this);
+    if (method_exists ($className, 'GetAliases')) {
+      $aliases = call_user_func (array (
+          $className,
+          'GetAliases' 
+      ));
+      // $aliases = $className::GetAliases ();
+      foreach ($this as $field => $value)
+        if (isset ($aliases [$field])) {
           // echo "Field exists in Aliases: " . $field . "\n";
           // echo "Alias Name:" . $aliases[$field] . "\n";
           // echo "Alias value:" . $value . "\n";
@@ -74,6 +82,7 @@ class Entity_Base {
   }
   
   /**
+   *
    *
    *
    * Set the data from array of alias to Entity
@@ -81,57 +90,68 @@ class Entity_Base {
    * @param $aAliasData array
    *          of data of aliases
    */
-  public function setAliasDataArray($aAliasData) {
+  public function setAliasDataArray($aAliasData)
+  {
     // get aliases from class
-    $className = get_class ( $this );
-    if (method_exists ( $className, 'GetAliases' )) {
-      $aliases = call_user_func(array($className, 'GetAliases'));
-      //$aliases = $className::GetAliases ();
-      foreach ( $this as $field => $value )
-        if (isset ( $aliases [$field] ))
+    $className = get_class ($this);
+    if (method_exists ($className, 'GetAliases')) {
+      $aliases = call_user_func (array (
+          $className,
+          'GetAliases' 
+      ));
+      // $aliases = $className::GetAliases ();
+      foreach ($this as $field => $value)
+        if (isset ($aliases [$field]))
           $this->{$field} = $aAliasData [$aliases [$field]];
     }
   }
   
   /**
+   *
    *
    *
    * Initialize object with values from $data.
    * The values from data use properties or alias array.
-   * 
+   *
    * @param
    *          $data
    */
-  protected function initializeObject($data) {
+  protected function initializeObject($data)
+  {
     // get aliases from class
-    $className = get_class ( $this );
+    $className = get_class ($this);
     $aliases = array ();
     $swAliases = false;
-    if (method_exists ( $className, 'GetAliases' )) {
-      $aliases = call_user_func(array($className, 'GetAliases'));
-      //$aliases = $className::GetAliases ();
+    if (method_exists ($className, 'GetAliases')) {
+      $aliases = call_user_func (array (
+          $className,
+          'GetAliases' 
+      ));
+      // $aliases = $className::GetAliases ();
       $swAliases = true;
     }
     // use object properties or aliases to initialize
-    foreach ( $this as $field => $value )
-      if (isset ( $data [$field] )) {
+    foreach ($this as $field => $value)
+      if (isset ($data [$field])) {
         $this->$field = $data [$field];
       }
-      elseif ($swAliases && isset ( $aliases [$field] ) && isset ( $data [$aliases [$field]] )) {
+      elseif ($swAliases && isset ($aliases [$field]) && isset ($data [$aliases [$field]])) {
         $this->$field = $data [$aliases [$field]];
       }
   }
   
-  public function serialize() {
-    if (isset ( $this->temp ))
-      unset ( $this->temp );
-    return serialize ( $this );
+  public function serialize()
+  {
+    if (isset ($this->temp))
+      unset ($this->temp);
+    return serialize ($this);
   }
   
-  public function unserialize($str) {
-    $className = get_class ( $this );
-    $data = unserialize ( $str );
-    return new $className ( $data );
+  public function unserialize($str)
+  {
+    $className = get_class ($this);
+    $data = unserialize ($str);
+    return new $className ($data);
   }
 
 }
\ No newline at end of file
diff --git a/workflow/engine/classes/entities/FacetGroup.php b/workflow/engine/classes/entities/FacetGroup.php
index 1b9b16f3b..4e3302d8d 100644
--- a/workflow/engine/classes/entities/FacetGroup.php
+++ b/workflow/engine/classes/entities/FacetGroup.php
@@ -2,10 +2,8 @@
 require_once ('Base.php');
 
 /**
- *
- *
  * Facet group entity that represent a facet group
- * 
+ *
  * @property $facetGroupName: The name of the facet (field name in solr index)
  * @property $facetGroupPrintName: The print name of the facet (Human readable
  *           description)
@@ -16,32 +14,36 @@ require_once ('Base.php');
  * @author dev-HebertSaak
  *        
  */
-class Entity_FacetGroup extends Entity_Base {
+class Entity_FacetGroup extends Entity_Base
+{
   public $facetGroupName = '';
   public $facetGroupPrintName = '';
   public $facetGroupType = ''; // field, daterange, query
   public $facetGroupId = '';
   public $facetItems = array ();
   
-  private function __construct() {
+  private function __construct()
+  {
   }
   
-  static function CreateEmpty() {
+  static function createEmpty()
+  {
     $obj = new Entity_FacetGroup ();
     return $obj;
   }
   
-  static function CreateForInsert($data) {
+  static function createForInsert($data)
+  {
     $obj = new Entity_FacetGroup ();
     
-    $obj->initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "facetGroupName",
         "facetItems" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/FacetInterfaceRequest.php b/workflow/engine/classes/entities/FacetInterfaceRequest.php
index 72b9f8a45..2b074a2a5 100644
--- a/workflow/engine/classes/entities/FacetInterfaceRequest.php
+++ b/workflow/engine/classes/entities/FacetInterfaceRequest.php
@@ -1,34 +1,38 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "searchText",
         "selectedFacetsString" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/FacetInterfaceResult.php b/workflow/engine/classes/entities/FacetInterfaceResult.php
index 37a12b76a..600581321 100644
--- a/workflow/engine/classes/entities/FacetInterfaceResult.php
+++ b/workflow/engine/classes/entities/FacetInterfaceResult.php
@@ -1,25 +1,29 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "aFacetGroup",
@@ -27,7 +31,7 @@ class Entity_FacetInterfaceResult extends Entity_Base {
         "sFilterText" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/FacetItem.php b/workflow/engine/classes/entities/FacetItem.php
index ae07719af..f710af459 100644
--- a/workflow/engine/classes/entities/FacetItem.php
+++ b/workflow/engine/classes/entities/FacetItem.php
@@ -2,39 +2,44 @@
 require_once ('Base.php');
 
 /**
+ *
  *
  *
  * Entity Face item, represent an option in a facet group
- * 
+ *
  * @author dev-HebertSaak
  *        
  */
-class Entity_FacetItem extends Entity_Base {
+class Entity_FacetItem extends Entity_Base
+{
   public $facetName = '';
   public $facetPrintName = '';
   public $facetCount = '';
   public $facetSelectCondition = ''; // selected condition used to select
-                                        // this facet
+                                     // this facet
   
-  private function __construct() {
+  private function __construct()
+  {
   }
   
-  static function CreateEmpty() {
+  static function createEmpty()
+  {
     $obj = new Entity_FacetItem ();
     return $obj;
   }
   
-  static function CreateForInsert($data) {
+  static function createForInsert($data)
+  {
     $obj = new Entity_FacetItem ();
     
-    $obj->initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "facetName",
         "facetCount" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/FacetRequest.php b/workflow/engine/classes/entities/FacetRequest.php
index 6c5d5b067..cfd82ed40 100644
--- a/workflow/engine/classes/entities/FacetRequest.php
+++ b/workflow/engine/classes/entities/FacetRequest.php
@@ -1,7 +1,8 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "workspace" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/FacetResult.php b/workflow/engine/classes/entities/FacetResult.php
index e50a0d66f..c115a6220 100644
--- a/workflow/engine/classes/entities/FacetResult.php
+++ b/workflow/engine/classes/entities/FacetResult.php
@@ -1,23 +1,27 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "aFacetGroups",
@@ -25,7 +29,7 @@ class Entity_FacetResult extends Entity_Base {
         "sFilterText" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/SelectedFacetGroupItem.php b/workflow/engine/classes/entities/SelectedFacetGroupItem.php
index f90cea42b..364ca2d74 100644
--- a/workflow/engine/classes/entities/SelectedFacetGroupItem.php
+++ b/workflow/engine/classes/entities/SelectedFacetGroupItem.php
@@ -1,34 +1,38 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "selectedFacetGroupName",
         "selectedFacetItemName" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/SolrQueryResult.php b/workflow/engine/classes/entities/SolrQueryResult.php
index 1ce33edb8..7be7246b5 100644
--- a/workflow/engine/classes/entities/SolrQueryResult.php
+++ b/workflow/engine/classes/entities/SolrQueryResult.php
@@ -1,25 +1,29 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         'sEcho',
@@ -28,7 +32,7 @@ class Entity_SolrQueryResult extends Entity_Base {
         'aaData' 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/SolrRequestData.php b/workflow/engine/classes/entities/SolrRequestData.php
index 84e66c0cc..931afbea4 100644
--- a/workflow/engine/classes/entities/SolrRequestData.php
+++ b/workflow/engine/classes/entities/SolrRequestData.php
@@ -1,7 +1,8 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         'workspace' 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/entities/SolrUpdateDocument.php b/workflow/engine/classes/entities/SolrUpdateDocument.php
index 6c32c5c38..6ce732516 100644
--- a/workflow/engine/classes/entities/SolrUpdateDocument.php
+++ b/workflow/engine/classes/entities/SolrUpdateDocument.php
@@ -1,29 +1,33 @@
 initializeObject ( $data );
+    $obj->initializeObject ($data);
     
     $requiredFields = array (
         "workspace",
         "document" 
     );
     
-    $obj->validateRequiredFields ( $requiredFields );
+    $obj->validateRequiredFields ($requiredFields);
     
     return $obj;
   }
diff --git a/workflow/engine/classes/model/AppSolrQueue.php b/workflow/engine/classes/model/AppSolrQueue.php
index 8d045c279..f8d0445fd 100644
--- a/workflow/engine/classes/model/AppSolrQueue.php
+++ b/workflow/engine/classes/model/AppSolrQueue.php
@@ -109,7 +109,7 @@ class AppSolrQueue extends BaseAppSolrQueue {
             $row = $rs->getRow();
             
             while (is_array($row)) {
-                $appSolrQueue = Entity_AppSolrQueue::CreateEmpty();
+                $appSolrQueue = Entity_AppSolrQueue::createEmpty();
                 $appSolrQueue->appUid = $row['APP_UID'];
                 $appSolrQueue->appUpdated = $row['APP_UPDATED'];
                 $updatedApplications[] = $appSolrQueue;