Files
luos/workflow/engine/src/BusinessModel/Cases.php

138 lines
4.7 KiB
PHP
Raw Normal View History

2014-03-14 15:33:35 -04:00
<?php
namespace BusinessModel;
use \G;
use \UsersPeer;
use \CasesPeer;
/**
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*/
class Cases
{
/**
* Get list for Cases
*
* @access public
* @param array $dataList, Data for list
* @return array
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*/
public function getList($dataList = array())
{
2014-03-17 15:13:34 -04:00
Validator::isArray($dataList, '$dataList');
if (!isset($dataList["userId"])) {
throw (new \Exception("The user with userId: '' does not exist."));
} else {
Validator::usrUid($dataList["userId"], "userId");
}
2014-03-14 15:33:35 -04:00
2014-03-17 15:13:34 -04:00
G::LoadClass("applications");
2014-03-14 15:33:35 -04:00
$solrEnabled = false;
$userUid = $dataList["userId"];
$callback = isset( $dataList["callback"] ) ? $dataList["callback"] : "stcCallback1001";
$dir = isset( $dataList["dir"] ) ? $dataList["dir"] : "DESC";
$sort = isset( $dataList["sort"] ) ? $dataList["sort"] : "APP_CACHE_VIEW.APP_NUMBER";
$start = isset( $dataList["start"] ) ? $dataList["start"] : "0";
$limit = isset( $dataList["limit"] ) ? $dataList["limit"] : "25";
$filter = isset( $dataList["filter"] ) ? $dataList["filter"] : "";
$process = isset( $dataList["process"] ) ? $dataList["process"] : "";
$category = isset( $dataList["category"] ) ? $dataList["category"] : "";
$status = isset( $dataList["status"] ) ? strtoupper( $dataList["status"] ) : "";
$user = isset( $dataList["user"] ) ? $dataList["user"] : "";
$search = isset( $dataList["search"] ) ? $dataList["search"] : "";
$action = isset( $dataList["action"] ) ? $dataList["action"] : "todo";
$type = "extjs";
$dateFrom = isset( $dataList["dateFrom"] ) ? substr( $dataList["dateFrom"], 0, 10 ) : "";
$dateTo = isset( $dataList["dateTo"] ) ? substr( $dataList["dateTo"], 0, 10 ) : "";
$first = isset( $dataList["first"] ) ? true :false;
2014-03-17 15:13:34 -04:00
$valuesCorrect = array('todo', 'draft', 'paused', 'sent', 'selfservice', 'unassigned', 'search');
if (!in_array($action, $valuesCorrect)) {
throw (new \Exception('The value for $action is incorrect.'));
}
2014-03-14 15:33:35 -04:00
if ($action == 'search' || $action == 'to_reassign') {
$userUid = ($user == "CURRENT_USER") ? $userUid : $user;
if ($first) {
$result = array();
$result['totalCount'] = 0;
$result['data'] = array();
return $result;
}
}
if ((
$action == "todo" || $action == "draft" || $action == "paused" || $action == "sent" ||
$action == "selfservice" || $action == "unassigned" || $action == "search"
) &&
(($solrConf = \System::solrEnv()) !== false)
) {
G::LoadClass("AppSolr");
$ApplicationSolrIndex = new \AppSolr(
$solrConf["solr_enabled"],
$solrConf["solr_host"],
$solrConf["solr_instance"]
);
if ($ApplicationSolrIndex->isSolrEnabled() && $solrConf['solr_enabled'] == true) {
//Check if there are missing records to reindex and reindex them
$ApplicationSolrIndex->synchronizePendingApplications();
$solrEnabled = true;
}
}
if ($solrEnabled) {
$result = $ApplicationSolrIndex->getAppGridData(
$userUid,
$start,
$limit,
$action,
$filter,
$search,
$process,
$status,
$type,
$dateFrom,
$dateTo,
$callback,
$dir,
$sort,
$category
);
} else {
G::LoadClass("applications");
$apps = new \Applications();
$result = $apps->getAll(
$userUid,
$start,
$limit,
$action,
$filter,
$search,
$process,
$status,
$type,
$dateFrom,
$dateTo,
$callback,
$dir,
(strpos($sort, ".") !== false)? $sort : "APP_CACHE_VIEW." . $sort,
$category
);
}
if (!empty($result['data'])) {
foreach ($result['data'] as &$value) {
$value = array_change_key_case($value, CASE_LOWER);
}
}
2014-03-14 15:33:35 -04:00
return $result;
}
}