Files
thetool/application/WorkerFlag/WorkerFlag.php
2024-02-06 18:42:55 +01:00

67 lines
1.5 KiB
PHP

<?php
class WorkerFlag {
private $db;
private $id;
private $worker_id = null;
private $name = null;
private $value = null;
private $user = null;
public function __construct($worker_id, $name) {
$this->db = FronkDB::singleton();
$user = new User($worker_id);
$this->user = $user;
$name = $this->db->escape($name);
$this->name = $name;
$res = $this->db->select("WorkerFlag", "*", "worker_id=".$this->user->id." AND name='$name'");
if($this->db->num_rows($res)) {
$data = $this->db->fetch_object($res);
$this->id = $data->id;
$this->value = $data->value;
}
}
public function value($value = null) {
if($value !== null) {
$this->value = $value;
}
return $this->value;
}
public function save() {
$id = $this->id;
$values['worker_id'] = $this->user->id;
$values['name'] = $this->name;
$values['value'] = $this->value;
$values['edit_by'] = $this->user->id;
$values['edit'] = date('U');
if($id) {
// update
$this->db->update("WorkerFlag", $values, "id=$id");
} else {
// insert
$values['create_by'] = $this->user->id;
$values['create'] = date('U');
$id = $this->db->insert("WorkerFlag", $values);
$this->id = $id;
}
}
public function delete() {
if($this->id) {
$this->db->delete("WorkerFlag", "id=".$this->id, 1);
}
return true;
}
public function __toString() {
return (string) $this->value;
}
}