Statistiques

Compteur d'affichages des articles
1006263

01 - Création du composant avec JFoobar

Nous allons dans un prier temps utiliser, comme d'habitude, jFoobar pour créer notre composant.

L'avantage de cette solution est que toute la structure du composant ainsi que la table sont crées sans effort. A nous de modifier cela pour que cela corresponde à ce que l'on veux.

02 - Modification de la table

La table crée ne correspond pas exactement à mon besoin.

Je supprime les champs :

  • subtitle
  • snippet
  • fulltexte
  • custom_fields

J'ajoute les champs suivants :

  • `company_status` varchar(40) DEFAULT NULL
  • `company_name` varchar(255) DEFAULT NULL
  • `company_director` varchar(255) DEFAULT NULL
  • `company_address` varchar(255) DEFAULT NULL
  • `company_address_complement` varchar(255) DEFAULT NULL
  • `company_postbox` varchar(40) DEFAULT NULL
  • `company_postcode` varchar(40) DEFAULT NULL
  • `company_town` varchar(255) DEFAULT NULL
  • `company_state` varchar(255) DEFAULT NULL
  • `company_country` varchar(255) DEFAULT NULL
  • `company_phone` varchar(40) DEFAULT NULL
  • `company_fax` varchar(40) DEFAULT NULL
  • `company_mobile` varchar(40) DEFAULT NULL
  • `company_email` varchar(255) DEFAULT NULL
  • `company_url` varchar(255) DEFAULT NULL
  • `company_siren` varchar(40) DEFAULT NULL
  • `company_siret` varchar(40) DEFAULT NULL
  • `company_ape` varchar(40) DEFAULT NULL
  • `company_tva` varchar(40) DEFAULT NULL
  • `company_capital` varchar(40) DEFAULT NULL
  • `company_cnil` varchar(255) DEFAULT NULL
  • `editor_name` varchar(255) DEFAULT NULL
  • `editor_address` varchar(255) DEFAULT NULL
  • `editor_address_complement` varchar(255) DEFAULT NULL
  • `editor_postbox` varchar(40) DEFAULT NULL
  • `editor_postcode` varchar(40) DEFAULT NULL
  • `editor_city` varchar(255) DEFAULT NULL
  • `editor_country` varchar(255) DEFAULT NULL
  • `editor_email` varchar(255) DEFAULT NULL
  • `editor_phone` varchar(40) DEFAULT NULL
  • `editor_fax` varchar(40) DEFAULT NULL
  • `editor_url` varchar(255) DEFAULT NULL
  • `host_name` varchar(255) DEFAULT NULL
  • `host_address` varchar(255) DEFAULT NULL
  • `host_address_complement` varchar(255) DEFAULT NULL
  • `host_postbox` varchar(40) DEFAULT NULL
  • `host_postcode` varchar(40) DEFAULT NULL
  • `host_city` varchar(255) DEFAULT NULL
  • `host_country` varchar(255) DEFAULT NULL
  • `host_email` varchar(255) DEFAULT NULL
  • `host_phone` varchar(40) DEFAULT NULL
  • `host_fax` varchar(40) DEFAULT NULL
  • `host_url` varchar(255) DEFAULT NULL
  • `legals_title` varchar(255) DEFAULT NULL
  • `legals_display_title` tinyint(1) NOT NULL DEFAULT '1'
  • `legals_alias` varchar(255) DEFAULT NULL
  • `legals_meta_title` varchar(255) DEFAULT NULL
  • `legals_meta_description` text
  • `legals_meta_keywords` text
  • `use_terms` text
  • `use_policy` text
  • `use_delivery`text

03 - Modifications des fichiers models

Nous devons modifier les fichiers models pour prendre en compte les modifications de la table.

administrator/components/com_prestalegals/models/prestalegals.php

La fonction __construct est à l'origine comme ceci :

	public function __construct($config = array())
	{
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array(
				'id', 'a.id',
				'title', 'a.title',
				'alias', 'a.alias',
				'checked_out', 'a.checked_out',
				'checked_out_time', 'a.checked_out_time',
				'catid', 'a.catid', 'category_title',
				'state', 'a.state',
				'access', 'a.access', 'access_level',
				'created', 'a.created',
				'created_by', 'a.created_by',
				'ordering', 'a.ordering',
				'publish_up', 'a.publish_up',
				'publish_down', 'a.publish_down',
			);
		}

		parent::__construct($config);
	}

