xref: /webtrees/app/Module/ResearchTaskModule.php (revision 369c0ce6d43eee62858778711fa4744ed347814a)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
4*369c0ce6SGreg Roach * Copyright (C) 2016 webtrees development team
58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
88c2e8227SGreg Roach * (at your option) any later version.
98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
128c2e8227SGreg Roach * GNU General Public License for more details.
138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
158c2e8227SGreg Roach */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
178c2e8227SGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
203d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDb;
213d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\GedcomTag;
230e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme;
258c2e8227SGreg Roachuse Rhumsaa\Uuid\Uuid;
268c2e8227SGreg Roach
278c2e8227SGreg Roach/**
288c2e8227SGreg Roach * Class ResearchTaskModule
298c2e8227SGreg Roach */
30e2a378d3SGreg Roachclass ResearchTaskModule extends AbstractModule implements ModuleBlockInterface {
318c2e8227SGreg Roach	/** {@inheritdoc} */
328c2e8227SGreg Roach	public function getTitle() {
338c2e8227SGreg Roach		return /* I18N: Name of a module. Tasks that need further research. */ I18N::translate('Research tasks');
348c2e8227SGreg Roach	}
358c2e8227SGreg Roach
368c2e8227SGreg Roach	/** {@inheritdoc} */
378c2e8227SGreg Roach	public function getDescription() {
388c2e8227SGreg Roach		return /* I18N: Description of “Research tasks” module */ I18N::translate('A list of tasks and activities that are linked to the family tree.');
398c2e8227SGreg Roach	}
408c2e8227SGreg Roach
4176692c8bSGreg Roach	/**
4276692c8bSGreg Roach	 * Generate the HTML content of this block.
4376692c8bSGreg Roach	 *
4476692c8bSGreg Roach	 * @param int      $block_id
4576692c8bSGreg Roach	 * @param bool     $template
46727f238cSGreg Roach	 * @param string[] $cfg
4776692c8bSGreg Roach	 *
4876692c8bSGreg Roach	 * @return string
4976692c8bSGreg Roach	 */
5076692c8bSGreg Roach	public function getBlock($block_id, $template = true, $cfg = array()) {
514b9ff166SGreg Roach		global $ctype, $controller, $WT_TREE;
528c2e8227SGreg Roach
53e2a378d3SGreg Roach		$show_other      = $this->getBlockSetting($block_id, 'show_other', '1');
54e2a378d3SGreg Roach		$show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', '1');
55e2a378d3SGreg Roach		$show_future     = $this->getBlockSetting($block_id, 'show_future', '1');
56e2a378d3SGreg Roach		$block           = $this->getBlockSetting($block_id, 'block', '1');
578c2e8227SGreg Roach
588c2e8227SGreg Roach		foreach (array('show_unassigned', 'show_other', 'show_future', 'block') as $name) {
598c2e8227SGreg Roach			if (array_key_exists($name, $cfg)) {
608c2e8227SGreg Roach				$$name = $cfg[$name];
618c2e8227SGreg Roach			}
628c2e8227SGreg Roach		}
638c2e8227SGreg Roach
648c2e8227SGreg Roach		$id    = $this->getName() . $block_id;
658c2e8227SGreg Roach		$class = $this->getName() . '_block';
664b9ff166SGreg Roach		if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
679353052eSGreg Roach			$title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
688c2e8227SGreg Roach		} else {
698c2e8227SGreg Roach			$title = '';
708c2e8227SGreg Roach		}
718c2e8227SGreg Roach		$title .= $this->getTitle();
728c2e8227SGreg Roach
738c2e8227SGreg Roach		$table_id = Uuid::uuid4(); // create a unique ID
748c2e8227SGreg Roach
758c2e8227SGreg Roach		$controller
768c2e8227SGreg Roach			->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
778c2e8227SGreg Roach			->addInlineJavascript('
788c2e8227SGreg Roach			jQuery("#' . $table_id . '").dataTable({
798c2e8227SGreg Roach				dom: \'t\',
808c2e8227SGreg Roach				' . I18N::datatablesI18N() . ',
818c2e8227SGreg Roach				autoWidth: false,
828c2e8227SGreg Roach				paginate: false,
838c2e8227SGreg Roach				lengthChange: false,
848c2e8227SGreg Roach				filter: false,
858c2e8227SGreg Roach				info: true,
868c2e8227SGreg Roach				jQueryUI: true,
878c2e8227SGreg Roach				columns: [
888c2e8227SGreg Roach					/* 0-DATE */     { visible: false },
898c2e8227SGreg Roach					/* 1-Date */     { dataSort: 0 },
908c2e8227SGreg Roach					/* 1-Record */   null,
918c2e8227SGreg Roach					/* 2-Username */ null,
928c2e8227SGreg Roach					/* 3-Text */     null
938c2e8227SGreg Roach				]
948c2e8227SGreg Roach			});
958c2e8227SGreg Roach			jQuery("#' . $table_id . '").css("visibility", "visible");
968c2e8227SGreg Roach			jQuery(".loading-image").css("display", "none");
978c2e8227SGreg Roach		');
988c2e8227SGreg Roach
998c2e8227SGreg Roach		$content = '';
1008c2e8227SGreg Roach		$content .= '<div class="loading-image">&nbsp;</div>';
1018c2e8227SGreg Roach		$content .= '<table id="' . $table_id . '" style="visibility:hidden;">';
1028c2e8227SGreg Roach		$content .= '<thead><tr>';
1038c2e8227SGreg Roach		$content .= '<th>DATE</th>'; //hidden by datables code
104764a01d9SGreg Roach		$content .= '<th>' . GedcomTag::getLabel('DATE') . '</th>';
1058c2e8227SGreg Roach		$content .= '<th>' . I18N::translate('Record') . '</th>';
1068c2e8227SGreg Roach		if ($show_unassigned || $show_other) {
1078c2e8227SGreg Roach			$content .= '<th>' . I18N::translate('Username') . '</th>';
1088c2e8227SGreg Roach		}
109764a01d9SGreg Roach		$content .= '<th>' . GedcomTag::getLabel('TEXT') . '</th>';
1108c2e8227SGreg Roach		$content .= '</tr></thead><tbody>';
1118c2e8227SGreg Roach
1128c2e8227SGreg Roach		$found  = false;
1138c2e8227SGreg Roach		$end_jd = $show_future ? 99999999 : WT_CLIENT_JD;
1143d7a8a4cSGreg Roach		foreach (FunctionsDb::getCalendarEvents(0, $end_jd, '_TODO', $WT_TREE) as $fact) {
1158c2e8227SGreg Roach			$record    = $fact->getParent();
1168c2e8227SGreg Roach			$user_name = $fact->getAttribute('_WT_USER');
1178c2e8227SGreg Roach			if ($user_name === Auth::user()->getUserName() || !$user_name && $show_unassigned || $user_name && $show_other) {
1188c2e8227SGreg Roach				$content .= '<tr>';
1198c2e8227SGreg Roach				//-- Event date (sortable)
1208c2e8227SGreg Roach				$content .= '<td>'; //hidden by datables code
1218c2e8227SGreg Roach				$content .= $fact->getDate()->julianDay();
1228c2e8227SGreg Roach				$content .= '</td>';
1238c2e8227SGreg Roach				$content .= '<td class="wrap">' . $fact->getDate()->display() . '</td>';
1248c2e8227SGreg Roach				$content .= '<td class="wrap"><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></td>';
1258c2e8227SGreg Roach				if ($show_unassigned || $show_other) {
1268c2e8227SGreg Roach					$content .= '<td class="wrap">' . $user_name . '</td>';
1278c2e8227SGreg Roach				}
1288c2e8227SGreg Roach				$text = $fact->getValue();
1298c2e8227SGreg Roach				$content .= '<td class="wrap">' . $text . '</td>';
1308c2e8227SGreg Roach				$content .= '</tr>';
1318c2e8227SGreg Roach				$found = true;
1328c2e8227SGreg Roach			}
1338c2e8227SGreg Roach		}
1348c2e8227SGreg Roach
1358c2e8227SGreg Roach		$content .= '</tbody></table>';
1368c2e8227SGreg Roach		if (!$found) {
1378c2e8227SGreg Roach			$content .= '<p>' . I18N::translate('There are no research tasks in this family tree.') . '</p>';
1388c2e8227SGreg Roach		}
1398c2e8227SGreg Roach
1408c2e8227SGreg Roach		if ($template) {
1418c2e8227SGreg Roach			if ($block) {
1428c2e8227SGreg Roach				$class .= ' small_inner_block';
1438c2e8227SGreg Roach			}
144cbc1590aSGreg Roach
1458c2e8227SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
1468c2e8227SGreg Roach		} else {
1478c2e8227SGreg Roach			return $content;
1488c2e8227SGreg Roach		}
1498c2e8227SGreg Roach	}
1508c2e8227SGreg Roach
1518c2e8227SGreg Roach	/** {@inheritdoc} */
1528c2e8227SGreg Roach	public function loadAjax() {
1538c2e8227SGreg Roach		return false;
1548c2e8227SGreg Roach	}
1558c2e8227SGreg Roach
1568c2e8227SGreg Roach	/** {@inheritdoc} */
1578c2e8227SGreg Roach	public function isUserBlock() {
1588c2e8227SGreg Roach		return true;
1598c2e8227SGreg Roach	}
1608c2e8227SGreg Roach
1618c2e8227SGreg Roach	/** {@inheritdoc} */
1628c2e8227SGreg Roach	public function isGedcomBlock() {
1638c2e8227SGreg Roach		return true;
1648c2e8227SGreg Roach	}
1658c2e8227SGreg Roach
16676692c8bSGreg Roach	/**
16776692c8bSGreg Roach	 * An HTML form to edit block settings
16876692c8bSGreg Roach	 *
16976692c8bSGreg Roach	 * @param int $block_id
17076692c8bSGreg Roach	 */
1718c2e8227SGreg Roach	public function configureBlock($block_id) {
1728c2e8227SGreg Roach		if (Filter::postBool('save') && Filter::checkCsrf()) {
173e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'show_other', Filter::postBool('show_other'));
174e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'show_unassigned', Filter::postBool('show_unassigned'));
175e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'show_future', Filter::postBool('show_future'));
176e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'block', Filter::postBool('block'));
1778c2e8227SGreg Roach		}
1788c2e8227SGreg Roach
179e2a378d3SGreg Roach		$show_other      = $this->getBlockSetting($block_id, 'show_other', '1');
180e2a378d3SGreg Roach		$show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', '1');
181e2a378d3SGreg Roach		$show_future     = $this->getBlockSetting($block_id, 'show_future', '1');
182e2a378d3SGreg Roach		$block           = $this->getBlockSetting($block_id, 'block', '1');
1838c2e8227SGreg Roach
1848c2e8227SGreg Roach		?>
1858c2e8227SGreg Roach		<tr>
1868c2e8227SGreg Roach			<td colspan="2">
1878c2e8227SGreg Roach				<?php echo I18N::translate('Research tasks are special events, added to individuals in your family tree, which identify the need for further research. You can use them as a reminder to check facts against more reliable sources, to obtain documents or photographs, to resolve conflicting information, etc.'); ?>
1888c2e8227SGreg Roach				<?php echo I18N::translate('To create new research tasks, you must first add “research task” to the list of facts and events in the family tree’s preferences.'); ?>
1898c2e8227SGreg Roach				<?php echo I18N::translate('Research tasks are stored using the custom GEDCOM tag “_TODO”. Other genealogy applications may not recognize this tag.'); ?>
1908c2e8227SGreg Roach			</td>
1918c2e8227SGreg Roach		</tr>
1928c2e8227SGreg Roach		<?php
1938c2e8227SGreg Roach
1948c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1958c2e8227SGreg Roach		echo I18N::translate('Show research tasks that are assigned to other users');
1968c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1973d7a8a4cSGreg Roach		echo FunctionsEdit::editFieldYesNo('show_other', $show_other);
1988c2e8227SGreg Roach		echo '</td></tr>';
1998c2e8227SGreg Roach
2008c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
2018c2e8227SGreg Roach		echo I18N::translate('Show research tasks that are not assigned to any user');
2028c2e8227SGreg Roach		echo '</td><td class="optionbox">';
2033d7a8a4cSGreg Roach		echo FunctionsEdit::editFieldYesNo('show_unassigned', $show_unassigned);
2048c2e8227SGreg Roach		echo '</td></tr>';
2058c2e8227SGreg Roach
2068c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
2078c2e8227SGreg Roach		echo I18N::translate('Show research tasks that have a date in the future');
2088c2e8227SGreg Roach		echo '</td><td class="optionbox">';
2093d7a8a4cSGreg Roach		echo FunctionsEdit::editFieldYesNo('show_future', $show_future);
2108c2e8227SGreg Roach		echo '</td></tr>';
2118c2e8227SGreg Roach
2128c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
2138c2e8227SGreg Roach		echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow');
2148c2e8227SGreg Roach		echo '</td><td class="optionbox">';
2153d7a8a4cSGreg Roach		echo FunctionsEdit::editFieldYesNo('block', $block);
2168c2e8227SGreg Roach		echo '</td></tr>';
2178c2e8227SGreg Roach	}
2188c2e8227SGreg Roach}
219