web-dev-qa-db-ja.com

ユーザーグループに基づいてユーザー登録を制限する方法

誰かが私を助けてくれるかどうか疑問に思っています。サイトに登録するユーザーの数を制限できるプラグインを開発しましたが、特定のユーザーグループに制限することでさらに開発したいと思います。

これはこれまでのところ私のコードです:

<?php
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

class plguserlimit extends JPlugin {

function __construct(&$subject, $config = array()) {
    parent::__construct($subject, $config);
}

public function onUserBeforeSave($user, $isnew, $new) {
    if ($isnew) {
        $limit   = $this->params->get('limit-text');
        $db    = JFactory::getDbo();
        $query = "select id from #__users";
        $db->setQuery($query);
        $db->query();
        $num_rows = $db->getNumRows();
        if ($limit > $num_rows) {
            echo $erMsg = "Sorry but you have exceeded your allocated number of licenses.<BR><BR>Please press the back button on your browser to go back to the previous page.<BR><BR> If you wish to purchase more licences please contact customer support team ";
            die;
            JFactory::getApplication()->redirect(JURI::base(), $erMsg, 'error');
        }
    }
}
}


<extension type="plugin" version="3.0" group="user" method="upgrade">
<name>plg_user_register_limit</name> 
<creationDate>June 2014</creationDate> 
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> 
<version>1.0.0</version> 
<description>
    <![CDATA[ 
        this plugin is used for limiting user registering
    ]]> 
    </description>
<files>
    <filename plugin="registerlimit">registerlimit.php</filename> 
    <filename>index.html</filename> 
    </files>
    <languages>
        <language tag="en-GB">en-GB.plg_user_regitesrlimit.ini</language> 
        <language tag="en-GB">en-GB.plg_user_regitesrlimit.sys.ini</language> 
        </languages>
        <config>
            <fields name="params">
                <fieldset name="basic">
                    <field name="limit-text" type="text" default="" label="Enter user Limit" description="Set limit" /> 
</fieldset>
</fields>
</config>
</extension>
3
user2513528

ユーザーグループごとに登録を制限するには、特定のグループのユーザー数を確認するために#_user_usergroup_mapテーブルを使用する必要があります。

SELECT * FROM #_user_usergroup_map どこ group_id = 'GROUP_ID';

ここで、特定のgroup_id値を置き換えます。

3
Nick