All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
  Print view

filter dependency by Table
Author Message
PostPosted: Wed Feb 09, 2011 5:09 pm 
Regular
Offline

Joined: Wed Aug 01, 2007 9:09 am
Posts: 121
Is it possible to incorporate into ATK a feature whereby a person can select records from different tables based on the option selected in the parent attribute.

It is like filtering by a field BUT in this case u select a different table.

what I basically want to do is to have a first attribute displaying a list of item groups(related or unrelated) eg.
    Cars, Generators,laptops
.
When I select a group,I want the next attribute to list the items that fall within that group.eg. if I select "Cars",it should query the Cars table a display the items in it. when I select "Generators" it should query the generator table and display the items in it.

Obviously this would have been easier if all items were in one table ;so that I could just filter but they all have different tables.

any thoughts


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Tue Feb 15, 2011 8:00 am 
Pro
Offline

Joined: Mon May 23, 2005 7:11 am
Posts: 412
Location: Tysse, Samnanger, Norway
Make a view out of your group types tables

create view group_types as
Select 'cars' as group_type.
cars.name as type
from cars
union all
Select 'generators' as group_type.
generators.name as type
from generators
etc.


Use this view as source in the attribute and filter it.

_________________
Br
Olav B. Lygre


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Tue Feb 15, 2011 2:29 pm 
Regular
Offline

Joined: Wed Aug 01, 2007 9:09 am
Posts: 121
oblygre wrote:
Make a view out of your group types tables

create view group_types as
Select 'cars' as group_type.
cars.name as type
from cars
union all
Select 'generators' as group_type.
generators.name as type
from generators
etc.


Use this view as source in the attribute and filter it.


i guess that would mean that i have to introduce a field in each of the tables that i can use for filtering.


Any other ideas


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Tue Feb 15, 2011 3:12 pm 
Pro
Offline

Joined: Mon May 23, 2005 7:11 am
Posts: 412
Location: Tysse, Samnanger, Norway
No, you just create that field in the view as shown above, its the group_type which you give unique, static values for each table.

_________________
Br
Olav B. Lygre


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Tue Feb 15, 2011 9:51 pm 
Regular
Offline

Joined: Wed Aug 01, 2007 9:09 am
Posts: 121
oblygre wrote:
No, you just create that field in the view as shown above, its the group_type which you give unique, static values for each table.


Thanks alot

I tried it But
Code:
$org = &$this->add(new  atklistAttribute("client_Type",array("individual","Group","Group Member"),AF_FORCE_LOAD| AF_OBLIGATORY),NULL,101);

$con = &$this->add(new atkManyToOneRelation("client","clients.allclients",AF_SEARCHABLE|AF_RELATION_AUTOLINK),null,111);;
    $con->setDestinationFilter("clientelle.group_type='['client_Type']'");
        
    $org->addDependee("client");


I get the following SQL output
Code:
SELECT `clientelle`.`idcode`, `clientelle`.`type` FROM (`clientelle`) WHERE (clientelle.group_type='')

Note that the where clause is empty
what went wrong


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Tue Feb 15, 2011 10:43 pm 
Pro
Offline

Joined: Mon May 23, 2005 7:11 am
Posts: 412
Location: Tysse, Samnanger, Norway
Should probably be:
Code:
$con->setDestinationFilter("clientelle.group_type='[client_Type]'"); // No qutes inside the square brackets

_________________
Br
Olav B. Lygre


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Wed Feb 16, 2011 12:31 am 
Evangelist
User avatar
Offline

Joined: Mon Oct 10, 2005 7:46 am
Posts: 2142
sphinix wrote:
Is it possible to incorporate into ATK a feature whereby a person can select records from different tables based on the option selected in the parent attribute.

It is like filtering by a field BUT in this case u select a different table.

what I basically want to do is to have a first attribute displaying a list of item groups(related or unrelated) eg.
    Cars, Generators,laptops
.
When I select a group,I want the next attribute to list the items that fall within that group.eg. if I select "Cars",it should query the Cars table a display the items in it. when I select "Generators" it should query the generator table and display the items in it.

Obviously this would have been easier if all items were in one table ;so that I could just filter but they all have different tables.

any thoughts


The way I've done similar features in the passed is by using custom javascript.

