Added OrderJournal
This commit is contained in:
38
application/OrderJournal/OrderJournal.php
Normal file
38
application/OrderJournal/OrderJournal.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class OrderJournal extends mfBaseModel {
|
||||
private $order;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
61
application/OrderJournal/OrderJournalController.php
Normal file
61
application/OrderJournal/OrderJournalController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
class OrderJournalController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin", "salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
if(!$this->me->is(["Admin", "salespartner"])) {
|
||||
$this->layout()->setFlash("Keine Berechtigung", "error");
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
|
||||
$r = $this->request;
|
||||
$order_id = $r->order_id;
|
||||
if(!is_numeric($order_id) || $order_id < 1) {
|
||||
$this->layout()->setFlash("Bestellung nicht gefunden!", "error");
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
$order = new Order($order_id);
|
||||
if(!$order->id) {
|
||||
$this->layout()->setFlash("Bestellung nicht gefunden!", "error");
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
$text = trim(htmlentities($r->text));
|
||||
if(!$text) {
|
||||
$this->layout()->setFlash("Bitte Text eingeben", "error");
|
||||
$this->redirect("Order", "Index", [], "order=".$order_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$journal = new OrderJournal();
|
||||
$journal->order_id = $order_id;
|
||||
$journal->text = $text;
|
||||
$journal->create_by = $this->me->id;
|
||||
$journal->edit_by = $this->me->id;
|
||||
|
||||
if(!$journal->save()) {
|
||||
$this->layout()->setFlash("Fehler beim speichern!", "error");
|
||||
$this->redirect("Order", "Index", [], "order=".$order_id);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Journaleintrag gespeichert", "success");
|
||||
$this->redirect("Order", "Index", [], "order=".$order_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
112
application/OrderJournal/OrderJournalModel.php
Normal file
112
application/OrderJournal/OrderJournalModel.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
class OrderJournalModel {
|
||||
public $name = null;
|
||||
public $order_id = null;
|
||||
public $text = null;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new OrderJournal();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getOne($id) {
|
||||
if(!is_numeric($id) || !$id) {
|
||||
throw new Exception("Invalid number", 400);
|
||||
}
|
||||
$item = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("OrderJournal", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OrderJournal($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("OrderJournal", "*");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new OrderJournal($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("OrderJournal", "*", "$where ORDER BY `create`");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new OrderJournal($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("OrderJournal", "*", "$where ORDER BY `create` DESC");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new OrderJournal($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("order_id", $filter)) {
|
||||
$orderid = $filter['order_id'];
|
||||
if(is_numeric($orderid)) {
|
||||
$where .= " AND order_id=$orderid";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user