How to get module's title in Joomla 2.5? - joomla

Inside my module (from within php code), say mod_mymodule, how can I retrieve my module's title, in case an administrator has changed it from the module management page?
Is it possible to retrieve the "Status" and "Position" the same way as the title?

Inside the module, there are two helpful variables available:
$module and $params.
You are looking for $module->title.

Try the below code.
<?php
if ($module->showtitle)
{
echo '<h2>' .$module->title .'</h2>';
}
?>
You can access the following things.
stdClass Object
(
[id] => 18
[title] => Login Form
[module] => mod_login
[position] => left
[content] =>
[showtitle] => 1
[control] =>
[params] => greeting=1
name=0
[user] => 0
[name] => login
[style] =>
)
Reference Joomla URL:
1. http://docs.joomla.org/JModuleHelper/getModule
2. http://docs.joomla.org/Customising_the_way_modules_are_displayed
Updates - 22nd Dec 2016
You can use jimport to get the module.
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'login' ); // Single
$module = JModuleHelper::getModule( 'mainmenu', 'Resources' ); // Multiple

Related

How to get the custom values and image in Magento in Topmenu?

I'm using magento 1.7.0.2. I have add the custom value in database. But how to retrive the custom value and image in Topmanu. I have tried in below mentioned code in the palce of 'my_attribute' to replace my attribute, but i din't get the result.
Model: Mage_Catalog_Model_Observer
Method: _addCategoriesToMenu()
$categoryData = array(
'name' => $category->getName(),
'id' => $nodeId,
//'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'my_attribute' => $category->getData('my_attribute') // Add our data in...
);
When i print the array i'll get this,
Array ( [name] => Matelas [id] => category-node-31 [is_active] => 1 [my_attribute] => )
Can any one guide me, Thanks in advance...
I am guessing you mean you have added a new custom attribute to the Category entity?
Becuase you are dealing with a Node_collection the full category object won't be loaded, try loading the full object to get what you're after:
$cat = Mage::getModel('catalog/category')->load($category->getId());
$categoryData = array(
name' => $category->getName(),
'id' => $nodeId,
//'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'my_attribute' => $cat->getData('my_attribute') // Add our data in...
);

How to add categories in Joomla 2.5

