diff --git a/app/Kintone/KintoneAccess.php b/app/Kintone/KintoneAccess.php index 39c11d4..22377d2 100644 --- a/app/Kintone/KintoneAccess.php +++ b/app/Kintone/KintoneAccess.php @@ -22,9 +22,10 @@ class KintoneAccess private int $appId; private const DEFAULT_FIELDS = [ - KintoneModel::FIELD_RECORD_NUMBER, - KintoneModel::FIELD_UPDATED_TIME, - KintoneModel::FIELD_RECORD_NUMBER, + "レコード番号", + 'RecordNo', + "作成日時", + "更新日時", ]; private array $fields = []; @@ -251,13 +252,13 @@ class KintoneAccess /** * @return Collection */ - public function all(KintoneRecordQuery|null $query = null, array|null $fields = null) + public function all(KintoneRecordQuery|null $query = null) { if ($this->cursor !== null) { $this->deleteCursor(); } - $this->createCursor($query, $fields); + $this->createCursor($query); $list = collect(); while (true) { diff --git a/app/Kintone/Models/Customer.php b/app/Kintone/Models/Customer.php new file mode 100644 index 0000000..f72ef20 --- /dev/null +++ b/app/Kintone/Models/Customer.php @@ -0,0 +1,28 @@ + FieldType::SINGLE_LINE_TEXT, + self::FIELD_EMAIL => FieldType::LINK, + ]; + + protected const FIELD_NAMES = [ + ...parent::FIELD_NAMES, + self::FIELD_CUSTOMER_NAME => 'customer_name', + self::FIELD_EMAIL => 'email', + ]; + + protected function setDataCustom(array $data): bool + { + return true; + } +} diff --git a/app/Kintone/Models/KintoneModel.php b/app/Kintone/Models/KintoneModel.php index e11d418..2449326 100644 --- a/app/Kintone/Models/KintoneModel.php +++ b/app/Kintone/Models/KintoneModel.php @@ -17,10 +17,6 @@ abstract class KintoneModel { const CONFIG_KEY = ""; - const FIELD_RECORD_NUMBER = "レコード番号"; - const FIELD_CREATED_TIME = "作成日時"; - const FIELD_UPDATED_TIME = "更新日時"; - static public function configKey(): string { if (!static::CONFIG_KEY) { @@ -191,6 +187,10 @@ abstract class KintoneModel data_set($this->data, $fieldCode, $value); } + if ($this->recordId === null) { + throw new LogicException(sprintf("レコード番号取得失敗 :%s", static::class)); + } + $ret = $this->setDataCustom($data); if ($ret) { $this->clean(); diff --git a/config/kintone.php b/config/kintone.php index 94c8723..04ab04e 100644 --- a/config/kintone.php +++ b/config/kintone.php @@ -26,6 +26,7 @@ return [ */ 'applications' => [ + ...App\Kintone\Models\Customer::setConfig(), ...App\Kintone\Models\SeasonTicketContract::setConfig(), ], diff --git a/tests/Feature/KintoneAccessTest.php b/tests/Feature/KintoneAccessTest.php index c99b016..e0d2530 100644 --- a/tests/Feature/KintoneAccessTest.php +++ b/tests/Feature/KintoneAccessTest.php @@ -2,12 +2,8 @@ namespace Tests\Feature; -use App\Kintone\KintoneAccess; -use App\Kintone\KintoneRecordQuery; -use App\Kintone\KintoneRecordQueryOperator; +use App\Kintone\Models\Customer; use App\Kintone\Models\SeasonTicketContract; -use App\Middlewares\Now; -use Illuminate\Support\Collection; use Tests\TestCase; class KintoneAccessTest extends TestCase @@ -48,75 +44,27 @@ class KintoneAccessTest extends TestCase } - // public function test_CarRoom(): void - // { - - // $model = new CarRoom(); - - // $access = new KintoneAccess(CarRoom::class); - - // $access->find(1, $model); - - // $this->assertEquals("岩渕パーク", $model->getStr(CarRoom::FIELD_PARK_NAME)); - // $this->assertEquals("5000", $model->getTable(CarRoom::FIELD_TABLE_FEE)[0][CarRoom::FIELD_TABLE_FEE_AMOUNT_PER_MONTH]); - // $this->assertEquals("自転車", $model->get(CarRoom::FIELD_CAN_USE_VEHICLE_TYPE)[0]); - // $this->assertEquals("普通自動車", $model->get(CarRoom::FIELD_CAN_USE_VEHICLE_TYPE)[1]); - // } - - // public function test_small() - // { - // $model = new Small(); - - // $access = new KintoneAccess(Small::class); - - // $model->set(Small::FIELD_NAME, "iwabuchi"); - // $model->set(Small::FIELD_AGE, "32"); - - // $res = $access->create($model); - // $this->assertTrue($res->ok()); - // } - - // /** - // * @group cursor - // */ - // public function test_cursor() - // { - // $access = new KintoneAccess(Small::class); - // $now = Now::get(); - // $query = Small::query() - // ->whereIn(Small::FIELD_NAME, ["iwabuchi", "aa"]) - // ->where(Small::FIELD_AGE, 32) - // ->whereDateTime(Small::FIELD_CREATED_TIME, $now, KintoneRecordQueryOperator::LT); - // $access->createCursor($query); - // $ret = $access->next(); - - // $this->assertTrue($ret instanceof Collection); - // $this->assertSame(1, $ret->count()); - - // $this->assertSame("iwabuchi", $ret->first()->getStr(Small::FIELD_NAME)); - // } - - // /** - // * @group cursor - // */ - // public function test_cursor_all() - // { - // $access = new KintoneAccess(Small::class); - // $now = Now::get(); - // $query = Small::query() - // ->orderByAsc(Small::FIELD_NAME); - - // $ret = $access->all($query, [ - // Small::FIELD_NAME, - // Small::FIELD_AGE, - // ]); - - // $this->assertTrue($ret instanceof Collection); - // $this->assertSame(2, $ret->count()); - - // $first = $ret->first(); - // $this->assertInstanceOf(Small::class, $first); - // $this->assertSame("iwabuchi", $ret->first()->getStr(Small::FIELD_NAME)); - // $this->assertSame(32, $ret->first()->getNumber(Small::FIELD_AGE)); - // } + public function test_customer(): void + { + + $access = Customer::getAccess(); + $query = Customer::getQuery(); + $query->where(Customer::FIELD_CUSTOMER_NAME, "山下千晶"); + + $list = $access->all($query); + + $this->assertEquals(1, $list->count()); + + /** + * @var Customer + */ + $model = $list[0]; + + $this->assertEquals("山下千晶", $model->getStr(Customer::FIELD_CUSTOMER_NAME)); + $this->assertEquals("shi.yy16@gmail.com", $model->getStr(Customer::FIELD_EMAIL)); + + $array = $model->toArray(); + $this->assertEquals("山下千晶", $array['customer_name']); + $this->assertEquals("shi.yy16@gmail.com", $array['email']); + } }