PostNuke: A Flexible Open Source Content Management System
home | forum | international support | contact us

Documentation Wiki

JOIN Operations


This section deals with LEFT joins.

selectExpandedObject


    /**
     * Select & return a object with it's left join fields filled in
     *
     * @param tablename         The tablename key for the PNTables structure
     * @param joinInfo          The array containing the extended join information
     * @param where             The where clause (optional)
     * @param columnArray       The columns to marshall into the resulting object (optional) (default=null)
     * @param permissionFilter  The permission structure to use for permission checking (optional) (default=null)
     *
     * @return The resulting object
     */

    function selectExpandedObject ($tablename, $joinInfo, $where='', $columnArray=null, $permissionFilter=null)


selectExpandedObjectArray


    /**
     * Select & return an array of objects with it's left join fields filled in
     *
     * @param tablename     The tablename key for the PNTables structure
     * @param joinInfo      The array containing the extended join information
     * @param where         The where clause (optional)
     * @param orderby       The order by clause (optional)
     * @param limitOffset   The lower limit bound (optional)
     * @param limitNumRows  The upper limit bound (optional)
     * @param assocKey      The key field to use to build the associative index (optional) (default='')
     * @param permissionFilter  The permission filter to use for permission checking (optional) (default=null)
     * @param columnArray   The columns to marshall into the resulting object (optional) (default=null)
     *
     * @return The resulting object
     */

    function selectExpandedObjectArray ($tablename, &$joinInfo, $where='', $orderby='',
                                        $limitOffset=-1, $limitNumRows=-1, $assocKey='',
                                        $permissionFilter=null, $columnArray=null)


selectExpandedObjectByID


    /**
     * Select & return an object by it's ID  with it's left join fields filled in
     *
     * @param tablename        The tablename key for the PNTables structure
     * @param joinInfo         The array containing the extended join information
     * @param id               The ID value to use for object retrieval
     * @param field            The field key which holds the ID value (optional) (default='id')
     * @param columnArray      The columns to marshall into the resulting object (optional) (default=null)
     * @param permissionFilter The permission structure to use for permission checking (optional) (default=null)
     *
     * @return The resulting object
     */

    function selectExpandedObjectByID ($tablename, $joinInfo, $id, $field='id', $columnArray=null, $permissionFilter=null)


selectExpandedObjectCount


    /**
     * Return the number of rows affected
     *
     * @param tablename     The tablename key for the PNTables structure
     * @param joinInfo      The array containing the extended join information
     * @param where         The where clause (optional) (default='')
     * @param column        The column to place in the count phrase (optional) (default='*')
     * @param distinct      Wether or not to count distinct entries (optional) (default='false')
     *
     * @return The resulting object count
     */

    function selectExpandedObjectCount ($tablename, $joinInfo, $where='', $column='id', $distinct=false)


From DBUtil.class.php


    /**
     * The strucuture of the parameters joinInfo..
     *
       * The joinInfo parameter has to be an array structured as follows:
       * $joinInfo[] = array ('join_table'         =>  'The tablekey to join to'
       *                      'join_field'         =>  'The field key of the field to join, can also be an array of fields',
       *                      'object_field_name'  =>  'The resulting field name, can also be an array if join_field is an array',
       *                      'compare_field_table'=>  'The compare field key (select table)',
       *                      'compare_field_join' =>  'The compare field key (join table)');
     * . . .
     */


Creating _objJoin arrays


The references in 'The structure of the parameters joinInfo?..' did not immediatly make sense to me as written in the above 'From DBUtil.class.php' comments, yet I now have a fully functional 3 array/table '_joinInfo?'. I'm going to try to describe in my own words how I now understand _joinInfo?.

First of all each module class has it's own _objType? which is just an alias for the primary tables pntables array index name (as set in the modules pntables.php).

See this example: http://community.postnuke.com/module-Forum-viewtopic-topic-53347-start-0.htm

My translation of the documentation


The documentation says this:
'join_table' => 'The tablekey to join to'
I say:
'join_table' => 'The table name as set in the modules pntables array you want to join on to the original '_objType?' table'

The documentation says this:
'join_field' => 'The field key of the field to join, can also be an array of fields',
I say:
The field, or an array of fields as set in the modules pntables array you want to extract from the join table and join to the original '_objType?' table'

The documentation says this:
'object_field_name' => 'The resulting field name, can also be an array if join_field is an array',
I say:
'object_field_name ' => 'The aliases that 'object_field_name' will appear as in the final object. This/ese will be the key references of the object array being returned that represent the actual pntable keys, or 'object_field_name', of the table being joined.

For example; the secondary join table has pntable keys set to 'tblID?' and 'field1?', but you want the resulting object to index these as 'ID' and 'SomethingElse?'. you would set 'join_field' to 'array(' tblID?', field1?)', and 'object_field_name' to array('ID', ' SomethingElse?'). If your only grabbing a single field from the secondary table then you would use single strings in this example as opposed to arrays,

The documentation says this:
'compare_field_table' => 'The compare field key (select table)',
I say:
'compare_field_table' => 'The field as set in the modules pntables array you want to join to in the original '_objType?' table',

