Customer Portal

Get Involved. Join the Conversation.

Topic

    Shiloh Madsen
    Filter on language?Answered
    Topic posted April 10, 2009 by Shiloh MadsenBronze Trophy: 5,000+ Points, last edited October 29, 2011 
    4377 Views, 34 Comments
    Title:
    Filter on language?
    Content:
    One of the fields in our knowledge conent items is Language. I would like to be able to use syndication to constrain on that, but I am not sure if that is possible. Are we limited to the few listed in the documentation, or can I filter by any field? If so, how do I do that? 

    Best Comment

    Anthony Arnone
    You're on the right track, but you will need a bit more information in that filter. You would be better served looking at the section of the opensearch controller that deals with the custom $filters['os_filter' . $filter_num]. Here's a modification of that code:

    $temp_filter = $this->Report_model->getFilterByName('access_id');

    $filters['my_filter']->filters->fltr_id = $temp_filter['fltr_id']; // alternately, this can be "<table_name>.<filter_name>"
    $filters['my_filter']->filters->oper_id = $temp_filter['oper_id']; // this is optional. if you're not changing it ever, you can leave this off*
    $filters['my_filter']->filters->rnSearchType = 'custom_search_type'; // this can be anything as long as it is not null or 0 or 1 (or true or false).
    $filters['my_filter']->filters->report_id = $this->report_id;
    $filters['my_filter']->filters->data[]  = $value; // this is the tricky part, and is dependent on what your filter is. For language, it would just be the language ID, but for access ID, it's the full 40 character access mask number (it's a length 128 bitmask).

    You can have multiple filters, just name the next one 'myfilter2' and so on.


    The correct way to set this up is using "report hooks", which will allow for proper customization of your filters by adding the code in hooks.php. Check the regular documentation for report hooks for more details (versions 9.2+). There may be hooks-specific requirements in addition to the regular filter code.


    Anthony

    * if you want to change the operator, you need to chose from this list. These should be the same ones that are defined for the xml api and are defined in rnwintf.php
    //define(OPER_EQ, 1);
    //define(OPER_NEQ, 2);
    //define(OPER_LT, 3);
    //define(OPER_LT_EQ, 4);
    //define(OPER_GT, 5);
    //define(OPER_GT_EQ, 6);
    //define(OPER_LIKE, 7);
    //define(OPER_NLIKE, 8);
    //define(OPER_RANGE, 9);
    //define(OPER_LIST, 10);
    //define(OPER_NLIST, 11);
    //define(OPER_IS_NULL, 12);
    //define(OPER_IS_NOT_NULL, 13);
    //define(OPER_NE_OR_NULL, 14);
    //define(OPER_NLIKE_OR_NULL, 15);
    //define(OPER_REGEXIZE, 19)
     

    Comment

    • Anthony Arnone

      Looking at the first error:

      Message: Missing argument 2 for Report_model::getFilterByName()

       

      And looking at your code:

       $temp_filter = $this->Report_model->getFilterByName('lang_id');

       

      You're missing the first argument to getFilterByName(). It should look like this:

       $temp_filter = $this->Report_model->getFilterByName($this->report_id, 'lang_id');

       

    • Shiloh Madsen

      Woot! You rock. The page displays now, but I am still doing something wrong. 

       

      When I pass https://motorola-roundarch-en.custhelp.com/ci/ajaxCustom/feed/lang/7

       

      I should be getting only faqs with the spanish access level, however I am still getting faqs in english.  

    • Shiloh Madsen

      So I did some further testing using the report itself. 

       

      When I go into the report and run it on language us-english, I get returns. When I run it on any other language, I get no returns. I assume that the behavior of the syndication widget is that, if the result set is 0, then display a basic list of answers.

       

      I tinkered around a bit with the report and found that if I remove the special settings filter, then the REPORT can display faq's in other languages, but this makes it stop working for the widget (as the manual would indicate would happen if this filter was removed). So...it would seem that my problem stems from that filter somehow preventing the use of language filters in the widget...would you have any clue why?

       

      If it would help I could publish this code to live for you to look at.  

    • Shiloh Madsen

      Ok, I think we know why I am getting zero results when I try to search on other languages. This is from our AE, Larry:

       

      I guess you DO need that filter on for enduser page AND syndication.  However, one thing that is holding you back is there is an “inherent” language constraint based on the interface you are on.  For example, even though the report doesn’t care when you run on US English interface it only looks for FAQs with that.  So if you have filter = Spanish (nothing returns because its says something like Language = Spanish  AND  language=English)

       

      Here is an email from another engineer that was looking to do the same thing:

       

       

       

       

      Basically, you need to generate a bit list, then use that bit list with the bit_list_to_where_clause() API function. That will generate the access mask portion of your queries WHERE clause.

       

              // $intf_ids is an array of the interface id’s

              $si = sql_prepare(sprintf("SELECT a.access_id FROM ans_access a, visibility v WHERE (v.tbl = 11) AND (v.interface_id IN (%s)) AND (v.id = a.access_id) AND (v.enduser = 1) GROUP BY a.access_id ORDER BY a.rank", implode(',', $intf_ids)));

              sql_bind_col($si, 1, BIND_INT, 0);

       

              $bit_list = array();

              while (list($access_id) = sql_fetch($si))

                  $bit_list[] = $access_id;

              sql_free($si);

       

      Then, you add:

       

      $where_clause = bit_list_to_where_clause($bit_list, 'answers.access_mask');

       

      You should be able to get a list of answers doing something like this:

       

      $si = sql_prepare(sprintf("SELECT answers.a_id FROM answers

                      JOIN meta_ans_vis META_ANS_prod_vis ON

                          answers.m_id=META_ANS_prod_vis.m_id AND

                          META_ANS_prod_vis.hm_type = 13 AND

                          META_ANS_prod_vis.interface_id IN (%s) AND

                          META_ANS_prod_vis.enduser_vis > 0

                      JOIN meta_ans_vis META_ANS_cat_vis ON

                          answers.m_id=META_ANS_cat_vis.m_id AND

                          META_ANS_cat_vis.hm_type = 14 AND

                          META_ANS_cat_vis.interface_id IN (%s) AND

                          META_ANS_cat_vis.enduser_vis > 0

                       WHERE %s AND (answers.status_type = 4 AND answers.lang_id IN (%s))", implode(‘,’, $intf_ids), implode(‘,’, $intf_ids), $where_clause, implode(‘,’, $langid_arr))); 

       

      So this would seem to be raw sql...something which should only exist in a model in CP as I understand it. Can you tell me if I have to actually go through figuring out what all of this is doing, or does CP offer a more elegant solution to this "inherent language restriction" ?