This article for those who wants integrate the ability of restrict something in their components with Mighty Member.
This is very easy task that you can accomplish in 2 steps.
Step 1: Prepare restriction parameter.
The main idea for step 1 is to allow admin to chose what plan should restrict what action and save it.
First you need to provide to admin of your component ability to set what subscriptions restrict what. No matter if you have it as a component parameter, component configuration or component element parameters. You need to show list of available subscription plans. We use parameters for that. First you need to add element to any folder you like but better to JPATH_ADMINISTRATOR.DS.'elements' to do this please save code below in file /administrator/components/com_mycomponent/elements/jssubscriptionplanlist.php
<?php defined('JPATH_BASE') or die(); class JElementJSSubscriptionPlanList extends JElement { function fetchElement($name, $value, &$node, $control_name) { if( !is_dir(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jcs') ){ return '<b>'.JText::sprintf('%sJomsuite Member%s is not installed on your Joomla site', '<a href="index.php?option=com_resource &view=article&article=15&Itemid=9">', '</a>').'</b>'; } if( !is_array($value) ) { $value = array( $value ); } $db = &JFactory::getDBO(); $query = "SELECT sp.id AS value, sp.name AS label, sp.catid, c.title AS cat_title FROM #__jcs_plans AS sp LEFT JOIN #__categories AS c ON c.id = sp.catid WHERE sp.published = 1 ORDER BY c.ordering, c.id, sp.name"; $db->setQuery($query); $plans = $db->loadObjectList(); $options[] = JHTML::_('select.option', '-1', JText::_( 'Everybody' ) ); if( !$plans ) $plans = Array(); $ccatid = ''; foreach ( $plans as $key => $plan ) { if ( $ccatid != $plan->catid ) { $options[] = JHTML::_('select.optgroup', $plan->cat_title ); $ccatid = $plan->catid; } $options[] = JHTML::_('select.option', $plan->value, $plan->label ); } if( count( $options ) >= 11 ) { $size = 11; } else { $size = count( $options ); } return JHTML::_('select.genericlist', $options, $control_name.'['.$name.'][]', 'size="'.$size.'" multiple="multiple"', 'value', 'text', $value ); } } ?>
This is ready param type. Now I will describe how to use it in params but you may use this code as base to find out how to create list of plans.
This is how you can use this param element.
<params addpath="/administrator/components/com_mycomponent/elements"> <param name="plans" type="jssubscriptionplanlist" default="-1" label="Restrict Plans" description="" /> <param name="count_mode" default="0" label="Count Mode"> <option value="0">Do not count</option> <option value="1">Count URL Unique Access</option> <option value="2">Count Every Access</option> </param> </params>
This param xml rendered through JParameter class will show list of plans. You may use it in your component parameters of component item parameters or anywhere. User chose it and you save it somewhere.
Also not that wee need other parameter Count Mode to support subscription times access limitation.
You may approach it differently but follow of main idea of step 1.
Step 2: Protection
To protect you need simple function that check if current user have one of the selected subscriptions active. And count if needed.
From Member v.2.3.1 member have api.php file and you do not need to care about functions. Your example code will looks like this
$API = JPATH_ROOT.DS.'components'.DS.'com_jcs'.DS.'api.php'; if(file_exists($API) && $params->get('plans')) { $res = JSMemberApi::jscCheckSubscription($params->get('plans'), JText::_('You need subscription to access this page'), $itemid, true, $params->get('count_mode')); if($res == 2) JSMemberApi::jscCountLimit($params->get('plans'), $params->get('count_mode')) }
jscCheckSubscription() will redirect to subscription plans or return FALSE if nothing to restrict. 1 if redirection off and user do not have subscription to access and 2 if youse have subscription. So we use jscCountLimit() to increase subscription usage.
on
on 
+1 (209) 800 1209