Files
thetool/application/File/File.php
2021-07-30 20:03:24 +02:00

64 lines
1.4 KiB
PHP

<?php
class File extends mfBaseModel {
private $creator;
private $editor;
public function delete() {
if($this->id) {
$id = $this->id;
// delete file in store
$path = MFUPLOAD_FILE_SAVE_PATH."/documents/".$this->store_filename;
if(!unlink($path)) {
$this->log->warn(__CLASS__."::delete(): Error unlinking file ($path)");
}
$where = "id=$id";
if($this->fieldprefix && !strstr($field,"_")) {
$where = $this->fieldprefix."_id=$id";
}
if($this->db->delete($this->table,$where)) {
if(method_exists($this, "afterDelete")) {
$this->afterDelete();
}
$this->data = new stdClass();
$this->id = "";
return true;
}
}
return false;
}
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "creator") {
$this->creator = new User($this->create_by);
return $this->creator;
}
if($name == "editor") {
$this->editor = new User($this->edit_by);
return $this->editor;
}
$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;
}
}