crud update

This commit is contained in:
Shish 2019-12-26 00:36:32 +00:00
parent 67afe948bd
commit bafdb1c769
7 changed files with 124 additions and 71 deletions

50
composer.lock generated
View file

@ -11,7 +11,7 @@
"version": "1.12.4",
"source": {
"type": "git",
"url": "https://github.com/jquery/jquery-dist.git",
"url": "git@github.com:jquery/jquery-dist.git",
"reference": "5e89585e0121e72ff47de177c5ef604f3089a53d"
},
"dist": {
@ -388,12 +388,12 @@
"source": {
"type": "git",
"url": "https://github.com/shish/microcrud.git",
"reference": "f64681c605922909d57e9c17c0b63311f3c8a5d6"
"reference": "1f9d64bf0ff8c035b0709273a86f4ff9b791fe6e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/shish/microcrud/zipball/f64681c605922909d57e9c17c0b63311f3c8a5d6",
"reference": "f64681c605922909d57e9c17c0b63311f3c8a5d6",
"url": "https://api.github.com/repos/shish/microcrud/zipball/1f9d64bf0ff8c035b0709273a86f4ff9b791fe6e",
"reference": "1f9d64bf0ff8c035b0709273a86f4ff9b791fe6e",
"shasum": ""
},
"require": {
@ -429,7 +429,7 @@
"crud",
"generator"
],
"time": "2019-12-16T00:07:35+00:00"
"time": "2019-12-25T17:02:45+00:00"
},
{
"name": "shish/microhtml",
@ -485,12 +485,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "eca6c638ef64433b2e36a9221826e75e39c65eb9"
"reference": "6a1471ddbf2f448b35f3a8e390c903435e6dd5de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/eca6c638ef64433b2e36a9221826e75e39c65eb9",
"reference": "eca6c638ef64433b2e36a9221826e75e39c65eb9",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/6a1471ddbf2f448b35f3a8e390c903435e6dd5de",
"reference": "6a1471ddbf2f448b35f3a8e390c903435e6dd5de",
"shasum": ""
},
"require": {
@ -533,7 +533,7 @@
"constructor",
"instantiate"
],
"time": "2019-12-06T20:47:21+00:00"
"time": "2019-12-23T19:18:31+00:00"
},
{
"name": "myclabs/deep-copy",
@ -695,12 +695,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
"reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a"
"reference": "b0843c8cbcc2dc5eda5158e583c7199a5e44c86d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a",
"reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/b0843c8cbcc2dc5eda5158e583c7199a5e44c86d",
"reference": "b0843c8cbcc2dc5eda5158e583c7199a5e44c86d",
"shasum": ""
},
"require": {
@ -739,7 +739,7 @@
"reflection",
"static analysis"
],
"time": "2018-08-07T13:53:10+00:00"
"time": "2019-12-20T12:45:35+00:00"
},
{
"name": "phpdocumentor/reflection-docblock",
@ -747,12 +747,12 @@
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "1aef412299c8901c2a80c384f026574557975894"
"reference": "c19ab7ef57e75b5790aa912fd1cd14708e811970"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/1aef412299c8901c2a80c384f026574557975894",
"reference": "1aef412299c8901c2a80c384f026574557975894",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/c19ab7ef57e75b5790aa912fd1cd14708e811970",
"reference": "c19ab7ef57e75b5790aa912fd1cd14708e811970",
"shasum": ""
},
"require": {
@ -792,7 +792,7 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2019-12-13T15:12:00+00:00"
"time": "2019-12-20T13:36:14+00:00"
},
{
"name": "phpdocumentor/type-resolver",
@ -842,33 +842,33 @@
},
{
"name": "phpspec/prophecy",
"version": "1.9.0",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203"
"reference": "cbe1df668b3fe136bcc909126a0f529a78d4cbbc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/f6811d96d97bdf400077a0cc100ae56aa32b9203",
"reference": "f6811d96d97bdf400077a0cc100ae56aa32b9203",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/cbe1df668b3fe136bcc909126a0f529a78d4cbbc",
"reference": "cbe1df668b3fe136bcc909126a0f529a78d4cbbc",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0",
"sebastian/comparator": "^1.1|^2.0|^3.0",
"sebastian/comparator": "^1.2.3|^2.0|^3.0",
"sebastian/recursion-context": "^1.0|^2.0|^3.0"
},
"require-dev": {
"phpspec/phpspec": "^2.5|^3.2",
"phpspec/phpspec": "^2.5 || ^3.2",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8.x-dev"
"dev-master": "1.10.x-dev"
}
},
"autoload": {
@ -901,7 +901,7 @@
"spy",
"stub"
],
"time": "2019-10-03T11:07:50+00:00"
"time": "2019-12-22T21:05:45+00:00"
},
{
"name": "phpunit/php-code-coverage",

View file

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\TextColumn;
use MicroCRUD\Table;
@ -13,10 +14,11 @@ class AliasTable extends Table
$this->primary_key = "oldtag";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new TextColumn("oldtag", "Old Tag"),
new TextColumn("newtag", "New Tag"),
];
new ActionColumn("oldtag"),
]);
$this->order_by = ["oldtag"];
$this->table_attrs = ["class" => "zebra"];
}

