Files
luos/workflow/engine/classes/model/AppThread.php

139 lines
4.7 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
/**
* AppThread.php
2011-01-31 14:14:55 +00:00
* @package workflow.engine.classes.model
2012-10-22 05:57:53 -04:00
*
2010-12-02 23:34:41 +00:00
* ProcessMaker Open Source Edition
2011-01-31 14:14:55 +00:00
* Copyright (C) 2004 - 2011 Colosa Inc.
2012-10-22 05:57:53 -04:00
*
2010-12-02 23:34:41 +00:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2012-10-22 05:57:53 -04:00
*
2010-12-02 23:34:41 +00:00
* 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/>.
2012-10-22 05:57:53 -04:00
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
2010-12-02 23:34:41 +00:00
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
2012-10-22 05:57:53 -04:00
*
2010-12-02 23:34:41 +00:00
*/
//require_once 'classes/model/om/BaseAppThread.php';
2010-12-02 23:34:41 +00:00
/**
* Skeleton subclass for representing a row from the 'APP_THREAD' table.
*
2012-10-22 05:57:53 -04:00
*
2010-12-02 23:34:41 +00:00
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
2011-01-31 14:14:55 +00:00
* @package workflow.engine.classes.model
2010-12-02 23:34:41 +00:00
*/
2012-10-22 05:57:53 -04:00
class AppThread extends BaseAppThread
{
public function createAppThread ($sAppUid, $iDelIndex, $iParent)
{
if (!isset($sAppUid) || strlen($sAppUid ) == 0 ) {
throw ( new Exception ( 'Column "APP_UID" cannot be null.' ) );
}
2010-12-02 23:34:41 +00:00
2012-10-22 05:57:53 -04:00
if (!isset($iDelIndex) || strlen($iDelIndex ) == 0 ) {
throw ( new Exception ( 'Column "DEL_INDEX" cannot be null.' ) );
}
2010-12-02 23:34:41 +00:00
2012-10-22 05:57:53 -04:00
if (!isset($iParent) || strlen($iDelIndex ) == 0 ) {
throw ( new Exception ( 'Column "APP_THREAD_INDEX" cannot be null.' ) );
}
2010-12-02 23:34:41 +00:00
2012-10-22 05:57:53 -04:00
$c = new Criteria ();
$c->clearSelectColumns();
$c->addSelectColumn ( 'MAX(' . AppThreadPeer::APP_THREAD_INDEX . ') ' );
$c->add ( AppThreadPeer::APP_UID, $sAppUid );
$rs = AppThreadPeer::doSelectRS ( $c );
$rs->next();
$row = $rs->getRow();
$iAppThreadIndex = $row[0] + 1;
2010-12-02 23:34:41 +00:00
2012-10-22 05:57:53 -04:00
$this->setAppUid ( $sAppUid );
$this->setAppThreadIndex ( $iAppThreadIndex );
$this->setAppThreadParent ( $iParent );
$this->setAppThreadStatus ( 'OPEN' );
$this->setDelIndex ( $iDelIndex );
2010-12-02 23:34:41 +00:00
2012-10-22 05:57:53 -04:00
if ($this->validate() ) {
try {
$res = $this->save();
} catch ( PropelException $e ) {
throw ( $e );
}
} else {
// Something went wrong. We can now get the validationFailures and handle them.
$msg = '';
$validationFailuresArray = $this->getValidationFailures();
foreach ($validationFailuresArray as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage();
}
throw ( new Exception ( 'Failed Data validation. ' . $msg ) );
}
return $iAppThreadIndex;
2010-12-02 23:34:41 +00:00
}
2012-10-22 05:57:53 -04:00
public function update($aData)
{
$con = Propel::getConnection( AppThreadPeer::DATABASE_NAME );
try {
$con->begin();
$oApp = AppThreadPeer::retrieveByPK( $aData['APP_UID'], $aData['APP_THREAD_INDEX'] );
if (is_object($oApp) && get_class ($oApp) == 'AppThread' ) {
$oApp->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
if ($oApp->validate()) {
$res = $oApp->save();
$con->commit();
return $res;
} else {
$msg = '';
foreach ($this->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "<br/>";
}
throw ( new PropelException ( 'The AppThread row cannot be created!', new PropelException ( $msg ) ) );
}
} else {
$con->rollback();
throw(new Exception( "This AppThread row doesn't exist!" ));
}
} catch (Exception $oError) {
throw($oError);
2010-12-02 23:34:41 +00:00
}
}
2016-08-11 10:42:29 -04:00
2018-04-20 08:57:55 -04:00
/**
* Count the open threads
*
* @param string $appUid
* @param string $status
*
* @return integer
*/
public static function countStatus($appUid, $status = 'OPEN')
{
2016-08-11 10:42:29 -04:00
$c = new Criteria('workflow');
$c->clearSelectColumns();
2018-04-20 08:57:55 -04:00
$c->addSelectColumn(AppThreadPeer::APP_THREAD_PARENT);
$c->add(AppThreadPeer::APP_UID, $appUid);
$c->add(AppThreadPeer::APP_THREAD_STATUS, $status);
2016-08-11 10:42:29 -04:00
$cant = AppThreadPeer::doCount($c);
2018-04-20 08:57:55 -04:00
2016-08-11 10:42:29 -04:00
return $cant;
}
2012-10-22 05:57:53 -04:00
}
2010-12-02 23:34:41 +00:00