1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice
  2. If you update to Joomla 3.9.16, you will have to update Fabrik from the latest GitHub version, to fix a bug introduced in Joomla, which makes it impossible to list front end folder locations in backend JForms. This affects things like template selection.
    Dismiss Notice

Get filter data (cascadingdropdown) PHP

Discussion in 'Standard Support' started by blue-mouse, Sep 27, 2015.

  1. blue-mouse

    blue-mouse Member

    Level: Community
    Hi,
    I have Joomla 2.5.28 and fabrik 3.0.9

    I try to capture cascading dropdown variable from filter and use them in a calculation element.
    I don't know what syntax to use to capture a data that is cascadingdropdown. (I could try it also for data field if this would be simpler)
    I found on forum thread:
    http://fabrikar.com/forums/index.php?threads/get-filter-data-dates-php.22273/
    where is something - code for filter data - and i try use it to my example.

    It is new function for me and i have no idea how to modify this code,
    I try this:


    PHP:
    echo "----- Test 1 --- Sum  pakietow AA:   <br/>";
    $db =& JFactory::getDBO();
    $table =& JModel::getInstance( 'Table', 'FabrikModel' );
    $table->setId(331); //replace 1 with your table id
    $filters = $table->getRequestData();
    $keys = JArrayHelper::getValue( $filters, 'key', array() );
    $vals = JArrayHelper::getValue( $filters, 'value', array() );

    //echo "<pre>";print_r($keys);echo '</pre>';
            for ($i = 0; $i < count($filters); $i++) {
                if (JArrayHelper::getValue( $keys, $i, '') === '`ccjom_cc_kk_karta_rejestr`.`zamow_symbol`') {
                    $var_keg = $vals[$i];
    $order1 = $var_keg[0];
                }  
            }

    echo " Nr zam ---- $order1";


    $query = "SELECT  `is_pak_xxxx` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  (`rodzaj_karty_np_wzorzec`='2' AND `zamow_symbol`=".$order1.")  ORDER BY `id`";
    $db->setQuery($query);
    $result = $db->loadResult();

    $resaa = mysql_query($query);
    $rrraa=array();
    $n=0;
    while($row = mysql_fetch_array($resaa))
       {
           $rrraa[$n]=  $row['is_pak_xxxx'];
    $n++;
                   }
    $newrrraa = array_count_values($rrraa);
                                    foreach ($newrrraa as $key => $value) {
    $query = "SELECT  `is_pak_wejsc_analog_aa` FROM  `ccjom_cc_kk_is_aa` WHERE `id`=$key ";
    $db->setQuery($query);
    $result1 = $db->loadResult();
    echo "$result1 ------ <strong>$value</strong> <br />"; }
    echo "<br/>";
     
    I get an error:
    Fatal error: Call to a member function setId() on a non-object in /var/www/cc.joomla/components/com_fabrik/views/list/tmpl/default-2015-09-11-table-kp5/default.php on line 160


    can i get any tip how to code my variable for field: '`ccjom_cc_kk_karta_rejestr`.`zamow_symbol`' that is cascading dropdown or any simpler code for field : '`ccjom_cc_kk_karta_rejestr`.`testfied1`' that can be type "field". ?
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    The mentioned thread is about Fabrik2...

    In an element's default you can get a filter value via

    FabrikHelperElement::filterValue(81); //with 81 = filter's element id, zamow_symbol's id in your case I assume
     
    blue-mouse likes this.
  3. blue-mouse

    blue-mouse Member

    Level: Community
    This 1 nice line really works !!! Thanks :)

    My code is:
    PHP:
    $db =& JFactory::getDBO();
    $order1 =FabrikHelperElement::filterValue(11152); //with 81
    if ($order1==0){
    $zam1 = 'Razem wszystkie zam?wienia';
    }
    else {
    $query = "SELECT  `ip2_zamowienie_symbol1` FROM  `ccjom_cc_kk_ip2_zamowienie`  WHERE  `id`= ".$order1."  ";
    $db->setQuery($query);
    $result = $db->loadResult();
    $zam1 = $result;
    }


    echo " -- Zam?wienie nr: $zam1 -- <br/><br/>";

    echo "----- Test 1 -----  Sum  pakietow AA:   <br/>";


    if ($order1==0){
    $query = "SELECT  `is_pak_xxxx` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  `rodzaj_karty_np_wzorzec`= '2'  ORDER BY `id`";
    }
    else {
    $query = "SELECT  `is_pak_xxxx` FROM  `ccjom_cc_kk_karta_rejestr` WHERE  `zamow_symbol`=".$order1."  ORDER BY `id`";
    }

    $db->setQuery($query);
    $result = $db->loadResult();

    $resaa = mysql_query($query);
    $rrraa=array();
    $n=0;
    while($row = mysql_fetch_array($resaa))
       {
           $rrraa[$n]=  $row['is_pak_xxxx'];
    $n++;
                   }
    $newrrraa = array_count_values($rrraa);
                                    foreach ($newrrraa as $key => $value) {
    $query = "SELECT  `is_pak_wejsc_analog_aa` FROM  `ccjom_cc_kk_is_aa` WHERE `id`=$key ";
    $db->setQuery($query);
    $result1 = $db->loadResult();
    echo "$result1 ------ <strong>$value</strong> <br />"; }
    echo "<br/>";

     

    Hovewer i get small error. When in Joomla configurations is set : error reporting = maximum

    i get result:
    Notice: Undefined offset: 0 in /var/www/cc.joomla/components/com_fabrik/helpers/element.php on line 91 -- Zam?wienie nr: Razem wszystkie zam?wienia --

    ----- Test 1 ----- Sum pakietow AA:
    2 x (In/2In) + 2 x 3Un ------ 30
    3 x (In/50In) +Io ------ 26

    --------------
    Case: $zam1 = 'Razem wszystkie zam?wienia';
    is for all "orderings no" in my table1 when i don't use filter in "search/filter subtable"
     
    Last edited: Sep 29, 2015
  4. rob

    rob Administrator Staff Member

    Level: Community
    I don't know from your code what line 91 is.
    Generally you should google for PHP notices - there will be lots of advice out there on what they mean. Quicker than waiting for a reply from us :)
     
  5. blue-mouse

    blue-mouse Member

    Level: Community
    Hmmmm,
    I am not advanced in fabrik code and line 91 is in fabrik file:
    /var/www/cc.joomla/components/com_fabrik/helpers/element.php

    line 91 ---- $value = $filters['value'][$index];
    sample of this code with line 91:
    PHP:
    public static function filterValue($elementId)
        {
            $app = JFactory::getApplication();
            $pluginManager = FabrikWorker::getPluginManager();
            $model = $pluginManager->getElementPlugin($elementId);
            $listModel = $model->getListModel();
            $listid = $listModel->getId();
            $key = 'com_fabrik.list' . $listid . '_com_fabrik_' . $listid . '.filter';
            $filters = JArrayHelper::fromObject($app->getUserState($key));
            $elementIds = (array) JArrayHelper::getValue($filters, 'elementid', array());
            $index = array_search($elementId, $elementIds);
            $value = $filters['value'][$index];

            return $value;
        }
    Error is displayed for case:
    $db =& JFactory::getDBO();
    $order1 =FabrikHelperElement::filterValue(11152); //with 81
    if ($order1==0){
    $zam1 = 'Razem wszystkie zam?wienia';
    }

    when case is "else":
    else {
    $query = "SELECT `ip2_zamowienie_symbol1` FROM `ccjom_cc_kk_ip2_zamowienie` WHERE `id`= ".$order1." ";
    $db->setQuery($query);
    $result = $db->loadResult();
    $zam1 = $result;
    }

    this error is not displayed.

    Using "google" - i read that problem is in my code with line:
    $order1 =FabrikHelperElement::filterValue(11152); //with 81

    when in Search/Filter-Table element (11152) is not set (= this field is empty)
    this line cause this error.

    But i don't know how to fix this probably bug?


    May be is possible to modify my code:
    $db =& JFactory::getDBO();
    $order1 =FabrikHelperElement::filterValue(11152); //with 81
    if ($order1==0){
    $zam1 = 'Razem wszystkie zam?wienia';
    }


    to something like:
    $db =& JFactory::getDBO();
    if (FabrikHelperElement::filterValue(11152) is not set)
    {$order1 == 0;}
    else
    {$order1 =FabrikHelperElement::filterValue(11152); //with 81}

    if ($order1==0){
    $zam1 = 'Razem wszystkie zam?wienia';
    }
    ......

    Can I get any more advanced tip?
     
    Last edited: Sep 30, 2015

Share This Page