PMCORE-2389

This commit is contained in:
Julio Cesar Laura Avendaño
2020-12-03 20:27:03 +00:00
parent bb935e1637
commit 91f1ff60e2
4 changed files with 219 additions and 2 deletions

View File

@@ -457,6 +457,12 @@
<column name="PRO_UID" type="VARCHAR" size="32" required="true" primaryKey="true" default=""/>
<column name="USR_UID" type="VARCHAR" size="32" required="true" primaryKey="true" default=""/>
<column name="APP_UID" type="VARCHAR" size="32" required="true" primaryKey="true" default=""/>
<index name="INDEX_CFG_UID">
<index-column name="CFG_UID"/>
</index>
<index name="INDEX_USR_UID">
<index-column name="USR_UID"/>
</index>
</table>
<table name="CONTENT">
<vendor type="mysql">

View File

@@ -211,8 +211,10 @@ CREATE TABLE `CONFIGURATION`
`PRO_UID` VARCHAR(32) default '' NOT NULL,
`USR_UID` VARCHAR(32) default '' NOT NULL,
`APP_UID` VARCHAR(32) default '' NOT NULL,
PRIMARY KEY (`CFG_UID`,`OBJ_UID`,`PRO_UID`,`USR_UID`,`APP_UID`)
)ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Stores the users, processes and/or applications configuratio';
PRIMARY KEY (`CFG_UID`,`OBJ_UID`,`PRO_UID`,`USR_UID`,`APP_UID`),
KEY `INDEX_CFG_UID`(`CFG_UID`),
KEY `INDEX_USR_UID`(`USR_UID`)
)ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Stores the users, processes and/or applications configuration';
#-----------------------------------------------------------------------------
#-- CONTENT
#-----------------------------------------------------------------------------

View File

@@ -0,0 +1,118 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Configuration;
use stdClass;
class Filter
{
const ADVANCED_SEARCH_FILTER_KEY = 'advanced-search-filter';
/**
* Get filters of the advanced search for the current user
*
* @param string $userUid
*
* @return array
*/
public static function getByUser($userUid)
{
// Initialize variables
$filters = [];
// Build query
$query = Configuration::query()->select(['CFG_VALUE']);
$query->where('CFG_UID', '=', self::ADVANCED_SEARCH_FILTER_KEY);
$query->where('USR_UID', '=', $userUid);
// Get results
$records = $query->get();
// Transform the serialized string to JSON object
$records->each(function ($record) use (&$filters) {
$filters[] = json_decode($record->CFG_VALUE);
});
// Return filters
return $filters;
}
/**
* Get a specific filter of the advanced search for the current user
*
* @param string $userUid
* @param string $filterUid
*
* @return object
*/
public static function getByUid($userUid, $filterUid)
{
// Initialize variables
$filter = null;
// Build query
$query = Configuration::query()->select(['CFG_VALUE']);
$query->where('CFG_UID', '=', self::ADVANCED_SEARCH_FILTER_KEY);
$query->where('USR_UID', '=', $userUid);
$query->where('OBJ_UID', '=', $filterUid);
// Get result
$record = $query->first();
if (!is_null($record)) {
$filter = json_decode($record->CFG_VALUE);
}
// Return filter
return $filter;
}
/**
* Save a new filter of the advanced search for the current user
*
* @param string $userUid
* @param string $name
* @param object $filters
*
* @return object
*/
public static function create($userUid, $name, $filters)
{
// Generate a new unique Uid
$filterUid = G::generateUniqueID();
// Build object to serialize and save
$filter = new stdClass();
$filter->id = $filterUid;
$filter->name = $name;
$filter->filters = $filters;
// Save new filter
$configuration = new Configuration();
$configuration->CFG_UID = self::ADVANCED_SEARCH_FILTER_KEY;
$configuration->OBJ_UID = $filterUid;
$configuration->CFG_VALUE = json_encode($filter);
$configuration->USR_UID = $userUid;
$configuration->save();
// Return the new filter
return $filter;
}
/**
* Delete a specific filter by filter Uid
*
* @param string $filterUid
*/
public static function delete($filterUid)
{
// Build the query
$query = Configuration::query()->where('CFG_UID', '=', self::ADVANCED_SEARCH_FILTER_KEY);
$query->where('OBJ_UID', '=', $filterUid);
// Delete filter
$query->delete();
}
}

View File

@@ -10,6 +10,7 @@ use Exception;
use ListUnassigned;
use Luracast\Restler\RestException;
use ProcessMaker\BusinessModel\Cases as BmCases;
use ProcessMaker\BusinessModel\Cases\Filter;
use ProcessMaker\BusinessModel\User as BmUser;
use ProcessMaker\Services\Api;
use ProcessMaker\Util\DateTime;
@@ -1463,4 +1464,94 @@ class Cases extends Api
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get filters of the advanced search for the current user
*
* @url GET /advanced-search/filters
*
* @return array
*
* @throws RestException
*/
public function doGetAdvancedSearchFilters()
{
try {
return Filter::getByUser($this->getUserId());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get a specific filter of the advanced search for the current user
*
* @url GET /advanced-search/filter/:filterUid
*
* @param string $filterUid {@min 32}{@max 32}
*
* @return object
*
* @throws RestException
*/
public function doGetAdvancedSearchFilter($filterUid)
{
try {
$filter = Filter::getByUid($this->getUserId(), $filterUid);
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
// If not exists the requested filter throw an 404 error
if (is_null($filter)) {
throw new RestException(404, "Filter with Uid '{$filterUid}'.");
}
return $filter;
}
/**
* Add a new filter of the advanced search for the current user
*
* @url POST /advanced-search/filter
*
* @param string $name
* @param string $filters
*
* @return object
*
* @throws RestException
*/
public function doPostAdvancedSearchFilter($name, $filters)
{
try {
// Create JSON object if is a serialized string
$filters = is_string($filters) ? json_decode($filters) : $filters;
// Create new filter
$filter = Filter::create($this->getUserId(), $name, $filters);
// Return the new filter
return $filter;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Delete a specific filter of the advanced search for the current user
*
* @url DELETE /advanced-search/filter/:filterUid
*
* @param string $filterUid {@min 32}{@max 32}
*
* @throws RestException
*/
public function doDeleteAdvancedSearchFilter($filterUid)
{
try {
Filter::delete($filterUid);
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}