<?php

/**
 * Implementation of hook_schema()
 *
 * Creates tables to hold custom permissions to be supplied for
 * hook_permission(), as as well as a table to hold the permission
 * that should be used for existing menu paths
 */
function custom_menu_perms_schema()
{
	$schema['cmp_permissions'] = array
	(
		'description' => 'Stores custom permissions that this module creates dynamically. These permissions will be supplied to hook_permission() when it is called.',
		'fields' => array
		(
			'perm_key' => array
			(
				'description' => 'The permission key used by the system',
				'type' => 'varchar',
				'length' => 255,
				'not null' => TRUE,
			),
			'perm_name' => array
			(
				'description' => 'The human readable name of the permission',
				'type' => 'varchar',
				'length' => 255,
				'not null' => TRUE,
			),
			'description' => array
			(
				'description' => 'The description of the permission',
				'type' => 'text',
			),
		),
		'primary key' => array('perm_key'),
		'indexes' => array
		(
			'perm_name' => array('perm_name'),
		),
	);

	$schema['cmp_menu_perms'] = array
	(
		'description' => 'Stores the custom permission to be used with user_access in order to access a given menu item',
		'fields' => array
		(
			'menu_path' => array
			(
				'description' => 'The menu path to which the permission will be used as the access arguments to be passed to user_access()',
				'type' => 'varchar',
				'length' => 255,
			),
			'cmp_permission_key' => array
			(
				'description' => 'The perm_key from {cmp_permissions} for the permission that should be applied to the given menu path',
				'type' => 'varchar',
				'length' => 255,
			),
		),
		'primary key' => array('menu_path'),
		'indexes' => array
		(
			'cmp_permission_key' => array('cmp_permission_key'),
		),
	);

	return $schema;
}
