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

329 lines
13 KiB
PHP
Raw Normal View History

2014-11-07 17:19:35 -04:00
<?php
require_once 'classes/model/om/BaseListParticipatedLast.php';
/**
* Skeleton subclass for representing a row from the 'LIST_PARTICIPATED_LAST' table.
*
*
2014-11-07 17:19:35 -04: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.
*
* @package classes.model
2015-03-02 11:10:40 -04:00
*/
2015-03-02 11:15:23 -04:00
2014-11-07 17:19:35 -04:00
class ListParticipatedLast extends BaseListParticipatedLast
{
/**
* Create List Participated History Table
*
* @param type $data
* @return type
*
*/
public function create($data)
{
2015-02-06 14:57:59 -04:00
$criteria = new Criteria();
$criteria->addSelectColumn(ApplicationPeer::APP_STATUS);
$criteria->add( ApplicationPeer::APP_UID, $data['APP_UID'], Criteria::EQUAL );
$dataset = UsersPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
$aRow = $dataset->getRow();
$data['APP_STATUS'] = $aRow['APP_STATUS'];
if ($data['USR_UID'] != 'SELF_SERVICES') {
if($data['USR_UID'] != ''){
$criteria = new Criteria();
$criteria->addSelectColumn(UsersPeer::USR_USERNAME);
$criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
$criteria->addSelectColumn(UsersPeer::USR_LASTNAME);
$criteria->add( UsersPeer::USR_UID, $data['USR_UID'], Criteria::EQUAL );
$dataset = UsersPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
$aRow = $dataset->getRow();
$data['DEL_CURRENT_USR_USERNAME'] = $aRow['USR_USERNAME'];
$data['DEL_CURRENT_USR_FIRSTNAME'] = $aRow['USR_FIRSTNAME'];
$data['DEL_CURRENT_USR_LASTNAME'] = $aRow['USR_LASTNAME'];
$users = new Users();
$users->refreshTotal($data['USR_UID'], 'add', 'participated');
}
}
2015-03-09 08:53:46 -04:00
$con = Propel::getConnection( ListParticipatedLastPeer::DATABASE_NAME );
2014-11-07 17:19:35 -04:00
try {
$this->fromArray( $data, BasePeer::TYPE_FIELDNAME );
if ($this->validate()) {
$result = $this->save();
} else {
$e = new Exception( "Failed Validation in class " . get_class( $this ) . "." );
$e->aValidationFailures = $this->getValidationFailures();
throw ($e);
}
$con->commit();
return $result;
} catch(Exception $e) {
$con->rollback();
throw ($e);
}
}
/**
* Update List Participated History Table
*
* @param type $data
* @return type
* @throws type
*/
public function update($data)
{
2015-02-27 16:27:11 -04:00
$data['DEL_THREAD_STATUS'] = (isset($data['DEL_THREAD_STATUS'])) ? $data['DEL_THREAD_STATUS'] : 'OPEN';
2014-11-07 17:19:35 -04:00
$con = Propel::getConnection( ListParticipatedLastPeer::DATABASE_NAME );
try {
$con->begin();
$this->setNew( false );
$this->fromArray( $data, BasePeer::TYPE_FIELDNAME );
if ($this->validate()) {
$result = $this->save();
$con->commit();
return $result;
} else {
$con->rollback();
throw (new Exception( "Failed Validation in class " . get_class( $this ) . "." ));
}
} catch (Exception $e) {
$con->rollback();
throw ($e);
}
}
2015-02-27 16:27:11 -04:00
/**
* Refresh List Participated Last
*
* @param type $seqName
* @return type
* @throws type
*
*/
public function refresh ($data, $isSelfService = false)
{
2015-02-27 16:27:11 -04:00
$data['APP_STATUS'] = (empty($data['APP_STATUS'])) ? 'TO_DO' : $data['APP_STATUS'];
if (!$isSelfService) {
if ($data["USR_UID"] == "") {
return;
}
$criteria = new Criteria();
$criteria->addSelectColumn(UsersPeer::USR_USERNAME);
$criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
$criteria->addSelectColumn(UsersPeer::USR_LASTNAME);
$criteria->add( UsersPeer::USR_UID, $data['USR_UID'], Criteria::EQUAL );
$dataset = UsersPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
$aRow = $dataset->getRow();
//Update - WHERE
$criteriaWhere = new Criteria("workflow");
$criteriaWhere->add(ListParticipatedLastPeer::APP_UID, $data["APP_UID"], Criteria::EQUAL);
//Update - SET
$criteriaSet = new Criteria("workflow");
$criteriaSet->add(ListParticipatedLastPeer::DEL_CURRENT_USR_USERNAME, $aRow['USR_USERNAME']);
$criteriaSet->add(ListParticipatedLastPeer::DEL_CURRENT_USR_FIRSTNAME, $aRow['USR_FIRSTNAME']);
$criteriaSet->add(ListParticipatedLastPeer::DEL_CURRENT_USR_LASTNAME, $aRow['USR_LASTNAME']);
BasePeer::doUpdate($criteriaWhere, $criteriaSet, Propel::getConnection("workflow"));
}
$this->update($data);
2015-02-27 16:27:11 -04:00
}
2014-11-07 17:19:35 -04:00
/**
* Remove List Participated History
*
* @param type $seqName
* @return type
* @throws type
*
*/
public function remove ($app_uid, $usr_uid, $del_index)
2014-11-07 17:19:35 -04:00
{
try {
$flagDelete = false;
2014-11-07 17:19:35 -04:00
if (!is_null(ListParticipatedLastPeer::retrieveByPK($app_uid, $usr_uid, $del_index))) {
$criteria = new Criteria("workflow");
$criteria->add(ListParticipatedLastPeer::APP_UID, $app_uid);
$criteria->add(ListParticipatedLastPeer::USR_UID, $usr_uid);
$criteria->add(ListParticipatedLastPeer::DEL_INDEX, $del_index);
$result = ListParticipatedLastPeer::doDelete($criteria);
$flagDelete = true;
} else {
$criteria = new Criteria("workflow");
$criteria->add(ListParticipatedLastPeer::APP_UID, $app_uid);
$criteria->add(ListParticipatedLastPeer::USR_UID, $usr_uid);
$rsCriteria = ListParticipatedLastPeer::doSelectRS($criteria);
if ($rsCriteria->next()) {
$criteria2 = clone $criteria;
$result = ListParticipatedLastPeer::doDelete($criteria2);
$flagDelete = true;
}
}
if ($flagDelete) {
$user = new Users();
$user->refreshTotal($usr_uid, "removed", "participated");
}
2014-11-07 17:19:35 -04:00
} catch (Exception $e) {
throw $e;
2014-11-07 17:19:35 -04:00
}
}
public function loadFilters (&$criteria, $filters)
{
$filter = isset($filters['filter']) ? $filters['filter'] : "";
$search = isset($filters['search']) ? $filters['search'] : "";
$process = isset($filters['process']) ? $filters['process'] : "";
$category = isset($filters['category']) ? $filters['category'] : "";
$dateFrom = isset($filters['dateFrom']) ? $filters['dateFrom'] : "";
$dateTo = isset($filters['dateTo']) ? $filters['dateTo'] : "";
if ($filter != '') {
switch ($filter) {
case 'read':
$criteria->add( ListParticipatedLastPeer::DEL_INIT_DATE, null, Criteria::ISNOTNULL );
break;
case 'unread':
$criteria->add( ListParticipatedLastPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
break;
}
}
if ($search != '') {
$criteria->add(
2015-02-27 16:27:11 -04:00
$criteria->getNewCriterion( ListParticipatedLastPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE )->
addOr( $criteria->getNewCriterion( ListParticipatedLastPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE )->
2014-11-07 17:19:35 -04:00
addOr( $criteria->getNewCriterion( ListParticipatedLastPeer::APP_NUMBER, $search, Criteria::LIKE ) ) ) );
}
if ($process != '') {
$criteria->add( ListParticipatedLastPeer::PRO_UID, $process, Criteria::EQUAL);
}
if ($category != '') {
// INNER JOIN FOR TAS_TITLE
$criteria->addSelectColumn(ProcessPeer::PRO_CATEGORY);
$aConditions = array();
$aConditions[] = array(ListParticipatedLastPeer::PRO_UID, ProcessPeer::PRO_UID);
$aConditions[] = array(ProcessPeer::PRO_CATEGORY, "'" . $category . "'");
$criteria->addJoinMC($aConditions, Criteria::INNER_JOIN);
}
if ($dateFrom != "") {
if ($dateTo != "") {
if ($dateFrom == $dateTo) {
$dateSame = $dateFrom;
$dateFrom = $dateSame . " 00:00:00";
$dateTo = $dateSame . " 23:59:59";
} else {
$dateFrom = $dateFrom . " 00:00:00";
$dateTo = $dateTo . " 23:59:59";
}
$criteria->add( $criteria->getNewCriterion( ListParticipatedLastPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL )->
addAnd( $criteria->getNewCriterion( ListParticipatedLastPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL ) ) );
} else {
$dateFrom = $dateFrom . " 00:00:00";
$criteria->add( ListParticipatedLastPeer::DEL_DELEGATE_DATE, $dateFrom, Criteria::GREATER_EQUAL );
}
} elseif ($dateTo != "") {
$dateTo = $dateTo . " 23:59:59";
$criteria->add( ListParticipatedLastPeer::DEL_DELEGATE_DATE, $dateTo, Criteria::LESS_EQUAL );
}
}
public function countTotal ($usr_uid, $filters = array())
{
$criteria = new Criteria();
$criteria->add( ListParticipatedLastPeer::USR_UID, $usr_uid, Criteria::EQUAL );
self::loadFilters($criteria, $filters);
$total = ListParticipatedLastPeer::doCount( $criteria );
return (int)$total;
}
public function loadList($usr_uid, $filters = array(), $callbackRecord = null)
2014-11-07 17:19:35 -04:00
{
$criteria = new Criteria();
$criteria->addSelectColumn(ListParticipatedLastPeer::APP_UID);
2015-02-27 16:27:11 -04:00
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_INDEX);
2014-11-07 17:19:35 -04:00
$criteria->addSelectColumn(ListParticipatedLastPeer::USR_UID);
$criteria->addSelectColumn(ListParticipatedLastPeer::TAS_UID);
$criteria->addSelectColumn(ListParticipatedLastPeer::PRO_UID);
$criteria->addSelectColumn(ListParticipatedLastPeer::APP_NUMBER);
$criteria->addSelectColumn(ListParticipatedLastPeer::APP_TITLE);
$criteria->addSelectColumn(ListParticipatedLastPeer::APP_PRO_TITLE);
$criteria->addSelectColumn(ListParticipatedLastPeer::APP_TAS_TITLE);
$criteria->addSelectColumn(ListParticipatedLastPeer::APP_STATUS);
2014-11-07 17:19:35 -04:00
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_PREVIOUS_USR_UID);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_PREVIOUS_USR_USERNAME);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_PREVIOUS_USR_FIRSTNAME);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_PREVIOUS_USR_LASTNAME);
2015-02-06 14:57:59 -04:00
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_CURRENT_USR_USERNAME);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_CURRENT_USR_FIRSTNAME);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_CURRENT_USR_LASTNAME);
2014-11-07 17:19:35 -04:00
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_DELEGATE_DATE);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_INIT_DATE);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_DUE_DATE);
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_PRIORITY);
2015-02-27 16:27:11 -04:00
$criteria->addSelectColumn(ListParticipatedLastPeer::DEL_THREAD_STATUS);
2014-11-07 17:19:35 -04:00
$criteria->add( ListParticipatedLastPeer::USR_UID, $usr_uid, Criteria::EQUAL );
self::loadFilters($criteria, $filters);
$sort = (!empty($filters['sort'])) ? $filters['sort'] : "DEL_DELEGATE_DATE";
$dir = isset($filters['dir']) ? $filters['dir'] : "ASC";
$start = isset($filters['start']) ? $filters['start'] : "0";
$limit = isset($filters['limit']) ? $filters['limit'] : "25";
$paged = isset($filters['paged']) ? $filters['paged'] : 1;
if ($dir == "DESC") {
$criteria->addDescendingOrderByColumn($sort);
} else {
$criteria->addAscendingOrderByColumn($sort);
}
if ($paged == 1) {
$criteria->setLimit( $limit );
$criteria->setOffset( $start );
}
$dataset = ListParticipatedLastPeer::doSelectRS($criteria, Propel::getDbConnection('workflow_ro') );
2014-11-07 17:19:35 -04:00
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$data = array();
$aPriorities = array ('1' => 'VL','2' => 'L','3' => 'N','4' => 'H','5' => 'VH');
while ($dataset->next()) {
$aRow = (is_null($callbackRecord))? $dataset->getRow() : $callbackRecord($dataset->getRow());
2014-11-07 17:19:35 -04:00
$aRow['DEL_PRIORITY'] = G::LoadTranslation( "ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}" );
$data[] = $aRow;
}
return $data;
}
}