Drupal Menu-How to get Hierarchy - php

In Drupal how can I get selected menu items hierarchy?
If I selected item3, how can I get the the entire hierarchy...(eg:item1->item2-item3)
If I use $menu_item = menu_get_item();, I will get active menu item name (eg: item3). But I want to get it like (item1->item2->item3).

$parent = menu_get_item($vars['mid']);
$vars['parent'] = $parent['pid'];
$hasParent = menu_get_menu();
$hasParent = $hasParent['items'][$parent]['pid'];
this code will give you the parent menus information and you can print that.

Related

PHP Group arrays by parameters on filtered query

I got three classes :
class libro {
var $id;
var $name;
var $editorial;
var $materia = array();
[... getters and setters ]
class editorial {
var $name;
var $id;
[...]
class materia {
var $name;
var $id;
[...]
This is working on a website catalogue, where I got an amount of books I get from an xml file. That works well, I checked it; i receive xml values good.
On my website's catalogue, I got a aside bar. By default, are shown all editorials and materias (categories), as well as all books.
So, when I click on a checkbox of one editorial/materia, page reloads with a new query from xml, where one of them are filtered. Books in catalogue are shown, but on the aside, I need to show only the element I checked in, and the other are grouped researching in the new xml query data.
For example, If I select editorial Great Books, page will reload showing only that one editorial on the checkbox, and on aside's section about Materias I will see all that are contained on the array(materia) inside every book, grouped by to not show repeated categories.
The other way of the example :
If I search by a Materia first, editorials on new query will be grouped by too. If I got Editorial selected and I click a category, only category and editorial selected will be shown, and upside down If I selected first the category.
I'm working with $_GET['editorial'] and $_GET['materia'] to work on new query data.
This is my code about grouping...
$bookList = array();
// Here are methods where I set xml data to classes, and I get an array (link below)
$groupedBookList = array();
foreach ($bookList as $book){
// ERROR IN LINE BELOW (Undefined offset: 0 in ...)
$groupBL_Element = &$groupedBookList[$book->get_editorial()->get_id() . "_" .$libro->get_materia(0)->get_id() ];
$groupBL_Element['editorial'] = $book->get_editorial()->get_id();
$groupBL_Element['materia'] = $book->get_materia(0)->get_id();
}
return array_values($groupedBookList);
goo.gl/ 397Wuz
Someone knows some way to group this? Thanks
The error I get is :
Undefined offset: 0 in (line selected by mine up)
I'm not sure if this is which you are looking for, but if you add to your foreach:
foreach ($bookList as $book){
$groupBL_Element = &$groupedBookList[$book->get_editorial()->get_id() . "_" .$libro->get_materia(0)->get_id() ];
$groupBL_Element['editorial'] = $book->get_editorial()->get_id();
$groupBL_Element['materia'] = $book->get_materia(0)->get_id();
$groupedBookList[] = $groupBL_Element;
}
Then you can return $groupedBookList with our your elements grouped.

How to display value option from dropdown list in Elgg

Elgg is build on the MVC framework. My main agenda is to be able to save the value selected from the dropdown list, after which is to then display the chosen value the item listing. The following code is actually constructed in PHP that is following the Elgg framework closely.
What I have managed to do is to make use of the existing Elgg framework to display the dropdown list. In which, the dropdown list is created by the creation of a form in the following directory: mod/plugin/views/default/forms/plugin/form.php. I have hence made use of the existing Elgg framework (input/dropdown)to create my dropdown list as a form.
Secondly, I have managed to save the values chosen in the dropdown list and display the value in a success message. This is done in the action directory which will allow the values to be saved into the database when user clicks on 'save' button.
Code for saving and displaying value:
<?php
/**
* Elgg options uploader/submit action
*
* #package ElggFile
*/
// get the input variables
$list = get_input('OptionItems');
$container_guid = (int) get_input('container_guid', 0);
if ($container_guid == 0)
{
$container_guid = elgg_get_logged_in_user_guid();
}
$my_select_guid = (int) get_input (file_guid);
//create a new my_select object
$my_select = new ElggObject();
$my_select -> dropdown = $list;
$my_select ->container_guid = $container_guid;
//save to database and get id of the new my_blog
$my_select_guid = $my_select->save();
if($my_select_guid){
system_message("Your action post = " . $list);
//to add new muy_select object to river
add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $list->guid);
}
else{
register_error("Your action post is not saved");
}
However, at this point, I am stuck in displaying the chosen value of the dropdown list as an extended view, within the view/default/object/file/
How am I able to do this?
It's all in Elgg documentation about the views that I linked for you before: http://learn.elgg.org/en/1.12/guides/views.html#extending-views

Magento duplicate attriubte set new attributes not showing in front end

Duplicated attriubte set for new product line.
Attributes set show in backend and front end.
Created new attribute and added to attribute set.
New attribute show's in back end but not front end.
If I add the new attribute to the origonal set that was duplicated the new attribute will now show on the front end for the product assoiated with the duplicated attribute group.
So basicly A new attribute added to a duplicate set won't show on the front end until its added to the attribute set that was duplicated.
I've checked to make sure the attribute is visable on front end etc and tried it several times checking the settings.
The goal is to be able to duplicate a attribute set and add new attributes for different product types. Then call the folder by id and display the assoiated attributes.
I've called the attribute group by ID (spec's). This code is working.
<?php
require_once 'app/Mage.php';
Mage::app();
$attributeGroupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection');
$product = $this->getProduct();
foreach ($attributeGroupCollection as $attributeGroup) {
$attributeGroup->getAttributeGroupId();
$attributeSpecs = Mage::getResourceModel('eav/entity_attribute_collection')
->setAttributeGroupFilter(41);
}
?>
Help is appreciated, thanks
Duplicating an attribute set is duplicating at a time (the moment when you click the button). If you want to add an attribute in both attribute sets, you need to create it in both, for that, you just need to create your attribute and drop it in the section you want to have it linked to (what you call "folder"). If you want to do it programmatically. You need to create an observer that will be fired after the attribute set is saved and that will add the attribute to the duplicated attribute set. I would not advise to do so because it means that you need to enter the ID of the attribute set duplicated and it can be tricky thing when it comes to pushing the development to the production. I am sure there is a workaround for what you want to achieve.
The problem was is magento creates a new id for each new group folder in the new duplicated attribute set (makes sense). I was calling by ID for the group and as a result will only show attributes in the origional folder (weird) even if the product was assoicated with the new attribute set. What I did was get the current attribute set id and then sort out the attribute groups by name so even if the attribute sets are coppied as long as the folde has the name it will display in the custom loop displaying the attributes. Here is my working code:
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($product->getAttributeSetId());
$attributeSetName = $attributeSetModel->getAttributeSetName();
$attributeSetID = $attributeSetModel->getAttributeSetID();
$groups = Mage::getModel('eav/entity_attribute_group')
->getResourceCollection()
->setAttributeSetFilter($attributeSetID)
->setSortOrder()
->load();
$attributeCodes = array();
foreach ($groups as $group) {
echo $groupName = $group->getAttributeGroupName();
$groupId = $group->getAttributeGroupId();
if (strpos($groupName , 'Specifications') !== false) {
echo 'true';
$specificationsNum = $groupId;
};
if (strpos($groupName , 'eatures') !== false) {
echo 'true';
$prodfeaturesNum = $groupId;
};
}
//echo $specifications;
$specifications = Mage::getResourceModel('eav/entity_attribute_collection')
->setAttributeGroupFilter($specificationsNum);
$prodfeatures = Mage::getResourceModel('eav/entity_attribute_collection')
->setAttributeGroupFilter($prodfeatures);

Joomla get content by ajax

How to get joomla content using ajax? (I want to show content of specyfic page in popup), this is my code: (called by ajax)
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo '<h2>'.$article->get("title").'</h2>';
echo $article->get("introtext"); // and/or fulltext
}
This works fine only for artilces, but the problem is when for example I want to show category, or component
Please see your if condition it checks if option is equal to com_content & view is equal to article only. If view contains category it won't work. So add the conditions in if statement so that your code gets executed.
for category you need to add view=category & like for other components as well.

