Tesseract

Store a picture in FAL, and retrieve file name using standard sql statement

Scenario: store a picture in FAL, and retrieve file name using standard sql statement
A) TCA declaration is as follows:
‘news_picture’ => array(
‘exclude’ => 0,
‘label’ => ‘LLL:EXT:mynews/Resources/Private/Language/Database.xlf:tx_mynews.news_picture’,
‘config’ => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
‘news_picture’,
array(
‘appearance’ => array(
‘collapseAll’ => TRUE
),
‘maxitems’ => 1,
)
)
),
B) An SQL example:
SELECT * FROM (
SELECT 
tx_mynews.uid as news_uid,
tx_mynews.news_title,
tx_mynews.news_subtitle,
`sys_file`.name AS filename,
`sys_file`.uid AS fileuid,
`sys_file`.identifier
FROM `tx_mynews` 
LEFT JOIN `sys_file_reference` ON 
`tx_mynews`.`uid` = `sys_file_reference`.`uid_foreign`
AND 
 `sys_file_reference`.`tablenames` = ‘tx_mynews’ 
 AND 
 `sys_file_reference`.`fieldname` = ‘news_picture’
 AND 
 `sys_file_reference`.`table_local` = ‘sys_file’ AND
 `sys_file_reference`.`deleted` = 0
LEFT JOIN `sys_file` 
ON
`sys_file_reference`.`uid_local` = `sys_file`.`uid`)
AS docs where docs.filename <> ”
ORDER BY news_title
LIMIT 100

Running a SQL Query using TypoScript

Well, after using this feature for quite long time, I though I should post this info:Consider the following Query:

SELECT DISTINCT FROM_UNIXTIME(`datetime`, ‘%Y’) AS `year` FROM tt_news where pid=113 order by datetime limit 1

My main goal was to get the latest year from the tt_news records, that is then going to be pushed to Tesseract filter.

Soln:

20 = CONTENT
20 {
table = tt_news
select {
selectFields = FROM_UNIXTIME(`datetime`, ‘%Y’) AS year
orderBy = datetime desc
pidInList = 113
max = 1
}
renderObj = TEXT
renderObj.field = year
}

Reference: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/5/#id2621093

Tesseract Tips / Notes

DATA FILTER:

Clear Filter/Query Cache: In some situations when “Additional SQL” field is cleared, the dataquery may still be using the cached value from this field.
In such case we should add following URL Parameter, which informs DataQuery to re-build the query from scratch.

EX:
www.example.com/?clear_cache = 1

Using main.subtable: When we wish to apply a specific condition to a sub-table, the query is applied on the JOIN itself:

EX 1:
subtable.uid = vars:event
maintable.uid = varsproject

This is translated to someting like this:

SELECT maintable.*, subtable.*
FROM maintable JOIN subtable
ON maintable.event_id = subtable.uid AND subtable.uid = 20
WHERE
maintable.uid = 45

However, if we add main.subtable.uid… the query gets converted to as shown below:
EX 2:
main.subtable.uid = vars:event
maintable.uid = varsproject

This is translated to someting like this:

SELECT maintable.*, subtable.*
FROM maintable JOIN subtable
ON maintable.event_id = subtable.uid
WHERE
subtable.uid = 20 AND maintable.uid = 45