<?php /*

 ocPortal
 Copyright (c) ocProducts, 2004-2012

 See text/EN/licence.txt for full licencing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license		http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright	ocProducts Ltd
 * @package		catalogues
 */

class Hook_content_meta_aware_catalogue_entry
{

	/**
	 * Standard modular info function for content_meta_aware hooks. Allows progmattic identification of ocPortal entity model (along with db_meta table contents).
	 *
	 * @return ?array	Map of award content-type info (NULL: disabled).
	 */
	function info()
	{
		return array(
			'content_type_label'=>'catalogues:CATALOGUE_ENTRY',

			'table'=>'catalogue_entries',
			'id_field'=>'id',
			'id_field_numeric'=>true,
			'parent_category_field'=>'cc_id',
			'parent_category_meta_aware_type'=>'catalogue_category',
			'title_field'=>'CALL: generate_catalogue_entry_moniker',
			'title_field_dereference'=>false,

			'is_category'=>false,
			'is_entry'=>true,
			'seo_type_code'=>'catalogue_entry',
			'feedback_type_code'=>'catalogues',
			'permissions_type_code'=>'catalogues_category', // NULL if has no permissions
			'view_pagelink_pattern'=>'_SEARCH:catalogues:entry:_WILD',
			'edit_pagelink_pattern'=>'_SEARCH:cms_catalogues:_ed:_WILD',
			'view_category_pagelink_pattern'=>'_SEARCH:catalogues:category:_WILD',
			'support_url_monikers'=>true,
			'search_hook'=>'catalogue_entries',
			'views_field'=>'ce_views',
			'submitter_field'=>'ce_submitter',
			'add_time_field'=>'ce_add_date',
			'edit_time_field'=>'ce_edit_date',
			'validated_field'=>'ce_validated',
			
			'addon_name'=>'catalogues',
			
			'module'=>'catalogues',

			'ocselect'=>'catalogues::_catalogues_ocselect',
			'ocselect_protected_fields'=>array(), // These are ones even some staff should never know
		);
	}
	
}

/**
 * Generate a catalogue entry URL moniker.
 *
 * @param  array	The URL parts to generate the moniker from.
 * @return string The generated moniker.
 */
function generate_catalogue_entry_moniker($url_parts)
{
	require_code('catalogues');
	$fields=get_catalogue_entry_field_values(NULL,intval($url_parts['id']),array(0),NULL);
	$field=array_shift($fields);
	$value=array_key_exists('effective_value_pure',$field)?$field['effective_value_pure']:$field['effective_value'];
	return strip_comcode($value);
}