View file

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\StringColumn;
use MicroCRUD\DateColumn;
use MicroCRUD\TextColumn;
@ -15,11 +16,12 @@ class HashBanTable extends Table
$this->primary_key = "hash";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new StringColumn("hash", "Hash"),
new TextColumn("reason", "Reason"),
new DateColumn("date", "Date"),
];
new ActionColumn("id"),
]);
$this->order_by = ["date DESC", "id"];
$this->create_url = make_link("image_hash_ban/add");
$this->delete_url = make_link("image_hash_ban/remove");

View file

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\InetColumn;
use MicroCRUD\StringColumn;
use MicroCRUD\DateColumn;
@ -21,7 +22,7 @@ class IPBanTable extends Table
";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new InetColumn("ip", "IP"),
new EnumColumn("mode", "Mode", [
"Block"=>"block",
@ -33,7 +34,8 @@ class IPBanTable extends Table
new StringColumn("banner", "Banner"),
new DateColumn("added", "Added"),
new DateColumn("expires", "Expires"),
];
new ActionColumn("id"),
]);
$this->order_by = ["expires", "id"];
$this->flags = [
"all" => ["((expires > CURRENT_TIMESTAMP) OR (expires IS NULL))", null],

View file

@ -8,6 +8,7 @@ use function MicroHTML\BR;
use function MicroHTML\SELECT;
use function MicroHTML\OPTION;
use function MicroHTML\rawHTML;
use MicroCRUD\ActionColumn;
use MicroCRUD\Column;
use MicroCRUD\DateTimeColumn;
use MicroCRUD\TextColumn;
@ -37,10 +38,55 @@ class ActorColumn extends Column
{
public function __construct($name, $title)
{
parent::__construct($name, $title, "((LOWER(username) LIKE LOWER(:{$name})) OR (address::text LIKE :{$name}))");
$this->input_mod = function ($var) {
return "%$var%";
};
parent::__construct($name, $title);
$this->sortable = false;
}
public function get_sql_filter(): string
{
$driver = $this->table->db->getAttribute(\PDO::ATTR_DRIVER_NAME);
switch ($driver) {
case "pgsql":
return "((username = :{$this->name}_0) OR (address && inet :{$this->name}_1))";
default:
return "((username = :{$this->name}_0) OR (address = :{$this->name}_1))";
}
}
public function read_input($inputs)
{
return emptyHTML(
INPUT([
"type" => "text",
"name" => "r_{$this->name}[]",
"placeholder" => "Username",
"value" => @$inputs["r_{$this->name}"][0]
]),
BR(),
INPUT([
"type" => "text",
"name" => "r_{$this->name}[]",
"placeholder" => "IP Address",
"value" => @$inputs["r_{$this->name}"][1]
])
);
}
public function modify_input_for_read($input)
{
list($un, $ip) = $input;
if (empty($un)) {
$un = null;
}
if (empty($ip)) {
$driver = $this->table->db->getAttribute(\PDO::ATTR_DRIVER_NAME);
switch ($driver) {
case "pgsql": $ip = "0.0.0.0/0"; break;
default: $ip = null; break;
}
}
return [$un, $ip];
>>>>>>> crud update
}
public function display($row)
@ -59,23 +105,13 @@ class MessageColumn extends Column
{
public function __construct($name, $title)
{
parent::__construct(
$name,
$title,
"($name LIKE :{$name}_0 AND priority >= :{$name}_1)"
);
$this->input_mod = function ($var) {
list($m, $l) = $var;
if (empty($m)) {
$m = "%";
} else {
$m = "%$m%";
}
if (empty($l)) {
$l = 0;
}
return [$m, $l];
};
parent::__construct($name, $title);
$this->sortable = false;
}
public function get_sql_filter(): string
{
return "({$this->name} LIKE :{$this->name}_0 AND priority >= :{$this->name}_1)";
}
public function read_input($inputs)
@ -109,6 +145,20 @@ class MessageColumn extends Column
return $ret;
}
public function modify_input_for_read($input)
{
list($m, $l) = $input;
if (empty($m)) {
$m = "%";
} else {
$m = "%$m%";
}
if (empty($l)) {
$l = 0;
}
return [$m, $l];
}
public function display($row)
{
$c = "#000";
@ -143,12 +193,13 @@ class LogTable extends Table
$this->base_query = "SELECT * FROM score_log";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new ShortDateTimeColumn("date_sent", "Time"),
new TextColumn("section", "Module"),
new ActorColumn("username_or_address", "User"),
new MessageColumn("message", "Message")
];
new MessageColumn("message", "Message"),
new ActionColumn("id"),
]);
$this->order_by = ["date_sent DESC"];
$this->table_attrs = ["class" => "zebra"];
}

