Skip to content

Commit

Permalink
kleines Update (#873)
Browse files Browse the repository at this point in the history
PSR korrigiert
Desc wird nun auch verlinkt
  • Loading branch information
hhunderter authored Nov 24, 2023
1 parent 701752d commit 1811170
Show file tree
Hide file tree
Showing 13 changed files with 659 additions and 416 deletions.
16 changes: 11 additions & 5 deletions application/modules/link/config/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2
* @package ilch
Expand All @@ -10,7 +11,7 @@ class Config extends \Ilch\Config\Install
{
public $config = [
'key' => 'link',
'version' => '1.10.0',
'version' => '1.10.1',
'icon_small' => 'fa-solid fa-arrow-up-right-from-square',
'author' => 'Veldscholten, Kevin',
'link' => 'https://ilch.de',
Expand All @@ -35,11 +36,11 @@ public function install()

public function uninstall()
{
$this->db()->queryMulti('DROP TABLE `[prefix]_links`;
DROP TABLE `[prefix]_link_cats`;');
$this->db()->drop('links', true);
$this->db()->drop('link_cats', true);
}

public function getInstallSql()
public function getInstallSql(): string
{
return 'CREATE TABLE IF NOT EXISTS `[prefix]_links` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -66,7 +67,7 @@ public function getInstallSql()
(1, "ilch", "Du suchst ein einfach strukturiertes Content Management System? Dann bist du bei ilch genau richtig! ", "https://www.ilch.de/include/images/linkus/468x60.png", "https://ilch.de");';
}

public function getUpdate($installedVersion)
public function getUpdate(string $installedVersion): string
{
switch ($installedVersion) {
case "1.0":
Expand All @@ -89,8 +90,13 @@ public function getUpdate($installedVersion)

// Update possibly existing default Ilch entry
$this->db()->query("UPDATE `[prefix]_links` SET `banner` = 'https://www.ilch.de/include/images/linkus/468x60.png', `link` = 'https://ilch.de' WHERE `id` = 1 AND `banner` = 'http://www.ilch.de/include/images/linkus/468x60.png' AND `link` = 'http://ilch.de';");
// no break
case "1.9.0":
$this->db()->query("UPDATE `[prefix]_modules` SET `icon_small` = 'fa-solid fa-arrow-up-right-from-square' WHERE `key` = 'link';");
// no break
case "1.10.0":
}

return '"' . $this->config['key'] . '" Update-function executed.';
}
}
46 changes: 20 additions & 26 deletions application/modules/link/controllers/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2
* @package ilch
Expand All @@ -16,40 +17,36 @@ public function indexAction()
$linkMapper = new LinkMapper();
$categoryMapper = new CategoryMapper();

$category = null;
if ($this->getRequest()->getParam('cat_id')) {
$category = $categoryMapper->getCategoryById($this->getRequest()->getParam('cat_id'));

if (empty($category)) {
if (!$category) {
$this->redirect()
->withMessage('categoryNotFound', 'warning')
->to(['action' => 'index']);
}
}

if (!empty($category)) {
$parentCategories = $categoryMapper->getCategoriesForParent($category->getParentId());
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuLinks'), ['action' => 'index']);

$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuLinks'), ['action' => 'index']);
if ($category) {
$parentCategories = $categoryMapper->getCategoriesForParent($category->getParentId());

if (!empty($parentCategories)) {
foreach ($parentCategories as $parent) {
$this->getLayout()->getHmenu()
->add($parent->getName(), ['action' => 'index', 'cat_id' => $parent->getId()]);
}
foreach ($parentCategories ?? [] as $parent) {
$this->getLayout()->getHmenu()
->add($parent->getName(), ['action' => 'index', 'cat_id' => $parent->getId()]);
}

$this->getLayout()->getHmenu()
->add($category->getName(), ['action' => 'index', 'cat_id' => $this->getRequest()->getParam('cat_id')]);
->add($category->getName(), ['action' => 'index', 'cat_id' => $category->getId()]);

$links = $linkMapper->getLinks(['cat_id' => $this->getRequest()->getParam('cat_id')]);
$categorys = $categoryMapper->getCategories(['parent_id' => $this->getRequest()->getParam('cat_id')]);
$links = $linkMapper->getLinksByCatId($category->getId());
$categorys = $categoryMapper->getCategorysByParentId($category->getId());
} else {
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuLinks'), ['action' => 'index']);

$links = $linkMapper->getLinks(['cat_id' => 0]);
$categorys = $categoryMapper->getCategories(['parent_id' => 0]);
$links = $linkMapper->getLinksByCatId(0);
$categorys = $categoryMapper->getCategorysByParentId(0);
}

$this->getView()->set('links', $links);
Expand All @@ -60,17 +57,14 @@ public function redirectAction()
{
$linkMapper = new LinkMapper();

if (empty($this->getRequest()->getParam('link_id')) || !is_numeric($this->getRequest()->getParam('link_id'))) {
return;
}

$linkModel = $linkMapper->getLinkById($this->getRequest()->getParam('link_id'));
if (!empty($linkModel)) {
$linkModel->setHits($linkModel->getHits() + 1);
$linkModel = $linkMapper->getLinkById($this->getRequest()->getParam('link_id') ?? 0);
if ($linkModel) {
$linkModel->addHits();
$linkMapper->save($linkModel);

header('location: ' .$linkModel->getLink());
header('location: ' . $linkModel->getLink());
exit;
}
$this->redirect(['action' => 'index']);
}
}
Loading

0 comments on commit 1811170

Please sign in to comment.