Files
thetool/application/Voicenumberblock/Voicenumberblock.php
2023-03-01 17:01:49 +01:00

77 lines
2.0 KiB
PHP

<?php
class Voicenumberblock extends mfBaseModel {
protected $forcestr = ['comment'];
private $number_first;
private $number_last;
private $base;
private $short_prefix;
private $short_first;
private $short_last;
private $files;
private $numbers;
public function isNumberInBlock($number) {
return ($number >= $this->first && $number <= $this->last);
}
public static function findBlock($number) {
// resolve number from right to left to find fitting block
$minLength = 4;
$try = $number;
while(strlen($try) >= $minLength) {
$block = VoicenumberblockModel::getFirst(['prefix' => $try]);
if($block) {
break;
}
$try = substr($try, 0, strlen($try)-1);
}
if(!$block) {
return false;
}
return $block;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "files") {
$this->files = VoiceblocknumberFileModel::search(["voicenumberblock_id" => $this->id]);
return $this->files;
}
if($name == "numbers") {
$this->numbers = VoicenumberModel::search(["voicenumberblock_id" => $this->id]);
return $this->numbers;
}
if($name == "short_prefix") {
$this->short_prefix = substr($this->prefix, strlen($this->countrycode.$this->areacode));
return $this->short_prefix;
}
if($name == "short_first") {
$this->short_first = substr($this->first, strlen($this->countrycode.$this->areacode));
return $this->short_first;
}
if($name == "short_last") {
$this->short_last = substr($this->last, strlen($this->countrycode.$this->areacode));
return $this->short_last;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = new $classname($this->$idfield);
if($this->$name->id) {
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
}