mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
New hooks for news management
Can be used for example as discord hooks
This commit is contained in:
parent
85bc2342cf
commit
36bd3eb846
@ -37,26 +37,27 @@ class News
|
|||||||
if(!self::verify($title, $body, $article_text, $article_image, $errors))
|
if(!self::verify($title, $body, $article_text, $article_image, $errors))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ModelsNews::create([
|
$currentTime = time();
|
||||||
'title' => $title,
|
|
||||||
'body' => $body,
|
$params = [
|
||||||
'type' => $type,
|
'title' => $title, 'body' => $body,
|
||||||
'date' => time(),
|
'type' => $type, 'category' => $category,
|
||||||
'category' => $category,
|
'date' => $currentTime,
|
||||||
'player_id' => isset($player_id) ? $player_id : 0,
|
'player_id' => $player_id ?? 0,
|
||||||
'comments' => $comments,
|
'comments' => $comments,
|
||||||
'article_text' => ($type == 3 ? $article_text : ''),
|
'article_text' => ($type == 3 ? $article_text : ''),
|
||||||
'article_image' => ($type == 3 ? $article_image : '')
|
'article_image' => ($type == 3 ? $article_image : '')
|
||||||
]);
|
];
|
||||||
|
|
||||||
global $hooks;
|
global $hooks;
|
||||||
|
if (!$hooks->trigger(HOOK_ADMIN_NEWS_ADD_PRE, $params)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newsModel = ModelsNews::create($params);
|
||||||
|
|
||||||
$hooks->trigger(HOOK_ADMIN_NEWS_ADD,
|
$hooks->trigger(HOOK_ADMIN_NEWS_ADD,
|
||||||
[
|
$params + ['id' => $newsModel->id],
|
||||||
'title' => $title, 'body' => $body,
|
|
||||||
'type' => $type, 'category' => $category,
|
|
||||||
'player_id' => $player_id, 'comments' => $comments,
|
|
||||||
'article_text' => $article_text, 'article_image' => $article_image,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
self::clearCache();
|
self::clearCache();
|
||||||
@ -69,30 +70,55 @@ class News
|
|||||||
|
|
||||||
static public function update($id, $title, $body, $type, $category, $player_id, $comments, $article_text, $article_image, &$errors)
|
static public function update($id, $title, $body, $type, $category, $player_id, $comments, $article_text, $article_image, &$errors)
|
||||||
{
|
{
|
||||||
if(!self::verify($title, $body, $article_text, $article_image, $errors))
|
if(!self::verify($title, $body, $article_text, $article_image, $errors)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ModelsNews::where('id', $id)->update([
|
$currentTime = time();
|
||||||
'title' => $title,
|
|
||||||
'body' => $body,
|
$params = [
|
||||||
'type' => $type,
|
'id' => $id,
|
||||||
'category' => $category,
|
'title' => $title, 'body' => $body,
|
||||||
'last_modified_by' => isset($player_id) ? $player_id : 0,
|
'type' => $type, 'category' => $category,
|
||||||
'last_modified_date' => time(),
|
'last_modified_by' => $player_id ?? 0, 'last_modified_date' => $currentTime,
|
||||||
'comments' => $comments,
|
'comments' => $comments,
|
||||||
'article_text' => $article_text,
|
'article_text' => ($type == 3 ? $article_text : ''),
|
||||||
'article_image' => $article_image
|
'article_image' => ($type == 3 ? $article_image : ''),
|
||||||
]);
|
];
|
||||||
|
|
||||||
|
global $hooks;
|
||||||
|
if (!$hooks->trigger(HOOK_ADMIN_NEWS_UPDATE_PRE, $params)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($params['id']);
|
||||||
|
|
||||||
|
ModelsNews::where('id', $id)->update($params);
|
||||||
|
|
||||||
|
$hooks->trigger(HOOK_ADMIN_NEWS_UPDATE,
|
||||||
|
$params + ['id' => $id]
|
||||||
|
);
|
||||||
|
|
||||||
self::clearCache();
|
self::clearCache();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function delete($id, &$errors)
|
static public function delete($id, &$errors)
|
||||||
{
|
{
|
||||||
|
global $hooks;
|
||||||
|
|
||||||
if(isset($id)) {
|
if(isset($id)) {
|
||||||
$row = ModelsNews::find($id);
|
$row = ModelsNews::find($id);
|
||||||
if($row) {
|
if($row) {
|
||||||
if (!$row->delete()) {
|
$params = ['id' => $id];
|
||||||
|
|
||||||
|
if (!$hooks->trigger(HOOK_ADMIN_NEWS_DELETE_PRE, $params)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row->delete()) {
|
||||||
|
$hooks->trigger(HOOK_ADMIN_NEWS_DELETE, $params);
|
||||||
|
} else {
|
||||||
$errors[] = 'Fail during delete News.';
|
$errors[] = 'Fail during delete News.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,22 +140,35 @@ class News
|
|||||||
|
|
||||||
static public function toggleHide($id, &$errors, &$status)
|
static public function toggleHide($id, &$errors, &$status)
|
||||||
{
|
{
|
||||||
if(isset($id))
|
global $hooks;
|
||||||
{
|
|
||||||
|
if(isset($id)) {
|
||||||
$row = ModelsNews::find($id);
|
$row = ModelsNews::find($id);
|
||||||
if($row)
|
if($row) {
|
||||||
{
|
$row->hide = ($row->hide == 1 ? 0 : 1);
|
||||||
$row->hide = $row->hide == 1 ? 0 : 1;
|
|
||||||
if (!$row->save()) {
|
$params = ['hide' => $row->hide];
|
||||||
|
|
||||||
|
if (!$hooks->trigger(HOOK_ADMIN_NEWS_TOGGLE_HIDE_PRE, $params)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row->save()) {
|
||||||
|
$hooks->trigger(HOOK_ADMIN_NEWS_TOGGLE_HIDE, $params);
|
||||||
|
}
|
||||||
|
else {
|
||||||
$errors[] = 'Fail during toggle hide News.';
|
$errors[] = 'Fail during toggle hide News.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = $row->hide;
|
$status = $row->hide;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
$errors[] = 'News with id ' . $id . ' does not exists.';
|
$errors[] = 'News with id ' . $id . ' does not exists.';
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
$errors[] = 'News id not set.';
|
$errors[] = 'News id not set.';
|
||||||
|
}
|
||||||
|
|
||||||
if(count($errors)) {
|
if(count($errors)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -71,7 +71,14 @@ define('HOOK_ADMIN_BODY_START', ++$i);
|
|||||||
define('HOOK_ADMIN_BODY_END', ++$i);
|
define('HOOK_ADMIN_BODY_END', ++$i);
|
||||||
define('HOOK_ADMIN_BEFORE_PAGE', ++$i);
|
define('HOOK_ADMIN_BEFORE_PAGE', ++$i);
|
||||||
define('HOOK_ADMIN_MENU', ++$i);
|
define('HOOK_ADMIN_MENU', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_ADD_PRE', ++$i);
|
||||||
define('HOOK_ADMIN_NEWS_ADD', ++$i);
|
define('HOOK_ADMIN_NEWS_ADD', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_UPDATE_PRE', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_UPDATE', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_DELETE_PRE', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_DELETE', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_TOGGLE_HIDE_PRE', ++$i);
|
||||||
|
define('HOOK_ADMIN_NEWS_TOGGLE_HIDE', ++$i);
|
||||||
define('HOOK_ADMIN_LOGIN_AFTER_ACCOUNT', ++$i);
|
define('HOOK_ADMIN_LOGIN_AFTER_ACCOUNT', ++$i);
|
||||||
define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i);
|
define('HOOK_ADMIN_LOGIN_AFTER_PASSWORD', ++$i);
|
||||||
define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i);
|
define('HOOK_ADMIN_LOGIN_AFTER_SIGN_IN', ++$i);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user