Below is you'll find some ideas:

1. Use the onChange() javascript function on the group selector node

2. Hide (with javascript) both sub lists attributes when creating a new record. Below is a sample javascript function to hide HTML elements:

Code:
/* Jorge Garifuna
 *
 * sets the display of an item to either show or none
 *
 **/
function set_item_display(elementid, display){
      document.getElementById(elementid).style.display = display;
}// end function



NOTE: ATK pre-appends "ar_" as the row ID of every attribute. For example if you have an attribute called "test", ATK would have a table row for this attribute as follows:

Code:
<tr id="ar_test" class="section_default">...</tr>


so to hide the row using the function above:

Code:
set_item_display('ar_test','none');


and the display the row:

Code:
set_item_display('ar_test','');



3. Call a custom javascript function when the user changes the value of your group selector attribute. This custom javascript function should collect enough information from the calling attribute to determine which sub list to process. upon determining the sub list to process, make that sub list visible and hide the unrelated sub list using the javascript function mentioned on the previous step.

4. When loading the record for editing or viewing mode, you can dynamically load javascript to show the proper sub list and hide the unrelated sub list. Below you will find come ATK code with comments where you could possibly choose to hide and display the sub lists. Review the detailPageFooter() function below. Please note that detailPageFooter() is not a native ATK function. I made this function to consolidate the calls of ATK functions: editPage(), viewPage(), addPage(), and adminPage():

Code:
           

      // this function is called when editing an individual record
      // any information here will be displayed on the footer section of the edited record page
      function editPage(&$handler, $record, $locked=false)
      {
         return $this->detailPageFooter($handler, $record, $locked);
      }
         

      // this function is called when viewing an individual record
      // any information here will be displayed on the footer section of the viewed record page
      function viewPage(&$handler, $record, $locked=false)
      {
         return $this->detailPageFooter($handler, $record, $locked,"view");
      }
         

                // this function is called when adding a new record
                function addPage(&$handler,$record){
                    return $this->detailPageFooter($handler, $record, $locked,"add");
                }
         

                // this function is called on admin mode
                function adminPage(&$handler){
                    return $this->detailPageFooter($handler, "admin", $locked,"admin");
                }
         


      // this is a custom helper function for editPage and viewPage
      // you can consolidate operations here unless you need to display different information
      // when editing and viewing the record
      // the information will be displayed on the footer page when editing or viewing an individual record
      function detailPageFooter(&$handler, $record, $locked=false, $mode="edit")
      {
         /* if($mode == "view"){
            $page = $handler->viewPage($record, $locked);
         }else{// edit
            $page = $handler->editPage($record, $locked);
         } */

                        $pageType = $mode."Page";
                        $page = $handler->$pageType($record, $locked);

// detect mode (edit or view) here
// load javascript to display related sub list and hide unrelated sub list attribute

         $data_info = "";
         $page .= $data_info;

         return $page;
      }       // end function


Hopefully this provides some useful ideas.

_________________
Jorge Garifuna
Professional Web Developer
Garinet Media Network, LLC
http://www.GariDigital.com

Proud ATK Supporter since 2005


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Wed Feb 16, 2011 2:00 pm 
Regular
Offline

Joined: Wed Aug 01, 2007 9:09 am
Posts: 121
oblygre wrote:
Should probably be:
Code:
$con->setDestinationFilter("clientelle.group_type='[client_Type]'"); // No qutes inside the square brackets



thanks ,it worked. :D


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Wed Feb 16, 2011 2:02 pm 
Regular
Offline

Joined: Wed Aug 01, 2007 9:09 am
Posts: 121
@Jarifuna


would try it. Thanks


Top
 Profile  
 

Re: filter dependency by Table
PostPosted: Mon Jan 23, 2012 9:02 am 
Offline

Joined: Mon Jan 23, 2012 8:49 am
Posts: 1
oblygre wrote:
Should probably be:
Code:
$con->setDestinationFilter("clientelle.group_type='[client_Type]'"); // No qutes inside the square brackets

Hi. I replaced the previous code with this one and got what i expected to have. Grateful!

Regards,
Nate


Last edited by Nataniell on Tue Mar 20, 2012 6:16 am, edited 1 time in total.

Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group