Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed May 31, 2024
1 parent 211e5d6 commit 0436563
Show file tree
Hide file tree
Showing 37 changed files with 211 additions and 262 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Questions for Elgg
==================

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/questions/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/questions/v/stable.svg)](https://packagist.org/packages/coldtrick/questions)
[![License](https://poser.pugx.org/coldtrick/questions/license.svg)](https://packagist.org/packages/coldtrick/questions)
Expand All @@ -17,4 +17,4 @@ Features
* Like questions + answers

(C) 2011 Evan Winslow
(C) 2015-2023 ColdTrick IT Solutions
(C) 2015-2024 ColdTrick IT Solutions
5 changes: 3 additions & 2 deletions classes/ColdTrick/Questions/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ColdTrick\Questions;

use Elgg\Database\MetadataTable;
use Elgg\Database\QueryBuilder;
use Elgg\Values;

Expand Down Expand Up @@ -105,7 +106,7 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
set_time_limit(0);

$status_where = function (QueryBuilder $qb, $main_alias) {
$sub = $qb->subquery('metadata')
$sub = $qb->subquery(MetadataTable::TABLE_NAME)
->select('entity_guid')
->where($qb->compare('name', '=', 'status', ELGG_VALUE_STRING))
->andWhere($qb->compare('value', '=', 'closed', ELGG_VALUE_STRING));
Expand All @@ -125,7 +126,7 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
// loop through all experts
/* @var $expert \ElggUser */
foreach ($experts as $expert) {
// fake a logged in user
// fake a logged-in user
$session_manager->setLoggedInUser($expert);

$subject = elgg_echo('questions:daily:notification:subject', [], $expert->getLanguage());
Expand Down
4 changes: 2 additions & 2 deletions classes/ColdTrick/Questions/Menus/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public static function registerAnswer(\Elgg\Event $event): ?MenuItems {

$result[] = \ElggMenuItem::factory([
'name' => 'questions-mark',
'icon' => 'check',
'text' => elgg_echo('questions:menu:entity:answer:mark'),
'href' => elgg_generate_action_url('answers/toggle_mark', [
'guid' => $entity->guid,
]),
'icon' => 'check',
'item_class' => $entity->isCorrectAnswer() ? 'hidden' : '',
'data-toggle' => 'questions-unmark',
]);

$result[] = \ElggMenuItem::factory([
'name' => 'questions-unmark',
'icon' => 'undo',
'text' => elgg_echo('questions:menu:entity:answer:unmark'),
'href' => elgg_generate_action_url('answers/toggle_mark', [
'guid' => $entity->guid,
]),
'icon' => 'undo',
'item_class' => $entity->isCorrectAnswer() ? '' : 'hidden',
'data-toggle' => 'questions-mark',
]);
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/Questions/Menus/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function registerQuestions(\Elgg\Event $event): MenuItems {
'name' => 'questions',
'icon' => 'question',
'text' => elgg_echo('questions'),
'href' => elgg_generate_url('collection:object:question:all'),
'href' => elgg_generate_url('default:object:question'),
]);

return $result;
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/Questions/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function addQuestionOwnerToCommentSubscribers(\Elgg\Event $event):
*/
public static function addQuestionSubscribersToCommentSubscribers(\Elgg\Event $event): ?array {
$notification_event = $event->getParam('event');
if (!$event instanceof SubscriptionNotificationEvent) {
if (!$notification_event instanceof SubscriptionNotificationEvent) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
class CorrectAnswerNotificationEventHandler extends NotificationEventHandler {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:answer:correct:subject', [$this->getQuestion()->getDisplayName()], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:answer:correct:summary', [$this->getQuestion()->getDisplayName()], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:answer:correct:message', [
Expand All @@ -45,7 +45,7 @@ protected function getQuestion(): \ElggQuestion {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public static function isConfigurableByUser(): bool {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
class CreateAnswerNotificationEventHandler extends NotificationEventHandler {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:answer:create:subject', [$this->getQuestion()->getDisplayName()], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:answer:create:summary', [$this->getQuestion()->getDisplayName()], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:answer:create:message', [
Expand All @@ -45,7 +45,7 @@ protected function getQuestion(): \ElggQuestion {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public static function isConfigurableByUser(): bool {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class CreateQuestionNotificationEventHandler extends NotificationEventHandler {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getSubscriptions(): array {
$result = parent::getSubscriptions();
Expand Down Expand Up @@ -65,21 +65,21 @@ public function getSubscriptions(): array {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:create:subject', [], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:create:summary', [], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:create:message', [
Expand All @@ -98,7 +98,7 @@ protected function getQuestion(): \ElggQuestion {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected static function isConfigurableForGroup(\ElggGroup $group): bool {
return $group->isToolEnabled('questions');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class MoveQuestionNotificationEventHandler extends NotificationEventHandler {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getSubscriptions(): array {
if (!questions_experts_enabled()) {
Expand Down Expand Up @@ -60,21 +60,21 @@ public function getSubscriptions(): array {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:move:subject', [], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:move:summary', [], $recipient->getLanguage());
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
return elgg_echo('questions:notifications:move:message', [
Expand All @@ -93,7 +93,7 @@ protected function getQuestion(): \ElggQuestion {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public static function isConfigurableByUser(): bool {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
class MigrateQuestions extends Migrate {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canBackDate(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeContainer(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeOwner(): bool {
return true;
Expand Down
8 changes: 4 additions & 4 deletions classes/ColdTrick/Questions/Router/ExpertGatekeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Elgg\Exceptions\Http\EntityPermissionsException;
use Elgg\Exceptions\HttpException;
use Elgg\Router\Middleware\Gatekeeper;

/**
* Only allow Question experts to view a page
*/
class ExpertGatekeeper {
class ExpertGatekeeper extends Gatekeeper {

/**
* Validate the page access
Expand All @@ -18,9 +19,8 @@ class ExpertGatekeeper {
* @return void
* @throws HttpException
*/
public function __invoke(\Elgg\Request $request) {
// make sure we're logged in
$request->elgg()->gatekeeper->assertAuthenticatedUser();
public function __invoke(\Elgg\Request $request): void {
parent::__invoke($request);

// make sure the current user is an expert
$page_owner = null;
Expand Down
14 changes: 7 additions & 7 deletions classes/ColdTrick/Questions/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class Search {
*
* @param \Elgg\Event $event 'search:config', 'type_subtype_pairs'
*
* @return mixed
* @return null|array
*/
public static function typeSubtypePairsConfig(\Elgg\Event $event) {
public static function typeSubtypePairsConfig(\Elgg\Event $event): ?array {
$types = $event->getValue();
$objects = elgg_extract('object', $types);
if (empty($objects)) {
return;
return null;
}

$key = array_search(\ElggAnswer::SUBTYPE, $objects);
if ($key === false) {
return;
return null;
}

unset($objects[$key]);
Expand All @@ -37,9 +37,9 @@ public static function typeSubtypePairsConfig(\Elgg\Event $event) {
*
* @param \Elgg\Event $event 'search:options', 'all'
*
* @return mixed
* @return null|array
*/
public static function optionsAddAnswers(\Elgg\Event $event) {
public static function optionsAddAnswers(\Elgg\Event $event): ?array {
$search_params = $event->getValue();

$type_subtype_pairs = false;
Expand All @@ -50,7 +50,7 @@ public static function optionsAddAnswers(\Elgg\Event $event) {
}

if (empty($subtypes) || !in_array(\ElggQuestion::SUBTYPE, $subtypes) || in_array(\ElggAnswer::SUBTYPE, $subtypes)) {
return;
return null;
}

$subtypes[] = \ElggAnswer::SUBTYPE;
Expand Down
8 changes: 4 additions & 4 deletions classes/ColdTrick/Questions/Seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Seeder extends Seed {

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function seed() {
$this->advance($this->getCount());
Expand Down Expand Up @@ -110,7 +110,7 @@ public function seed() {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function unseed() {
/* @var $entities \ElggBatch */
Expand Down Expand Up @@ -138,14 +138,14 @@ public function unseed() {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public static function getType(): string {
return \ElggQuestion::SUBTYPE;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
protected function getCountOptions(): array {
return [
Expand Down
Loading

0 comments on commit 0436563

Please sign in to comment.