0
votes

I am very new to Typo3/TypoScript and I wondered if and how it is possible to give the result of a sql-statement in TypoScript to a php function.

I've managed the userFunc so far, but i'm getting confused with the rest. Here is my try:

temp.pidList = CONTENT
temp.pidList {
  table = tx_eepcollect_sessions
  #table = tt_content
  select {
    pidInList < plugin.tx_eepcollect_pi1.pid_list
   where {
      stdWrap.cObject = TEXT
      stdWrap.cObject {
        data = global : _COOKIE | tx_eepcollect_pi1
        wrap = ses_id='|'
      }
    }
  }
  renderObj = COA
  renderObj {
    10 = TEXT
    10.field = ses_data
    #30 = TEXT
    #30.data = debug:data
  }
}


includeLibs.user_idList = fileadmin/services/user_IdList.php
temp.ListOfIds = USER
temp.ListOfIds.userFunc = user_IdList->get_IdList
#temp.pidList = TEXT
#temp.pidList = {"1275":{"id":"1275","tx_eepcollect_pi1":{"prozess":"add","pid":"1275","ctrl":"1360858765"},"cHash":"e90b62584f3f0e4f71bf1100faf39d83"}}
temp.ListOfIds.userFunc.jsonList < temp.pidList


temp.mainContent = COA_INT
temp.mainContent.10 = TEXT
temp.mainContent.10.stdWrap.cObject < temp.ListOfIds

The output is an array of a lot of stuff, but not the result of the database-query.

1
What is exactly needed? the output of temp.pidList or temp.ListOfIds ? If you are asking about the userfunc, then please copy-paste the php code. - Sankar V

1 Answers

1
votes

TypoScript is not a programming language, so it is not executed in any meaning. You should think about TS as set of instructions for the Core. So, following line:

temp.ListOfIds.userFunc.jsonList < temp.pidList

will not put result of temp.pidList into temp.ListOfIds.userFunc.jsonList, as you would expect from a programming language - it will simply copy set of instructions, so at the end you'll have following structure:

temp.ListOfIds = USER
temp.ListOfIds.userFunc = user_IdList->get_IdList
temp.ListOfIds.userFunc.jsonList = CONTENT
temp.ListOfIds.userFunc.jsonList.table = tx_eepcollect_sessions
[...]

And since jsonList is your custom property you need to bring stdWrap to it by following method:

TypoScript

temp.ListOfIds.userFunc.jsonList.cObject < temp.pidList

PHP

$jsonList = $this->cObj->stdWrap($conf['jsonList'], $conf['jsonList.']);

I assume, that you call it from a method get_IdList of class user_IdList with two params: $content and $conf.

As an additional measerue, you can make it as extension with a kickstarter or extension builder, so it'll be easier for you to work with configuration.

Another thing is, that your code have potential SQL injection vulnerability here:

   where {
      stdWrap.cObject = TEXT
      stdWrap.cObject {
        data = global : _COOKIE | tx_eepcollect_pi1
        wrap = ses_id='|'
      }
    }

So, you may consider reading about markers