booleanise tips

This commit is contained in:
Shish 2020-10-26 18:22:47 +00:00
parent 0c8c31b6c9
commit 3a8817bf57

View File

@ -35,20 +35,24 @@ class Tips extends Extension
if ($this->get_version("ext_tips_version") < 1) { if ($this->get_version("ext_tips_version") < 1) {
$database->create_table("tips", " $database->create_table("tips", "
id SCORE_AIPK, id SCORE_AIPK,
enable SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N, enable BOOLEAN NOT NULL DEFAULT FALSE,
image TEXT NOT NULL, image TEXT NOT NULL,
text TEXT NOT NULL, text TEXT NOT NULL,
"); ");
$database->execute( $database->execute(
" "
INSERT INTO tips (enable, image, text) INSERT INTO tips (enable, image, text)
VALUES (:enable, :image, :text)", VALUES (:enable, :image, :text)",
["enable"=>"Y", "image"=>"coins.png", "text"=>"Do you like this extension? Please support us for developing new ones. <a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8235933\" target=\"_blank\">Donate through paypal</a>."] ["enable"=>true, "image"=>"coins.png", "text"=>"Do you like this extension? Please support us for developing new ones. <a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8235933\" target=\"_blank\">Donate through paypal</a>."]
); );
$this->set_version("ext_tips_version", 1); $this->set_version("ext_tips_version", 2);
}
if ($this->get_version("ext_tips_version") < 2) {
$database->standardise_boolean("tips", "enable");
$this->set_version("ext_tips_version", 2);
} }
} }
@ -132,7 +136,7 @@ class Tips extends Extension
" "
INSERT INTO tips (enable, image, text) INSERT INTO tips (enable, image, text)
VALUES (:enable, :image, :text)", VALUES (:enable, :image, :text)",
["enable"=>$event->enable ? "Y" : "N", "image"=>$event->image, "text"=>$event->text] ["enable"=>$event->enable, "image"=>$event->image, "text"=>$event->text]
); );
} }
@ -145,7 +149,7 @@ class Tips extends Extension
$tip = $database->get_row("SELECT * ". $tip = $database->get_row("SELECT * ".
"FROM tips ". "FROM tips ".
"WHERE enable = 'Y' ". "WHERE enable = true ".
"ORDER BY RAND() ". "ORDER BY RAND() ".
"LIMIT 1"); "LIMIT 1");
@ -172,11 +176,7 @@ class Tips extends Extension
$tip = $database->get_row("SELECT * FROM tips WHERE id = :id ", ["id"=>$tipID]); $tip = $database->get_row("SELECT * FROM tips WHERE id = :id ", ["id"=>$tipID]);
if (bool_escape($tip['enable'])) { $enable = bool_escape($tip['enable']);
$enable = "N";
} else {
$enable = "Y";
}
$database->execute("UPDATE tips SET enable = :enable WHERE id = :id", ["enable"=>$enable, "id"=>$tipID]); $database->execute("UPDATE tips SET enable = :enable WHERE id = :id", ["enable"=>$enable, "id"=>$tipID]);
} }