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/CensusAssistantModule.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/CensusAssistantModule.php')
| -rw-r--r-- | app/Module/CensusAssistantModule.php | 321 |
1 files changed, 166 insertions, 155 deletions
diff --git a/app/Module/CensusAssistantModule.php b/app/Module/CensusAssistantModule.php index 6ef3594ad6..6d5b24d6ef 100644 --- a/app/Module/CensusAssistantModule.php +++ b/app/Module/CensusAssistantModule.php @@ -27,184 +27,195 @@ use Symfony\Component\HttpFoundation\Response; /** * Class CensusAssistantModule */ -class CensusAssistantModule extends AbstractModule { - /** {@inheritdoc} */ - public function getTitle() { - return /* I18N: Name of a module */ - I18N::translate('Census assistant'); - } +class CensusAssistantModule extends AbstractModule +{ + /** {@inheritdoc} */ + public function getTitle() + { + return /* I18N: Name of a module */ + I18N::translate('Census assistant'); + } - /** {@inheritdoc} */ - public function getDescription() { - return /* I18N: Description of the “Census assistant” module */ - I18N::translate('An alternative way to enter census transcripts and link them to individuals.'); - } + /** {@inheritdoc} */ + public function getDescription() + { + return /* I18N: Description of the “Census assistant” module */ + I18N::translate('An alternative way to enter census transcripts and link them to individuals.'); + } - /** - * @param Request $request - * - * @return Response - */ - public function getCensusHeaderAction(Request $request): Response { - $census = $request->get('census'); + /** + * @param Request $request + * + * @return Response + */ + public function getCensusHeaderAction(Request $request): Response + { + $census = $request->get('census'); - $html = $this->censusTableHeader(new $census); + $html = $this->censusTableHeader(new $census); - return new Response($html); - } + return new Response($html); + } - /** - * @param Request $request - * - * @return Response - */ - public function getCensusIndividualAction(Request $request): Response { - /** @var Tree $tree */ - $tree = $request->attributes->get('tree'); + /** + * @param Request $request + * + * @return Response + */ + public function getCensusIndividualAction(Request $request): Response + { + /** @var Tree $tree */ + $tree = $request->attributes->get('tree'); - $census = $request->get('census'); + $census = $request->get('census'); - $individual = Individual::getInstance($request->get('xref'), $tree); - $head = Individual::getInstance($request->get('head'), $tree); - $html = $this->censusTableRow(new $census, $individual, $head); + $individual = Individual::getInstance($request->get('xref'), $tree); + $head = Individual::getInstance($request->get('head'), $tree); + $html = $this->censusTableRow(new $census, $individual, $head); - return new Response($html); - } + return new Response($html); + } - /** - * @param Individual $individual - * - * @return string - */ - public function createCensusAssistant(Individual $individual) { - return view('modules/census-assistant', [ - 'individual' => $individual, - ]); - } + /** + * @param Individual $individual + * + * @return string + */ + public function createCensusAssistant(Individual $individual) + { + return view('modules/census-assistant', [ + 'individual' => $individual, + ]); + } - /** - * @param Individual $individual - * @param string $fact_id - * @param string $newged - * @param bool $keep_chan - * - * @return string - */ - public function updateCensusAssistant(Individual $individual, $fact_id, $newged, $keep_chan) { - $ca_title = Filter::post('ca_title'); - $ca_place = Filter::post('ca_place'); - $ca_citation = Filter::post('ca_citation'); - $ca_individuals = Filter::postArray('ca_individuals'); - $ca_notes = Filter::post('ca_notes'); - $ca_census = Filter::post('ca_census', 'Fisharebest\\\\Webtrees\\\\Census\\\\CensusOf[A-Za-z0-9]+'); + /** + * @param Individual $individual + * @param string $fact_id + * @param string $newged + * @param bool $keep_chan + * + * @return string + */ + public function updateCensusAssistant(Individual $individual, $fact_id, $newged, $keep_chan) + { + $ca_title = Filter::post('ca_title'); + $ca_place = Filter::post('ca_place'); + $ca_citation = Filter::post('ca_citation'); + $ca_individuals = Filter::postArray('ca_individuals'); + $ca_notes = Filter::post('ca_notes'); + $ca_census = Filter::post('ca_census', 'Fisharebest\\\\Webtrees\\\\Census\\\\CensusOf[A-Za-z0-9]+'); - if ($ca_census !== '' && !empty($ca_individuals)) { - $census = new $ca_census; + if ($ca_census !== '' && !empty($ca_individuals)) { + $census = new $ca_census; - $note_text = $this->createNoteText($census, $ca_title, $ca_place, $ca_citation, $ca_individuals, $ca_notes); - $note_gedcom = '0 @new@ NOTE ' . str_replace("\n", "\n1 CONT ", $note_text); - $note = $individual->getTree()->createRecord($note_gedcom); + $note_text = $this->createNoteText($census, $ca_title, $ca_place, $ca_citation, $ca_individuals, $ca_notes); + $note_gedcom = '0 @new@ NOTE ' . str_replace("\n", "\n1 CONT ", $note_text); + $note = $individual->getTree()->createRecord($note_gedcom); - $newged .= "\n2 NOTE @" . $note->getXref() . '@'; + $newged .= "\n2 NOTE @" . $note->getXref() . '@'; - // Add the census fact to the rest of the household - foreach (array_keys($ca_individuals) as $xref) { - if ($xref !== $individual->getXref()) { - Individual::getInstance($xref, $individual->getTree()) - ->updateFact($fact_id, $newged, !$keep_chan); - } - } - } + // Add the census fact to the rest of the household + foreach (array_keys($ca_individuals) as $xref) { + if ($xref !== $individual->getXref()) { + Individual::getInstance($xref, $individual->getTree()) + ->updateFact($fact_id, $newged, !$keep_chan); + } + } + } - return $newged; - } + return $newged; + } - /** - * @param CensusInterface $census - * @param string $ca_title - * @param string $ca_place - * @param string $ca_citation - * @param string[][] $ca_individuals - * @param string $ca_notes - * - * @return string - */ - private function createNoteText(CensusInterface $census, $ca_title, $ca_place, $ca_citation, $ca_individuals, $ca_notes) { - $text = $ca_title . "\n" . $ca_citation . "\n" . $ca_place . "\n\n"; + /** + * @param CensusInterface $census + * @param string $ca_title + * @param string $ca_place + * @param string $ca_citation + * @param string[][] $ca_individuals + * @param string $ca_notes + * + * @return string + */ + private function createNoteText(CensusInterface $census, $ca_title, $ca_place, $ca_citation, $ca_individuals, $ca_notes) + { + $text = $ca_title . "\n" . $ca_citation . "\n" . $ca_place . "\n\n"; - foreach ($census->columns() as $n => $column) { - if ($n === 0) { - $text .= "\n"; - } else { - $text .= ' | '; - } - $text .= $column->abbreviation(); - } + foreach ($census->columns() as $n => $column) { + if ($n === 0) { + $text .= "\n"; + } else { + $text .= ' | '; + } + $text .= $column->abbreviation(); + } - foreach ($census->columns() as $n => $column) { - if ($n === 0) { - $text .= "\n"; - } else { - $text .= ' | '; - } - $text .= '-----'; - } + foreach ($census->columns() as $n => $column) { + if ($n === 0) { + $text .= "\n"; + } else { + $text .= ' | '; + } + $text .= '-----'; + } - foreach ($ca_individuals as $xref => $columns) { - $text .= "\n" . implode(' | ', $columns); - } + foreach ($ca_individuals as $xref => $columns) { + $text .= "\n" . implode(' | ', $columns); + } - return $text . "\n\n" . $ca_notes; - } + return $text . "\n\n" . $ca_notes; + } - /** - * Generate an HTML row of data for the census header - * Add prefix cell (store XREF and drag/drop) - * Add suffix cell (delete button) - * - * @param CensusInterface $census - * - * @return string - */ - public static function censusTableHeader(CensusInterface $census) { - $html = ''; - foreach ($census->columns() as $column) { - $html .= '<th class="wt-census-assistant-field" title="' . $column->title() . '">' . $column->abbreviation() . '</th>'; - } + /** + * Generate an HTML row of data for the census header + * Add prefix cell (store XREF and drag/drop) + * Add suffix cell (delete button) + * + * @param CensusInterface $census + * + * @return string + */ + public static function censusTableHeader(CensusInterface $census) + { + $html = ''; + foreach ($census->columns() as $column) { + $html .= '<th class="wt-census-assistant-field" title="' . $column->title() . '">' . $column->abbreviation() . '</th>'; + } - return '<tr class="wt-census-assistant-row"><th hidden></th>' . $html . '<th></th></tr>'; - } + return '<tr class="wt-census-assistant-row"><th hidden></th>' . $html . '<th></th></tr>'; + } - /** - * Generate an HTML row of data for the census - * Add prefix cell (store XREF and drag/drop) - * Add suffix cell (delete button) - * - * @param CensusInterface $census - * - * @return string - */ - public static function censusTableEmptyRow(CensusInterface $census) { - return '<tr class="wt-census-assistant-row"><td hidden></td>' . str_repeat('<td class="wt-census-assistant-field"><input type="text" class="form-control wt-census-assistant-form-control"></td>', count($census->columns())) . '<td><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>'; - } + /** + * Generate an HTML row of data for the census + * Add prefix cell (store XREF and drag/drop) + * Add suffix cell (delete button) + * + * @param CensusInterface $census + * + * @return string + */ + public static function censusTableEmptyRow(CensusInterface $census) + { + return '<tr class="wt-census-assistant-row"><td hidden></td>' . str_repeat('<td class="wt-census-assistant-field"><input type="text" class="form-control wt-census-assistant-form-control"></td>', count($census->columns())) . '<td><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>'; + } - /** - * Generate an HTML row of data for the census - * Add prefix cell (store XREF and drag/drop) - * Add suffix cell (delete button) - * - * @param CensusInterface $census - * @param Individual $individual - * @param Individual $head - * - * @return string - */ - public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head) { - $html = ''; - foreach ($census->columns() as $column) { - $html .= '<td class="wt-census-assistant-field"><input class="form-control wt-census-assistant-form-control" type="text" value="' . $column->generate($individual, $head) . '" name="ca_individuals[' . $individual->getXref() . '][]"></td>'; - } + /** + * Generate an HTML row of data for the census + * Add prefix cell (store XREF and drag/drop) + * Add suffix cell (delete button) + * + * @param CensusInterface $census + * @param Individual $individual + * @param Individual $head + * + * @return string + */ + public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head) + { + $html = ''; + foreach ($census->columns() as $column) { + $html .= '<td class="wt-census-assistant-field"><input class="form-control wt-census-assistant-form-control" type="text" value="' . $column->generate($individual, $head) . '" name="ca_individuals[' . $individual->getXref() . '][]"></td>'; + } - return '<tr class="wt-census-assistant-row"><td class="wt-census-assistant-field" hidden>' . $individual->getXref() . '</td>' . $html . '<td class="wt-census-assistant-field"><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>'; - } + return '<tr class="wt-census-assistant-row"><td class="wt-census-assistant-field" hidden>' . $individual->getXref() . '</td>' . $html . '<td class="wt-census-assistant-field"><a class="icon-remove" href="#" title="' . I18N::translate('Remove') . '"></a></td></tr>'; + } } |
