Showing posts with label Joomla. Show all posts
Showing posts with label Joomla. Show all posts

Thursday, January 23, 2014

Setting up a global state variable Joomla

Sometimes it is necessary to maintain a state variable across the site.
For example, to check whether Jquery is already loaded in another custom built component or module.

Setting up a state variable

$app = JFactory::getApplication();
$app->setUserState( 'myvar', $myvarvalue );
$app->setUserState( 'com_yourcomponent.data', $yourvalue );

Retrieving a variable saved

$app = JFactory::getApplication();
$variable = $app->getUserStateFromRequest( "com_yourcomponent.data" );

Tuesday, January 21, 2014

List documents in Joomla media manager

By normal, Joomla media manager does not default display the documents manager.

In some cases we need to show them in media manager to link to document.


  1. In administrator/com_media/views/imagelist.php, add the following function
          # Test to list PDF files
function setDocument($index = 0)
{
if (isset($this->documents[$index]))
{
$this->_tmp_document = &$this->documents[$index];
}
else
{
$this->_tmp_document = new JObject;
}
}

Add this in in the apt place in display function
# Test to list PDF files
$documents = $this->get('documents');
$this->documents = &$documents;

      2.  In administrator/com_media/views/tmpl/default.php, add this snippet next to image block
     
       <?php for ($i = 0, $n = count($this->documents); $i < $n; $i++) :
$this->setDocument($i);
echo $this->loadTemplate('document');
endfor; ?>   

      3.  Create a file 'default_document.php' inside administrator/com_media/views/tmpl/, and add this code

       <?php
       defined('_JEXEC') or die;
        
        $params = new JRegistry;
        $dispatcher = JEventDispatcher::getInstance();
        $dispatcher->trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_document, &$params));
        ?>
        <li class="imgOutline thumbnail height-80 width-80 center">
        <a class="img-preview" href="javascript:ImageManager.populateFields('<?php echo $this->_tmp_document->path_relative; ?>')" title="<?php echo $this->_tmp_document->name; ?>" >
        <div class="height-50">
        <!--<?php echo JHtml::_('image', $this->baseURL . '/' . $this->_tmp_document->path_relative, JText::sprintf('COM_MEDIA_IMAGE_TITLE', $this->_tmp_document->title, JHtml::_('number.bytes', $this->_tmp_document->size)), array('width' => $this->_tmp_document->width_60, 'height' => $this->_tmp_document->height_60)); ?>-->
        <?php echo JHtml::_('image', $this->_tmp_document->icon_32, $this->_tmp_document->name, null, true, true) ? JHtml::_('image', $this->_tmp_document->icon_32, $this->_tmp_document->title, null, true) : JHtml::_('image', 'media/con_info.png', $this->_tmp_document->name, null, true); ?></a>
        </div>
        <div class="small">
        <?php echo JHtml::_('string.truncate', $this->_tmp_document->name, 10, false); ?>
        </div>
        </a>
        </li>
        <?php
        $dispatcher->trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_document, &$params));
        ?>




Thursday, December 12, 2013

Joomla load module anywhere

if (!class_exists( 'CarsModelCars' )){
   JLoader::import( 'cars', JPATH_BASE . DS . 'components' . DS . 'com_cars' . DS . 'models' );
}

Now create an object for that class

Thursday, December 5, 2013

Use JQuery Squeeze box for modal display

To use modal pop up in joomla, there is an in-built javascript plugin Squeeze box based on the mootools library.

JHtml::_('behavior.modal');

This will add the squeeze box modal library.

And then add a class "modal" to the anchor.

Example
<a href="http://www.example.com/somepage.html" 
class="modal" rel="{size: {x: 700, y: 500}, handler:'iframe'}" 
id="modalLink1">
Click here to see this interesting page</a>

The above will load a iframe in modal box.

Reference
http://www.spiralscripts.co.uk/Joomla-Tips/using-modal-windows-with-joomla.html

Friday, August 30, 2013

Joomla find current page URL with query string

$uri = & JFactory::getURI();
$pageURL = $uri->toString();
echo $pageURL;


This will find the absolute path, but will not fetch query string
$pageURL = JURI::current();
echo $pageURL;


Thursday, August 8, 2013

Find Children of a Class or ID

To find the children of a a specific div or any class or ID in jQuery

trs = $('#jevents_body').find('table.day-list > tbody > tr');

Joomla JEvents Category Filtering

(function ($){
 var ready = (function(){
  setUpCalModule();
 });


 // events calendar category checkbox filtering
 var setUpCalModule = (function(){
   var left, trs;
   left = $('.content-area-left').children('.moduletable');
   if (!left.length) return;

   trs = $('#jevents_body').find('table.day-list > tbody > tr');

   left.on('change','#jevent-mod-cat-checks', function(){
     var checks = $(this).find('input[type="checkbox"]'),
 checked = checks.filter(':checked'),
 notChecked = checks.not(checked);

     checked.each(function(){
      deleteCookieValue(this.value);
trs.filter('[data-cat="'+this.value+'"]').show();
     });

     notChecked.each(function(){
      setCookie(this.value);      
trs.filter('[data-cat="'+this.value+'"]').hide();
     });

   });
 });

 // get ready ... go!
 jQuery(document).ready(ready);

})(jQuery);

