diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 67fe092..6147873 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -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 diff --git a/README.md b/README.md index 5d63d83..0a6e01e 100644 --- a/README.md +++ b/README.md @@ -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) @@ -17,4 +17,4 @@ Features * Like questions + answers (C) 2011 Evan Winslow -(C) 2015-2023 ColdTrick IT Solutions +(C) 2015-2024 ColdTrick IT Solutions diff --git a/classes/ColdTrick/Questions/Cron.php b/classes/ColdTrick/Questions/Cron.php index 0590f0f..b0a1b4e 100644 --- a/classes/ColdTrick/Questions/Cron.php +++ b/classes/ColdTrick/Questions/Cron.php @@ -125,7 +125,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()); diff --git a/classes/ColdTrick/Questions/Menus/Entity.php b/classes/ColdTrick/Questions/Menus/Entity.php index 75d7443..737eaf5 100644 --- a/classes/ColdTrick/Questions/Menus/Entity.php +++ b/classes/ColdTrick/Questions/Menus/Entity.php @@ -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', ]); diff --git a/classes/ColdTrick/Questions/Menus/Site.php b/classes/ColdTrick/Questions/Menus/Site.php index 38dfe83..1e92791 100644 --- a/classes/ColdTrick/Questions/Menus/Site.php +++ b/classes/ColdTrick/Questions/Menus/Site.php @@ -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; diff --git a/classes/ColdTrick/Questions/Notifications.php b/classes/ColdTrick/Questions/Notifications.php index 5d29956..7c9bffa 100644 --- a/classes/ColdTrick/Questions/Notifications.php +++ b/classes/ColdTrick/Questions/Notifications.php @@ -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; } diff --git a/classes/ColdTrick/Questions/Notifications/CorrectAnswerNotificationEventHandler.php b/classes/ColdTrick/Questions/Notifications/CorrectAnswerNotificationEventHandler.php index 2b06504..c1b6781 100644 --- a/classes/ColdTrick/Questions/Notifications/CorrectAnswerNotificationEventHandler.php +++ b/classes/ColdTrick/Questions/Notifications/CorrectAnswerNotificationEventHandler.php @@ -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', [ @@ -45,7 +45,7 @@ protected function getQuestion(): \ElggQuestion { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function isConfigurableByUser(): bool { return false; diff --git a/classes/ColdTrick/Questions/Notifications/CreateAnswerNotificationEventHandler.php b/classes/ColdTrick/Questions/Notifications/CreateAnswerNotificationEventHandler.php index 820951e..1b54662 100644 --- a/classes/ColdTrick/Questions/Notifications/CreateAnswerNotificationEventHandler.php +++ b/classes/ColdTrick/Questions/Notifications/CreateAnswerNotificationEventHandler.php @@ -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', [ @@ -45,7 +45,7 @@ protected function getQuestion(): \ElggQuestion { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function isConfigurableByUser(): bool { return false; diff --git a/classes/ColdTrick/Questions/Notifications/CreateQuestionNotificationEventHandler.php b/classes/ColdTrick/Questions/Notifications/CreateQuestionNotificationEventHandler.php index 418b879..16678d1 100644 --- a/classes/ColdTrick/Questions/Notifications/CreateQuestionNotificationEventHandler.php +++ b/classes/ColdTrick/Questions/Notifications/CreateQuestionNotificationEventHandler.php @@ -10,7 +10,7 @@ class CreateQuestionNotificationEventHandler extends NotificationEventHandler { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getSubscriptions(): array { $result = parent::getSubscriptions(); @@ -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', [ @@ -98,7 +98,7 @@ protected function getQuestion(): \ElggQuestion { } /** - * {@inheritDoc} + * {@inheritdoc} */ protected static function isConfigurableForGroup(\ElggGroup $group): bool { return $group->isToolEnabled('questions'); diff --git a/classes/ColdTrick/Questions/Notifications/MoveQuestionNotificationEventHandler.php b/classes/ColdTrick/Questions/Notifications/MoveQuestionNotificationEventHandler.php index bf979fb..f1c9421 100644 --- a/classes/ColdTrick/Questions/Notifications/MoveQuestionNotificationEventHandler.php +++ b/classes/ColdTrick/Questions/Notifications/MoveQuestionNotificationEventHandler.php @@ -10,7 +10,7 @@ class MoveQuestionNotificationEventHandler extends NotificationEventHandler { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getSubscriptions(): array { if (!questions_experts_enabled()) { @@ -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', [ @@ -93,7 +93,7 @@ protected function getQuestion(): \ElggQuestion { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function isConfigurableByUser(): bool { return false; diff --git a/classes/ColdTrick/Questions/Plugins/EntityTools/MigrateQuestions.php b/classes/ColdTrick/Questions/Plugins/EntityTools/MigrateQuestions.php index d32e96f..8d8206c 100644 --- a/classes/ColdTrick/Questions/Plugins/EntityTools/MigrateQuestions.php +++ b/classes/ColdTrick/Questions/Plugins/EntityTools/MigrateQuestions.php @@ -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; diff --git a/classes/ColdTrick/Questions/Router/ExpertGatekeeper.php b/classes/ColdTrick/Questions/Router/ExpertGatekeeper.php index e35b835..1330871 100644 --- a/classes/ColdTrick/Questions/Router/ExpertGatekeeper.php +++ b/classes/ColdTrick/Questions/Router/ExpertGatekeeper.php @@ -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 @@ -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; diff --git a/classes/ColdTrick/Questions/Search.php b/classes/ColdTrick/Questions/Search.php index 3a8e394..bd566a5 100644 --- a/classes/ColdTrick/Questions/Search.php +++ b/classes/ColdTrick/Questions/Search.php @@ -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]); @@ -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; @@ -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; diff --git a/classes/ColdTrick/Questions/Seeder.php b/classes/ColdTrick/Questions/Seeder.php index 79cb393..bf00cc8 100644 --- a/classes/ColdTrick/Questions/Seeder.php +++ b/classes/ColdTrick/Questions/Seeder.php @@ -12,7 +12,7 @@ class Seeder extends Seed { /** - * {@inheritDoc} + * {@inheritdoc} */ public function seed() { $this->advance($this->getCount()); @@ -110,7 +110,7 @@ public function seed() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function unseed() { /* @var $entities \ElggBatch */ @@ -138,14 +138,14 @@ public function unseed() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function getType(): string { return \ElggQuestion::SUBTYPE; } /** - * {@inheritDoc} + * {@inheritdoc} */ protected function getCountOptions(): array { return [ diff --git a/classes/ElggAnswer.php b/classes/ElggAnswer.php index 3ac1dea..6ca6abf 100644 --- a/classes/ElggAnswer.php +++ b/classes/ElggAnswer.php @@ -2,13 +2,15 @@ /** * Answer entity class + * + * @property bool $correct_answer is this the correct answer */ class ElggAnswer extends \ElggObject { const SUBTYPE = 'answer'; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function initializeAttributes() { parent::initializeAttributes(); @@ -17,7 +19,7 @@ protected function initializeAttributes() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getURL(): string { // make sure we can get the container @@ -33,7 +35,7 @@ public function getURL(): string { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function canComment($user_guid = 0): bool { $container = $this->getContainerEntity(); @@ -47,7 +49,7 @@ public function canComment($user_guid = 0): bool { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getDisplayName(): string { $question = $this->getContainerEntity(); @@ -56,9 +58,9 @@ public function getDisplayName(): string { } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function delete(bool $recursive = true): bool { + protected function persistentDelete(bool $recursive = true): bool { // make sure the question gets reopened if ($this->isCorrectAnswer()) { // only if this is the correct answer @@ -67,7 +69,7 @@ public function delete(bool $recursive = true): bool { }); } - return parent::delete($recursive); + return parent::persistentDelete($recursive); } /** @@ -99,7 +101,7 @@ public function isCorrectAnswer(): bool { /** * Check if the user can mark this answer as the correct one * - * @param \ElggUser $user (optional) user to check the ability for (default: current user) + * @param null|\ElggUser $user (optional) user to check the ability for (default: current user) * * @return bool */ diff --git a/classes/ElggQuestion.php b/classes/ElggQuestion.php index 4b5b7b3..2d8ae32 100644 --- a/classes/ElggQuestion.php +++ b/classes/ElggQuestion.php @@ -16,7 +16,7 @@ class ElggQuestion extends \ElggObject { const STATUS_CLOSED = 'closed'; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function initializeAttributes() { parent::initializeAttributes(); @@ -27,7 +27,7 @@ protected function initializeAttributes() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function canComment(int $user_guid = 0): bool { if (!$this->commentsEnabled()) { @@ -47,7 +47,10 @@ public function canComment(int $user_guid = 0): bool { */ public function getAnswers(array $options = []) { $defaults = [ - 'order_by' => new OrderByClause('time_created', 'asc'), + 'sort_by' => [ + 'property' => 'time_created', + 'direction' => 'ASC', + ], ]; $overrides = [ diff --git a/composer.json b/composer.json index b4e9f9f..4fa5fae 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,6 @@ "issues": "https://github.com/ColdTrick/questions/issues" }, "conflict": { - "elgg/elgg": "<5.1" + "elgg/elgg": "<6.0" } } diff --git a/composer.lock b/composer.lock index 1f410ff..406eb06 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "047b3e2af6d15c4bd199be4b3e1db81c", + "content-hash": "7a76c46964d1ca0b93ab7d6e04bd9de2", "packages": [], "packages-dev": [], "aliases": [], diff --git a/lib/functions.php b/lib/functions.php index 722a0b8..553fe1c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -3,6 +3,7 @@ * All helper functions for the questions plugin can be found in this file. */ +use Elgg\Database\EntityTable; use Elgg\Database\QueryBuilder; /** @@ -52,8 +53,8 @@ function questions_experts_only_answer(): bool { /** * Check if a user is an expert * - * @param \ElggEntity $container the container where a question was asked, leave empty for any relationship - * @param \ElggUser $user the user to check (defaults to current user) + * @param null|\ElggEntity $container the container where a question was asked, leave empty for any relationship + * @param null|\ElggUser $user the user to check (defaults to current user) * * @return bool */ @@ -221,7 +222,7 @@ function questions_get_group_access_level(\ElggGroup $group) { /** * Return the number of days it should take to solve a question. * - * @param \ElggEntity $container if a group is provided, first the setting of the group is checked, then the default setting of the site + * @param null|\ElggEntity $container if a group is provided, first the setting of the group is checked, then the default setting of the site * * @return int */ @@ -268,8 +269,8 @@ function questions_limited_to_groups(): bool { /** * Check if a user can ask a question in a container * - * @param \ElggEntity $container the container to check (default: page_owner) - * @param \ElggUser $user the user askting the question (default: current user) + * @param null|\ElggEntity $container the container to check (default: page_owner) + * @param null|\ElggUser $user the user askting the question (default: current user) * * @return bool */ @@ -299,8 +300,8 @@ function questions_can_ask_question(\ElggEntity $container = null, \ElggUser $us /** * Check if a user can answer a question * - * @param \ElggQuestion $question the question that needs answer - * @param \ElggUser $user the user askting the question (default: current user) + * @param null|\ElggQuestion $question the question that needs answer + * @param null|\ElggUser $user the user askting the question (default: current user) * * @return bool */ @@ -360,8 +361,8 @@ function questions_can_answer_question(\ElggQuestion $question, \ElggUser $user * * NOTE: for now this is only supported in groups * - * @param \ElggEntity $container the container of the questions (group or user) - * @param \ElggUser $user the user doing the action (default: current user) + * @param \ElggEntity $container the container of the questions (group or user) + * @param null|\ElggUser $user the user doing the action (default: current user) * * @return bool */ @@ -418,7 +419,7 @@ function questions_get_expert_where_sql(int $user_guid = 0): ?callable { // site expert if (questions_is_expert($site, $user)) { // filter all non group questions - $sub = $qb->subquery('entities') + $sub = $qb->subquery(EntityTable::TABLE_NAME) ->select('guid') ->where($qb->compare('type', '=', 'group', ELGG_VALUE_STRING)) ->andWhere($qb->compare('enabled', '=', 'yes', ELGG_VALUE_STRING)); diff --git a/views/default/groups/profile/module/questions.php b/views/default/groups/profile/module/questions.php index 9cb67bb..af7f826 100644 --- a/views/default/groups/profile/module/questions.php +++ b/views/default/groups/profile/module/questions.php @@ -10,5 +10,4 @@ 'no_results' => elgg_echo('questions:none'), ]; $params = $params + $vars; - echo elgg_view('groups/profile/module', $params); diff --git a/views/default/object/answer.php b/views/default/object/answer.php index 2df2a33..50dea8f 100644 --- a/views/default/object/answer.php +++ b/views/default/object/answer.php @@ -7,15 +7,12 @@ return; } -$full_view = (bool) elgg_extract('full_view', $vars, false); - /* @var $question ElggQuestion */ $question = elgg_call(ELGG_IGNORE_ACCESS, function() use ($answer) { return $answer->getContainerEntity(); }); $params = [ - 'entity' => $answer, 'access' => false, 'icon_entity' => $answer->getOwnerEntity(), 'imprint' => [], @@ -37,20 +34,12 @@ ]; } -if (!$full_view) { +if (!(bool) elgg_extract('full_view', $vars, false)) { // listing view // make title - $answer_link = elgg_view('output/url', [ - 'text' => elgg_echo('questions:search:answer:title'), - 'href' => $answer->getURL(), - 'is_trusted' => true, - ]); - $question_link = elgg_view('output/url', [ - 'text' => $question->getDisplayName(), - 'href' => $question->getURL(), - 'is_trusted' => true, - ]); + $answer_link = elgg_view_url($answer->getURL(), elgg_echo('questions:search:answer:title')); + $question_link = elgg_view_entity_url($question); $params['title'] = elgg_echo('generic_comment:on', [$answer_link, $question_link]); diff --git a/views/default/object/question.php b/views/default/object/question.php index 9e78366..b777a4a 100644 --- a/views/default/object/question.php +++ b/views/default/object/question.php @@ -16,7 +16,6 @@ } $params = [ - 'entity' => $question, 'icon_entity' => $question->getOwnerEntity(), ]; @@ -62,10 +61,8 @@ ]; } -$excerpt = elgg_get_excerpt((string) $question->description); - -$params['content'] = $excerpt; +$params['content'] = elgg_get_excerpt((string) $question->description); $params['imprint'] = $imprint; -$params = $params + $vars; +$params = $params + $vars; echo elgg_view('object/elements/summary', $params); diff --git a/views/default/object/question/full.php b/views/default/object/question/full.php index 3f73e3f..1025db9 100644 --- a/views/default/object/question/full.php +++ b/views/default/object/question/full.php @@ -51,5 +51,4 @@ } $params = $params + $vars; - echo elgg_view('object/elements/full', $params); diff --git a/views/default/questions/filter.php b/views/default/questions/filter.php index 3326891..df31396 100644 --- a/views/default/questions/filter.php +++ b/views/default/questions/filter.php @@ -1,5 +1,7 @@ subquery('metadata', 'md_sub'); - $subquery->select('md_sub.entity_guid'); + $subquery = $qb->subquery(MetadataTable::TABLE_NAME, 'md_sub'); + $subquery->select("{$subquery->getTableAlias()}.entity_guid"); foreach ($tags as $index => $tag) { - $md = $subquery->joinMetadataTable('md_sub', 'entity_guid', 'tags', 'inner', "mdf{$index}"); + $md = $subquery->joinMetadataTable($subquery->getTableAlias(), 'entity_guid', 'tags', 'inner', "mdf{$index}"); $subquery->andWhere($qb->compare("{$md}.value", '=', $tag, ELGG_VALUE_STRING)); } diff --git a/views/default/questions/listing/all.php b/views/default/questions/listing/all.php new file mode 100644 index 0000000..a6ddaec --- /dev/null +++ b/views/default/questions/listing/all.php @@ -0,0 +1,44 @@ + 'object', + 'subtype' => \ElggQuestion::SUBTYPE, + 'no_results' => elgg_echo('questions:none'), + 'wheres' => [], +]; + +$options = (array) elgg_extract('options', $vars); +$options = array_merge($defaults, $options); + +$tags = elgg_extract('tags', $vars); +if (!empty($tags)) { + if (is_string($tags)) { + $tags = elgg_string_to_array($tags); + } + + $options['wheres'][] = function(QueryBuilder $qb, $main_alias) use ($tags) { + $ands = []; + foreach ($tags as $index => $tag) { + $md = $qb->joinMetadataTable($main_alias, 'guid', 'tags', 'inner', "md{$index}"); + + $ands[] = $qb->compare("{$md}.value", '=', $tag, ELGG_VALUE_STRING); + } + + return $qb->merge($ands); + }; +} + +if ((bool) elgg_extract('show_filter', $vars, true)) { + echo elgg_view('questions/filter', ['options' => $options]); +} + +echo elgg_list_entities($options); diff --git a/views/default/questions/listing/group.php b/views/default/questions/listing/group.php new file mode 100644 index 0000000..22649b9 --- /dev/null +++ b/views/default/questions/listing/group.php @@ -0,0 +1,22 @@ + $entity->guid, + 'preload_containers' => false, +]; + +$vars['options'] = array_merge($options, $group_options); + +echo elgg_view('questions/listing/all', $vars); diff --git a/views/default/questions/listing/owner.php b/views/default/questions/listing/owner.php new file mode 100644 index 0000000..e5c8b86 --- /dev/null +++ b/views/default/questions/listing/owner.php @@ -0,0 +1,22 @@ + $entity->guid, + 'preload_owners' => false, +]; + +$vars['options'] = array_merge($options, $owner_options); + +echo elgg_view('questions/listing/all', $vars); diff --git a/views/default/resources/answers/edit.php b/views/default/resources/answers/edit.php index b7002d8..5a340dd 100644 --- a/views/default/resources/answers/edit.php +++ b/views/default/resources/answers/edit.php @@ -6,7 +6,7 @@ $answer_guid = (int) elgg_extract('guid', $vars); elgg_entity_gatekeeper($answer_guid, 'object', \ElggAnswer::SUBTYPE, true); -/* @var $answer ElggAnswer */ +/* @var $answer \ElggAnswer */ $answer = get_entity($answer_guid); $question = $answer->getContainerEntity(); diff --git a/views/default/resources/questions/add.php b/views/default/resources/questions/add.php index af8451e..729e483 100644 --- a/views/default/resources/questions/add.php +++ b/views/default/resources/questions/add.php @@ -20,10 +20,8 @@ $form_vars['class'] = 'questions-validate-container'; } -$content = elgg_view_form('object/question/save', $form_vars); - // draw page echo elgg_view_page(elgg_echo('add:object:question'), [ - 'content' => $content, + 'content' => elgg_view_form('object/question/save', $form_vars), 'filter_id' => 'question/edit', ]); diff --git a/views/default/resources/questions/all.php b/views/default/resources/questions/all.php index 4d9bacd..390df3f 100644 --- a/views/default/resources/questions/all.php +++ b/views/default/resources/questions/all.php @@ -7,42 +7,11 @@ elgg_register_title_button('add', 'object', \ElggQuestion::SUBTYPE); -// prepare options -$options = [ - 'type' => 'object', - 'subtype' => \ElggQuestion::SUBTYPE, - 'no_results' => elgg_echo('questions:none'), - 'wheres' => [], -]; - -$tags = get_input('tags'); -if (!empty($tags)) { - if (is_string($tags)) { - $tags = elgg_string_to_array($tags); - } - - $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($tags) { - $ands = []; - foreach ($tags as $index => $tag) { - $md = $qb->joinMetadataTable($main_alias, 'guid', 'tags', 'inner', "md{$index}"); - - $ands[] = $qb->compare("{$md}.value", '=', $tag, ELGG_VALUE_STRING); - } - - return $qb->merge($ands); - }; -} - -// build content -$title = elgg_echo('questions:everyone'); - -$filter = elgg_view('questions/filter', ['options' => $options]); - -$content = elgg_list_entities($options); - // draw page -echo elgg_view_page($title, [ - 'content' => $filter . $content, +echo elgg_view_page(elgg_echo('questions:everyone'), [ + 'content' => elgg_view('questions/listing/all', [ + 'tags' => get_input('tags'), + ]), 'filter_id' => 'questions', 'filter_value' => 'all', ]); diff --git a/views/default/resources/questions/edit.php b/views/default/resources/questions/edit.php index dfd9c52..832d658 100644 --- a/views/default/resources/questions/edit.php +++ b/views/default/resources/questions/edit.php @@ -19,10 +19,8 @@ $form_vars['class'] = 'questions-validate-container'; } -$content = elgg_view_form('object/question/save', $form_vars, ['entity' => $question]); - // draw page echo elgg_view_page(elgg_echo('edit'), [ - 'content' => $content, + 'content' => elgg_view_form('object/question/save', $form_vars, ['entity' => $question]), 'filter_id' => 'question/edit', ]); diff --git a/views/default/resources/questions/group.php b/views/default/resources/questions/group.php index dbd30f1..aba952b 100644 --- a/views/default/resources/questions/group.php +++ b/views/default/resources/questions/group.php @@ -12,45 +12,12 @@ elgg_register_title_button('add', 'object', \ElggQuestion::SUBTYPE); -// prepare options -$options = [ - 'type' => 'object', - 'subtype' => \ElggQuestion::SUBTYPE, - 'container_guid' => $page_owner->guid, - 'full_view' => false, - 'list_type_toggle' => false, - 'no_results' => elgg_echo('questions:none'), - 'wheres' => [], -]; - -$tags = get_input('tags'); -if (!empty($tags)) { - if (is_string($tags)) { - $tags = elgg_string_to_array($tags); - } - - $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($tags) { - $ands = []; - foreach ($tags as $index => $tag) { - $md = $qb->joinMetadataTable($main_alias, 'guid', 'tags', 'inner', "md{$index}"); - - $ands[] = $qb->compare("{$md}.value", '=', $tag, ELGG_VALUE_STRING); - } - - return $qb->merge($ands); - }; -} - -// build page elements -$title = elgg_echo('questions:owner', [$page_owner->getDisplayName()]); - -$filter = elgg_view('questions/filter', ['options' => $options]); - -$content = elgg_list_entities($options); - // draw page -echo elgg_view_page($title, [ - 'content' => $filter . $content, +echo elgg_view_page(elgg_echo('questions:owner', [$page_owner->getDisplayName()]), [ + 'content' => elgg_view('questions/listing/group', [ + 'entity' => $page_owner, + 'tags' => get_input('tags'), + ]), 'filter_id' => 'questions/groups', 'filter_value' => 'all', ]); diff --git a/views/default/resources/questions/owner.php b/views/default/resources/questions/owner.php index 2f818b8..a5f611b 100644 --- a/views/default/resources/questions/owner.php +++ b/views/default/resources/questions/owner.php @@ -9,45 +9,12 @@ elgg_register_title_button('add', 'object', \ElggQuestion::SUBTYPE); -// prepare options -$options = [ - 'type' => 'object', - 'subtype' => \ElggQuestion::SUBTYPE, - 'owner_guid' => $page_owner->guid, - 'full_view' => false, - 'list_type_toggle' => false, - 'no_results' => elgg_echo('questions:none'), - 'wheres' => [], -]; - -$tags = get_input('tags'); -if (!empty($tags)) { - if (is_string($tags)) { - $tags = elgg_string_to_array($tags); - } - - $options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($tags) { - $ands = []; - foreach ($tags as $index => $tag) { - $md = $qb->joinMetadataTable($main_alias, 'guid', 'tags', 'inner', "md{$index}"); - - $ands[] = $qb->compare("{$md}.value", '=', $tag, ELGG_VALUE_STRING); - } - - return $qb->merge($ands); - }; -} - -// build page elements -$title = elgg_echo('questions:owner', [$page_owner->getDisplayName()]); - -$filter = elgg_view('questions/filter', ['options' => $options]); - -$content = elgg_list_entities($options); - // draw page -echo elgg_view_page($title, [ - 'content' => $filter . $content, +echo elgg_view_page(elgg_echo('questions:owner', [$page_owner->getDisplayName()]), [ + 'content' => elgg_view('questions/listing/owner', [ + 'entity' => $page_owner, + 'tags' => get_input('tags'), + ]), 'filter_id' => 'questions', 'filter_value' => ($page_owner->guid === elgg_get_logged_in_user_guid()) ? 'mine' : 'none', ]); diff --git a/views/default/river/object/answer/create.php b/views/default/river/object/answer/create.php index e4d7b66..053eeb5 100644 --- a/views/default/river/object/answer/create.php +++ b/views/default/river/object/answer/create.php @@ -16,19 +16,8 @@ $subject = $item->getSubjectEntity(); $question = $answer->getContainerEntity(); -$subject_link = elgg_view('output/url', [ - 'text' => $subject->getDisplayName(), - 'href' => $subject->getURL(), - 'class' => 'elgg-river-subject', - 'is_trusted' => true, -]); - -$object_link = elgg_view('output/url', [ - 'text' => elgg_get_excerpt($question->getDisplayName(), 100), - 'href' => $question->getURL(), - 'class' => 'elgg-river-object', - 'is_trusted' => true, -]); +$subject_link = elgg_view_entity_url($subject, ['class' => 'elgg-river-subject']); +$object_link = elgg_view_entity_url($question, ['class' => 'elgg-river-object']); echo elgg_view('river/elements/layout', [ 'item' => $item, diff --git a/views/default/widgets/questions/content.php b/views/default/widgets/questions/content.php index 095cac0..49da88b 100644 --- a/views/default/widgets/questions/content.php +++ b/views/default/widgets/questions/content.php @@ -20,22 +20,14 @@ 'full_view' => false, 'pagination' => false, 'no_results' => elgg_echo('questions:none'), + 'widget_more' => elgg_view_url($widget->getURL(), elgg_echo('widget:questions:more')) ]; -$route = 'collection:object:question:all'; -$route_params = []; - switch ($widget->context) { case 'profile': - $route = 'collection:object:question:owner'; - $route_params['username'] = $widget->getOwnerEntity()->username; - $options['owner_guid'] = $widget->owner_guid; break; case 'dashboard': - $route = 'collection:object:question:owner'; - $route_params['username'] = $widget->getOwnerEntity()->username; - $type = $widget->content_type; if (($type === 'todo') && !questions_is_expert()) { $type = 'mine'; @@ -44,9 +36,6 @@ // user shows owned switch ($type) { case 'todo': - $route = 'collection:object:question:todo'; - unset($route_params['username']); - // prepare options $options['wheres'] = [ function (QueryBuilder $qb, $main_alias) { @@ -67,9 +56,6 @@ function (QueryBuilder $qb, $main_alias) { break; case 'all': // just get all questions - $route = 'collection:object:question:all'; - unset($route_params['username']); - break; case 'mine': default: @@ -78,9 +64,6 @@ function (QueryBuilder $qb, $main_alias) { } break; case 'groups': - $route = 'collection:object:question:group'; - $route_params['guid'] = $widget->owner_guid; - // only in this container $options['container_guid'] = $widget->owner_guid; break; @@ -89,9 +72,6 @@ function (QueryBuilder $qb, $main_alias) { // check if a group was selected using the grouppicker $groups = $widget->group_guid; if (!empty($groups)) { - $route = 'collection:object:question:group'; - $route_params['guid'] = is_array($groups) ? $groups[0] : $groups; - // only in this container $options['container_guid'] = $groups; } @@ -109,9 +89,4 @@ function (QueryBuilder $qb, $main_alias) { $route_params['tags'] = $filter_tags; } -$url = elgg_generate_url($route, $route_params); -if (!empty($url)) { - $options['widget_more'] = elgg_view_url($url, elgg_echo('widget:questions:more')); -} - echo elgg_list_entities($options);