Joomla : how to get the url of a specific Menu itemID?

Friends a newbie question.........I need help in getting the URL of a specific Menu itemID. The situation is like this:
I am running Joomla and asking for a user to input for a menu ID and choose a layout for that menu ID.
I want to do something else with this URL of the Menu itemID.
How can I get the URL of this Menu itemID provided by the user?
For Example if the user input is liek $this->get ('menulayoutid'>; and he inputs and ID of 54 then how do I get the URL for Menu ID 54.
Please note: I want to get this URL from within my PHP file and not in the browser so that I can use the value of that URL for some other purpose.
Kindly help.
$itemid = JRequest::getVar('Itemid');
$application = JFactory::getApplication();
$menu = $application->getMenu();
$item = $menu->getItem($itemid);
$link = new JURI($item->link);
$link->setVar('ItemId', $itemid);
Source: http://forum.joomla.org/viewtopic.php?p=1836005
However, we get the Itemid from anywhere (user input, from our own developed module using the "menu item" field type in the xml file as described in the Joomla Docs - Standard form field types)
// get the menuItemId from wherever...
// as described above or as in other posts here and do whatever with that!
$menuItemId = 'fromWherever'; // as an example "107";
// build the link to the menuItemId is just easy and simple
$url = JRoute::_('index.php?Itemid=' . $menuItemId);
i think if we need only a link to a specific menu id, this is the best solution, because we have absolutely less requests and a clean code
this works also in Joomla 3.0, 3.1
I just want to add that if you need to target a specific menu you pass the menu name as an argument to getMenu().
$itemid = JRequest::getVar('Itemid');
$application = JFactory::getApplication();
$menu = $application->getMenu( 'menu-name' );
$item = $menu->getItem($itemid);
$link = new JURI($item->link);
$link->setVar('ItemId', $itemid);
I'm not sure if Joomla changed the way this works since 2.5 or even 1.7 but I spent the worse half of 2 hours looking for this.
Hopefully it helps someone.
$menuID = $params->get('menuItem'); // from module field menu ex. '105'
$js = new JSite;
$menu = $js->getMenu();
$link = $menu->getItem($menuID)->route;
//Returns URL Friendly Link -> menu/article
//Then format it ->
$link = 'http://www.yoursite.com/index.php/'.$link;
echo 'Borrowed Menu Link Path";
When you need to get your active menu item ID in Joomla to display some specific content for only that menu item or just to show the ID of the menu item, insert the following code where you wish to display the active menu item ID:
<?php
$currentMenuId = JSite::getMenu()->getActive()->id;
echo $currentMenuId;
?>

Categories