Added Sources

This commit is contained in:
2021-03-19 23:19:10 -03:00
parent 99c18cb871
commit 0c8cb81ef3
3 changed files with 36 additions and 2 deletions

View File

@ -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) {

27
src/Source.php Normal file
View File

@ -0,0 +1,27 @@
<?php
namespace ProVM\Money;
use Carbon\CarbonInterval;
use ProVM\Common\Alias\Model;
/**
* @property int $id
* @property Currency $currency_id
* @property string $url
* @property \DateInterval $frecuency
*/
class Source extends Model {
protected $currency;
public function currency(): ?Currency {
if ($this->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);
}
}

View File

@ -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) {