Added preorder network select to user/form
This commit is contained in:
67
application/WorkerFlag/WorkerFlag.php
Normal file
67
application/WorkerFlag/WorkerFlag.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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 = new FronkDB();
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user