Does anyone know how to properly insert new content categories to the DB programatically?
For each post in the categories table, there is also a post saved in the assets table with lft and rgt set.
Is there any native Joomla class I can use for this instead of plain SQL?
Please Please Only use the native classes, which categories will handle for you seamlessly. As soon as you add categories the whole thing will be handled automagically. Just look at any core component to see how.
It is not easy to update the assets table using sql, it is all very specifically managed and part of a complex series of foreign keyed tables.
Extend JTable or JTableContent to handle this.
Here is some code I just whipped together that just uses the JTableCategory class, so it can be used simply on the front or admin side of Joomla
$table = JTable::getInstance('category');
$data = array();
// name the category
$data['title'] = $title;
// set the parent category for the new category
$data['parent_id'] = $parent_id;
// set what extension the category is for
$data['extension'] = $extension;
// Set the category to be published by default
$data['published'] = 1;
// setLocation uses the parent_id and updates the nesting columns correctly
$table->setLocation($data['parent_id'], 'last-child');
// push our data into the table object
$table->bind($data);
// some data checks including setting the alias based on the name
if ($table->check()) {
// and store it!
$table->store();
// Success
} else {
// Error
}
Naturally you would want to get the data pieces set correctly, but these are the core ones to set.
Here is a function I've created just for this purpose, after some digging & experimenting.
It uses core classes, so it needs an access to them (for me it's basically a part of Joomla component).
Mind, it's for Joomla 3, for Joomla 2.5 and before, you need to change JModelLegacy to JModel.
function createCategory( $name, $parent_id, $note )
{
JTable::addIncludePath( JPATH_ADMINISTRATOR . '/components/com_categories/tables' );
$cat_model = JModelLegacy::getInstance( 'Category', 'CategoriesModel' );
$data = array (
'id' => 0,
'parent_id' => $parent_id,
'extension' => 'com_content',
'title' => $name,
'alias' => '',
'note' => $note,
'description' => '',
'published' => '1',
'access' => '1',
'metadesc' => '',
'metakey' => '',
'created_user_id' => '0',
'language' => '*',
'rules' => array(
'core.create' => array(),
'core.delete' => array(),
'core.edit' => array(),
'core.edit.state' => array(),
'core.edit.own' => array(),
),
'params' => array(
'category_layout' => '',
'image' => '',
),
'metadata' => array(
'author' => '',
'robots' => '',
),
);
if( !$cat_model->save( $data ) )
{
return NULL;
}
$categories = JCategories::getInstance( 'Content' );
$subcategory = $categories->get( $cat_model->getState( "category.id" ) );
return $subcategory;
}
You can perhaps use the save() in category.php file.
File location: root\administrator\components\com_categories\models\category.php
It saves the form data supplied to it!
The JOS_assets table is to store the ACL for each asset that is created.
If you do not update this table while programatically creating the category, the default ACL will apply. And when later you open and save the category in the administrative panel, the ACL will be updated as it should have been by core Joomla!.
You can create an SQL query very easily though and update the asset table as well. Its easy to understand once you open the table's content in phpmyadmin.

count the usage of a module type

How to know how many copies of a module type are in use in all positions?
I have to know it and use it in my module script.
Because the module has a JavaScript code, and it should print just one time.
Is it possible ?
let assume that It's login module
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule( 'login' );
echo '<pre>';
print_r( $module );
echo '</pre>'
which will return
stdClass Object
(
[id] => 18
[title] => Login Form
[module] => mod_login
[position] => left
[content] =>
[showtitle] => 1
[control] =>
[params] => greeting=1
name=0
[user] => 0
[name] => login
[style] =>
)
Looking at the above result you can develop your logic. Read more

Add product with custom option to existing Order

$quoteItem = Mage::getModel('sales/quote_item')->setProduct($product)
->setQuote(Mage::getModel('sales/quote')->load($order->getQuoteId()));
$orderItem = Mage::getModel('sales/convert_quote')->itemToOrderItem($quoteItem)->setProduct($product);
this is the code i use to add a simple product to existing order , but i am having issues adding custom option product to the order.
$quoteItem->addOption(new Varien_Object(
array(
'product' => $quoteItem->getProduct(),
'code' => 'option_ids',
'value' => 1 // 45,46,55
)
));
$quoteItem->addOption(new Varien_Object(
array(
'product' => $quoteItem->getProduct(),
'code' => 'option_1', //45
'value' => 2 // ‘White’
)
));
after the first line , but no success.
Any help please.
Thanks
There is one method to change exitsting order:
http://prattski.com/2013/04/22/magento-adding-items-to-existing-orders/

Magento - Show Creation Date/Time for CMS pages

I have created a custom CMS layout by copying (and renaming) the 2columns-left.phtml and setting the appropriate xml configuration options, etc.
I would like to display the CMS Creation Time (the creation_time field) below the content. How do I do it?
Alternatively, in a CMS layout page, how can I access the underlying CMS page data?
<?php
$collection = Mage::getModel('cms/page')->getCollection();
foreach($collection as $page) {
print_r($page->debug());
}
?>
[Array]
(
[page_id] => 2
[title] => Home Page
[root_template] => three_columns
[meta_keywords] =>
[meta_description] =>
[identifier] => home
[content] => Hello...
[creation_time] => 2012-01-11 21:15:34
[update_time] => 2012-01-11 21:18:16
[is_active] => 1
[sort_order] => 0
[layout_update_xml] =>
[custom_theme] =>
)
Here is the array, rest of things its up to you...

Resources