Display initials in table of contents

Hello,

I’m using OSJ 3.0.2.0
I need to display last name and first letter of first name in table of contents.
I have a code (written by someone else, used in OJS 2.4.2.0). I tried to implement this code in my upgraded site, tried to call function getInitialsFullName in article_summary.tpl but it doesn’t work. I’m not familiar with PHP enough to make this work.

function getInitialsFullName($lastFirst = true) {
if ($lastFirst) return $this->getData('lastName') . ' ' .
substr($this->getData('firstName'),0,1) .
($this->getData('middleName') != '' ? ' ' .
substr($this->getData('middleName'),0,1) : '');
else return substr($this->getData('firstName'),0,1) . ' ' .
($this->getData('middleName') != '' ? substr($this->getData('middleName'),0,1) . ' ' : '') .
$this->getData('lastName') .
($this->getData('suffix') != '' ? ', ' . $this->getData('suffix') : '');
}

Can I ask for some help or hints?

Have a nice day.

Hi @kaysh,

Where did you place that new function?

Did you find any error messages in your PHP error log with the changes in place?

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher

I placed function in lib/pkp/classes/submissions/Submission.inc.php

About error log: do you mean error log that I can enable via config or PHP error log that I don’t know how to print out?

Hi @kaysh,

Your PHP error log. Have a look at How do I find my PHP error log? for information on locating it.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher

I checked logs but didn’t find anything related.

Hi @kaysh,

Could you include any log entries with a date/time that corresponds to the request that seems broken?

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher

I noticed that I haven’t any error connected to my OJS3 based journal at all. Tried to call undefined function (and got fatal error on journal site) and then I relized that there is literally nothing in error log from my server. Should I contact my hosting provider? Or is it about OJS?

Hi @kaysh,

Yes, I think this will be related to your PHP configuration. Some providers permit configuring your PHP environment using e.g. .htaccess, but the details will vary. Your provider’s knowledge base may also be useful.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher

Thank you for tips, I enabled error reporting.
But still there is nothing related to this function getInitialsFullName .
Here are logs related to journal.
exampleundefined() is a function I called to check if error log is working.

[Fri Sep 01 14:25:43.202863 2017] [proxy_fcgi:error] [pid 26:tid 140349112538880] [client 195.150.12.77:40546] AH01071: Got error 'PHP message: PHP Fatal error: Call to undefined method PublishedArticle::exampleundefined() in   journal3/cache/t_compile/c4befc66d67bd32c2e928d767edffef3064ec10f^%%A0^A0A^A0AA4E57%%article_summary.tpl.php on line 44\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:25:43.202582 2017] [proxy_fcgi:error] [pid 26:tid 140349112538880] [client 195.150.12.77:40546] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:25:40.199793 2017] [proxy_fcgi:error] [pid 26:tid 140349078968064] [client 195.150.12.77:40546] AH01071: Got error 'PHP message: PHP Fatal error: Call to undefined method PublishedArticle::exampleundefined() in   journal3/cache/t_compile/c4befc66d67bd32c2e928d767edffef3064ec10f^%%A0^A0A^A0AA4E57%%article_summary.tpl.php on line 44\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:25:40.199566 2017] [proxy_fcgi:error] [pid 26:tid 140349078968064] [client 195.150.12.77:40546] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:22:33.271283 2017] [proxy_fcgi:error] [pid 26:tid 140349028611840] [client 195.150.12.77:39981] AH01071: Got error 'PHP message: PHP Fatal error: Call to undefined method PublishedArticle::exampleundefined() in   journal3/cache/t_compile/c4befc66d67bd32c2e928d767edffef3064ec10f^%%A0^A0A^A0AA4E57%%article_summary.tpl.php on line 44\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:22:33.271037 2017] [proxy_fcgi:error] [pid 26:tid 140349028611840] [client 195.150.12.77:39981] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:18:39.923765 2017] [proxy_fcgi:error] [pid 26:tid 140349276239616] [client 195.150.12.77:23892] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:17:29.296762 2017] [proxy_fcgi:error] [pid 26:tid 140349078968064] [client 195.150.12.77:51131] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 14:16:02.791609 2017] [proxy_fcgi:error] [pid 26:tid 140349137716992] [client 195.150.12.77:38542] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 13:55:56.275847 2017] [proxy_fcgi:error] [pid 26:tid 140349179680512] [client 195.150.12.77:57939] AH01071: Got error 'PHP message: PHP Warning: Cannot modify header information - headers already sent by (output started at   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php:102) in   journal3/lib/pkp/classes/template/PKPTemplateManager.inc.php on line 770\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 13:55:56.275827 2017] [proxy_fcgi:error] [pid 26:tid 140349179680512] [client 195.150.12.77:57939] AH01071: Got error 'PHP message: PHP Warning: Cannot modify header information - headers already sent by (output started at   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php:102) in   journal3/lib/pkp/classes/template/PKPTemplateManager.inc.php on line 767\n', referer:  journal3/index.php/crcd/about
[Fri Sep 01 13:55:56.275753 2017] [proxy_fcgi:error] [pid 26:tid 140349179680512] [client 195.150.12.77:57939] AH01071: Got error 'PHP message: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, class 'DefaultManuscriptChildThemePlugin' does not have a method 'loadTemplateData' in   journal3/lib/pkp/classes/plugins/HookRegistry.inc.php on line 102\n', referer:  journal3/index.php/crcd/about

Hi @kaysh,

The problem is that the getData calls you’re using – for data like lastName and firstName – are being called on an article object, but they appear to have been written for an author object. You’ll probably want to use the getAuthors function on the submission object to get the list of authors, then work with those objects to get the name information you’re looking for.

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher

Thanks, it worked. Although now I have next issue. Function returns “Array” instead of authors names and initials and my error log says:
PHP Warning: substr() expects parameter 1 to be string, array given in

Hi @kaysh,

Yes, the getAuthors function will return an array of Author objects, which you can then call functions on. There’s an API reference here: Open Journal Systems: OJS API Reference

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher

Thank you so much for help!

Have a nice day.