2016-04-01 16:43:37 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once 'classes/model/om/BaseAppSequence.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'APP_SEQUENCE' table.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
|
|
|
|
* application requirements. This class will only be generated as
|
|
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
|
*
|
|
|
|
|
* @package classes.model
|
|
|
|
|
*/
|
|
|
|
|
class AppSequence extends BaseAppSequence {
|
|
|
|
|
|
2020-10-26 22:14:48 +00:00
|
|
|
const APP_TYPE_NORMAL = 'NORMAL';
|
|
|
|
|
const APP_TYPE_WEB_ENTRY = 'WEB_ENTRY';
|
|
|
|
|
|
2016-04-01 16:43:37 -04:00
|
|
|
/**
|
|
|
|
|
* Get an Set new sequence number
|
|
|
|
|
*
|
2020-10-26 22:14:48 +00:00
|
|
|
* @param string $sequenceType
|
2016-04-01 16:43:37 -04:00
|
|
|
* @return mixed
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2020-10-26 22:14:48 +00:00
|
|
|
public function sequenceNumber($sequenceType)
|
2016-04-01 16:43:37 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$con = Propel::getConnection('workflow');
|
|
|
|
|
$stmt = $con->createStatement();
|
2020-10-26 22:14:48 +00:00
|
|
|
$sql = "UPDATE APP_SEQUENCE SET ID=LAST_INSERT_ID(ID+1) WHERE APP_TYPE = '{$sequenceType}'";
|
2016-04-01 16:43:37 -04:00
|
|
|
$stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$sql = "SELECT LAST_INSERT_ID()";
|
|
|
|
|
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$result = $row['LAST_INSERT_ID()'];
|
2020-10-26 22:14:48 +00:00
|
|
|
|
|
|
|
|
// If the type is WEB_ENTRY, we need to change to negative
|
|
|
|
|
if ($sequenceType === 'WEB_ENTRY') {
|
|
|
|
|
$result *= -1;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
2016-04-01 16:43:37 -04:00
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update sequence number
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function updateSequenceNumber($number)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$con = Propel::getConnection('workflow');
|
|
|
|
|
$stmt = $con->createStatement();
|
2016-04-05 16:00:49 -04:00
|
|
|
$c = new Criteria();
|
|
|
|
|
$rs = AppSequencePeer::doSelectRS($c);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
if ($row) {
|
|
|
|
|
$sql = "UPDATE APP_SEQUENCE SET ID=LAST_INSERT_ID('$number')";
|
|
|
|
|
} else {
|
|
|
|
|
$sql = "INSERT INTO APP_SEQUENCE (ID) VALUES ('$number');";
|
|
|
|
|
}
|
2016-04-01 16:43:37 -04:00
|
|
|
$stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // AppSequence
|