how to render a unix timestamp and links in typo3 4.5 backend module fluid template?

415 views Asked by At

I tried this :

$items =  ($report->http_response_body->items );
$this->view->assign('items', $items);
$this->view->assign('page', $report->http_response_body->paging);

 {item.timestamp} <f:format.date format="d.m.Y - H:i:s">@{item.timestamp}</f:format.date> 

but it renders different tiamstamps like so(either it fails completely or renders incorrectly):

1435146156.574 "@1435146156.574" could not be parsed by DateTime constructor.   
1435146154.602 "@1435146154.602" could not be parsed by DateTime constructor.   
1435141273.1495 24.06.1540 - 05:21:13

The items are from a mailgun response https://documentation.mailgun.com/api-events.html#examples

Also this is for a backend module, so how would I handle the paging? I have this so far

 <f:link.action class="button show" action="list" arguments="{page : page.first}">First</f:link.action> 
 <f:link.action class="button show" action="list" arguments="{page : page.previous}">Previous</f:link.action> 
 <f:link.action class="button show" action="list" arguments="{page : page.next}">Next</f:link.action> 
 <f:link.action class="button show" action="list" arguments="{page : page.last}">Last</f:link.action> 

but when you click a link it gives the error:

Oops, an error occured!  The endpoint you've tried to access does not exist. Check your URL.

Thanks (Sorry for such a newbie Q but I've never written a backend module before) PS in order to even get this far I had to copyu the Backend templates up a folder to be found so now my backend module is using the default templates found under Resources/Private/Templates instead of Resources/Backend/Private/Templates, here is my list template:

 <f:layout name="Default" />

This Template is responsible for creating a table of domain objects.

If you modify this template, do not forget to change the overwrite settings
in /Configuration/ExtensionBuilder/settings.yaml:
  Resources:
    Private:
      Templates:
        List.html: keep

Otherwise your changes will be overwritten the next time you save the extension in the extension builder

<f:section name="content">
<h1>Listing for MailgunLog</h1>

<f:flashMessages />

<table  class="tx_mailgunlog" >
    <tr>

        <th> Date</th>
        <th> Summary</th>
    </tr>


    <f:for each="{items}" as="item">
        <tr>
            <td>{item.timestamp}   <f:format.date format="d.m.Y - H:i:s">@{item.timestamp}</f:format.date> </td>
            <td> {item.event} {item.recipient} {item.message.headers.subject} </td>
        </tr>
    </f:for>
</table>

 <f:link.action class="button show" action="list" arguments="{page : page.first}">First</f:link.action> 
 <f:link.action class="button show" action="list" arguments="{page : page.previous}">Previous</f:link.action> 
 <f:link.action class="button show" action="list" arguments="{page : page.next}">Next</f:link.action> 
 <f:link.action class="button show" action="list" arguments="{page : page.last}">Last</f:link.action> 



</f:section> 

Thanks!

PS: Thanks to mtness I added this code to controller to fix date issue:

 foreach($report->http_response_body->items as $item){
            if(strpos($item->timestamp, ".")!==FALSE){
            $item->timestamp =  strstr($item->timestamp, '.', TRUE); 
        }
       }

now to figure out the link issue.

Since the action is all in the listAction I thought I'd post the function sig:

 /**
    * action list
    * @param string emailaddress to search for
    * @param string PAGE IF THERE IS PAGING TO BE DONE
    * @return void
    */
    public function listAction($email ='', $page='') {
1

There are 1 answers

0
The Newbie Qs On

for now I've had to add a quick hack like so:

 $getvars = t3lib_div::_GET();
 $email = mysql_real_escape_string($getvars["email"]);
 $page = mysql_real_escape_string($getvars["page"]);
 $report = $this->report($email, $page);

and just append the paging url to the links like so:

<f:if condition="{page.first}">
  <a href="http://www.ontariotaxsales.ca/typo3/mod.php?M=web_MailgunlogMailgunlog&page={page.first}">First</a>
</f:if>
<f:if condition="{page.previous}">
  <a href="http://www.ontariotaxsales.ca/typo3/mod.php?M=web_MailgunlogMailgunlog&page={page.previous}">Previous</a>
</f:if>
<f:if condition="{page.next}"> 
  <a href="mod.php?M=web_MailgunlogMailgunlog&page={page.next}">Next</a>
</f:if>
<f:if condition="{page.last}">
  <a href="http://www.ontariotaxsales.ca/typo3/mod.php?M=web_MailgunlogMailgunlog&page={page.last}">Last</a>
</f:if>

and the search by email looks like this:

<form action="http://www.ontariotaxsales.ca/typo3/mod.php?" method="GET">
  <input type="hidden" name="M" value="web_MailgunlogMailgunlog"/>
  Email Search <input name="email" type="email" />
</form>

/**
  * Report
  * show outbound log from mailgun
  * @param string email
  * @param string page the paging url
  * @return void
  */
public function report( $email='', $page='' ) {
    $APIKey = 'key-...';
    $MailgunDomain = 'https://api.mailgun.net/v3/outbound.....ca/events';

    $mgClient = new Mailgun($APIKey);  
    # Issue the call to the client.  

    $queryString = array(   
        'pretty' => 'no'        
    );
    if($page !=''){
        $MailgunDomain =  $page;           
    } 
    if ($email != '') {
        $queryString['recipient']=$email;
    }

    # Make the call to the client.
    $result = $mgClient->get("$MailgunDomain", $queryString   );
    return $result ;

}

An ugly shameless hack but I needed to get it done quick.