Merge branch 'spidev' into 'master'

Kalender Updates

See merge request fronk/thetool!900
This commit is contained in:
Daniel Spitzer
2025-01-14 17:57:08 +00:00
10 changed files with 1185 additions and 204 deletions

View File

@@ -326,11 +326,13 @@ class CalendarController extends mfBaseController
protected function indexAction()
{
$this->layout()->setTemplate("Calendar/Index");
$calendars = CalendarModel::getAll();
$calendarTemplateEventTypes = CalendarTemplateModel::$calendarTemplateEventTypes;
$this->layout()->set("calendarTemplateEventTypes", $calendarTemplateEventTypes);
$calendartemplates = CalendarTemplateModel::getAll();
$this->layout()->set("calendartemplates", $calendartemplates);
$this->layout()->set("calendars", $calendars);
}
protected function addAction()

View File

@@ -0,0 +1,59 @@
<?php
class CalendarTemplate extends mfBaseModel
{
private $editor;
private $creator;
public function getProperty($name)
{
if ($this->$name == null) {
if (!$this->id) {
return null;
}
if ($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-" . $this->create_by);
if ($this->creator === null) {
$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 = mfValuecache::singleton()->get("Worker-id-" . $this->edit_by);
if ($this->editor === null) {
$this->editor = new User($this->edit_by);
if ($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-" . $this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name . "_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
if (!$this->$name) {
$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;
}
}

View File

@@ -0,0 +1,150 @@
<?php
class CalendarTemplateController 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"])) {
$this->redirect("Dashboard");
}
}
protected function apiAction()
{
$r = $this->request;
$do=$r->do;
switch ($do) {
case "getPreview":
$event_type = $r->event_type;
$calendartemplates = CalendarTemplateModel::search(array("event_type"=>$event_type));
$result['status'] = "success";
$result['data'] = $calendartemplates;
break;
default:
$result['status'] = "error";
$result['message'] = "Aktion nicht gefunden";
break;
}
echo json_encode($result);
die();
}
protected function indexAction()
{
$this->layout()->setTemplate("CalendarTemplate/Index");
$calendartemplates = CalendarTemplateModel::getAll();
$calendarTemplateEventTypes=CalendarTemplateModel::$calendarTemplateEventTypes;
$this->layout()->set("calendarTemplateEventTypes", $calendarTemplateEventTypes);
$this->layout()->set("calendartemplates", $calendartemplates);
}
protected function addAction()
{
$this->layout()->setTemplate("CalendarTemplate/Form");
}
protected function editAction()
{
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Vorlage nicht gefunden", "error");
$this->redirect("CalendarTemplate");
}
$calendartemplates = new CalendarTemplate($id);
if ($calendartemplates->id != $id) {
$this->layout()->setFlash("Vorlage nicht gefunden", "error");
$this->redirect("CalendarTemplate");
}
$calendarTemplateEventTypes=CalendarTemplateModel::$calendarTemplateEventTypes;
$this->layout()->set("calendarTemplateEventTypes", $calendarTemplateEventTypes);
$this->layout()->set("calendartemplates", $calendartemplates);
return $this->addAction();
}
protected function saveAction()
{
$r = $this->request;
$id = $r->id;
//var_dump($r->get());exit;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$calendartemplates = new CalendarTemplate($id);
if (!$calendartemplates->id) {
$this->layout()->setFlash("Vorlagen nicht gefunden", "error");
$this->redirect("Calendar");
}
} else {
$mode = "add";
}
$data = [];
$data['event_type'] = trim($r->event_type);
$data['name'] = trim($r->name);
$data['is_reminder'] = trim($r->is_reminder);
$data['text'] = trim($r->text);
if (!$data['event_type']) {
$data['event_type']=NULL;
}
if (!$data['name']) {
$data['name']=NULL;
}
if (!$data['is_reminder']) {
$data['is_reminder']=0;
}
if (!$data['text']) {
$data['text']=NULL;
}
// var_dump($_FILES);
// var_dump($upload);
// exit;
if ($mode == "edit") {
$calendartemplates->update($data);
} else {
$calendartemplates = CalendarTemplateModel::create($data);
}
// var_dump($filestore);
// exit;
$id = $calendartemplates->save();
if (!$id) {
$this->layout()->setFlash("Vorlage konnte nicht angelegt werden", "error");
$this->redirect("CalendarTemplate");
}
if ($mode == "edit") {
$this->layout()->setFlash("Vorlage erfolgreich geändert", "success");
} else if ($mode = "add") {
$this->layout()->setFlash("Vorlage erfolgreich angelegt", "success");
}
$this->redirect("Calendar");
}
protected function deleteAction()
{
$id = $this->request->id;
$calendartemplates = new CalendarTemplate($id);
if (!$calendartemplates->id || $calendartemplates->id != $id) {
$this->layout()->setFlash("Vorlage nicht gefunden.", "error");
$this->redirect("CalendarTemplate");
}
$calendartemplates->delete();
$this->redirect("Calendar");
}
}

View File

@@ -0,0 +1,134 @@
<?php
class CalendarTemplateModel
{
private $event_type;
private $name;
private $is_reminder;
private $text;
public static $calendarTemplateEventTypes=array(
"1"=>"Termin",
"2"=>"IBN",
"3"=>"IBN E-Stmk",
"4"=>"IBN Snopp",
"5"=>"Störungen"
);
public static function find($data)
{
}
public static function create(array $data)
{
$model = new CalendarTemplate();
foreach ($data as $field => $value) {
if (property_exists(get_called_class(), $field)) {
if (substr($field, 0, 5) == "vlan_" && !$value) {
$model->$field = null;
continue;
}
$model->$field = $value;
}
}
$me = mfValuecache::singleton()->get("me");
if (!$me) {
$me = new User();
$me->loadMe();
mfValuecache::singleton()->set("me", $me);
}
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("CalendarTemplate", "*", "id=$id LIMIT 1");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new CalendarTemplate($data);
}
return $item;
}
public static function getAll()
{
$items = [];
$db = FronkDB::singleton();
$res = $db->select("CalendarTemplate", "*", "1=1");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new CalendarTemplate($data);
}
}
return $items;
}
public static function getFirst()
{
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$res = $db->select("CalendarTemplate", "*", "$where ");
if ($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new CalendarTemplate($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("CalendarTemplate", "*", "$where");
if ($db->num_rows($res)) {
while ($data = $db->fetch_object($res)) {
$items[] = new CalendarTemplate($data);
}
}
return $items;
}
private static function getSqlFilter($filter)
{
$where = "1=1 ";
//var_dump($filter);exit;
if (array_key_exists("event_type", $filter)) {
$event_type = $filter['event_type'];
if (is_numeric($event_type)) {
$where .= " AND event_type=$event_type";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}