PMCORE-1122
This commit is contained in:
@@ -474,13 +474,14 @@ class Delegation extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count the self-services cases by user
|
* Get the self-services query by user
|
||||||
*
|
*
|
||||||
* @param string $usrUid
|
* @param string $usrUid
|
||||||
|
* @param bool $count
|
||||||
*
|
*
|
||||||
* @return integer
|
* @return \Illuminate\Database\Query\Builder | string
|
||||||
*/
|
*/
|
||||||
public static function countSelfService($usrUid)
|
public static function getSelfServiceQuery($usrUid, $count = false)
|
||||||
{
|
{
|
||||||
// Set the 'usrUid' property to preserve
|
// Set the 'usrUid' property to preserve
|
||||||
Delegation::$usrUid = $usrUid;
|
Delegation::$usrUid = $usrUid;
|
||||||
@@ -530,6 +531,10 @@ class Delegation extends Model
|
|||||||
whereRaw($complexJoin);
|
whereRaw($complexJoin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clean static properties
|
||||||
|
Delegation::$usrUid = '';
|
||||||
|
Delegation::$groups = [];
|
||||||
|
|
||||||
// Get self services tasks related to the user
|
// Get self services tasks related to the user
|
||||||
$selfServiceTasks = TaskUser::getSelfServicePerUser($usrUid);
|
$selfServiceTasks = TaskUser::getSelfServicePerUser($usrUid);
|
||||||
|
|
||||||
@@ -540,22 +545,68 @@ class Delegation extends Model
|
|||||||
$query2->noUserInThread();
|
$query2->noUserInThread();
|
||||||
|
|
||||||
// Build the complex query that uses "UNION DISTINCT" clause
|
// Build the complex query that uses "UNION DISTINCT" clause
|
||||||
$unionQuery = sprintf('select count(*) as aggregate from ((%s) union distinct (%s)) self_service_cases',
|
$query = sprintf('select ' . ($count ? 'count(*) as aggregate' : 'APP_NUMBER') .
|
||||||
toSqlWithBindings($query1), toSqlWithBindings($query2));
|
' from ((%s) union distinct (%s)) self_service_cases', toSqlWithBindings($query1), toSqlWithBindings($query2));
|
||||||
|
|
||||||
// Execute the query
|
return $query;
|
||||||
$result = DB::selectOne($unionQuery);
|
|
||||||
$count = $result->aggregate;
|
|
||||||
} else {
|
} else {
|
||||||
// Execute the query
|
return $query1;
|
||||||
$count = $query1->count();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the self-services cases by user
|
||||||
|
*
|
||||||
|
* @param string $usrUid
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getSelfService($usrUid)
|
||||||
|
{
|
||||||
|
// Initializing the variable to return
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
// Get the query
|
||||||
|
$query = self::getSelfServiceQuery($usrUid);
|
||||||
|
|
||||||
|
// Get data
|
||||||
|
if (!is_string($query)) {
|
||||||
|
$items = $query->get();
|
||||||
|
$items->each(function ($item) use (&$data) {
|
||||||
|
$data[] = get_object_vars($item);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$items = DB::select($query);
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$data[] = get_object_vars($item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean static properties
|
// Return data
|
||||||
Delegation::$usrUid = '';
|
return $data;
|
||||||
Delegation::$groups = [];
|
}
|
||||||
|
|
||||||
// Return value
|
/**
|
||||||
|
* Count the self-services cases by user
|
||||||
|
*
|
||||||
|
* @param string $usrUid
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public static function countSelfService($usrUid)
|
||||||
|
{
|
||||||
|
// Get the query
|
||||||
|
$query = self::getSelfServiceQuery($usrUid, true);
|
||||||
|
|
||||||
|
// Get count value
|
||||||
|
if (!is_string($query)) {
|
||||||
|
$count = $query->count();
|
||||||
|
} else {
|
||||||
|
$result = DB::selectOne($query);
|
||||||
|
$count = $result->aggregate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return data
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user