Add filters for task start date

This commit is contained in:
David Bomba 2023-07-19 08:01:47 +10:00
parent 5fff511869
commit a028456a09
3 changed files with 65 additions and 4 deletions

View File

@ -101,9 +101,6 @@ class TaskRepository extends BaseRepository
$key_values = array_column($time_log, 0); $key_values = array_column($time_log, 0);
array_multisort($key_values, SORT_ASC, $time_log); array_multisort($key_values, SORT_ASC, $time_log);
// array_multisort($time_log);
// ksort($time_log);
if (isset($data['action'])) { if (isset($data['action'])) {
if ($data['action'] == 'start') { if ($data['action'] == 'start') {
$task->is_running = true; $task->is_running = true;
@ -121,8 +118,12 @@ class TaskRepository extends BaseRepository
$task->is_running = $data['is_running'] ? 1 : 0; $task->is_running = $data['is_running'] ? 1 : 0;
} }
$task->calculated_start_date = $this->harvestStartDate($time_log);
$task->time_log = json_encode($time_log); $task->time_log = json_encode($time_log);
$task->saveQuietly(); $task->saveQuietly();
if (array_key_exists('documents', $data)) { if (array_key_exists('documents', $data)) {
@ -132,6 +133,17 @@ class TaskRepository extends BaseRepository
return $task; return $task;
} }
private function harvestStartDate($time_log)
{
if(isset($time_log[0][0])){
return \Carbon\Carbon::createFromTimestamp($time_log[0][0]);
}
return null;
}
/** /**
* Store tasks in bulk. * Store tasks in bulk.
* *
@ -199,8 +211,12 @@ class TaskRepository extends BaseRepository
if (strlen($task->time_log) < 5) { if (strlen($task->time_log) < 5) {
$log = []; $log = [];
$log = array_merge($log, [[time(), 0]]); $start_time = time();
$log = array_merge($log, [[$start_time, 0]]);
$task->time_log = json_encode($log); $task->time_log = json_encode($log);
$task->calculated_start_date = \Carbon\Carbon::createFromTimestamp($start_time);
$task->saveQuietly(); $task->saveQuietly();
} }

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tasks', function (Blueprint $table) {
$table->date('calculated_start_date')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
};

View File

@ -31,6 +31,8 @@ class TaskApiTest extends TestCase
use DatabaseTransactions; use DatabaseTransactions;
use MockAccountData; use MockAccountData;
private $faker;
protected function setUp() :void protected function setUp() :void
{ {
parent::setUp(); parent::setUp();
@ -100,6 +102,20 @@ class TaskApiTest extends TestCase
} }
} }
public function testStartDate()
{
$x = [];
$this->assertFalse(isset($x[0][0]));
$x[0][0] = 'a';
$this->assertTrue(isset($x[0][0]));
$this->assertNotNull(\Carbon\Carbon::createFromTimestamp($x[0][0]));
}
public function testMultiSortArray() public function testMultiSortArray()
{ {