Elle devient :

	public function __construct($config = array())
	{
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array(
				'id', 'a.id',
				'title', 'a.title',
				'alias', 'a.alias',
				'checked_out', 'a.checked_out',
				'checked_out_time', 'a.checked_out_time',
				'catid', 'a.catid', 'category_title',
				'state', 'a.state',
				'access', 'a.access', 'access_level',
				'created', 'a.created',
				'created_by', 'a.created_by',
				'ordering', 'a.ordering',
				'publish_up', 'a.publish_up',
				'publish_down', 'a.publish_down',
				'company_status', 'a.company_status',
				'company_name', 'a.company_name',
				'company_director', 'a.company_director',
				'company_address', 'a.company_address',
				'company_address_complement', 'a.company_address_complement',
				'company_postbox', 'a.company_postbox',
				'company_postcode', 'a.company_postcode',
				'company_town', 'a.company_town',
				'company_state', 'a.company_state',
				'company_country', 'a.company_country',
				'company_phone', 'a.company_phone',
				'company_fax', 'a.company_fax',
				'company_mobile', 'a.company_mobile',
				'company_email', 'a.company_email',
				'company_url', 'a.company_url',
				'company_siren', 'a.company_siren',
				'company_siret', 'a.company_siret',
				'company_ape', 'a.company_ape',
				'company_tva', 'a.company_tva',
				'company_capital', 'a.company_capital',
				'company_cnil', 'a.company_cnil',
				'editor_name', 'a.editor_name' ,
				'editor_address', 'a.editor_address' ,
				'editor_address_complement', 'a.editor_address_complement' ,
				'editor_postbox', 'a.editor_postbox' ,
				'editor_postcode', 'a.editor_postcode' ,
				'editor_city', 'a.editor_city' ,
				'editor_country', 'a.editor_country' ,
				'editor_email', 'a.editor_email' ,
				'editor_phone', 'a.editor_phone' ,
				'editor_fax', 'a.editor_fax' ,
				'editor_url', 'a.editor_url' ,
				'host_name', 'a.host_name' ,
				'host_address', 'a.host_address' ,
				'host_address_complement', 'a.host_address_complement' ,
				'host_postbox', 'a.host_postbox' ,
				'host_postcode', 'a.host_postcode' ,
				'host_city', 'a.host_city' ,
				'host_country', 'a.host_country' ,
				'host_email', 'a.host_email' ,
				'host_phone', 'a.host_phone' ,
				'host_fax', 'a.host_fax' ,
				'host_url', 'a.host_url' ,
				'legals_title', 'a.legals_title' ,
				'legals_display_title', 'a.legals_display_title' ,
				'legals_alias', 'a.legals_alias' ,
				'legals_meta_title', 'a.legals_meta_title' ,
				'legals_meta_description', 'a.legals_meta_description' ,
				'legals_meta_keywords', 'a.legals_meta_keywords' ,
				'use_terms', 'a.use_terms' ,
				'use_policy', 'a.use_policy' ,
				'use_delivery' , 'a.use_delivery'
			);
		}

		parent::__construct($config);
	}

La fonction getListQuery est :

	protected function getListQuery()
	{
		// Create a new query object.
		$db		= $this->getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();

		// Select the required fields from the table.
		$query->select(
			$this->getState(
				'list.select',
				'a.id, a.title, a.alias, a.subtitle, ' .
				'a.snippet, a.fulltext, a.catid, ' .
                'a.created, a.created_by, a.created_by_alias, '.
                'a.modified, a.modified_by, '.
                'a.checked_out, a.checked_out_time, ' .
				'a.state, a.publish_up, a.publish_down, ' .
				'a.access, a.asset_id, a.version, a.language, a.ordering, ' .
                'a.metakey, a.metadesc, a.metadata, ' .
				'a.parameters, a.custom_fields'
			)
		);
		$query->from('#__prestalegals AS a');

Elle devient :

	protected function getListQuery()
	{
		// Create a new query object.
		$db		= $this->getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();

		// Select the required fields from the table.
		$query->select(
			$this->getState(
				'list.select',
				'a.id, a.title, a.alias, a.catid, ' .
                'a.created, a.created_by, a.created_by_alias, '.
                'a.modified, a.modified_by, '.
                'a.checked_out, a.checked_out_time, ' .
				'a.state, a.publish_up, a.publish_down, ' .
				'a.access, a.asset_id, a.version, a.language, a.ordering, ' .
                'a.metakey, a.metadesc, a.metadata, ' .
				'a.parameters,' .
				'a.company_status, a.company_name,' .
				'a.company_director, a.company_address,' .
				'a.company_address_complement, a.company_postbox,' .
				'a.company_postcode, a.company_town,' .
				'a.company_state, a.company_country,' .
				'a.company_phone, a.company_fax,' .
				'a.company_mobile, a.company_email,' .
				'a.company_url, a.company_siren,' .
				'a.company_siret, a.company_ape,' .
				'a.company_tva, a.company_capital,' .
				'a.company_cnil,' .
				'a.editor_name, a.editor_address,' .
				'a.editor_address_complement, a.editor_postbox,' .
				'a.editor_postcode, a.editor_city,' .
				'a.editor_country, a.editor_email,' .
				'a.editor_phone, a.editor_fax,' .
				'a.editor_url, a.host_name,' .
				'a.host_address, a.host_address_complement,' .
				'a.host_postbox, a.host_postcode,' .
				'a.host_city, a.host_country,' .
				'a.host_email, a.host_phone,' .
				'a.host_fax, a.host_url,' .
				'a.legals_title, a.legals_display_title,' .
				'a.legals_alias, a.legals_meta_title,' .
				'a.legals_meta_description, a.legals_meta_keywords,' .
				'a.use_terms, a.use_policy, a.use_delivery'
			)
		);
		$query->from('#__prestalegals AS a');

04 - Modification des fichiers helpers

Comme nous ne gérons pas les catégories, nous devons enlever l'affichage des catégories sur la page liste.

administrator/components/com_prestalegals/helpers/prestalegals.php

Suppression des lignes :

		JSubMenuHelper::addEntry(
			JText::_('COM_PRESTALEGALS_SUBMENU_CATEGORIES'),
			'index.php?option=com_categories&extension=com_prestalegals',
			$vName == 'categories');

Suite au prochain article.