From 0c8cb81ef34e1bceb5e12f5679af4ee4f7f287b1 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Fri, 19 Mar 2021 23:19:10 -0300 Subject: [PATCH] Added Sources --- src/Currency.php | 9 ++++++++- src/Source.php | 27 +++++++++++++++++++++++++++ src/Value.php | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/Source.php diff --git a/src/Currency.php b/src/Currency.php index bedadd7..02cf51f 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -31,6 +31,13 @@ class Currency extends Model { } return $this->latest; } + protected $sources; + public function sources(): ?array { + if ($this->sources === null) { + $this->sources = $this->parentOf(Source::class, [Model::CHILD_KEY => 'currency_id']); + } + return $this->sources; + } protected static $fields = ['code', 'name']; public static function add(ModelFactory $factory, $info) { @@ -49,7 +56,7 @@ class Currency extends Model { protected function checkCode(string $code): bool { return ($this->find(Currency::class)->where([['code', $code]])->one()) ? true : false; } - public function edit($info) { + public function edit($info): bool { $data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields)); $edited = false; foreach ($data as $field => $value) { diff --git a/src/Source.php b/src/Source.php new file mode 100644 index 0000000..a271cb2 --- /dev/null +++ b/src/Source.php @@ -0,0 +1,27 @@ +currency === null) { + $this->currency = $this->childOf(Currency::class, [Model::SELF_KEY => 'currency_id']); + } + return $this->currency; + } + public function frecuency(\DateInterval $frecuency = null) { + if ($frecuency == null) { + return new \CarbonInterval($this->fecuency); + } + $this->frecuency = CarbonInterval::getDateIntervalSpec($frecuency); + } +} diff --git a/src/Value.php b/src/Value.php index 66824aa..4c51532 100644 --- a/src/Value.php +++ b/src/Value.php @@ -46,7 +46,7 @@ class Value extends Model { $result->value = $value->asArray(); return $result; } - public function edit($info) { + public function edit($info): bool { $data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields)); $edited = false; foreach ($data as $field => $value) {