Added News
This commit is contained in:
@@ -16,5 +16,32 @@
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<?php if(is_array($newss) && count($newss)): ?>
|
||||
<h4>Neuigkeiten</h4>
|
||||
|
||||
<?php foreach($newss as $news): ?>
|
||||
<div class="row">
|
||||
<div class="col-12 col-xl-10">
|
||||
<div class="card">
|
||||
<div class="card-header bg-info text-white pt-2 pb-2" style="font-size: 1rem; font-weight: 400;">
|
||||
<span><?=date("d.m.Y", $news->create)?>:</span>
|
||||
<?php if($news->subject): ?>
|
||||
<?=$news->subject?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="card-body pb-0">
|
||||
<div class="row col-12">
|
||||
<div><?=$news->text?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer bg-light text-secondary text-monospace font-italic">
|
||||
<?=$news->editor->name?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
8
Layout/default/News/Form.php
Normal file
8
Layout/default/News/Form.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
77
Layout/default/News/Index.php
Normal file
77
Layout/default/News/Index.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
|
||||
<li class="breadcrumb-item active">News</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">News</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title">Liste aller News</h4>
|
||||
|
||||
<?php foreach($newss as $news): ?>
|
||||
<div class="card mb-1" style="border: 1px solid #ddd">
|
||||
<div class="card-header bg-light text-monospace text-muted pl-2 pr-2 pt-1 pb-1"><span class="font-weight-bold" ><i class="fas fa-clock"></i> <?=date("d.m.Y H:i:s", $news->create)?></span> Eingetragen von <strong><?=$news->editor->name?></strong> <span class="float-right"><a class="text-danger" href="<?=self::getUrl("News", "delete", ['id' => $news->id])?>" onclick="if(!confirm('Eintrag wirklich löschen?')) return false;"><i class="fas fa-trash"></i></a></span></div>
|
||||
<div class="card-body ml-2 mr-2 pt-1 pb-1">
|
||||
<div class="row mb-2 font-weight-bold">
|
||||
Betreff: <?=$news->subject?>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div><?=$news->text?></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title border-bottom">Neuer Newseintrag</h4>
|
||||
|
||||
<form method="post" action="<?=self::getUrl("News","Save")?>">
|
||||
<div class="form-group mt-2">
|
||||
<label for="subject">Betreff (optional):</label>
|
||||
<input type="text" id="subject" name="subject" class="form-control" value="<?=$new_news->subject?>" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new_text">Text:</label>
|
||||
<textarea class="textarea" name="new_text" id="new_id" placeholder="Place some text here" rows="8" style="width: 100%; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;"><?=$new_news->text?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<input type="submit" name="submit" value="Speichern" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="<?=self::getResourcePath()?>plugins/summernote/summernote-bs4.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$('.textarea').summernote({
|
||||
height: 400
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
@@ -18,6 +18,7 @@
|
||||
<link href="<?=self::getResourcePath()?>assets/libs/select2/select2.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="<?=self::getResourcePath()?>assets/css/bootstrap-select.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="<?=self::getResourcePath()?>css/bootstrap-datepicker3.min.css" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="<?=self::getResourcePath()?>plugins/summernote/summernote-bs4.css" />
|
||||
|
||||
<script type="text/javascript" src="<?=self::getResourcePath()?>js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="<?=self::getResourcePath()?>assets/libs/select2/select2.min.js"></script>
|
||||
|
||||
@@ -4,11 +4,21 @@
|
||||
<!-- Navigation Menu-->
|
||||
<ul class="navigation-menu">
|
||||
|
||||
<?php if(!$me->is("Admin")): ?>
|
||||
<li class="has-submenu">
|
||||
<a href="<?=self::getUrl("Dashboard")?>"><i class="fe-airplay"></i>Dashboard</a>
|
||||
<a href="<?=self::getUrl("Dashboard")?>"><i class="fe-airplay"></i> Dashboard</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if($me->is("Admin")): ?>
|
||||
<li class="has-submenu">
|
||||
<a href="<?=self::getUrl("Dashboard")?>"><i class="fe-airplay"></i> Dashboard <div class="arrow-down"></div></a>
|
||||
<ul class="submenu">
|
||||
<li><a href="<?=self::getUrl("News")?>"><i class="fas fa-th-list"></i> News</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="has-submenu">
|
||||
<a href="#">
|
||||
<i class="fas fa-database"></i>Stammdaten <div class="arrow-down"></div>
|
||||
|
||||
@@ -11,7 +11,8 @@ class DashboardController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
|
||||
$newss = NewsModel::getAll();
|
||||
$this->layout()->set("newss", $newss);
|
||||
}
|
||||
|
||||
|
||||
|
||||
9
application/News/News.php
Normal file
9
application/News/News.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class News extends mfBaseModel {
|
||||
public $editor;
|
||||
|
||||
protected function afterLoad() {
|
||||
$this->editor = new User($this->edit_by);
|
||||
}
|
||||
}
|
||||
86
application/News/NewsController.php
Normal file
86
application/News/NewsController.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
class NewsController 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 indexAction() {
|
||||
$this->layout()->setTemplate("News/Index");
|
||||
|
||||
$newss = NewsModel::getAll();
|
||||
$this->layout()->set("newss", $newss);
|
||||
}
|
||||
|
||||
protected function saveAction($request) {
|
||||
if(!$this->me->isAdmin()) {
|
||||
return $this->redirect("News");
|
||||
}
|
||||
|
||||
$id = false;
|
||||
|
||||
$cl = new News();
|
||||
|
||||
$cl->subject = $request['subject'];
|
||||
$cl->text = preg_replace('/<[^>]*script/','',$request['new_text']);
|
||||
|
||||
|
||||
if(!$id) {
|
||||
$cl->create_by = $this->me->id;
|
||||
}
|
||||
$cl->edit_by = $this->me->id;
|
||||
|
||||
if(!$cl->save()) {
|
||||
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut!", "error");
|
||||
$this->layout()->set("new_news", $cl);
|
||||
$this->layout()->setTemplate("News/Index");
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("News gespeichert!","success");
|
||||
$this->redirect("News");
|
||||
|
||||
}
|
||||
|
||||
protected function deleteAction($request) {
|
||||
if(!$this->me->isAdmin()) {
|
||||
$this->redirect("News");
|
||||
}
|
||||
|
||||
if(!isset($request['id']) || !is_numeric($request['id']) || $request['id'] < 1) {
|
||||
$this->layout()->setFlash("Eintrag nicht gefunden", "error");
|
||||
$this->redirect("News");
|
||||
}
|
||||
$id = $request['id'];
|
||||
|
||||
$cl = new News($id);
|
||||
$cl->delete();
|
||||
$this->layout()->setFlash("Eintrag mit ID $id wurde gelöscht.","success");
|
||||
$this->redirect("News");
|
||||
|
||||
}
|
||||
|
||||
private function getNews() {
|
||||
$cl = [];
|
||||
|
||||
$res = $this->db()->select("News", "*", "1=1 ORDER BY `create` DESC");
|
||||
if(!$this->db()->num_rows($res)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
$cl[] = new News($data);
|
||||
}
|
||||
|
||||
return $cl;
|
||||
}
|
||||
}
|
||||
108
application/News/NewsModel.php
Normal file
108
application/News/NewsModel.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
class NewsModel {
|
||||
public $subject = 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 News();
|
||||
|
||||
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("News", "*", "id=$id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new News($data);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("News", "*", "1 = 1 ORDER BY `create` DESC,`edit` DESC");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new News($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("News", "*", "$where ORDER BY `create`,`edit` DESC LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new News($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("News", "*", "$where ORDER BY `create`,`edit` DESC");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new News($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -393,4 +393,4 @@ td.controls {
|
||||
|
||||
.pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user