itemid.php 2.19 KB
<?php
/* ======================================================
# Monthly Archive - Joomla! Component v4.3.3 (PRO version)
# -------------------------------------------------------
# For Joomla! 3.x
# Author: Yiannis Christodoulou (yiannis@web357.eu)
# Copyright (©) 2009-2018 Web357. All rights reserved.
# License: GNU/GPLv3, http://www.gnu.org/licenses/gpl-3.0.html
# Website: https://www.web357.eu/
# Demo: http://demo.web357.eu/?item=monthlyarchive
# Support: support@web357.eu
# Last modified: 09 Feb 2018, 13:55:18
========================================================= */

defined('JPATH_BASE') or die;

jimport('joomla.form.formfield');
jimport( 'joomla.form.form' );

class JFormFielditemid extends JFormField {
	
	protected $type = 'itemid';

	protected function getLabel()
	{
		return '<label id="jform_params_itemid-lbl" for="jform_params_itemid" class="hasTooltip" title="&lt;strong&gt;'.JText::_('MOD_MONTHLYARCHIVE').' - '.JText::_('MOD_MONTHLYARCHIVE_MENU_ITEMID_LBL').'&lt;/strong&gt;&lt;br /&gt;'.JText::_('MOD_MONTHLYARCHIVE_MENU_ITEMID_DESC').'">'.JText::_('MOD_MONTHLYARCHIVE_MENU_ITEMID_LBL').'</label>';	
	}

	protected function getInput() 
	{
		// Get item ids from menu manager, that are assigned with Monthly Archive.
		$db = JFactory::getDBO();
		$query = "SELECT m.*, ext.* "
		."FROM #__menu AS m "
		."LEFT JOIN #__extensions AS ext ON ext.extension_id = m.component_id "
		."WHERE m.link = 'index.php?option=com_monthlyarchive&view=archive' AND m.client_id = 0 AND m.published = 1 AND (ext.type = 'component' OR ext.type = 'module') "
		;
		$db->setQuery($query);
		$db->query();
		$item_ids = $db->loadObjectlist();

		$html = '';
		$html .= '<select id="'.$this->id.'" name="'.$this->name.'" class="bg_layout_type" style="width: 300px;">';
		$html .= '<option value="">Select a Menu Item</option>';
		foreach ($item_ids as $item_id):
			$html .= '<option value="'.$item_id->id.'"'.(($this->value == $item_id->id) ? ' selected="selected"' : '').'>';
			$html .= $item_id->title.' (';
			$html .= 'id:'.$item_id->id;
			$html .= ($item_id->language != '*') ? ' - language: '.$item_id->language : '';
			$html .= ')';
			$html .= '</option>';
		endforeach;
		$html .= '</select> ';
		
		return $html;
	}
	
}