Skip to content

Commit 0bbcd67

Browse files
committed
changed: updated for Elgg 6.3
1 parent cda8658 commit 0bbcd67

File tree

22 files changed

+195
-108
lines changed

22 files changed

+195
-108
lines changed

CONTRIBUTORS.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
* Evan Winslow <[email protected]>
32
* Liang Lee
43
* ColdTrick IT Solutions <www.coldtrick.com>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Questions for Elgg
22
==================
33

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

1919
(C) 2011 Evan Winslow
20-
(C) 2015-2024 ColdTrick IT Solutions
20+
(C) 2015-2025 ColdTrick IT Solutions

classes/ColdTrick/Questions/Cron.php

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ public static function autoCloseQuestions(\Elgg\Event $event): void {
2525
}
2626

2727
elgg_call(ELGG_IGNORE_ACCESS, function() use ($auto_close_days) {
28-
$site = elgg_get_site_entity();
29-
30-
// backup session
31-
$backup_user = elgg_get_logged_in_user_entity();
32-
$session_manager = elgg()->session_manager;
33-
3428
// get open questions last modified more than x days ago
3529
/* @var $batch \ElggBatch */
3630
$batch = elgg_get_entities([
@@ -44,42 +38,25 @@ public static function autoCloseQuestions(\Elgg\Event $event): void {
4438
'batch' => true,
4539
'batch_inc_offset' => false,
4640
]);
41+
4742
/* @var $question \ElggQuestion */
4843
foreach ($batch as $question) {
44+
/* @var $owner \ElggUser */
4945
$owner = $question->getOwnerEntity();
50-
$session_manager->setLoggedInUser($owner);
5146

5247
// close the question
5348
$question->close();
5449

5550
// notify the user that the question was closed
56-
$subject = elgg_echo('questions:notification:auto_close:subject', [$question->getDisplayName()]);
57-
$message = elgg_echo('questions:notification:auto_close:message', [
58-
$question->getDisplayName(),
59-
$auto_close_days,
60-
$question->getURL(),
51+
$owner->notify('close', $question, [
52+
'days' => $auto_close_days,
6153
]);
62-
63-
$notification_params = [
64-
'summary' => elgg_echo('questions:notification:auto_close:summary', [$question->getDisplayName()]),
65-
'object' => $question,
66-
'action' => 'close',
67-
];
68-
69-
notify_user($owner->guid, $site->guid, $subject, $message, $notification_params);
70-
}
71-
72-
// restore session
73-
if ($backup_user instanceof \ElggUser) {
74-
$session_manager->setLoggedInUser($backup_user);
75-
} else {
76-
$session_manager->removeLoggedInUser();
7754
}
7855
});
7956
}
8057

8158
/**
82-
* A event handler for the CRON, so we can send out notifications to the experts about their workload
59+
* An event handler for the CRON, so we can send out notifications to the experts about their workload
8360
*
8461
* @param \Elgg\Event $event 'cron', 'daily'
8562
*
@@ -109,7 +86,7 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
10986
$sub = $qb->subquery(MetadataTable::TABLE_NAME)
11087
->select('entity_guid')
11188
->where($qb->compare('name', '=', 'status', ELGG_VALUE_STRING))
112-
->andWhere($qb->compare('value', '=', 'closed', ELGG_VALUE_STRING));
89+
->andWhere($qb->compare('value', '=', \ElggQuestion::STATUS_CLOSED, ELGG_VALUE_STRING));
11390

11491
return $qb->compare("{$main_alias}.guid", 'NOT IN', $sub->getSQL());
11592
};
@@ -129,8 +106,9 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
129106
// fake a logged-in user
130107
$session_manager->setLoggedInUser($expert);
131108

132-
$subject = elgg_echo('questions:daily:notification:subject', [], $expert->getLanguage());
133-
$message = '';
109+
$overdue = '';
110+
$due = '';
111+
$new = '';
134112

135113
$container_where = questions_get_expert_where_sql($expert->guid);
136114
if (empty($container_where)) {
@@ -157,14 +135,9 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
157135
];
158136
$questions = elgg_get_entities($question_options);
159137
if (!empty($questions)) {
160-
$message .= elgg_echo('questions:daily:notification:message:overdue', [], $expert->getLanguage()) . PHP_EOL;
161-
162138
foreach ($questions as $question) {
163-
$message .= " - {$question->getDisplayName()} ({$question->getURL()})" . PHP_EOL;
139+
$overdue .= " - {$question->getDisplayName()} ({$question->getURL()})" . PHP_EOL;
164140
}
165-
166-
$message .= elgg_echo('questions:daily:notification:message:more', [], $expert->getLanguage());
167-
$message .= ' ' . elgg_generate_url('collection:object:question:todo') . PHP_EOL . PHP_EOL;
168141
}
169142

170143
// get due questions
@@ -186,14 +159,9 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
186159

187160
$questions = elgg_get_entities($question_options);
188161
if (!empty($questions)) {
189-
$message .= elgg_echo('questions:daily:notification:message:due', [], $expert->getLanguage()) . PHP_EOL;
190-
191162
foreach ($questions as $question) {
192-
$message .= " - {$question->getDisplayName()} ({$question->getURL()})" . PHP_EOL;
163+
$due .= " - {$question->getDisplayName()} ({$question->getURL()})" . PHP_EOL;
193164
}
194-
195-
$message .= elgg_echo('questions:daily:notification:message:more', [], $expert->getLanguage());
196-
$message .= ' ' . elgg_generate_url('collection:object:question:todo') . PHP_EOL . PHP_EOL;
197165
}
198166

199167
// get new questions
@@ -208,20 +176,18 @@ public static function notifyQuestionExperts(\Elgg\Event $event): void {
208176

209177
$questions = elgg_get_entities($question_options);
210178
if (!empty($questions)) {
211-
$message .= elgg_echo('questions:daily:notification:message:new', [], $expert->getLanguage()) . PHP_EOL;
212-
213179
foreach ($questions as $question) {
214-
$message .= " - {$question->getDisplayName()} ({$question->getURL()})" . PHP_EOL;
180+
$new .= " - {$question->getDisplayName()} ({$question->getURL()})" . PHP_EOL;
215181
}
216-
217-
$message .= elgg_echo('questions:daily:notification:message:more', [], $expert->getLanguage());
218-
$message .= ' ' . elgg_generate_url('collection:object:question:all') . PHP_EOL . PHP_EOL;
219182
}
220183

221-
// is there content in the message
222-
if (!empty($message)) {
223-
// force to email
224-
notify_user($expert->guid, 0, $subject, $message, [], 'email');
184+
// is there content for the message
185+
if (!empty($overdue) || !empty($due) || !empty($new)) {
186+
$expert->notify('questions_expert_workload', $expert, [
187+
'overdue' => $overdue,
188+
'due' => $due,
189+
'new' => $new,
190+
]);
225191
}
226192
}
227193

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace ColdTrick\Questions\Notifications;
4+
5+
use Elgg\Notifications\InstantNotificationEventHandler;
6+
7+
/**
8+
* Notification about the auto closing of a question
9+
*/
10+
class AutoCloseQuestionHandler extends InstantNotificationEventHandler {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
16+
$question = $this->getEventEntity();
17+
if (!$question instanceof \ElggQuestion) {
18+
return parent::getNotificationSubject($recipient, $method);
19+
}
20+
21+
return elgg_echo('questions:notification:auto_close:subject', [$question->getDisplayName()]);
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
28+
$question = $this->getEventEntity();
29+
if (!$question instanceof \ElggQuestion) {
30+
return parent::getNotificationSubject($recipient, $method);
31+
}
32+
33+
return elgg_echo('questions:notification:auto_close:summary', [$question->getDisplayName()]);
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
40+
$question = $this->getEventEntity();
41+
if (!$question instanceof \ElggQuestion) {
42+
return parent::getNotificationSubject($recipient, $method);
43+
}
44+
45+
return elgg_echo('questions:notification:auto_close:message', [
46+
$question->getDisplayName(),
47+
(int) $this->getParam('days'),
48+
$question->getURL(),
49+
]);
50+
}
51+
}

classes/ColdTrick/Questions/Notifications/CorrectAnswerNotificationEventHandler.php renamed to classes/ColdTrick/Questions/Notifications/CorrectAnswerHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Notification handler for when a correct answer is given
99
*/
10-
class CorrectAnswerNotificationEventHandler extends NotificationEventHandler {
10+
class CorrectAnswerHandler extends NotificationEventHandler {
1111

1212
/**
1313
* {@inheritdoc}

classes/ColdTrick/Questions/Notifications/CreateAnswerNotificationEventHandler.php renamed to classes/ColdTrick/Questions/Notifications/CreateAnswerHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Notification handler for when an answer is created
99
*/
10-
class CreateAnswerNotificationEventHandler extends NotificationEventHandler {
10+
class CreateAnswerHandler extends NotificationEventHandler {
1111

1212
/**
1313
* {@inheritdoc}

classes/ColdTrick/Questions/Notifications/CreateQuestionNotificationEventHandler.php renamed to classes/ColdTrick/Questions/Notifications/CreateQuestionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Notification handler for when a question is created
99
*/
10-
class CreateQuestionNotificationEventHandler extends NotificationEventHandler {
10+
class CreateQuestionHandler extends NotificationEventHandler {
1111

1212
/**
1313
* {@inheritdoc}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace ColdTrick\Questions\Notifications;
4+
5+
use Elgg\Notifications\InstantNotificationEventHandler;
6+
7+
/**
8+
* Notification about a Questions expert workload
9+
*/
10+
class ExpertWorkloadHandler extends InstantNotificationEventHandler {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected function getNotificationSubject(\ElggUser $recipient, string $method): string {
16+
return elgg_echo('questions:daily:notification:subject');
17+
}
18+
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
protected function getNotificationSummary(\ElggUser $recipient, string $method): string {
23+
return elgg_echo('questions:daily:notification:subject');
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
protected function getNotificationBody(\ElggUser $recipient, string $method): string {
30+
$message = '';
31+
32+
$overdue = $this->getParam('overdue');
33+
if (!empty($overdue)) {
34+
$message .= elgg_echo('questions:daily:notification:message:overdue') . PHP_EOL;
35+
$message .= $overdue;
36+
$message .= elgg_echo('questions:daily:notification:message:more');
37+
$message .= ' ' . elgg_generate_url('collection:object:question:todo') . PHP_EOL . PHP_EOL;
38+
}
39+
40+
$due = $this->getParam('due');
41+
if (!empty($due)) {
42+
$message .= elgg_echo('questions:daily:notification:message:due') . PHP_EOL;
43+
$message .= $due;
44+
$message .= elgg_echo('questions:daily:notification:message:more');
45+
$message .= ' ' . elgg_generate_url('collection:object:question:todo') . PHP_EOL . PHP_EOL;
46+
}
47+
48+
$new = $this->getParam('new');
49+
if (!empty($new)) {
50+
$message .= elgg_echo('questions:daily:notification:message:new') . PHP_EOL;
51+
$message .= $new;
52+
$message .= elgg_echo('questions:daily:notification:message:more');
53+
$message .= ' ' . elgg_generate_url('collection:object:question:all') . PHP_EOL . PHP_EOL;
54+
}
55+
56+
return trim($message);
57+
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
protected function getNotificationURL(\ElggUser $recipient, string $method): string {
63+
return elgg_generate_url('collection:object:question:todo');
64+
}
65+
66+
/**
67+
* {@inheritdoc}
68+
*/
69+
protected function getNotificationMethods(): array {
70+
return ['email'];
71+
}
72+
}

classes/ColdTrick/Questions/Notifications/MoveQuestionNotificationEventHandler.php renamed to classes/ColdTrick/Questions/Notifications/MoveQuestionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Notification handler for when a Question is moved to a different container (group)
99
*/
10-
class MoveQuestionNotificationEventHandler extends NotificationEventHandler {
10+
class MoveQuestionHandler extends NotificationEventHandler {
1111

1212
/**
1313
* {@inheritdoc}

classes/ElggAnswer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
class ElggAnswer extends \ElggObject {
99

10-
const SUBTYPE = 'answer';
10+
public const SUBTYPE = 'answer';
1111

1212
/**
1313
* {@inheritdoc}

0 commit comments

Comments
 (0)