Displaying list of logged in users in Front side using Joomla 2.5 component - joomla

I would like to display all login user list in Front side using Joomla 2.5 component.
Can any body tell me how do do this?
I would also want to develop change password and news subscription module.

Try this,
$db =JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__users');
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$user = JFactory::getUser($row->id);
$status = $user->guest;
if(!$status){
echo $row->name.'---Email'.$row->email;
}
}
Use this extension to implement its in your site if you need quick solution.
Hope it helps..

Related

Call function inside Joomla articles

I am facing a problem. I have created a article in Joomla administrator and i have created a function in a php file. I have to call that function in that article . I don't know how do i call function in article.
Here is the code:
class modVodesbalanceHelper {
function deductBalance()
{
$db = JFactory::getDBO();
$result = null;
$user = JFactory::getUser();
if ($user->guest) {
return false;
}
$query = 'SELECT credit' .
' FROM #__vodes_credits' .
' WHERE userid = ' . (int) $user->id
;
$db->setQuery($query);
$result = $db->loadResult();
$result_final=$result-10;
$query = 'update #__vodes_credits SET credit='.$result_final.
' WHERE userid = ' . (int) $user->id
;
//echo $query;
$db->setQuery($query);
$result = $db->loadResult();
}
}
In admin panel, in article i have write this code:
<script>
window.onload=function()
{
var a=confirm("do you want to purchase this credit");
if(a)
{
document.location.href ="index.php?option=com_content&view=featured";
}
else
{
document.location.href="index.php?option=com_content&view=article&id=3";
}
}
</script>
I have to call deductBalance when user click on the "OK" of comfirm box.
Please tell me to sought it .
You can't add PHP to Joomla article by default. For this you need to use a 3rd party plugin. Personally, I would recommend using Sourcerer. Once installed and enabled, you can use the following in your article:
{source}
<?php
// All your PHP code
?>
{/source}
Don't include PHP files inside your article
I would use Sourcerer to add php code inside joomla article.
Check the sourcerer plugin to be enabled (check plugin enabled status here: extensions->plugin manager->sourcerer).
Then, use the "Insert Code" button at the bottom of your WYSIWYG editor when adding your PHP scripts. Your code should be wrapped with
{source}
//php code wrapped by <?php ?>
{/source}
If you need to use code directly within Joomla article then use Sourcerer as in above questions. If you feel to keep the PHP code in seperate module. Use Blank Module
Or mod_php module. Then in your Joomla Article you can place the code like this,
{loadposition}*Your Custom Module Position*{/loadposition}

Code to display articles from category ID?

What would be the code to display articles from category (specified by ID)?
In Wordpress this is fairly easy by doing:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
I'm looking for similar code for Joomla.
$db = JFactory::getDbo();
$id = 50;//example
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('catid="'.$id.'"');
$db->setQuery((string)$query);
$res = $db->loadObjectList();
foreach($res as $r){
echo '<h3>'.$r->title.'</h3>';
echo $r->introtext;
}
You can use next code template:
$categoryId = $[category id];
require_once("components/com_content/models/category.php");
$category = new ContentModelCategory();
$category->hit($categoryId);
$articles = $category->getItems();
print_r($articles);
There is no direct code for getting this in joomla like word press.
If you want to check the code you can check the code for achieving this by following path.
components/com_content/view/category/view.html.php
and
components/com_content/view/category/tmpl/blog.php
According to my Guess your requirement is to display the articles from same category.
then in joomla you dont need to edit in any code.
for achieving this you can simply create a menu.
and menu layout type should be category blog and Choose your category from the right side category options.
This will get the complete article from that category.
If you want to manage it in your style you can add style based on blog.php file .
Hope this will help you..
Try this:
$articles = JFactory::getDBO()->setQuery("SELECT * FROM #__content WHERE catid = '21'")->loadObjectList();
Of course replace '21' with id of your category.
This is quite easy in Joomla. You can find the code in /components/com_content/models/category.php under getItems()
Below is an example
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category_id);
$articles = $model->getItems();

How to Get User Group Names in Joomla 2.5

I'm writing a Joomla 2.5 component that I had been developing in Joomla 1.7. I have been using code like this:
$user = JFactory::getUser();
$groups = $user->get('groups');
The $groups array would contain a list of ids with the group name as the index. Joomla 2.5 seems to have scrapped this functionality. I have been unable to find out how to get the group names without directly querying the database. Is there any method for getting a list of the groups a user is a member of without having to resort to querying the database?
The code I generated below gets the names of all the groups the user is a part of and stores them in the variable $groupNames separated by line breaks:
foreach ($user->groups as $groupId => $value){
$db = JFactory::getDbo();
$db->setQuery(
'SELECT `title`' .
' FROM `#__usergroups`' .
' WHERE `id` = '. (int) $groupId
);
$groupNames .= $db->loadResult();
$groupNames .= '<br/>';
}
print $groupNames;
It technically queries the database but is done via the Joomla API. This is working well for me on Joomla 2.5.
Yes, this changed.
But what you should be using instead is:
JFactory::getUser()->getAuthorisedGroups();
or just getUserGroups
Real snippet:
$user = JFactory::getUser();
$db = JFactory::getDBO();
$db->setQuery($db->getQuery(true)
->select('*')
->from("#__usergroups")
);
$groups=$db->loadRowList();
$userGroups = $user->groups;
$return=array();
foreach ($groups as $key=>$g){
if (array_key_exists($g[0],$userGroups)) array_push($return,$g[4]);
}
$groups=$return;
/////printing groupnames for current user/////////////
print_r($groups);
Here it is:
<?php
$user =& JFactory::getUser();
foreach ($user->groups as $key => $value){
echo $key.'<br>';
}
?>
This will print all the user group names to the screen. The user group names are the "keys" of the array $user->groups.

How do I get the options for bundled products on the success page?

On the success page, I have no trouble getting a list of the products purchased with the following code:
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($order->getAllItems() as $item){
$subtotal = number_format($item->getSubtotal(),2);
}
What I can't figure out, is how to get an object or an array of the options for bundled products. These are standard options like what color a product is.
I have not specifically tried this with bundled products, but the code below works with configurable products, and I'm sure you can modify it as needed to fit your situation.
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($order->getAllItems() as $item){
$productOptions = $item->getProductOptions();
if (isset($productOptions['attributes_info'])) {
foreach ($productOptions['attributes_info'] as $productOption) {
echo $label = $productOption['label'];
echo '<br />';
echo $value = $productOption['value'];
}
}
}
My suggestion is to start broad (i.e. at the $item level), see what Magento returns (using Zend_Debug::dump($item->getData()), and then work your way down to what you need.
Hope that helps.

Post data in codeigniter can be retrieved as an array or object?

In one of my new codeigniter project, one of my colleague wrote a helper method array_to_object so that he can call the variables in views as $row->field instead of $row['field'].
I thought codeigniter default behaviour allows us to retrieve data from database in $row->field (as object). Can anyone pls enlight me data flow in codeigniter?
Codeigniter supports both an array and an object oriented style to retrieve data from DB so both of these styles are equal(from the user guide):
oop style
$query = $this->db->query('SELECT name, title, email FROM my_table');
foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->email;
}
array style
$query = $this->db->query('SELECT name, title, email FROM my_table');
foreach ($query->result_array() as $row)
{
echo $row['title'];
echo $row['name'];
echo $row['email'];
}
here is the user guide:
http://codeigniter.com/user_guide/database/examples.html

Resources