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

Allowed memory size of … bytes exhausted

Recently, I had to do a t3d export/import, where the data size was nearly 2GB, and no matter what memory_limit we tried, it always failed. Finally we tried memory_limit = -1, which basically removes the memory limit, and lets us use the max available memory of the Operating System.

Often we may need some special setup for a special case/cause.

Recently, I had to do a t3d export/import, where the data size was nearly 2GB, and no matter what memory_limit we tried, it always failed.

Finally we tried memory_limit = -1, which basically removes the memory limit, and lets us use the max available memory of the Operating System.

This solution did helped us, and we were able to do the export smoothly.

CAUTION: On a production server try not to do this, if we forget to revert this change, things can get worse!
Instead make a local copy, and then we have a total freedom.

A simple note on using “Fluid Display”

Tesseract is a powerful tool, combined with “Fluid Display” the possibilities are almost limitless.

Here is a simple note on how to use it to group based on a specific field.

The Query:

SELECT
  doc_cat.title AS mydocs.title,
mydocs.name,
mydocs.path,
mydocs.file_path

FROM mydocs
LEFT JOIN doc_cat_mm
ON …
LEFT JOIN
doc_cat
ON …

The Fluid Display:


<f:if condition="{datastructure.count} == 0">
<f:else>
<f:groupedFor
each="{datastructure.mydocs.records}"
as="docCategories"
groupBy="title"
groupKey="title">
{title_cat}
<f:for each="{docCategories}" as="document">
{document.title}
An example for using TypoScript inside
<f:cObject typoscriptObjectPath="lib.docFileSize" data="{document.file_size}" />
</f:for>
</f:groupedFor>
</f:else>
</f:if>

Now TyposCript will be something as below: (NOTE: make sure you use .current = 1 )
lib.docFileSize = TEXT
lib.docFileSize.current = 1
lib.docFileSize.bytes = 1
lib.docFileSize.bytes.labels = |kb|Mb|Gb

That should be it!

Some points of interest:
<f:debug>{datastructure}</f:debug>
<f:if condition=”{0: datastructure.count} == {0: ‘0’}”>

IF this didn’t work, try
<f:if condition=”{0: datastructure.tablename.count} == {0: ‘0’}”>

URLs of interest:
http://www.t3node.com/blog/combining-fluid-viewhelpers-and-typoscript-in-typo3-5-basic-examples/
http://wiki.typo3.org/Fluid

A simple Big Click function

The following function is useful when we wish to make a certain area clickable. This takes in the first link, and makes the entire area clickable. This code has support for normal links as well as external links.

Necessary JS:

function cw_bigclick(){
    if($('.cw-bigclick .bigitem').length){
        $('.cw-bigclick .bigitem').on('click', function() {
            if ($(this).find('a').length > 0) {
                if($(this).find('a').attr('target')=='_blank'){
                    window.open($(this).find('a').attr('href'));
                }else{
                    window.location.href= $(this).find('a').attr('href');
                }
                return false;
            }
        });
    }
}

Expected HTML

<div class=”cw-bigclick”>
<div class=”bigitem”>
<a href=”#”></a>
</div>
<div class=”bigitem”>
<a href=”#” target=”_blank”></a>
</div>
</div>

Teeseract and JOIN tables using a CSV field

Latest News allows us to use content elements within a News. This opens up a vast set of possibilities.

However, when we look in depth, the news manages related content element IDs in a CSV format.

Now this seems like a bad way to mange it, as we do not have a mm_table, and there is no easy way to handle this, than using DB specific functions.

Luckily Tesseract supports most of the MYSQL functions, and thus we can make use of the FIND_IN_SET function here.

ex:
select tt_content.uid,tt_content.header, news.content_elements
FROM tx_news_domain_model_news AS news
LEFT JOIN tt_content
ON find_in_set(tt_content.uid, news.content_elements) WHERE news.uid=1

Hope this helps you.