Another WIP
parent
2fe526da09
commit
5bfede1d45
|
@ -5,4 +5,5 @@ www/css/archive/*
|
|||
www/js/archive/*
|
||||
vendor
|
||||
config/config.ini
|
||||
tmp/
|
||||
tmp/
|
||||
translationkeys.txt
|
||||
|
|
|
@ -11,6 +11,8 @@ abstract class DataTypes {
|
|||
const INTEGER = 0x02;
|
||||
const BOOLEAN = 0x03;
|
||||
const DOUBLE = 0x04;
|
||||
const DATE = 0x05;
|
||||
const DATETIME = 0x06;
|
||||
}
|
||||
|
||||
abstract class Model {
|
||||
|
@ -85,6 +87,15 @@ abstract class Model {
|
|||
}
|
||||
}
|
||||
|
||||
public function __get($name){
|
||||
if($name == 'primaryfield'){
|
||||
return $this->{ array_keys( static::$fields )[0] };
|
||||
}
|
||||
else {
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
|
@ -206,8 +217,22 @@ abstract class Model {
|
|||
|
||||
$currValue = $this->{ $field };
|
||||
if(!empty($this->initialValues) && (!$obligatory || $currValue != $this->initialValues[$field])){
|
||||
$newFields[] = $field;
|
||||
$newValues[] = $currValue;
|
||||
if($type[0] === DataTypes::DATETIME){
|
||||
if($currValue === "now"){
|
||||
$currValue = date('Y-m-d H:i:s');
|
||||
}
|
||||
// TODO: Probably pick up keywords like "now" to insert into database
|
||||
}
|
||||
switch ($type[0]){
|
||||
case DataTypes::INTEGER:
|
||||
case DataTypes::BOOLEAN:
|
||||
$newFields[] = $field;
|
||||
$newValues[] = (int) $currValue;
|
||||
break;
|
||||
default:
|
||||
$newFields[] = $field;
|
||||
$newValues[] = $currValue;
|
||||
}
|
||||
}
|
||||
if($fieldCount > 0){
|
||||
$allExceptFirstField[] = $field;
|
||||
|
@ -227,7 +252,13 @@ abstract class Model {
|
|||
$updateSets[] = "`$field` = ?";
|
||||
}
|
||||
|
||||
DB::queryPreview(sprintf('UPDATE %s.%s SET %s WHERE %s LIMIT 1', static::$database, static::$table, implode(', ', $updateSets), "`" . array_keys(static::$fields)[0] . "` = ?"), array_merge($newValues, [$this->{array_keys(static::$fields)[0]}]));
|
||||
DB::query(sprintf(
|
||||
'UPDATE %s.%s SET %s WHERE %s LIMIT 1',
|
||||
static::$database,
|
||||
static::$table,
|
||||
implode(', ', $updateSets),
|
||||
"`" . array_keys(static::$fields)[0] . "` = ?"),
|
||||
array_merge($newValues, [$this->primaryfield]));
|
||||
}
|
||||
elseif(!empty($allExceptFirstValue)){
|
||||
$sql = sprintf('INSERT INTO %s.%s (%s) VALUE (%s)', static::$database, static::$table, implode(', ', $allExceptFirstField), implode(', ', array_fill(0, count($allExceptFirstField), '?')));
|
||||
|
@ -242,11 +273,21 @@ abstract class Model {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function delete(){
|
||||
public function delete($multidelete = false){
|
||||
if($this->isLoaded()){
|
||||
Utils::debug($this);
|
||||
exit;
|
||||
$sql = "DELETE FROM ";
|
||||
if(in_array('deleted', array_keys(static::$fields))){
|
||||
$new = new Static($this->primaryfield);
|
||||
$new->deleted = 'now';
|
||||
$new->save();
|
||||
}
|
||||
else {
|
||||
Utils::debug($this);
|
||||
$sql = sprintf("DELETE FROM %s.%s WHERE %s = ?", static::$database, static::$table, array_keys(static::$fields)[0]);
|
||||
if(!$multidelete){ $sql .= " LIMIT 1"; }
|
||||
Utils::debug($sql);
|
||||
DB::queryPreview($sql, $this->{array_keys(static::$fields)[0]});
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,4 +298,6 @@ abstract class Model {
|
|||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Interface hasDeletedColumn {}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
//namespace models;
|
||||
|
||||
class PlanStoreItem extends Model {
|
||||
class PlanStoreItem extends Model implements hasDeletedColumn {
|
||||
protected static $table = "plan_store_item";
|
||||
protected static $fields = [
|
||||
"plan_item_id" => [ Datatypes::INTEGER, OBLIGATORY ],
|
||||
|
@ -11,7 +11,8 @@ class PlanStoreItem extends Model {
|
|||
"name" => [ Datatypes::TEXT, OBLIGATORY ],
|
||||
"price" => [ Datatypes::DOUBLE, OBLIGATORY ],
|
||||
"amount" => [ DataTypes::DOUBLE ],
|
||||
"checked" => [ DataTypes::BOOLEAN ]
|
||||
"checked" => [ DataTypes::BOOLEAN ],
|
||||
"deleted" => [ DataTypes::DATETIME ]
|
||||
];
|
||||
|
||||
public function __set($name, $value){
|
||||
|
|
|
@ -5,25 +5,40 @@
|
|||
<div class="container-sm" style="padding-top: 5px;">
|
||||
|
||||
<div class="card-group" style="text-align: center;">
|
||||
|
||||
<div class="card h-100" style="">
|
||||
<!-- <img src="#" class="card-img-top" alt="Plan">-->
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Menu</h5>
|
||||
<p class="card-text">
|
||||
<ul class="list-group">
|
||||
{% for item in planner %}
|
||||
<li class="list-group-item {{ item.isred ? 'text-danger' : '' }}">
|
||||
<strong>{{ item.daytxt }}:</strong><br />
|
||||
- Unknown
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% apply t %}
|
||||
<div class="card h-100" style="">
|
||||
<a href='./plan'>
|
||||
<!-- <img src="#" class="card-img-top" alt="Plan">-->
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ 'Plan shopping'|t }}</h5>
|
||||
<h5 class="card-title">Plan shopping</h5>
|
||||
<p class="card-text"></p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% apply t %}
|
||||
<div class="card h-100" style="">
|
||||
<!-- <img src="#" class="card-img-top" alt="Review">-->
|
||||
{% endapply %}
|
||||
<!--<div class="card h-100" style="">
|
||||
< !-- <img src="#" class="card-img-top" alt="Review">-- >
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Review</h5>
|
||||
<p class="card-text">Coming soon</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endapply %}
|
||||
</div>-->
|
||||
</div>
|
||||
|
||||
<div class="card-group" style="text-align: center;">
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
<!-- jsDelivr :: Sortable :: Latest (https://www.jsdelivr.com/package/npm/sortablejs) -->
|
||||
<script src="/js/sortable/Sortable.min.js"></script> <!-- CDN: https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js -->
|
||||
<script src="/js/sortable/jquery-sortable.js"></script> <!-- CDN: https://cdn.jsdelivr.net/npm/jquery-sortablejs@latest/jquery-sortable.js -->
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
|
||||
/*
|
||||
function reorderArray($array): array {
|
||||
$arrays = array();
|
||||
|
||||
foreach ($array as $k1 => $v1){
|
||||
if($k1 > 2){ break; }
|
||||
|
||||
$newArr = array();
|
||||
$newArr[] = $v1;
|
||||
foreach ($array as $v2){
|
||||
if(!in_array($v2, $newArr)){
|
||||
$newArr[] = $v2;
|
||||
}
|
||||
}
|
||||
$arrays[] = $newArr;
|
||||
|
||||
if(count($array) > 2){
|
||||
$newArr = array();
|
||||
$newArr[] = $v1;
|
||||
foreach (array_reverse($array) as $v2){
|
||||
if(!in_array($v2, $newArr)){
|
||||
$newArr[] = $v2;
|
||||
}
|
||||
}
|
||||
$arrays[] = $newArr;
|
||||
}
|
||||
}
|
||||
|
||||
return $arrays;
|
||||
}
|
||||
|
||||
$array = array("revet","ost","tine","pizza");
|
||||
|
||||
echo "<pre>".print_r(reorderArray($array), true)."</pre>";
|
||||
*/
|
||||
|
|
@ -4,7 +4,7 @@ const VERIFY_STRING = "string";
|
|||
const VERIFY_INT = "integer";
|
||||
const VERIFY_NUMBER = "number";
|
||||
|
||||
const DEBUG = true;
|
||||
//const DEBUG = true;
|
||||
|
||||
|
||||
abstract class Api {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_startup_errors', 0);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
include_once '../../../Router.php';
|
||||
|
|
|
@ -12,6 +12,19 @@ class HomePage extends WebPage {
|
|||
$this->changes = file_get_contents('changes.txt');
|
||||
}
|
||||
|
||||
$current = new DateTime();
|
||||
|
||||
$planner = [];
|
||||
for($i = 0; $i < 7; $i++){
|
||||
$planner[$current->format('Ymd')] = [
|
||||
'day' => $current,
|
||||
'daytxt' => $current->format( __('D jS') ),
|
||||
'isred' => $current->format('N') == 7
|
||||
];
|
||||
$current->add(DateInterval::createFromDateString('1 day'));
|
||||
}
|
||||
|
||||
$this->planner = $planner;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue