Added Sources
This commit is contained in:
@ -31,6 +31,13 @@ class Currency extends Model {
|
|||||||
}
|
}
|
||||||
return $this->latest;
|
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'];
|
protected static $fields = ['code', 'name'];
|
||||||
public static function add(ModelFactory $factory, $info) {
|
public static function add(ModelFactory $factory, $info) {
|
||||||
@ -49,7 +56,7 @@ class Currency extends Model {
|
|||||||
protected function checkCode(string $code): bool {
|
protected function checkCode(string $code): bool {
|
||||||
return ($this->find(Currency::class)->where([['code', $code]])->one()) ? true : false;
|
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));
|
$data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
||||||
$edited = false;
|
$edited = false;
|
||||||
foreach ($data as $field => $value) {
|
foreach ($data as $field => $value) {
|
||||||
|
27
src/Source.php
Normal file
27
src/Source.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -46,7 +46,7 @@ class Value extends Model {
|
|||||||
$result->value = $value->asArray();
|
$result->value = $value->asArray();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
public function edit($info) {
|
public function edit($info): bool {
|
||||||
$data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
$data = array_intersect_key((array) $info, array_combine(self::$fields, self::$fields));
|
||||||
$edited = false;
|
$edited = false;
|
||||||
foreach ($data as $field => $value) {
|
foreach ($data as $field => $value) {
|
||||||
|
Reference in New Issue
Block a user