The documentation says this:
'compare_field_join' => 'The compare field key (join table)');
I say:
'compare_field_join' => 'The field as set in the modules pntables array you want to join to in the secondary table (as set in 'join_table' =>).

Example of usage


First of all each module class has it's own _objType? which is just an alias for the primary tables pntables array index name (as set in the modules pntables.php file).

Using RosterMaster? as an example I have done this:

My tables are set up as such (shortened for brevity)...
$rmTable['rostermaster_object'] = $prefix . '_rostermaster_object';
$rmTable['rostermaster_object_column'] = array('ObjID'   => 'rmobj_id',
                                                                'ObjClass' => 'rmobj_object_class',
                                                                'Name'     => 'rmobj_name',
                                                                'Field_1'   => 'rmobj_field_1',
                                                                'Field_2'   => 'rmobj_field_2');

$rmTable['rostermaster_members'] = $prefix . '_rostermaster_members';
$rmTable['rostermaster_members_column'] = array('MbrID'  => 'rmbr_id',
                                                                'ObjID'           => 'rmbr_obj_id',
                                                                'Name'           => 'rmbr_name',
                                                                'Field_1'         => 'rmbr_field_1',
                                                                'Field_2'         => 'rmbr_field_2');

$rmTable['rostermaster_users'] = $prefix . '_rostermaster_users';
$rmTable['rostermaster_users_column'] = array('rmUID' => 'rmusr_id',
                                                                'MbrID'    => 'rmusr_member_id',
                                                                'UserID'   => 'rmusr_user_id',
                                                                'Desc'      => 'rmusr_description');

The _objType? is set to 'rostermaster_members' so it is being used as the primary table and all fields are called in this case. Now I want to add in some info to each member array from the 'rostermaster_object' table. My first '_objJoin?' array looks like this...
$objTblJoin = array ('join_table'                => 'rostermaster_object',
                           'join_field'                   => array('Name', 'Field_1', 'Field_2'),
                           'object_field_name'    => array('Guild', 'GuildID', 'Server'),
                           'compare_field_table' => 'ObjID',
                           'compare_field_join'   => 'ObjID'):

'join_table' is obviously the table name of the secondary table.

'join_field' is the table fields from the 'rostermaster_object' table that are required.

'object_field_name' represents what ' join_field' will be called in the resulting array. Which takes care of a problem I would have otherwise had since there are duplicate field names between the 2 tables. And since this is a 'game specific' object I take advantage of the opportunity to appropriately name them... nifty eh?

'compare_field_table' is the id field name you want joined/referenced from the primary table '_objType?', in this case I used identical field names for clarities sake.

'compare_field_join' is the name of the id field in the secondary table that needs to match the value of ' compare_field_table'

Ok... so now I want to add items from the 'rostermaster_users' table. So my second '_objJoin?' array looks like this...
$usrTblJoin = array ('join_table'                 => 'rostermaster_users',
                            'join_field'                   => array('UserID', 'Description'),
                            'object_field_name'    => array('UserID', 'Description'),
                            'compare_field_table' => 'MbrID',
                            'compare_field_join'   => 'MbrID');

'join_table' is obviously the table name of the tertiary (third) table.

'join_field' is the table fields from the 'rostermaster_users' (tertiary (third)) table that are required.

'object_field_name' represents what ' join_field' will be called in the resulting array.

'compare_field_table' is the id field name you want joined/referenced from the primary table '_objType?', in this case I used identical field names for clarities sake.

'compare_field_join' is the name of the id field in the tertiary (third) table that needs to match the value of ' compare_field_table'... nice eh?

Ok... so now I got greedy. I wanted the PostNuke username, as associated to via 'rostermaster_users' table ' UserID?' added to this object without having to store it myself... I hate redundancy. Using pntables.php from the user module for reference, in my third '_objJoin?' array looks like this...
$pnUserTblJoin = array ('join_table'                 =>  'users',
                                 'join_field'                   => 'uname',
                                 'object_field_name'    => 'UserName',
                                 'compare_field_table' => 'rmusr_user_id',
                                 'compare_field_join'   => 'uid');

'join_table' is obviously the table name of the quaternary(fourth(pn_users)) table.

'join_field' is the table fields from the 'users' (quaternary (fourth (pn_users))) table that are required. In this case I only require one field so it is a string rather than an array.

'object_field_name' represents what ' join_field' will be called in the resulting array. In this case I only require one field so it is a string rather than an array.

'compare_field_table' is the id field name you want joined/referenced from, in this case, the 'rostermaster_users' (tertiary (third))table.

Oddly enough I could not use the $pntables field reference for the field name even though other references work, I had to usse the actual table name. I will likely file a bug report on this.

'compare_field_join' is the name of the id field in the tertiary (third) table that needs to match the value of 'users' (quaternary (fourth (pn_users))) table.

Now hows that for flexability? Now all you need to do is assign these arrays to '_objJoin?' in the class constructor like this...
$this->_objJoin = array($objTblJoin, $usrTblJoin, $pnUserTblJoin)


Previous | Top | Next

CategoryDeveloperDocs
XML Revisions of $tag
Page history :: Last Editor [ Guite ] :: Owner [ markwest ] ::
Valid XHTML :: Valid CSS :: Powered by pnWikka 1.0 (A wiki fork from WikkaWiki)
 

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to PostNuke