<commit_before><?php
/**
  * This file is part of taolin project (http://taolin.fbk.eu)
  * Copyright (C) 2008, 2009 FBK Foundation, (http://www.fbk.eu)
  * Authors: SoNet Group (see AUTHORS.txt)
  *
  * Taolin is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
  * the Free Software Foundation version 3 of the License.
  *
  * Taolin is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Affero General Public License for more details.
  *
  * You should have received a copy of the GNU Affero General Public License
  * along with Taolin. If not, see <http://www.gnu.org/licenses/>.
  *
  */

class CommentComponent extends Object {
    var $user = null;
    var $cacheName = TIMELINE_CACHE_FILENAME;
    var $components = array('Conf');

    function addComment(&$Model, $params, $user_id, $tpl_params = array(), $comment_type_name = null, $model_alias = null){
        $mrClean = new Sanitize();
        $notification_data = a();
        
        $foreign_id = $params['form']['foreign_id'];
        $text = $mrClean->html($params['form']['comment']);

        $comment = array('Comment' => array(
            'body' => $text,
            'name' => $user_id,
            'email' => '<EMAIL>'
        ));

        $out = $Model->createComment($foreign_id, $comment);
        $comment_id = $Model->Comment->id;

        if(!$model_alias)
            $model_alias = $Model->alias;
        
        // Retrieve ids belonging to users that have be notified (eg each users that commented this object before)
        $comments = Set::extract(
            $this->getComments($Model, $foreign_id, TRUE),
            '{n}.Comment.name'
        );

        // Remove duplicated values
        $tbn = array_unique($comments);
      
        // Retrieve owner of the commented object
        $owner = $Model->read('user_id', $foreign_id);
        $owner_id =$owner[$model_alias]['user_id'];

        // owner should be notified as well
        if(!in_array($owner_id, $tbn))
            array_push($tbn, $owner_id);

        $users = array_diff($tbn, array($user_id));

        if( !empty($users) ){
            
            $this->setupUserModel();
            $commenter = $this->user->read(array('name', 'surname'), $user_id);
            $owner = $this->user->read(array('name', 'surname'), $owner_id);
            $sender = $this->user->getemail($user_id, $this->Conf->get('Organization.domain'));
            $subject = $this->Conf->get('Site.name')." comment notification";

            foreach($users as $c_id){

                // check whether the user is can be notified or not
                $nfb = $this->user->read('notification', $c_id);
                if($nfb['User']['notification']){

                    if($c_id == $owner_id)
                        $is_owner = true;
                    else 
                        $is_owner = false;

                    array_push($notification_data, array(
                            'from' => $sender,
                            'to' => $this->user->getemail($c_id, $this->Conf->get('Organization.domain')),
                            'subject' => $subject,<commit_msg>Sending notifications to champions only<commit_after><?php
/**
  * This file is part of taolin project (http://taolin.fbk.eu)
  * Copyright (C) 2008, 2009 FBK Foundation, (http://www.fbk.eu)
  * Authors: SoNet Group (see AUTHORS.txt)
  *
  * Taolin is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
  * the Free Software Foundation version 3 of the License.
  *
  * Taolin is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Affero General Public License for more details.
  *
  * You should have received a copy of the GNU Affero General Public License
  * along with Taolin. If not, see <http://www.gnu.org/licenses/>.
  *
  */

class CommentComponent extends Object {
    var $user = null;
    var $cacheName = TIMELINE_CACHE_FILENAME;
    var $components = array('Acl', 'Conf');

    function addComment(&$Model, $params, $user_id, $tpl_params = array(), $comment_type_name = null, $model_alias = null){
        $mrClean = new Sanitize();
        $notification_data = a();
        
        $foreign_id = $params['form']['foreign_id'];
        $text = $mrClean->html($params['form']['comment']);

        $comment = array('Comment' => array(
            'body' => $text,
            'name' => $user_id,
            'email' => '<EMAIL>'
        ));

        $out = $Model->createComment($foreign_id, $comment);
        $comment_id = $Model->Comment->id;

        if(!$model_alias)
            $model_alias = $Model->alias;
        
        // Retrieve ids belonging to users that have be notified (eg each users that commented this object before)
        $comments = Set::extract(
            $this->getComments($Model, $foreign_id, TRUE),
            '{n}.Comment.name'
        );

        // Remove duplicated values
        $tbn = array_unique($comments);
      
        // Retrieve owner of the commented object
        $owner = $Model->read('user_id', $foreign_id);
        $owner_id =$owner[$model_alias]['user_id'];

        // owner should be notified as well
        if(!in_array($owner_id, $tbn))
            array_push($tbn, $owner_id);

        $users = array_diff($tbn, array($user_id));

        if( !empty($users) ){
            
            $this->setupUserModel();
            $commenter = $this->user->read(array('name', 'surname'), $user_id);
            $owner = $this->user->read(array('name', 'surname'), $owner_id);
            $sender = $this->user->getemail($user_id, $this->Conf->get('Organization.domain'));
            $subject = $this->Conf->get('Site.name')." comment notification";

            foreach($users as $c_id){

                // check whether the user is can be notified or not
                $active = $this->Acl->check(
                    array('model' => 'User', 'foreign_key' => $c_id),
                    'site'
                );
                $nfb = $this->user->read('notification', $c_id);
                if($active && $nfb['User']['notification']){

                    if($c_id == $owner_id)
                        $is_owner = true;
                    else 
                        $is_owner = false;

                    array_push($notification_data, array(
                            'from' => $sender,
                            'to' => $this->user->getemail($c_id, $this->Conf->get('Organization.domain')),
                            'subject' => $subject,
{'fraction_non_alphanumeric': 0.13809592812635849, 'fraction_numerical': 0.002608317635125344, 'mean_word_length': 2.141556668183887, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 73, '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': '4918866', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1918, 'n_words': 540}