narcis VIP
Total posts: 138
16 Jun 2016 19:59

Hi there,

I try to set this sql query in a multiselect field in order to get only the two first words at the begining of the sentence:

SELECT SUBSTRING_INDEX(title , ' ', 2 ) AS text FROM #__js_res_record AS r WHERE r.section_id IN(2,9) AND r.user_id != [USER_ID]

Everything seems fine on the frontend. The field displays only the two first words in values as expected. For example, instead of "Article Alpha: Computing science courses" i get "Article Alpha:". But when i select one value and save the record, i get a 500 error page.

I forgot something ?

Help please.

Last Modified: 22 Jun 2016


Sergey
Total posts: 13,748
17 Jun 2016 15:25

The render of values in article is taken from JSON not with query. You can always use php substr() function in output template to trim titles.


narcis VIP
Total posts: 138
18 Jun 2016 11:25

Hi,

Sergey The render of values in article is taken from JSON not with query

Excuse me in advance because i'm not a developer, but are u talking about any query or just SUBSTRING query ? Indeed, in some multiselect field, i applied a sql query before to retrieve entire article value, and record was saved as well.

If it's because of SUBSTRING query, is there some similar sql query i can use ?

Regards.


Sergey
Total posts: 13,748
21 Jun 2016 05:25

Look into this file components/com_cobalt/fields/multilevelselect/tmpl/output/default.php. this is uotput template. You can create copy of it with any other name and then select it as output template in field parameters.

there is a line 19

$level = JText::_($level);

You can change it to

$level = substr(JText::_($level), 0, 3);

narcis VIP
Total posts: 138
21 Jun 2016 15:39

Hi Sergey,

I found the file components/com_cobalt/fields/multilevelselect/tmpl/output/default.php

I copied it, and i renamed it. Then, i selected it in the field paramaters (as u said).

But, the trouble is that i haven't found $level = JText::_($level); in the file. Here is the content of components/com_cobalt/fields/multilevelselect/tmpl/output/default.php:

default.PNG

However, i copied $level = substr(JText::_($level), 0, 3); at the end. I also changed my sql query in the multified field as following : SELECT (title) AS text FROM #__js_res_record AS r WHERE r.section_id IN(2,9) AND r.user_id != [USER_ID]

Now, after saving the record, i get a blank page.

Regards.


pepperstreet VIP
Total posts: 3,837
22 Jun 2016 00:17

narcis I found the file components/com_cobalt/fields/multilevelselect/tmpl/output/default.php

Do you have the latest version/update? I have 2 output templates:

default.php
detailed.php

Here is my current content of default.php:

<?php
/**
 * Cobalt by MintJoomla
 * a component for Joomla! 1.7 - 2.5 CMS ( http://www.joomla.org )
 * Author Website:  http://www.mintjoomla.com/ 
 * @copyright Copyright (C) 2012 MintJoomla ( http://www.mintjoomla.com ). All rights reserved.
 * @license GNU/GPL  http://www.gnu.org/copyleft/gpl.html 
 */
defined('_JEXEC') or die();
$value = array();
?>
<?php if(count($this->value)) :?>
    <?php foreach ($this->value as $item) :

        $full = array();
        $title = array();
        foreach ($item as $id => $level)
        {
            $level = JText::_($level);
            $full[] = $level;
            if ($this->params->get('params.filter_enable'))
            {
                $tip = ($this->params->get('params.filter_tip') ? JText::sprintf($this->params->get('params.filter_tip'), '<b>' . $this->label . '</b>', "<b>".implode($this->params->get('params.separator', ' '), $full)."</b>") : NULL);
                switch ($this->params->get('params.filter_linkage'))
                {
                    case 1 :
                        $level = FilterHelper::filterLink('filter_' . $this->id, $id, $level, $this->type_id, $tip, $section);
                        break;

                    case 2 :
                        $level = $level . ' ' . FilterHelper::filterButton('filter_' . $this->id, $id, $this->type_id, $tip, $section, $this->params->get('params.filter_icon', 'funnel-small.png'));
                        break;
                }
            }
            $title[] = $level;
        }
        $value[] = implode($this->params->get('params.separator', ' '), $title);
        ?>
    <?php endforeach;?>
<?php endif;?>

<?php if(count($value) == 1):?>
    <?php echo $value[0];?>
<?php elseif(count($value) > 1):?>
    <ul>
      <li><?php echo implode('</li><li>', $value);?></li>
    </ul>
<?php endif;?>


narcis VIP
Total posts: 138
22 Jun 2016 10:01

Ok, i see the problem.

Actually, i'm talking about the MULTISELECT field as i mentionned it at my first post, not the MULTI LEVEL SELECT field. I apologise, because when i copied the path of the default.php file above i did not remark that the field type was not the same. So, the file i renamed is rather :

components/com_cobalt/fields/multiselect/tmpl/output/default.php

And u will find out that the default.php content is different (Cobalt V8.707 installed).

May be i should specify that i enabled the SQL query feature (in multiselect field parameter) and i set SUBSTRING query there.

Regards.


Sergey
Total posts: 13,748
22 Jun 2016 15:05

Then use somethign like this in output template of multiselect field

foreach($this->value AS $val) {
    echo substr($val, 0, 3);
}

narcis VIP
Total posts: 138
22 Jun 2016 16:24

Ok, thanks.

Powered by Cobalt