CODE STYLE class.sessions.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 13:22:53 -04:00
parent b5a9522b6c
commit f11a2fdd93

View File

@@ -1,6 +1,7 @@
<?php <?php
/** /**
* class.Sessions.php * class.Sessions.php
*
* @package workflow.engine.ProcessMaker * @package workflow.engine.ProcessMaker
* *
* ProcessMaker Open Source Edition * ProcessMaker Open Source Edition
@@ -13,246 +14,248 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* For more information, contact Colosa Inc, 2566 Le Jeune Rd., * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
* *
*/ */
require_once 'classes/model/Session.php'; require_once 'classes/model/Session.php';
/** /**
* Sessions - Sessions class * Sessions - Sessions class
*
* @package workflow.engine.ProcessMaker * @package workflow.engine.ProcessMaker
* @author Everth S. Berrios Morales * @author Everth S. Berrios Morales
* @copyright 2008 COLOSA * @copyright 2008 COLOSA
*/ */
class Sessions { class Sessions
{
protected $tmpfile; protected $tmpfile;
private $sessionId; private $sessionId;
private $globals; private $globals;
/** /**
* This function is the constructor of the Sessions class * This function is the constructor of the Sessions class
* @param string $sSessionId *
* @return void * @param string $sSessionId
*/ * @return void
public function __construct($sSessionId=NULL){ */
$this->sessionId = $sSessionId; public function __construct ($sSessionId = NULL)
} {
$this->sessionId = $sSessionId;
/**
* This function gets the user session
*
*
* @name getSessionUser
*
* @param string sSessionId
* @return array
*/
public function getSessionUser($sSessionId=NULL)
{
try
{
if($sSessionId != NULL){
$this->sessionId = $sSessionId;
} else if($this->sessionId == NULL){
throw new Exception('session id was not set.');
} }
$oCriteria = new Criteria('workflow'); /**
$oCriteria->addSelectColumn(SessionPeer::USR_UID); * This function gets the user session
$oCriteria->addSelectColumn(SessionPeer::SES_STATUS); *
$oCriteria->addSelectColumn(SessionPeer::SES_DUE_DATE); *
$oCriteria->add(SessionPeer::SES_UID, $this->sessionId); * @name getSessionUser
*
* @param string sSessionId
* @return array
*/
public function getSessionUser ($sSessionId = NULL)
{
try {
if ($sSessionId != NULL) {
$this->sessionId = $sSessionId;
} else if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$oDataset = SessionPeer::doSelectRS($oCriteria); $oCriteria = new Criteria( 'workflow' );
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oCriteria->addSelectColumn( SessionPeer::USR_UID );
$oDataset->next(); $oCriteria->addSelectColumn( SessionPeer::SES_STATUS );
$aRow = $oDataset->getRow(); $oCriteria->addSelectColumn( SessionPeer::SES_DUE_DATE );
$oCriteria->add( SessionPeer::SES_UID, $this->sessionId );
if( !is_array($aRow) ){ $oDataset = SessionPeer::doSelectRS( $oCriteria );
$this->deleteTmpfile(); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
$aRow = $oDataset->getRow();
if (! is_array( $aRow )) {
$this->deleteTmpfile();
}
return $aRow;
} catch (Exception $oError) {
throw ($oError);
}
} }
return $aRow;
/**
* This function checks the user session
*
*
* @name verifySession
*
* @param string sSessionId
* @return array
*/
public function verifySession ($sSessionId = NULL)
{
try {
if ($sSessionId != NULL) {
$this->sessionId = $sSessionId;
} else if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$date = date( 'Y-m-d H:i:s' );
$oCriteria = new Criteria( 'workflow' );
$oCriteria->addSelectColumn( SessionPeer::USR_UID );
$oCriteria->addSelectColumn( SessionPeer::SES_STATUS );
$oCriteria->addSelectColumn( SessionPeer::SES_DUE_DATE );
$oCriteria->add( SessionPeer::SES_UID, $this->sessionId );
$oCriteria->add( SessionPeer::SES_STATUS, 'ACTIVE' );
$oCriteria->add( SessionPeer::SES_DUE_DATE, $date, Criteria::GREATER_EQUAL );
$oDataset = SessionPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
$aRow = $oDataset->getRow();
if (! is_array( $aRow )) {
$this->deleteTmpfile();
}
return $aRow;
} catch (Exception $oError) {
throw ($oError);
}
} }
catch (Exception $oError) {
throw($oError); /**
* This function registers into globals variables
*
*
* @name registerGlobal
*
* @param string $name
* @param string $value
* @return void
*/
public function registerGlobal ($name, $value)
{
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if ($this->sessionId == NULL) {
throw new Exception( 'session id was not set.' );
}
$tmpfile_content = '';
if (is_file( $this->tmpfile ) && trim( file_get_contents( $this->tmpfile ) ) != '') {
$tmpfile_content = file_get_contents( $this->tmpfile );
}
//getting the global array
if ($tmpfile_content != '') {
$this->globals = unserialize( $tmpfile_content );
} else {
$this->globals = Array ();
}
//registering the new global variable
$this->globals[$name] = $value;
//saving the global array
$tmpfile_content = serialize( $this->globals );
file_put_contents( $this->tmpfile, $tmpfile_content );
} }
}
/** /**
* This function checks the user session * This function gets a global variable
* *
* *
* @name verifySession * @name getGlobal
* *
* @param string sSessionId * @param string $name
* @return array * @return string
*/ */
public function verifySession($sSessionId=NULL) public function getGlobal ($name)
{ {
try $this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
{
if($sSessionId != NULL){
$this->sessionId = $sSessionId;
} else if($this->sessionId == NULL){
throw new Exception('session id was not set.');
}
$date=date('Y-m-d H:i:s'); if ($this->sessionId == NULL) {
$oCriteria = new Criteria('workflow'); throw new Exception( 'session id was not set.' );
$oCriteria->addSelectColumn(SessionPeer::USR_UID); }
$oCriteria->addSelectColumn(SessionPeer::SES_STATUS);
$oCriteria->addSelectColumn(SessionPeer::SES_DUE_DATE);
$oCriteria->add(SessionPeer::SES_UID, $this->sessionId);
$oCriteria->add(SessionPeer::SES_STATUS, 'ACTIVE');
$oCriteria->add(SessionPeer::SES_DUE_DATE, $date, Criteria::GREATER_EQUAL);
$oDataset = SessionPeer::doSelectRS($oCriteria); $tmpfile_content = '';
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); if (is_file( $this->tmpfile ) && trim( file_get_contents( $this->tmpfile ) ) != '') {
$oDataset->next(); $tmpfile_content = file_get_contents( $this->tmpfile );
$aRow = $oDataset->getRow(); }
if( !is_array($aRow) ){ //getting the global array
$this->deleteTmpfile(); if ($tmpfile_content != '') {
} $this->globals = unserialize( $tmpfile_content );
} else {
$this->globals = Array ();
}
return $aRow; //getting the new global variable
} if (isset( $this->globals[$name] )) {
catch (Exception $oError) { return $this->globals[$name];
throw($oError); } else {
} return '';
} }
}
/**
* This function registers into globals variables /**
* * This function gets all globals variables
* *
* @name registerGlobal *
* * @name getGlobals
* @param string $name *
* @param string $value * @param string $name
* @return void * @return array
*/ */
public function registerGlobal($name, $value) public function getGlobals ()
{ {
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}"; $this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if($this->sessionId == NULL){ if ($this->sessionId == NULL) {
throw new Exception('session id was not set.'); throw new Exception( 'session id was not set.' );
} }
$tmpfile_content = ''; $tmpfile_content = '';
if( is_file($this->tmpfile) && trim(file_get_contents($this->tmpfile)) != '' ) { if (is_file( $this->tmpfile ) && trim( file_get_contents( $this->tmpfile ) ) != '') {
$tmpfile_content = file_get_contents($this->tmpfile); $tmpfile_content = file_get_contents( $this->tmpfile );
} }
//getting the global array //getting the global array
if( $tmpfile_content != ''){ if ($tmpfile_content != '') {
$this->globals = unserialize($tmpfile_content); $this->globals = unserialize( $tmpfile_content );
} else { } else {
$this->globals = Array(); $this->globals = Array ();
} }
return $this->globals;
//registering the new global variable }
$this->globals[$name] = $value;
/**
//saving the global array * This function removes a temporal file
$tmpfile_content = serialize($this->globals); *
file_put_contents($this->tmpfile, $tmpfile_content); *
* @name deleteTmpfile
} *
* param
/** * @return void
* This function gets a global variable */
* private function deleteTmpfile ()
* {
* @name getGlobal if ($this->sessionId == NULL) {
* throw new Exception( 'session id was not set.' );
* @param string $name }
* @return string $this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
*/ @unlink( $this->tmpfile );
public function getGlobal($name)
{
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if($this->sessionId == NULL){
throw new Exception('session id was not set.');
}
$tmpfile_content = '';
if( is_file($this->tmpfile) && trim(file_get_contents($this->tmpfile)) != '' ) {
$tmpfile_content = file_get_contents($this->tmpfile);
}
//getting the global array
if( $tmpfile_content != ''){
$this->globals = unserialize($tmpfile_content);
} else {
$this->globals = Array();
}
//getting the new global variable
if( isset($this->globals[$name]) ){
return $this->globals[$name];
} else {
return '';
}
}
/**
* This function gets all globals variables
*
*
* @name getGlobals
*
* @param string $name
* @return array
*/
public function getGlobals()
{
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
if($this->sessionId == NULL){
throw new Exception('session id was not set.');
}
$tmpfile_content = '';
if( is_file($this->tmpfile) && trim(file_get_contents($this->tmpfile)) != '' ) {
$tmpfile_content = file_get_contents($this->tmpfile);
}
//getting the global array
if( $tmpfile_content != ''){
$this->globals = unserialize($tmpfile_content);
} else {
$this->globals = Array();
}
return $this->globals;
}
/**
* This function removes a temporal file
*
*
* @name deleteTmpfile
*
* param
* @return void
*/
private function deleteTmpfile(){
if($this->sessionId == NULL){
throw new Exception('session id was not set.');
} }
$this->tmpfile = G::sys_get_temp_dir() . PATH_SEP . "pm-rg-{$this->sessionId}";
@unlink($this->tmpfile);
}
} }