Shortened some code

This commit is contained in:
slawkens 2019-03-18 20:00:33 +01:00
parent 7c8f87bd78
commit 8c50a84516
2 changed files with 19 additions and 44 deletions

View File

@ -131,13 +131,12 @@ if($action == 'edit' || $action == 'new') {
}
$query = $db->query('SELECT * FROM ' . $db->tableName(TABLE_PREFIX . 'news'));
$newses = $tickers = $articles = array();
$newses = array();
foreach ($query as $_news) {
$_player = new OTS_Player();
$_player->load($_news['player_id']);
if($_news['type'] == constant('NEWS')){
$newses[] = array(
$newses[$_news['type']][] = array(
'id' => $_news['id'],
'hidden' => $_news['hidden'],
'archive_link' => getLink('news') . '/archive/' . $_news['id'],
@ -146,34 +145,10 @@ foreach ($query as $_news) {
'player_name' => isset($_player) && $_player->isLoaded() ? $_player->getName() : '',
'player_link' => isset($_player) && $_player->isLoaded() ? getPlayerLink($_player->getName(), false) : '',
);
} else if ($_news['type'] == constant('TICKER')) {
$tickers[] = array(
'id' => $_news['id'],
'hidden' => $_news['hidden'],
'archive_link' => getLink('news') . '/archive/' . $_news['id'],
'title' => $_news['title'],
'date' => $_news['date'],
'player_name' => isset($_player) && $_player->isLoaded() ? $_player->getName() : '',
'player_link' => isset($_player) && $_player->isLoaded() ? getPlayerLink($_player->getName(), false) : '',
);
} else if ($_news['type'] == constant('ARTICLE')) {
$articles[] = array(
'id' => $_news['id'],
'hidden' => $_news['hidden'],
'archive_link' => getLink('news') . '/archive/' . $_news['id'],
'title' => $_news['title'],
'date' => $_news['date'],
'player_name' => isset($_player) && $_player->isLoaded() ? $_player->getName() : '',
'player_link' => isset($_player) && $_player->isLoaded() ? getPlayerLink($_player->getName(), false) : '',
);
}
}
$twig->display('admin.news.html.twig', array(
'newses' => $newses,
'tickers' => $tickers,
'articles' => $articles
'newses' => $newses
));
class News

View File

@ -19,7 +19,7 @@
</tr>
</thead>
<tbody>
{% for news in newses %}
{% for news in newses[constant('NEWS')] %}
<tr>
<td>{{ news.id|raw }}</td>
<td><i><a href="?p=news&action=edit&id={{ news.id }}">{{ news.title }}</a></i></td>
@ -80,7 +80,7 @@
</tr>
</thead>
<tbody>
{% for ticker in tickers %}
{% for ticker in newses[constant('TICKER')] %}
<tr>
<td>{{ ticker.id|raw }}</td>
<td><i><a href="?p=news&action=edit&id={{ ticker.id }}">{{ ticker.title }}</a></i></td>
@ -141,7 +141,7 @@
</tr>
</thead>
<tbody>
{% for article in articles %}
{% for article in newses[constant('ARTICLE')] %}
<tr>
<td>{{ article.id|raw }}</td>
<td><i><a href="?p=news&action=edit&id={{ article.id }}">{{ article.title }}</a></i></td>