diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2018-07-16 08:20:33 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2018-07-16 08:20:33 +0100 |
| commit | c1010eda29c0909ed4d5d463f32d32bfefdd4dfe (patch) | |
| tree | fbb656ebc014aa1295ac8e6176f41e89f94b91e7 /app/Module/ResearchTaskModule.php | |
| parent | 782f08d9bd2bfa06635da947ee34f8e1afd65088 (diff) | |
| download | webtrees-c1010eda29c0909ed4d5d463f32d32bfefdd4dfe.tar.gz webtrees-c1010eda29c0909ed4d5d463f32d32bfefdd4dfe.tar.bz2 webtrees-c1010eda29c0909ed4d5d463f32d32bfefdd4dfe.zip | |
Use PSR2 code style
Diffstat (limited to 'app/Module/ResearchTaskModule.php')
| -rw-r--r-- | app/Module/ResearchTaskModule.php | 234 |
1 files changed, 125 insertions, 109 deletions
diff --git a/app/Module/ResearchTaskModule.php b/app/Module/ResearchTaskModule.php index 750a66c94c..bf8c016a63 100644 --- a/app/Module/ResearchTaskModule.php +++ b/app/Module/ResearchTaskModule.php @@ -25,135 +25,151 @@ use Fisharebest\Webtrees\Tree; /** * Class ResearchTaskModule */ -class ResearchTaskModule extends AbstractModule implements ModuleBlockInterface { - const DEFAULT_SHOW_OTHER = '1'; - const DEFAULT_SHOW_UNASSIGNED = '1'; - const DEFAULT_SHOW_FUTURE = '1'; - const DEFAULT_BLOCK = '1'; +class ResearchTaskModule extends AbstractModule implements ModuleBlockInterface +{ + const DEFAULT_SHOW_OTHER = '1'; + const DEFAULT_SHOW_UNASSIGNED = '1'; + const DEFAULT_SHOW_FUTURE = '1'; + const DEFAULT_BLOCK = '1'; - /** {@inheritdoc} */ - public function getTitle() { - return /* I18N: Name of a module. Tasks that need further research. */ I18N::translate('Research tasks'); - } + /** {@inheritdoc} */ + public function getTitle() + { + return /* I18N: Name of a module. Tasks that need further research. */ + I18N::translate('Research tasks'); + } - /** {@inheritdoc} */ - public function getDescription() { - return /* I18N: Description of “Research tasks” module */ I18N::translate('A list of tasks and activities that are linked to the family tree.'); - } + /** {@inheritdoc} */ + public function getDescription() + { + return /* I18N: Description of “Research tasks” module */ + I18N::translate('A list of tasks and activities that are linked to the family tree.'); + } - /** - * 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; - $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); - $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); - $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); + $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); + $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); + $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); - extract($cfg, EXTR_OVERWRITE); + extract($cfg, EXTR_OVERWRITE); - $end_jd = $show_future ? 99999999 : WT_CLIENT_JD; + $end_jd = $show_future ? 99999999 : WT_CLIENT_JD; - $xrefs = Database::prepare( - "SELECT DISTINCT d_gid FROM `##dates`" . - " WHERE d_file = :tree_id AND d_fact = '_TODO' AND d_julianday1 < :jd" - )->execute([ - 'tree_id' => $tree->getTreeId(), - 'jd' => $end_jd, - ])->fetchOneColumn(); + $xrefs = Database::prepare( + "SELECT DISTINCT d_gid FROM `##dates`" . + " WHERE d_file = :tree_id AND d_fact = '_TODO' AND d_julianday1 < :jd" + )->execute([ + 'tree_id' => $tree->getTreeId(), + 'jd' => $end_jd, + ])->fetchOneColumn(); - $records = array_map(function ($xref) use ($tree) { - return GedcomRecord::getInstance($xref, $tree); - }, $xrefs); + $records = array_map(function ($xref) use ($tree) { + return GedcomRecord::getInstance($xref, $tree); + }, $xrefs); - $tasks = []; + $tasks = []; - foreach ($records as $record) { - foreach ($record->getFacts('_TODO') as $task) { - $user_name = $task->getAttribute('_WT_USER'); + foreach ($records as $record) { + foreach ($record->getFacts('_TODO') as $task) { + $user_name = $task->getAttribute('_WT_USER'); - if ($user_name === Auth::user()->getUserName() || empty($user_name) && $show_unassigned || !empty($user_name) && $show_other) { - $tasks[] = $task; - } - } - } + if ($user_name === Auth::user()->getUserName() || empty($user_name) && $show_unassigned || !empty($user_name) && $show_other) { + $tasks[] = $task; + } + } + } - if (empty($records)) { - $content = '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>'; - } else { - $content = view('modules/todo/research-tasks', ['tasks' => $tasks]); - } + if (empty($records)) { + $content = '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>'; + } else { + $content = view('modules/todo/research-tasks', ['tasks' => $tasks]); + } - 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; + } + } - /** {@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, 'show_other', Filter::postBool('show_other')); - $this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned')); - $this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future')); + /** + * 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, 'show_other', Filter::postBool('show_other')); + $this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned')); + $this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future')); - return; - } + return; + } - $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); - $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); - $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); + $show_other = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER); + $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED); + $show_future = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE); - echo view('modules/todo/config', [ - 'show_future' => $show_future, - 'show_other' => $show_other, - 'show_unassigned' => $show_unassigned, - ]); + echo view('modules/todo/config', [ + 'show_future' => $show_future, + 'show_other' => $show_other, + 'show_unassigned' => $show_unassigned, + ]); - } + } } |
