Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report additions #4945

Closed
wants to merge 46 commits into from
Closed

Report additions #4945

wants to merge 46 commits into from

Conversation

sevtor
Copy link
Contributor

@sevtor sevtor commented Jan 23, 2024

The app/Report tool creates reports from the collected gedcom data. The current version has some limitation and shortcomings that this update addresses. A detailed description is included as a pdf file, and in short the changes are:

Report tries to place text on an exact position on a page. But many pitfalls on the way. Counting lines in a textbox is not enough, the lines may be set in different font sizes; converting lines to points in HTML uses a much too high number, which results in a lot of white space, especially for long reports (many pages). The PDF reports have problems to predict when the tool TcPdf will break a line or add a page. This applies to the files HtmlRenderer.php, ReportHtmlTextbox.php, ReportHtmlText.php, PdfRenderer.php, ReportPdfTextBox.php and ReportPdfText.php,

The file ReportParserGenerate.php is responsible for the interpretation of the xml code that defines the layout and contents of the report. A number of addition have been introduced.
(1) GetPersonName has got a new attribute, select=..., that allows the report to present the last name used or a combination of latest and surname at birth. Another attribute, fam_relation="1", will add the relation the current person to the start person of a report, e.g. mmf which means mother's mother's father.
(2) The value that is returned by GedcomValue can be a very long string. An attribute truncate=... already exists but has been two new possibilities for dates: "Y" will give only the year and "d" gives the date with the three character short for the month, "dd mmm yyyy".
(3) The calculation of the family relation that can be give with the name requires a substantial amount of code.
(4) The xml keyword Facts returns all facts and events of the current object (person, family) in the order they appear. But in a report one wants chronological order and that has been implemented. A special addition is that a temporary gedcom event is introduced in the process, _SP_DEAT, which when a spouse has died, if applicable. This is used only during calculations, not added to the Gedcom database or file. This (hidden) gedcom value must be added to the gedcom.php file. (A similar presentation is given on the main page for each person.)
(5) The keyword SetVar has been expanded with new possibilities for the attribute value=.... The value can now specify "@$xxx" which means the the value of xxx is interpreted as the name of the varible to select. Other new values are "@Format" that responds PDF or HTML depending on whichever form of report is selected. "@$dump" can give some help in debugging new or modified reports.
(6) Sometimes ancestors have married a relative. In pedigree charts these persons were given as separate persons, although with tha same name, birthdate, et c. But now such persons are detected and the second occurrance is given as "same person as ...".
(7) Some errors are corrected.

Seved Torstendahl added 4 commits January 22, 2024 22:28
The app/Report tool creates reports from the collected gedcom data. The current versio has some
limitation and shortcomings that this update addresses. A detailed description is incuded as a
pdf file, and in short the changes are:

Report tries to place text on an exact position on a page. But many pitfalls on the way. Counting lines
in a textbox is not enough, the lines may be set in different font sizes; converting lines to points
in HTML uses a much too high number, which results in a lot of white space, especially for long reports
(many pages). The PDF reports have problems to predict when the tool TcPdf will break a line or add a page.
This applies to the files HtmlRenderer.php, ReportHtmlTextbox.php, ReportHtmlText.php, PdfRenderer.php,
ReportPdfTextBox.php and ReportPdfText.php,

The file ReportParserGenerate.php is responsible for the interpretation of the xml code that defines
the layout and contents of the report. A number of addition have been introduced.
(1) GetPersonName has got a new attribute, select=..., that allows the report to present the last name
used or a combination of latest and surname at birth. Another attribute, fam_relation="1", will add
the relation the current person to the start person of a report, e.g. mmf which means mother's
mother's father.
(2) The value that is returned by GedcomValue can be a very long string. An attribute truncate=... already
exists but has been two new possibilities for dates: "Y" will give only the year and "d" gives the date
with the three character short for the month, "dd mmm yyyy".
(3) The calculation of the family relation that can be give with the name requires a substatial amount
of code.
(4) The xml keyword Facts returns all facts and events of the current object (person, family) in the
order they appear. But in a report one wants chronological order and that has been implemented. A special
addition is that a temporary gedcom event is introduced in the process, _SP_DEAT, which when a spouse
has died, if applicable. This is used only during calculations, not added to the Gedcom database or file.
This (hidden) gedcom value must be added to the gedcom.php file.
(A similar presentation is given on the main page for each person.)
(5) The keyword SetVar has been expanded with new possibilities for the attribute value=.... The value can
now specify "@$xxx" which means the the value of xxx is interpreted as the name of the varible to select.
Other new values are "@Format" that responds PDF or HTML depending on whichever form of report is selected.
"@$dump" can give some help in debugging new or modified reports.
(6) Sometimes ancestors have married a relative. In pedigree charts these persons were given as separate
persons, although with tha same name, birthdate, et c. But now such persons are detected and the second
occurrance is given as "same person as ...".
(7) Some errors are corrected.
Some of the reports supplied with webtrees relies on the current app/Report tool. The layout can be
slightly changed with the suggested new app/report. A couple of reports try to give the result as tables.
The changes here take care of that. These new  xml files work well with the old app/Report xml tool.
Not sure were to put it but this seems to be a logical place.
@sevtor
Copy link
Contributor Author

