<?php
namespace Bdp\Libs;

class CommonModel extends \stdClass {
	protected string $_tablename;

	public static function load_by_id(string $table_name, int $object_id) {
		global $dbHandler;

		$data = $dbHandler->readFromDb($table_name, ['id' => $object_id]);
		$class = new CommonModel();

		foreach (get_object_vars($data[0]) as $key => $value) {
			$class->$key = $value;
		}

		return $class;
	}

	public function delete() {
		global $dbHandler;

	}
	public function is_fullaged() : bool {
		return kompass_is_fullaged($this->geburtsdatum);
	}

	public function get_age() {
		$obj_birthday = \DateTime::createFromFormat('Y-m-d',  $this->geburtsdatum);
		$today = new \DateTime();
		$compare = date_diff($today, $obj_birthday);
		return $compare->y;
	}
}