Skip to content

Commit

Permalink
Merge pull request #26 from alexplusde/type_hinting
Browse files Browse the repository at this point in the history
type hinting, rexstan
  • Loading branch information
alxndr-w authored Nov 24, 2023
2 parents 4fe3a32 + 34b9fb8 commit baef070
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Tablesets aktualisieren */

rex_yform_manager_table_api::importTablesets(rex_file::get(rex_path::addon($this->name, 'install/rex_qanda.tableset.json')));
rex_yform_manager_table_api::importTablesets(rex_file::get(rex_path::addon('qanda', 'install/rex_qanda.tableset.json')));

rex_yform_manager_table::deleteCache();
/*
Expand Down
24 changes: 12 additions & 12 deletions lib/qanda.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@

class qanda extends \rex_yform_manager_dataset
{
public function getCategory()
public function getCategory(): ?rex_yform_manager_dataset
{
return $this->getCategories()[0];
return $this->getCategories()->first();
}

public function getCategories()
public function getCategories(): ?rex_yform_manager_collection
{
return $this->getRelatedCollection('category_ids');
}

public function getQuestion($lang = null): string
public function getQuestion(?string $lang = null): string
{
if ($lang) {
return $this->getTranslation($lang)->getValue('question');
}
return $this->getValue('question');
}

public static function findByIds(array $ids, float $status = 1)
public static function findByIds(array $ids, float $status = 1): ?rex_yform_manager_collection
{
$ids = implode(',', $ids);
return self::query()->whereRaw('status >= ' . $status . ' AND FIND_IN_SET(id, "' . $ids . '")')->find();
}

public static function findByCategoryIds(array $category_ids, float $status = 1)
public static function findByCategoryIds(array $category_ids, float $status = 1): ?rex_yform_manager_collection
{
$ids = implode(',', $category_ids);
return self::query()->whereRAW('status >= ' . $status . ' AND FIND_IN_SET(category_ids, "' . $ids . '")')->find();
}

public function getAnswer($lang = null): string
public function getAnswer(?string $lang = null): string
{
if ($lang) {
return $this->getTranslation($lang)->getValue('answer');
}
return $this->getValue('answer');
}

public function getAnswerAsPlaintext($lang = null): string
public function getAnswerAsPlaintext(?string $lang = null): string
{
if ($lang) {
return strip_tags($this->getTranslation($lang)->getValue('answer'));
}
return strip_tags($this->getValue('answer'));
}

public function getTranslation($lang = null): mixed
public function getTranslation(?string $lang = null): mixed
{
if ($lang) {
return qanda_lang::getTranslation($this->getId(), $lang);
Expand All @@ -61,7 +61,7 @@ public function getAuthor(): string
return $this->getValue('author');
}

public function getUrl($param = 'question-header-')
public function getUrl(string $param = 'question-header-'): string
{
if (rex_addon::get('yrewrite') && rex_addon::get('yrewrite')->isAvailable()) {
$host = rex_yrewrite::getFullUrlByArticleId(rex_article::getCurrentId(), rex_clang::getCurrentId());
Expand All @@ -72,14 +72,14 @@ public function getUrl($param = 'question-header-')
return rtrim($host, '/') . '#' . $param . $this->getId();
}

public static function showJsonLd($question)
public static function showJsonLd(int|rex_yform_manager_dataset $question): string
{
$fragment = new rex_fragment();
$fragment->setVar('question', $question);
return $fragment->parse('qanda.json-ld.php');
}

public static function showFAQPage($questions)
public static function showFAQPage(array|rex_yform_manager_collection $questions): string
{
$fragment = new rex_fragment();
$fragment->setVar('questions', $questions);
Expand Down
8 changes: 4 additions & 4 deletions lib/qanda_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

class qanda_category extends \rex_yform_manager_dataset
{
public function getName()
public function getName(): string
{
return $this->getValue('name');
}

public static function findByIds($ids, $status = 1)
public static function findByIds(array|string $ids, int $status = 1): ?rex_yform_manager_collection
{
if (is_array($ids)) {
$ids = implode(',', $ids);
}
return self::query()->whereRaw('status >= ' . $status . ' AND FIND_IN_SET(id, "' . $ids . '")')->find();
}

public function find($status = 1)
public function find(int $status = 1): ?rex_yform_manager_collection
{
return qanda::query()->where('status', $status, '>=')->whereListContains('category_ids', $this->id)->find();
return qanda::query()->where('status', $status, '>=')->whereListContains('category_ids', $this->getId())->find();
}
}
6 changes: 3 additions & 3 deletions lib/qanda_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ public function getAnswerAsPlaintext(): string
return strip_tags($this->getValue('answer'));
}

public function getQuestion()
public function getQuestion(): string
{
return $this->getValue('question');
}

public function getAnswer()
public function getAnswer(): string
{
return $this->getValue('answer');
}

public static function getTranslation($question, $lang): self
public static function getTranslation(int $question, string $lang): ?self
{
return self::query()->where('qanda_id', $question)->where('clang_id', $lang)->findOne();
}
Expand Down
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: qanda
version: '2.1.0'
version: '2.1.1'
author: 'Alexander Walther'
supportpage: https://alexplusde.github.io/qanda/
load: late
Expand Down
2 changes: 1 addition & 1 deletion pages/data_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$_REQUEST['table_name'] = $table_name;
}

if (true !== $currentPage->getItemAttr('show_title', false)) {
if (true !== $currentPage->getItemAttr('show_title')) {
rex_extension::register('YFORM_MANAGER_DATA_PAGE_HEADER', static function ($ep) {
if ($ep->getParam('yform')->table->getTableName() !== $ep->getParam('table_name')) {
return;
Expand Down
4 changes: 0 additions & 4 deletions pages/index.php

This file was deleted.

1 change: 0 additions & 1 deletion pages/qanda.dev.php

This file was deleted.

3 changes: 2 additions & 1 deletion pages/qanda.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

echo rex_view::title($this->getProperty('page')['title']);
$addon = rex_addon::get('qanda');
echo rex_view::title($addon->getProperty('page')['title']);
rex_be_controller::includeCurrentPageSubPath();
4 changes: 2 additions & 2 deletions pages/qanda.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

$fragment = new rex_fragment();
$fragment->setVar('class', 'info', false);
$fragment->setVar('title', $this->i18n('qanda_donate'), false);
$fragment->setVar('body', '<p>' . $this->i18n('qanda_info_donate') . '</p>' . $anchor, false);
$fragment->setVar('title', $addon->i18n('qanda_donate'), false);
$fragment->setVar('body', '<p>' . $addon->i18n('qanda_info_donate') . '</p>' . $anchor, false);
echo !rex_config::get('alexplusde', 'donated') ? $fragment->parse('core/page/section.php') : '';
?>
</div>
Expand Down

0 comments on commit baef070

Please sign in to comment.