110 lines
3.2 KiB
PHP
110 lines
3.2 KiB
PHP
<?php
|
|
|
|
class Voiceplan extends mfBaseModel {
|
|
private $creator;
|
|
private $editor;
|
|
|
|
private $destinations;
|
|
|
|
public function importDestinationsFromCsv(File $file) {
|
|
if(!$this->id) {
|
|
return false;
|
|
}
|
|
try {
|
|
$i = 0;
|
|
$filename = $file->getFullPath();
|
|
$input = fopen($filename, "r");
|
|
while($csv = fgetcsv($input, 0, ",")) {
|
|
$i++;
|
|
if($i == 1) continue;
|
|
|
|
if(!trim($csv[0])) {
|
|
continue;
|
|
}
|
|
|
|
$name = trim($csv[0]);
|
|
$prefix = trim($csv[1]);
|
|
$price_ek = str_replace(",",".", trim($csv[2]));
|
|
$price_vk = str_replace(",",".", trim($csv[3]));
|
|
|
|
if(!$name || !$prefix || !$price_ek || !$price_vk) {
|
|
$this->log->warning("not Importing Voiceplandestination with empty value: destination: $name | prefix: $prefix | ek: $price_ek | vk: $price_vk");
|
|
continue;
|
|
}
|
|
|
|
$destination = VoiceplandestinationModel::getFirst(["voiceplan_id" => $this->id, "destination" => $name, "prefix" => $prefix]);
|
|
|
|
if($destination) {
|
|
$this->log->warning("Destination gibts schon, updateing prices: voiceplan_id: ".$this->id." | destination: $name | prefix: $prefix");
|
|
|
|
$destination->purchase_price = $price_ek;
|
|
$destination->price = $price_vk;
|
|
$destination->save();
|
|
continue;
|
|
}
|
|
|
|
$destination = VoiceplandestinationModel::create([
|
|
'voiceplan_id' => $this->id,
|
|
'destination' => $name,
|
|
'prefix' => $prefix,
|
|
'increment_first' => $this->increment_first,
|
|
'increment' => $this->increment,
|
|
'purchase_price' => $price_ek,
|
|
'price' => $price_vk
|
|
]);
|
|
$destination->save();
|
|
|
|
}
|
|
return true;
|
|
|
|
|
|
} catch(Exception $e) {
|
|
echo $e->getCode().": ".$e->getMessage();exit;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "destinations") {
|
|
$this->destinations = VoiceplandestinationModel::search(["voiceplan_id" => $this->id]);
|
|
return $this->destinations;
|
|
}
|
|
|
|
if($name == "creator") {
|
|
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
|
if($user) {
|
|
$this->creator = $user;
|
|
return $this->creator;
|
|
}
|
|
$this->creator = new User($this->create_by);
|
|
if($this->creator->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
|
}
|
|
return $this->creator;
|
|
}
|
|
|
|
if($name == "editor") {
|
|
$this->editor = new User($this->edit_by);
|
|
return $this->editor;
|
|
}
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
|
if($this->$name === null) {
|
|
$this->$name = new $classname($this->$idfield);
|
|
}
|
|
|
|
if($this->$name->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
} |