sevtor commented Jan 26, 2024

Unfortunately I used my own indentation rules and did not know how to fix it. So please make the corrections!
And please tell me how I can use the tool StyleCI in the future.

Copy link

codecov bot commented Jan 27, 2024

Codecov Report

Attention: Patch coverage is 68.13725% with 130 lines in your changes missing coverage. Please review.

Project coverage is 32.53%. Comparing base (d5c9d9c) to head (42b74bb).
Report is 284 commits behind head on main.

Files with missing lines Patch % Lines
app/Report/ReportParserGenerate.php 59.52% 119 Missing ⚠️
app/Report/ReportHtmlTextbox.php 88.23% 4 Missing ⚠️
app/Report/ReportPdfTextBox.php 85.18% 4 Missing ⚠️
app/Gedcom.php 0.00% 2 Missing ⚠️
app/Report/PdfRenderer.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4945      +/-   ##
============================================
+ Coverage     32.29%   32.53%   +0.24%     
- Complexity    11401    11535     +134     
============================================
  Files          1171     1172       +1     
  Lines         48056    48166     +110     
============================================
+ Hits          15521    15673     +152     
+ Misses        32535    32493      -42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sevtor
Copy link
Contributor Author

sevtor commented Jan 28, 2024

The static analysis checks that still fail relate to code that "always" has been there.

Therefore I want this pull request to be set to 'Ready for review' !

@sevtor
Copy link
Contributor Author

sevtor commented Feb 1, 2024

PR ready for review!

@sevtor
Copy link
Contributor Author

sevtor commented Feb 9, 2024

This PR solved the 'Missing data' Feature Request.
It also handles translations for custom modules, especially reports, where the title and description strings were un-translated (because the translations were included too late).

Seved Torstendahl added 5 commits February 11, 2024 16:24
The change was due to bad test environment
HerzScheisse proposed this in general but that is not good for most other languages.
@BertKoor
Copy link
Contributor

Is this PR still a candidate to be merged with the dev branch?
Headers & footers on reports are mentioned again in the forum:
https://www.webtrees.net/index.php/forum/2-open-discussion/39136-reports-download

@sevtor
Copy link
Contributor Author

sevtor commented Jul 24, 2024

Yes it is!

@elysch
Copy link

elysch commented Aug 11, 2024

Hello.
I decided to try these changes. Generated a patch file and applied it to a clean 2.1.20 sources directory.

I got these errors:

can't find file to patch at input line 5939          
Perhaps you used the wrong -p or --strip option?     
The text leading up to this was:                     
--------------------------                           
|diff --git a/phpstan-baseline.php b/phpstan-baseline.php                                                 
|index 8e433dded66..4596026fff8 100644               
|--- a/phpstan-baseline.php                          
|+++ b/phpstan-baseline.php                          -
-------------------------                           
File to patch:                                       
Skip this patch? [y]                                 
Skipping patch.                                      
1 out of 1 hunk ignored                              
can't find file to patch at input line 5952          
Perhaps you used the wrong -p or --strip option?     
The text leading up to this was:                     
--------------------------
|diff --git a/phpstan-baseline.php b/phpstan-baseline.php                                                 
|index 4596026fff8..03a51d7ca51 100644               
|--- a/phpstan-baseline.php                          
|+++ b/phpstan-baseline.php                          
--------------------------                           
File to patch:                                       
Skip this patch? [y]                                 
Skipping patch.                                      
4 out of 4 hunks ignored                                                                                  

...                                                                                              

patching file app/Module/ModuleCustomTrait.php       
Hunk #3 FAILED at 112.                               
1 out of 4 hunks FAILED -- saving rejects to file app/Module/ModuleCustomTrait.php.rej

...                                                                                                       

patching file app/Report/ReportParserGenerate.php    
Reversed (or previously applied) patch detected!  Assume -R? [n]                                          
Apply anyway? [n]                                    
Skipping patch.                                      
3 out of 3 hunks ignored -- saving rejects to file app/Report/ReportParserGenerate.php.rej

Is it ok that there is a missing file?
Does the "Reversed" change should be applied?

[root@xxx public_html]# cat webtrees-2.1.20-test/app/Report/ReportParserGenerate.php.rej
--- app/Report/ReportParserGenerate.php
+++ app/Report/ReportParserGenerate.php
@@ -22,7 +22,6 @@
 use DomainException;
 use Fisharebest\Webtrees\Auth;
 use Fisharebest\Webtrees\Date;
-use Fisharebest\Webtrees\DB;
 use Fisharebest\Webtrees\Elements\UnknownElement;
 use Fisharebest\Webtrees\Factories\MarkdownFactory;
 use Fisharebest\Webtrees\Family;
