.
*/
declare(strict_types=1);
namespace Fisharebest\Webtrees\Module;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\Functions\FunctionsDate;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Mail;
use Fisharebest\Webtrees\Site;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\User;
use Symfony\Component\HttpFoundation\Request;
/**
* Class ReviewChangesModule
*/
class ReviewChangesModule extends AbstractModule implements ModuleBlockInterface
{
/** {@inheritdoc} */
public function getTitle(): string
{
/* I18N: Name of a module */
return I18N::translate('Pending changes');
}
/** {@inheritdoc} */
public function getDescription(): string
{
/* I18N: Description of the “Pending changes” module */
return I18N::translate('A list of changes that need to be reviewed by a moderator, and email notifications.');
}
/**
* Generate the HTML content of this block.
*
* @param Tree $tree
* @param int $block_id
* @param string $ctype
* @param string[] $cfg
*
* @return string
*/
public function getBlock(Tree $tree, int $block_id, string $ctype = '', array $cfg = []): string
{
$sendmail = $this->getBlockSetting($block_id, 'sendmail', '1');
$days = $this->getBlockSetting($block_id, 'days', '1');
extract($cfg, EXTR_OVERWRITE);
$changes = Database::prepare(
"SELECT 1" .
" FROM `##change`" .
" WHERE status='pending'" .
" LIMIT 1"
)->fetchOne();
if ($changes === '1' && $sendmail === '1') {
// There are pending changes - tell moderators/managers/administrators about them.
if (WT_TIMESTAMP - (int) Site::getPreference('LAST_CHANGE_EMAIL') > (60 * 60 * 24 * $days)) {
// Which users have pending changes?
foreach (User::all() as $user) {
if ($user->getPreference('contactmethod') !== 'none') {
foreach (Tree::getAll() as $tmp_tree) {
if ($tmp_tree->hasPendingEdit() && Auth::isManager($tmp_tree, $user)) {
I18N::init($user->getPreference('language'));
$sender = new User(
(object) [
'user_id' => null,
'user_name' => '',
'real_name' => $tmp_tree->title(),
'email' => $tmp_tree->getPreference('WEBTREES_EMAIL'),
]
);
Mail::send(
$sender,
$user,
$sender,
I18N::translate('Pending changes'),
view('emails/pending-changes-text', [
'tree' => $tmp_tree,
'user' => $user,
]),
view('emails/pending-changes-html', [
'tree' => $tmp_tree,
'user' => $user,
])
);
I18N::init(WT_LOCALE);
}
}
}
}
Site::setPreference('LAST_CHANGE_EMAIL', (string) WT_TIMESTAMP);
}
}
if (Auth::isEditor($tree) && $tree->hasPendingEdit()) {
$content = '';
if (Auth::isModerator($tree)) {
$content .= '' . I18N::translate('There are pending changes for you to moderate.') . '
';
}
if ($sendmail === '1') {
$last_email_timestamp = (int) Site::getPreference('LAST_CHANGE_EMAIL');
$content .= I18N::translate('Last email reminder was sent ') . FunctionsDate::formatTimestamp($last_email_timestamp) . '
';
$content .= I18N::translate('Next email reminder will be sent after ') . FunctionsDate::formatTimestamp($last_email_timestamp + 60 * 60 * 24 * $days) . '
';
}
$content .= '