Control modules on SOBI2 pages

(13 votes, average 4.08 out of 5)

SOBI2 (SigSiu Online Business Index 2) is a Content Construction Kit extension for Joomla. You can use the following recipes to target modules onto different pages within the extension, or to select modules based on the category of the item being displayed.

Detect the categories (by name) for a directory entry

This recipe allows you to target modules onto a directory entry page based on the category or categories it is in. Because each post can be in more than one category, this recipe may return more than one module. Here, we specify the categories by name. This is fine as long as you don't have more than one category with the same name (in which case, the module would show up for all categories sharing that name). Note that the name matching is case sensitive (i.e. restaurant is not the same as Restaurant)

if ($option == 'com_sobi2') {
  if ( JRequest::getVar( 'sobi2Task' ) == 'sobi2Details') {
    $sobi2Id = JRequest::getVar( 'sobi2Id' );
    $query = 'SELECT c.name from #__sobi2_cat_items_relations r
      LEFT JOIN #__sobi2_categories c on r.catid = c.catid
      WHERE r.itemid = ' . $db->quote($db->getEscaped( $sobi2Id ));
    $db->setQuery( $query );
    $res = $db->loadResultArray();
    $mods = array();
    // was Restaurants one of the categories? If so add mod 101
    if ( array_search('Restaurants', $res) !== false ) $mods[] = 101;
    // was Cafes one of the tags? If so add mod 102
    if ( array_search('Cafes', $res) !== false ) $mods[] = 102;
    return $mods;
  }
}
 

Detect the categories (by id) for a directory entry

This recipe is the same as the one above, except that it selects SOBI2 categories by their ID number. This is better when more than one category has the same name and you need to distinguish between them.

if ($option == 'com_sobi2') {
  if ( JRequest::getVar( 'sobi2Task' ) == 'sobi2Details') {
    $sobi2Id = JRequest::getVar( 'sobi2Id' );
    $query = 'SELECT c.catid from #__sobi2_cat_items_relations r
      LEFT JOIN #__sobi2_categories c on r.catid = c.catid
      WHERE r.itemid = ' . $db->quote($db->getEscaped( $sobi2Id ));
    $db->setQuery( $query );
    $res = $db->loadResultArray();
    $mods = array();
    // was category 23 one of the categories? If so add mod 101
    if ( array_search( 23, $res) !== false ) $mods[] = 101;
    // was category 24 one of the tags? If so add mod 102
    if ( array_search( 24, $res) !== false ) $mods[] = 102;
    return $mods;
  }
}
 

Detect the category when viewing a list of items in that category

This recipe detects the tag name, when the viewer is viewing a page like http://www.example.com/sobi2?catid=23.

if ( $option == 'com_sobi2' and ($catid = JRequest::getVar('catid')) != '' ) {
  if ( $catid == 23 ) return 101; /* replace 101 with module to show for category 23 */
  if ( $catid == 34 ) return 102; /* replace 102 with module to show for category 34 */
}

If you want your category-related modules to show up for certain categories on both “category listing” pages and individual items that have that category, you can combine the two rules:

if ($option == 'com_sobi2') {
  $res = array();
  $mods = array();
  if ( JRequest::getVar( 'sobi2Task' ) == 'sobi2Details') {
    $sobi2Id = JRequest::getVar( 'sobi2Id' );
    $query = 'SELECT c.catid from #__sobi2_cat_items_relations r
      LEFT JOIN #__sobi2_categories c on r.catid = c.catid
      WHERE r.itemid = ' . $db->quote($db->getEscaped( $sobi2Id ));
    $db->setQuery( $query );
    $res = $db->loadResultArray();
    $catid = '';
  } else {
    $catid = JRequest::getVar('catid');
  }
  // was category 23 one of the categories? If so add mod 101
  if ( array_search( 23, $res) !== false or $catid == 23 ) $mods[] = 101;
  // was category 24 one of the tags? If so add mod 102
  if ( array_search( 24, $res) !== false or $catid == 24 ) $mods[] = 102;
  return $mods;
}
 

Detecting individual entry pages

You can isolate particular items by ID, and give them different modules:

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == 'sobi2Details' ) {
  $sobi2Id = JRequest::getVar( 'sobi2Id' );
  if ( $sobi2Id == 41 ) return 101; /* replace 101 with the module to use for SOBI2 item 41 */
  if ( $sobi2Id == 42 ) return 102; /* replace 102 with the module to use for SOBI2 item 42 */
  if ( $sobi2Id == 44 ) return 103; /* replace 103 with the module to use for SOBI2 item 43 */
}

Detecting other SOBI2 page types

SOBI2 main page

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == ''
    and JRequest::getVar('catid') == '')
  return 101;

On any category page (incl SOBI2 main page)

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == '' ) return 101;

SOBI2 search page

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == 'search' ) return 101;

Add Entry page

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == 'addNew' ) return 101;

Item view page

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == 'sobi2Details' ) return 101;

Item Edit page

if ( $option == "com_sobi2" and JRequest::getVar('sobi2Task') == 'editSobi' ) return 101;