Friday, July 19, 2013

Render modukes inside componet - Joomla

<?php
 $modules =& JModuleHelper::getModules('contact');
 foreach ($modules as $module)
 {
echo JModuleHelper::renderModule($module);
 }
 ?>

Where 'contact' is the name of the position

Monday, April 15, 2013

Creating an optgroup dynamically


$results = $database->loadObjectList();
        $groups = array();
        foreach ($results as $result) {
            $groups[$result->regionname][$result->locid] = $result->locname;
        }
        foreach($groups as $label => $opt):
        $options[] = JHTML::_('select.optgroup', $label);
        foreach ($opt as $id => $name):
        $options[] = JHTML::_('select.option', $id, $name);
        endforeach;
        $options[] = JHTML::_('select.option', '');
        endforeach;
       
        JHTML::_('select.genericlist', $options, 'locid', 'class="chzn-select" style="width:122px;" tabindex="4"','value', 'text', '', false);
        $select = JHTML::_(
         'select.genericlist', // Because we are creating a 'select' element
         $options,             // The options we created above
         'locid',        // The name your select element should have in your HTML
         'size="1" ',          // Extra parameters to add to your element
         'value',              // The name of the object variable for the option value
         'text',               // The name of the object variable for the option text
         'selected_key',       // The key that is selected (accepts an array or a string)
         false                 // Translate the option results?
        );

   
        print_r($select);

Create OPTGROUP in CakePHP


// Define arrays filled with test data; would normally come from your database
    $cars = array('Ferrari', 'Bugatti', 'Porsche');
    $babes = array('Megan Fox', 'Alyssa Milano', 'Doutzen Kroes');
 
    // Create an empty array to be filled with options
    $options = array();
 
    // Create the initial option
    $options[] = JHTML :: _('select.option', '', '- What do you like most -');
 
    // Open our 'Cars' optgroup
    $options[] = JHTML::_('select.optgroup', 'Cars');
 
    // Loop through the 'Cars' data
    foreach($cars as $key => $text) {
     // Create each option tag within this optgroup
     $options[] = JHTML::_('select.option', $key, $text);
    }
 
    // Use the hack below to close the optgroup
    $options[] = JHTML::_('select.option', '');
 
    // Now open our 'Babes' optgroup
    $options[] = JHTML::_('select.optgroup', 'Babes');
 
    // Loop through the 'Babes' data this time
    foreach($babes as $key => $text) {
     // Create each option tag within this optgroup
     $options[] = JHTML::_('select.option', $key, $text);
    }
 
    // Use the hack below to close this last optgroup
    $options[] = JHTML::_('select.option', '');
 
    // Generate the select element with our parameters
    $select = JHTML::_(
     'select.genericlist', // Because we are creating a 'select' element
     $options,             // The options we created above
     'select_name',        // The name your select element should have in your HTML
     'size="1" ',          // Extra parameters to add to your element
     'value',              // The name of the object variable for the option value
     'text',               // The name of the object variable for the option text
     'selected_key',       // The key that is selected (accepts an array or a string)
     false                 // Translate the option results?
    );
 
echo $select;
    ?>

Creating optgroup in Joomla


// Define arrays filled with test data; would normally come from your database
$cars = array('Ferrari', 'Bugatti', 'Porsche');
$babes = array('Megan Fox', 'Alyssa Milano', 'Doutzen Kroes');

// Create an empty array to be filled with options
$options = array();

// Create the initial option
$options[] = JHTML :: _('select.option', '', '- What do you like most -');

// Open our 'Cars' optgroup
$options[] = JHTML::_('select.optgroup', 'Cars');

// Loop through the 'Cars' data
foreach($cars as $key => $text) {
 // Create each option tag within this optgroup
 $options[] = JHTML::_('select.option', $key, $text);
}

// Use the hack below to close the optgroup
$options[] = JHTML::_('select.option', '');

// Now open our 'Babes' optgroup
$options[] = JHTML::_('select.optgroup', 'Babes');

// Loop through the 'Babes' data this time
foreach($babes as $key => $text) {
 // Create each option tag within this optgroup
 $options[] = JHTML::_('select.option', $key, $text);
}

// Use the hack below to close this last optgroup
$options[] = JHTML::_('select.option', '');

// Generate the select element with our parameters
$select = JHTML::_(
 'select.genericlist', // Because we are creating a 'select' element
 $options,             // The options we created above
 'select_name',        // The name your select element should have in your HTML 
 'size="1" ',          // Extra parameters to add to your element
 'value',              // The name of the object variable for the option value
 'text',               // The name of the object variable for the option text
 'selected_key',       // The key that is selected (accepts an array or a string)
 false                 // Translate the option results?
);
 
// Display our select box
echo $select;

Wednesday, February 27, 2013

Call a Module inside a component



$modName = 'mod_refinesearch '; // not mod_mostread
$modTitle = 'Refine Search';
$mod = JModuleHelper::getModule($modName, $modTitle);
$content = JModuleHelper::renderModule($mod);
echo $content;

Monday, February 18, 2013

Find current template name in module


<?php
$app = JFactory::getApplication();
$templateDir = JURI::base() . 'templates/' . $app->getTemplate();
?>