Monthly Archives: April 2012

How can get register user list in joomla?

In Your view.html.php
define or assign:
$lists[‘user_id’] = JHTML::_ ( ‘list.users’, ‘user_id’, (here view folder name)->user_id, 1, NULL, ‘name’, 0 );
$this->assignRef ( “lists”, $lists );

and display in your form.

User lists[‘user_id’];?>
Advertisements

How can show tree list (recursive) in joomla for custome component?

1. First in Your component module class with function

function getTotal()
{
if (empty($this->_total))
{
$query = $this->_buildQuery();
$this->_total = $this->_getListCount($query);
}
return $this->_total;
}

replace with function
function getData()
{
if (empty($this->_data))
{
$query = $this->_buildQuery();
$this->_data = $this->_getList($query);
$children = array ();
// first pass – collect children
foreach ( $this->_data as $v ) {
$pt = $v->parent_id;
$list = @$children [$pt] ? $children [$pt] : array ();
array_push ( $list, $v );
$children [$pt] = $list;
}
// second pass – get an indent list of the items
$list = JHTML::_ ( ‘menu.treerecurse’, 0, ”, array (), $children, 9999, 0, 0 );
$this->_data = array_slice ( $list, $this->getState(‘limitstart’), $this->getState(‘limit’));
}
return $this->_data;
}

2. In View (folder) Your default view listing
for ($i=0, $n=count( $this->items ); $i items[$i];
//category name print like
treename ; ?>
}

3. In Your Form view

add code for recursive function like for example

$value)
{
$stateslist1[] = JHTML::_(‘select.option’, $key, $value, ‘id’, ‘title’ );
}
$stateslist2 = array_merge( $stateslist,$stateslist1 );
$lists[‘id’] = JHTML::_(‘select.genericlist’, $stateslist2, ‘parent_id’, ‘class=”inputbox” size=”1″ style=”width:200px;”‘,’id’, ‘title’, $this->category->parent_id );

echo $lists[‘id’];

function getTree($id=0)
{
static $cates = array();
static $times = 0;
$times++;
$db =& JFactory::getDBO();
$query = ‘SELECT * FROM #__dir_categories where parent_id=’.$id;
$db->setQuery( $query );
$rowdata = $db->loadObjectList();
foreach($rowdata as $val)
{
$cates[$val->id] = str_repeat(“… “,$times-1).$val->title;
getTree($val->id);
}
$times=$times-1;
return $cates;
}
?>

How can use select group option in joomla

<?php

$db = &JFactory::getDBO();

$query = “SELECT id, title as name,parent_id FROM #__dir_categories ”
.”WHERE published=1 and parent_id=0 ORDER BY title ASC”;
//print $query;
$db->setQuery( $query );
$categories = $db->loadObjectList();
//        print_r($categories);
$query = “SELECT id, title as text,parent_id FROM #__dir_categories ”
.”WHERE published=1  ORDER BY title ASC”;
//print $query;
$db->setQuery( $query );

$products = $db->loadObjectList();
//        print_r($products);
if(!count($categories) || !count($products)) $html = ‘<div>’.JText::_(‘NO Directoty’).'</div>’;
else {
foreach($products as $product){
$options[$product->parent_id][] = $product;
}
foreach($categories as $category) {
$groups[] = JHTMLSelect::optgroup($category->name);
if(is_array($options[$category->id]))
foreach($options[$category->id] as $option){
$groups[] = JHTMLSelect::option($option->id, $option->text);
}
}
$html = JHTMLSelect::genericList($groups, ‘category_id[]’, ‘class=”inputbox”  size=”10″ style=”width: 95%”‘, ‘value’, ‘text’,  $this->directory->category_id );
}
print $html;

?>

How can write insert, update and delete query in joomla

for insert

$db            = & JFactory::getDBO();

$ins = new stdClass();
$ins->id = NULL;  // here id is auto increment id and primary key

$ins->table_field =$post[‘table_field’]; // table field name

…………………..

……………………..

if($db->insertObject(“jos_tablename”, $ins, ‘id’)){
unset($db);
}else{
echo $db->stderr();
}

for update

$ins->id = NULL;  // here id is  post/get retrieve value

$ins->table_field =$post[‘table_field’]; // table field name

…………………..

……………………..

if($db->updateObject(“jos_tablename”, $ins, ‘id’)){
unset($db);
}else{
echo $db->stderr();
}

foe delete

$db       =& JFactory::getDBO();
$query = ‘DELETE FROM jos_tablename’;
$db->setQuery( $query );
$db->query();