View file

@ -1,5 +1,6 @@
<?php
use MicroCRUD\ActionColumn;
use MicroCRUD\TextColumn;
use MicroCRUD\Table;
@ -13,10 +14,11 @@ class NotATagTable extends Table
$this->primary_key = "tag";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new TextColumn("tag", "Tag"),
new TextColumn("redirect", "Redirect"),
];
new ActionColumn("id"),
]);
$this->order_by = ["tag", "redirect"];
$this->create_url = make_link("untag/add");
$this->delete_url = make_link("untag/remove");
@ -116,6 +118,7 @@ class NotATag extends Extension
$database->scoreql_to_sql(
"DELETE FROM untags WHERE LOWER(tag) = LOWER(:tag)"
),
["tag"=>$input['d_tag']]
);
$page->flash("Image ban removed");

View file

@ -3,7 +3,7 @@
require_once "events.php";
use function MicroHTML\A;
use MicroCRUD\Column;
use MicroCRUD\ActionColumn;
use MicroCRUD\EnumColumn;
use MicroCRUD\TextColumn;
use MicroCRUD\Table;
@ -16,21 +16,14 @@ class UserNameColumn extends TextColumn
}
}
class UserLinksColumn extends Column
class UserActionColumn extends ActionColumn
{
public function __construct()
{
parent::__construct("links", "User Links", "(1=1)");
parent::__construct("id", "User Links");
$this->sortable = false;
}
public function create_input(array $inputs)
{
return "";
}
public function read_input(array $inputs)
{
return "";
}
public function display(array $row)
{
return A(["href"=>make_link("post/list/user={$row['name']}/1")], "Posts");
@ -52,13 +45,13 @@ class UserTable extends Table
$this->base_query = "SELECT * FROM users";
$this->size = 100;
$this->limit = 1000000;
$this->columns = [
$this->set_columns([
new UserNameColumn("name", "Name"),
new EnumColumn("class", "Class", $classes),
// Added later, for admins only
// new TextColumn("email", "Email"),
new UserLinksColumn(),
];
new UserActionColumn(),
]);
$this->order_by = ["name"];
$this->table_attrs = ["class" => "zebra"];
}