summaryrefslogtreecommitdiff
path: root/app/Module/ReviewChangesModule.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2018-07-16 08:20:33 +0100
committerGreg Roach <fisharebest@webtrees.net>2018-07-16 08:20:33 +0100
commitc1010eda29c0909ed4d5d463f32d32bfefdd4dfe (patch)
treefbb656ebc014aa1295ac8e6176f41e89f94b91e7 /app/Module/ReviewChangesModule.php
parent782f08d9bd2bfa06635da947ee34f8e1afd65088 (diff)
downloadwebtrees-c1010eda29c0909ed4d5d463f32d32bfefdd4dfe.tar.gz
webtrees-c1010eda29c0909ed4d5d463f32d32bfefdd4dfe.tar.bz2
webtrees-c1010eda29c0909ed4d5d463f32d32bfefdd4dfe.zip
Use PSR2 code style
Diffstat (limited to 'app/Module/ReviewChangesModule.php')
-rw-r--r--app/Module/ReviewChangesModule.php304
1 files changed, 163 insertions, 141 deletions
diff --git a/app/Module/ReviewChangesModule.php b/app/Module/ReviewChangesModule.php
index ab90ec0e01..f5bd65849e 100644
--- a/app/Module/ReviewChangesModule.php
+++ b/app/Module/ReviewChangesModule.php
@@ -29,163 +29,185 @@ use Fisharebest\Webtrees\User;
/**
* Class ReviewChangesModule
*/
-class ReviewChangesModule extends AbstractModule implements ModuleBlockInterface {
- /** {@inheritdoc} */
- public function getTitle() {
- return /* I18N: Name of a module */ I18N::translate('Pending changes');
- }
+class ReviewChangesModule extends AbstractModule implements ModuleBlockInterface
+{
+ /** {@inheritdoc} */
+ public function getTitle()
+ {
+ return /* I18N: Name of a module */
+ I18N::translate('Pending changes');
+ }
- /** {@inheritdoc} */
- public function getDescription() {
- return /* I18N: Description of the “Pending changes” module */ I18N::translate('A list of changes that need to be reviewed by a moderator, and email notifications.');
- }
+ /** {@inheritdoc} */
+ public function getDescription()
+ {
+ return /* I18N: Description of the “Pending changes” module */
+ 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 bool $template
- * @param string[] $cfg
- *
- * @return string
- */
- public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string {
- global $ctype;
+ /**
+ * Generate the HTML content of this block.
+ *
+ * @param Tree $tree
+ * @param int $block_id
+ * @param bool $template
+ * @param string[] $cfg
+ *
+ * @return string
+ */
+ public function getBlock(Tree $tree, int $block_id, bool $template = true, array $cfg = []): string
+ {
+ global $ctype;
- $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1');
- $days = $this->getBlockSetting($block_id, 'days', '1');
+ $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1');
+ $days = $this->getBlockSetting($block_id, 'days', '1');
- extract($cfg, EXTR_OVERWRITE);
+ extract($cfg, EXTR_OVERWRITE);
- $changes = Database::prepare(
- "SELECT 1" .
- " FROM `##change`" .
- " WHERE status='pending'" .
- " LIMIT 1"
- )->fetchOne();
+ $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 $tree) {
- if ($tree->hasPendingEdit() && Auth::isManager($tree, $user)) {
- I18N::init($user->getPreference('language'));
+ 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 $tree) {
+ if ($tree->hasPendingEdit() && Auth::isManager($tree, $user)) {
+ I18N::init($user->getPreference('language'));
- $sender = new User(
- (object) [
- 'user_id' => null,
- 'user_name' => '',
- 'real_name' => $tree->getTitle(),
- 'email' => $tree->getPreference('WEBTREES_EMAIL'),
- ]
- );
+ $sender = new User(
+ (object)[
+ 'user_id' => null,
+ 'user_name' => '',
+ 'real_name' => $tree->getTitle(),
+ 'email' => $tree->getPreference('WEBTREES_EMAIL'),
+ ]
+ );
- Mail::send(
- $sender,
- $user,
- $sender,
- I18N::translate('Pending changes'),
- view('emails/pending-changes-text', ['tree' => $tree, 'user' => $user]),
- view('emails/pending-changes-html', ['tree' => $tree, 'user' => $user])
- );
- I18N::init(WT_LOCALE);
- }
- }
- }
- }
- Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP);
- }
- }
- if (Auth::isEditor($tree) && $tree->hasPendingEdit()) {
- $content = '';
- if (Auth::isModerator($tree)) {
- $content .= '<a href="' . e(route('show-pending', ['ged' => $tree->getName()])) . '">' . I18N::translate('There are pending changes for you to moderate.') . '</a><br>';
- }
- if ($sendmail === '1') {
- $content .= I18N::translate('Last email reminder was sent ') . FunctionsDate::formatTimestamp(Site::getPreference('LAST_CHANGE_EMAIL')) . '<br>';
- $content .= I18N::translate('Next email reminder will be sent after ') . FunctionsDate::formatTimestamp((int) Site::getPreference('LAST_CHANGE_EMAIL') + (60 * 60 * 24 * $days)) . '<br><br>';
- }
- $content .= '<ul>';
- $changes = Database::prepare(
- "SELECT xref" .
- " FROM `##change`" .
- " WHERE status='pending'" .
- " AND gedcom_id=?" .
- " GROUP BY xref"
- )->execute([$tree->getTreeId()])->fetchAll();
- foreach ($changes as $change) {
- $record = GedcomRecord::getInstance($change->xref, $tree);
- if ($record->canShow()) {
- $content .= '<li><a href="' . e($record->url()) . '">' . $record->getFullName() . '</a></li>';
- }
- }
- $content .= '</ul>';
+ Mail::send(
+ $sender,
+ $user,
+ $sender,
+ I18N::translate('Pending changes'),
+ view('emails/pending-changes-text', [
+ 'tree' => $tree,
+ 'user' => $user,
+ ]),
+ view('emails/pending-changes-html', [
+ 'tree' => $tree,
+ 'user' => $user,
+ ])
+ );
+ I18N::init(WT_LOCALE);
+ }
+ }
+ }
+ }
+ Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP);
+ }
+ }
+ if (Auth::isEditor($tree) && $tree->hasPendingEdit()) {
+ $content = '';
+ if (Auth::isModerator($tree)) {
+ $content .= '<a href="' . e(route('show-pending', ['ged' => $tree->getName()])) . '">' . I18N::translate('There are pending changes for you to moderate.') . '</a><br>';
+ }
+ if ($sendmail === '1') {
+ $content .= I18N::translate('Last email reminder was sent ') . FunctionsDate::formatTimestamp(Site::getPreference('LAST_CHANGE_EMAIL')) . '<br>';
+ $content .= I18N::translate('Next email reminder will be sent after ') . FunctionsDate::formatTimestamp((int)Site::getPreference('LAST_CHANGE_EMAIL') + (60 * 60 * 24 * $days)) . '<br><br>';
+ }
+ $content .= '<ul>';
+ $changes = Database::prepare(
+ "SELECT xref" .
+ " FROM `##change`" .
+ " WHERE status='pending'" .
+ " AND gedcom_id=?" .
+ " GROUP BY xref"
+ )->execute([$tree->getTreeId()])->fetchAll();
+ foreach ($changes as $change) {
+ $record = GedcomRecord::getInstance($change->xref, $tree);
+ if ($record->canShow()) {
+ $content .= '<li><a href="' . e($record->url()) . '">' . $record->getFullName() . '</a></li>';
+ }
+ }
+ $content .= '</ul>';
- if ($template) {
- if ($ctype === 'gedcom' && Auth::isManager($tree)) {
- $config_url = route('tree-page-block-edit', ['block_id' => $block_id, 'ged' => $tree->getName()]);
- } elseif ($ctype === 'user' && Auth::check()) {
- $config_url = route('user-page-block-edit', ['block_id' => $block_id, 'ged' => $tree->getName()]);
- } else {
- $config_url = '';
- }
+ if ($template) {
+ if ($ctype === 'gedcom' && Auth::isManager($tree)) {
+ $config_url = route('tree-page-block-edit', [
+ 'block_id' => $block_id,
+ 'ged' => $tree->getName(),
+ ]);
+ } elseif ($ctype === 'user' && Auth::check()) {
+ $config_url = route('user-page-block-edit', [
+ 'block_id' => $block_id,
+ 'ged' => $tree->getName(),
+ ]);
+ } else {
+ $config_url = '';
+ }
- return view('modules/block-template', [
- 'block' => str_replace('_', '-', $this->getName()),
- 'id' => $block_id,
- 'config_url' => $config_url,
- 'title' => $this->getTitle(),
- 'content' => $content,
- ]);
- } else {
- return $content;
- }
- }
+ return view('modules/block-template', [
+ 'block' => str_replace('_', '-', $this->getName()),
+ 'id' => $block_id,
+ 'config_url' => $config_url,
+ 'title' => $this->getTitle(),
+ 'content' => $content,
+ ]);
+ } else {
+ return $content;
+ }
+ }
- return '';
- }
+ return '';
+ }
- /** {@inheritdoc} */
- public function loadAjax(): bool {
- return false;
- }
+ /** {@inheritdoc} */
+ public function loadAjax(): bool
+ {
+ return false;
+ }
- /** {@inheritdoc} */
- public function isUserBlock(): bool {
- return true;
- }
+ /** {@inheritdoc} */
+ public function isUserBlock(): bool
+ {
+ return true;
+ }
- /** {@inheritdoc} */
- public function isGedcomBlock(): bool {
- return true;
- }
+ /** {@inheritdoc} */
+ public function isGedcomBlock(): bool
+ {
+ return true;
+ }
- /**
- * An HTML form to edit block settings
- *
- * @param Tree $tree
- * @param int $block_id
- *
- * @return void
- */
- public function configureBlock(Tree $tree, int $block_id) {
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $this->setBlockSetting($block_id, 'days', Filter::postInteger('num', 1, 180, 1));
- $this->setBlockSetting($block_id, 'sendmail', Filter::postBool('sendmail'));
+ /**
+ * An HTML form to edit block settings
+ *
+ * @param Tree $tree
+ * @param int $block_id
+ *
+ * @return void
+ */
+ public function configureBlock(Tree $tree, int $block_id)
+ {
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $this->setBlockSetting($block_id, 'days', Filter::postInteger('num', 1, 180, 1));
+ $this->setBlockSetting($block_id, 'sendmail', Filter::postBool('sendmail'));
- return;
- }
+ return;
+ }
- $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1');
- $days = $this->getBlockSetting($block_id, 'days', '1');
+ $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1');
+ $days = $this->getBlockSetting($block_id, 'days', '1');
- echo view('modules/review_changes/config', [
- 'days' => $days,
- 'sendmail' => $sendmail,
- ]);
- }
+ echo view('modules/review_changes/config', [
+ 'days' => $days,
+ 'sendmail' => $sendmail,
+ ]);
+ }
}