<commit_before><?php
/*=========================================================================
 MIDAS Server
 Copyright (c) Kitware SAS. 26 rue <NAME>. 69100 Villeurbanne, FRANCE
 All rights reserved.
 More information http://www.kitware.com

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0.txt

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
=========================================================================*/
require_once BASE_PATH . '/modules/api/library/APIEnabledNotification.php';
/**
 * Notification manager for the autoregister module.
 *
 * @package Modules\Autoregister\Notification
 */
class Autoregister_Notification extends ApiEnabled_Notification
{
    /** @var string */
    public $moduleName = 'autoregister';
    public $_moduleComponents = array('Api');

    /**  Initialize the notification process. */
    public function init() {
        $fc = Zend_Controller_Front::getInstance();
        $this->moduleWebroot = $fc->getBaseUrl().'/modules/'.$this->moduleName;
        $this->coreWebroot = $fc->getBaseUrl().'/core';
        $this->enableWebAPI($this->moduleName);
        $this->addCallBack('CALLBACK_CORE_NEW_USER_ADDED', 'handleUserAdded');
        $this->addCallBack('CALLBACK_CORE_NEW_COMMUNITY_ADDED', 'handleCommunityAdded');
    }
    //TODO
    //db change
    //adapt existing changes/callbacks to list
    ///** when created, take all comm and add them to db */
    /* when a comm is deleted, if in our db, remove it */
    /* this db is comm and then a boolean that is registered */
    /**
     *
     * @param array $params parameters
     */
    public function handleUserAdded($params) {
        $user = $params['userDao'];
        $communityModel = MidasLoader::loadModel('Community');
        $groupModel = MidasLoader::loadModel('Group');
        $communities = $communityModel->getAll();
        foreach ($communities as $community) {
            $memberGroup = $community->getMemberGroup();
            $groupModel->addUser($memberGroup, $user);
        }
    }

    /**
     *<commit_msg>Add registering users only to targeted communities<commit_after><?php
/*=========================================================================
 MIDAS Server
 Copyright (c) Kitware SAS. 26 rue <NAME>. 69100 Villeurbanne, FRANCE
 All rights reserved.
 More information http://www.kitware.com

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0.txt

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
=========================================================================*/
require_once BASE_PATH . '/modules/api/library/APIEnabledNotification.php';
/**
 * Notification manager for the autoregister module.
 *
 * @package Modules\Autoregister\Notification
 */
class Autoregister_Notification extends ApiEnabled_Notification
{
    /** @var string */
    public $moduleName = 'autoregister';
    public $_moduleComponents = array('Api');

    /**  Initialize the notification process. */
    public function init() {
        $fc = Zend_Controller_Front::getInstance();
        $this->moduleWebroot = $fc->getBaseUrl().'/modules/'.$this->moduleName;
        $this->coreWebroot = $fc->getBaseUrl().'/core';
        $this->enableWebAPI($this->moduleName);
        $this->addCallBack('CALLBACK_CORE_NEW_USER_ADDED', 'handleUserAdded');
        $this->addCallBack('CALLBACK_CORE_NEW_COMMUNITY_ADDED', 'handleCommunityAdded');
    }
    //TODO
    //  default value
    //db change
    //adapt existing changes/callbacks to list
    ///** when created, take all comm and add them to db */
    /* when a comm is deleted, if in our db, remove it */
    /* this db is comm and then a boolean that is registered */
    /**
     *
     * @param array $params parameters
     */
    public function handleUserAdded($params) {
        $user = $params['userDao'];
        $targetedcommunityModel = MidasLoader::loadModel('Targetedcommunity', 'autoregister');
        $communities = $targetedcommunityModel->getAllTargeted();
        $groupModel = MidasLoader::loadModel('Group');
        foreach ($communities as $community) {
            $memberGroup = $community->getMemberGroup();
            $groupModel->addUser($memberGroup, $user);
        }
    }

    /**
     *
{'fraction_non_alphanumeric': 0.16413793103448276, 'fraction_numerical': 0.004334975369458128, 'mean_word_length': 3.5402504472271916, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6563852', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1286, 'n_words': 411}