PMCORE-2537

This commit is contained in:
Andrea Adamczyk
2020-12-17 15:18:07 -04:00
parent df40b1c7c6
commit c740d135e0
3 changed files with 152 additions and 13 deletions

View File

@@ -94,9 +94,9 @@ class TaskTest extends TestCase
$taskInstance = new Task();
$taskInfo = $taskInstance->information($del->APP_UID, $del->TAS_UID, $del->DEL_INDEX);
$result = ' 4 ' . G::LoadTranslation('ID_DAY_DAYS');
$result .= ' 01 '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
$result .= ' 01 ' . G::LoadTranslation('ID_HOUR_ABBREVIATE');
$result .= ' 01 ' . G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$result .= ' 01 ' . G::LoadTranslation('ID_SECOND_ABBREVIATE');
$this->assertEquals($taskInfo['DURATION'], $result);
}
@@ -121,9 +121,9 @@ class TaskTest extends TestCase
$taskInstance = new Task();
$taskInfo = $taskInstance->information($del->APP_UID, $del->TAS_UID, $del->DEL_INDEX);
$result = ' 4 ' . G::LoadTranslation('ID_DAY_DAYS');
$result .= ' 01 '. G::LoadTranslation('ID_HOUR_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$result .= ' 01 '. G::LoadTranslation('ID_SECOND_ABBREVIATE');
$result .= ' 01 ' . G::LoadTranslation('ID_HOUR_ABBREVIATE');
$result .= ' 01 ' . G::LoadTranslation('ID_MINUTE_ABBREVIATE');
$result .= ' 01 ' . G::LoadTranslation('ID_SECOND_ABBREVIATE');
$this->assertEquals($taskInfo['DURATION'], $result);
}
@@ -186,4 +186,47 @@ class TaskTest extends TestCase
$result = $tas->taskCaseTitle($task->TAS_UID);
$this->assertNotEmpty($result);
}
/**
* It test get tasks for the new home view
*
* @covers \ProcessMaker\Model\Task::getTasksForHome()
* @test
*/
public function it_should_test_get_tasks_for_home_method()
{
Task::truncate();
Process::truncate();
$process1 = factory(Process::class)->create();
$process2 = factory(Process::class)->create();
factory(Task::class)->create([
'PRO_UID' => $process1->PRO_UID,
'TAS_TITLE' => 'Task 1'
]);
factory(Task::class)->create([
'PRO_UID' => $process1->PRO_UID,
'TAS_TITLE' => 'Task 2'
]);
factory(Task::class)->create([
'PRO_UID' => $process1->PRO_UID,
'TAS_TITLE' => 'Task 3'
]);
factory(Task::class)->create([
'PRO_UID' => $process2->PRO_UID,
'TAS_TITLE' => 'Task 1'
]);
factory(Task::class)->create([
'PRO_UID' => $process2->PRO_UID,
'TAS_TITLE' => 'Task 2'
]);
$this->assertCount(5, Task::getTasksForHome());
$this->assertCount(2, Task::getTasksForHome('Task 1'));
$this->assertCount(3, Task::getTasksForHome(null, $process1->PRO_ID));
$this->assertCount(5, Task::getTasksForHome(null, null, null, 2));
$this->assertCount(1, Task::getTasksForHome(null, null, 2, 1));
}
}

View File

@@ -57,6 +57,36 @@ class Task extends Model
->where('TAS_GROUP_VARIABLE', '=', '');
}
/**
* Scope a query to specific title
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $title
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTitle($query, $title)
{
return $query->where('TAS_TITLE', 'LIKE', "%{$title}%");
}
/**
* Scope a query to include a specific process
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $category
* @return \Illuminate\Database\Eloquent\Builder
* @todo Auto populate the PRO_ID in TASK table
*/
public function scopeProcessId($query, $proId)
{
$query->join('PROCESS', function ($join) use ($proId) {
$join->on('TASK.PRO_UID', '=', 'PROCESS.PRO_UID')
->where('PROCESS.PRO_ID', '=', $proId);
});
return $query;
}
/**
* Get the title of the task
*
@@ -191,4 +221,42 @@ class Task extends Model
return $query->get()->values()->toArray()['0']['TAS_DEF_TITLE'];
}
/**
* Get all tasks, paged optionally, can be sent a string to filter results by "TAS_TITLE"
*
* @param string $text
* @param string $proId
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function getTasksForHome($text = null, $proId = null, $offset = null, $limit = null)
{
// Get base query
$query = Task::query()->select(['TAS_ID', 'TAS_TITLE']);
// Set "TAS_TITLE" condition if is sent
if (!is_null($text)) {
$query->title($text);
}
// Set "PRO_ID" condition if is sent
if (!is_null($proId)) {
$query->processId($proId);
}
// Set pagination if offset and limit are sent
if (!is_null($offset) && !is_null($limit)) {
$query->offset($offset);
$query->limit($limit);
}
// Order by "TAS_TITLE"
$query->orderBy('TAS_TITLE');
// Return tasks
return $query->get()->toArray();
}
}

View File

@@ -17,6 +17,7 @@ use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\User;
use ProcessMaker\Model\Task;
use ProcessMaker\Services\Api;
use RBAC;
use stdClass;
@@ -662,4 +663,31 @@ class Home extends Api
return $result;
}
/**
* Get all tasks, paged optionally, can be sent a text to filter results by "TAS_TITLE"
*
* @url GET /tasks
*
* @param string $text
* @param string $proId
* @param int $offset
* @param int $limit
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function getTasks($text = null, $proId = null, $offset = null, $limit = null)
{
try {
$tasks = Task::getTasksForHome($text, $proId, $offset, $limit);
return $tasks;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}