@@ -36,6 +35,7 @@
 use Fisharebest\Webtrees\Place;
 use Fisharebest\Webtrees\Registry;
 use Fisharebest\Webtrees\Tree;
+use Illuminate\Database\Capsule\Manager as DB; // webtrees 2.1.x
 use Illuminate\Database\Query\Builder;
 use Illuminate\Database\Query\Expression;
 use Illuminate\Database\Query\JoinClause;
@@ -2058,7 +2058,7 @@ protected function imageStartHandler(array $attrs): void

         if ($file === '@FILE') {
             $match = [];
-            if (preg_match("/\d OBJE @(.+)@/", $this->gedrec, $match)) {
+            if (preg_match("/1 OBJE @(.+)@/", $this->gedrec, $match)) {
                 $mediaobject = Registry::mediaFactory()->make($match[1], $this->tree);
                 $media_file  = $mediaobject->firstImageFile();

Just in case it helps.

@elysch
Copy link

elysch commented Aug 11, 2024

I doubt this is right:

diff --git a/app/Gedcom.php b/app/Gedcom.php
index 1af380bbb33..b9881765ba0 100644
--- a/app/Gedcom.php
+++ b/app/Gedcom.php
@@ -595,8 +594,8 @@ private function gedcom551Tags(): array
             'INDI:BARM:DATE'             => new DateValue(I18N::translate('Date of bar mitzvah')),
             'INDI:BARM:PLAC'             => new PlaceName(I18N::translate('Place of bar mitzvah')),
             'INDI:BASM'                  => new BasMitzvah(I18N::translate('Bat mitzvah')),
-            'INDI:BASM:DATE'             => new DateValue(I18N::translate('Date of bat mitzvah')),
-            'INDI:BASM:PLAC'             => new PlaceName(I18N::translate('Place of bat mitzvah')),
+            'INDI:BASM:DATE'             => new BasMitzvah(I18N::translate('Date of bat mitzvah')),
+            'INDI:BASM:PLAC'             => new DateValue(I18N::translate('Place of bat mitzvah')),
             'INDI:BIRT'                  => new Birth(I18N::translate('Birth')),
             'INDI:BIRT:DATE'             => new DateValue(I18N::translate('Date of birth')),
             'INDI:BIRT:FAMC'             => new XrefFamily(I18N::translate('Birth parents')),

Is it?

@elysch
Copy link

elysch commented Aug 11, 2024

Does the line with a fixed "55.5" is right?

diff --git a/app/Report/PdfRenderer.php b/app/Report/PdfRenderer.php
index bbe261242b4..ba12d1416ea 100644
--- a/app/Report/PdfRenderer.php
+++ b/app/Report/PdfRenderer.php
@@ -363,8 +364,8 @@ public function setup(): void
             'UTF-8',
             self::DISK_CACHE
         );
-
-        $this->tcpdf->setMargins($this->left_margin, $this->top_margin, $this->right_margin);
+        $this->tcpdf->setPrintFooter(true);
+        $this->tcpdf->setMargins($this->left_margin, 55.5 /*$this->top_margin*/, $this->right_margin); // header-height?
         $this->tcpdf->setHeaderMargin($this->header_margin);
         $this->tcpdf->setFooterMargin($this->footer_margin);
         $this->tcpdf->setAutoPageBreak(true, $this->bottom_margin);

EDIT
What I mean is I think it should be in a configuration file... I'm not questioning if the value is correct or not.

@sevtor
Copy link
Contributor Author

sevtor commented Nov 7, 2024

Hello Elysch! I am really sorry that I missed your comments earlier, but I have been very busy lately.

  1. The file phpstan-baseline.php is only used by the Pull Request and as a user you should not have it.
    The file ModuleCustomTrait.php should not be patched, I don't understand how it came into your diff.
    You should check that the two rejected parts for ReportParserGenerate.php are actually already there (except for my comment about 2.1.x).
  2. The Gedcom.php file should not be patched at all.
  3. In PdfRenderer.php I have an explicit constant 55.5 because I could not find the value for the height of the header, as I tried to indicate in the comment.

Recently I applied the changes I was using in wt 2.1.18 to a fresh installation of 2.1.20 and everything worked out fine and I am now using the patched 2.1.20. You can fetch these files from my repo sevtor/modules.

I am now trying to figure out how I shall continue. The history of this PR is too long and files are modified and reverted so either I shall continue here or restart with a new PR. There are also some numerical constants in other places that I don't like but I hesitated earlier to make more elaborated changes to the code but now I know more about how to use php.

@sevtor
Copy link
Contributor Author

sevtor commented Nov 15, 2024

I am now working intensively with updates and will create a new PR that will replace this one!

@sevtor
Copy link
Contributor Author

sevtor commented Nov 15, 2024

This PR includes many additions and changes starting with webtrees 2.1.17 and has become hard to update.
A new PR #5055 has pure modification of app/Reports and some report definitions in resources/xml/reports.

@sevtor sevtor closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants