diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php new file mode 100644 index 000000000..cf5fa88c0 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/AppNotesTest.php @@ -0,0 +1,47 @@ +states('foreign_keys')->create(); + $notes = new AppNotes(); + $res = $notes->getNotes($appNotes->APP_UID); + $this->assertNotEmpty($res); + } + + /** + * Review get total cases notes by cases + * + * @test + */ + public function it_test_get_total_case_notes() + { + $application = factory(Application::class)->create(); + $appNotes = factory(AppNotes::class, 10)->states('foreign_keys')->create([ + 'APP_UID' => $application->APP_UID + ]); + $notes = new AppNotes(); + $total = $notes->getTotal($application->APP_UID); + $this->assertEquals(10, $total); + } +} \ No newline at end of file diff --git a/workflow/engine/controllers/appProxy.php b/workflow/engine/controllers/appProxy.php index f105d3b71..0038f01d3 100644 --- a/workflow/engine/controllers/appProxy.php +++ b/workflow/engine/controllers/appProxy.php @@ -117,6 +117,7 @@ class AppProxy extends HttpProxyController // Get the notes $appNote = new Notes(); + $total = $appNote->getTotal($appUid); $response = $appNote->getNotes($appUid, $httpData->start, $httpData->limit); $response = AppNotes::applyHtmlentitiesInNotes($response); @@ -128,6 +129,8 @@ class AppProxy extends HttpProxyController $response['notes'][$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID']); $iterator++; } + // Get the total of cases notes by case + $response['totalCount'] = $total; require_once("classes/model/Application.php"); $application = new Application(); diff --git a/workflow/engine/src/ProcessMaker/Model/AppNotes.php b/workflow/engine/src/ProcessMaker/Model/AppNotes.php index 66c00b43b..b5195e9c5 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppNotes.php +++ b/workflow/engine/src/ProcessMaker/Model/AppNotes.php @@ -98,9 +98,22 @@ class AppNotes extends Model $notes['notes'][] = $row; }); - // Add the total of rows to return - $notes['totalCount'] = $limit; - return $notes; } + + /** + * Return the total notes by case + * + * @param string $appUid + * + * @return array + */ + public static function getTotal(string $appUid) + { + $query = AppNotes::query()->select(['NOTE_ID']); + $query->appUid($appUid); + $total = $query->get()->count(); + + return $total; + } }