<commit_before><?php
App::import('Model', 'EvaluationMixeval');
App::import('Model', 'EvaluationMixevalDetail');

/**
 * Event
 *
 * @uses AppModel
 * @package   CTLT.iPeer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 All rights reserved.
 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
 */
class Event extends AppModel
{
    public $name = 'Event';
    /* Accordion's panelHeight - Height various based on the no. of questions and evaluation types*/
    public $SIMPLE_EVAL_HEIGHT = array('2'=>'200', '3'=>'250');
    public $RUBRIC_EVAL_HEIGHT = array('2'=>'200', '3'=>'250');

    public $validate = array(
        'title' => array('rule' => 'notEmpty',
        'message' => 'Title is required.',
        'allowEmpty' => false),
        'due_date' => '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( ([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d)*$/',
        'release_date_begin' => '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( ([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d)*$/',
        'release_date_end' => '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( ([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d)*$/'
    );

    public $actsAs = array('ExtendAssociations', 'Containable', 'Habtamable', 'Traceable');

    /* tables related: events, group_events,
     * evaluation_submissions,
     * evaluation_rubrics, evaluation_rubrics_details,
     * evaluation_simples,
     * evaluation_mixevals, evaluation_mixeval_details
     */

    public $belongsTo = array('EventTemplateType', 'Course');

    public $hasAndBelongsToMany = array('Group' =>
        array('className'    =>  'Group',
            'joinTable'    =>  'group_events',
            'foreignKey'   =>  'event_id',
            'associationForeignKey'    =>  'group_id',
            'conditions'   =>  '',
            'order'        =>  '',
            'limit'        => '',
            'unique'       => true,
            'finderQuery'  => '',
            'deleteQuery'  => '',
            'dependent'    => false,
        ),
    );

    public $hasMany = array(
        'GroupEvent' =>
        array(
            'className' => 'GroupEvent',
            'conditions' => '',
            'order' => '',
            'dependent' => true,
            'foreignKey' => 'event_id'
        ),
        'EvaluationSubmission' =>
        array(
            'className' => 'EvaluationSubmission',
            'conditions' => '',
            'order' => '',
            'dependent' => true,
            'foreignKey' => 'event_id'
        ),
 /*                     'EvaluationRubric' =>
                        array(
                          'className' => 'EvaluationRubric',
                          'conditions' => '',
                          'order' => '',
                          'dependent' => true,
                          'foreignKey' => 'event_id'
                        ),
                      'EvaluationSimple' =>
                        array(
                          'className' => 'EvaluationSimple',
                          'conditions' => '',
                          'order' => '',
                          'dependent' => true,
                          'foreignKey' => 'event_id'
                        ),
                      'EvaluationMixeval' =>
                        array(
                          'className' => 'EvaluationMixeval',
                          'conditions' => '',
                          'order' => '',
                          'dependent' => true,
                          'foreignKey' => 'event_id'
 )*/
    );

    /**
     * __construct
     *
     * @param bool $id    id
     * @param bool $table table
     * @param bool $ds    data source
     *
     * @access protected
     * @return void
     */
    function __construct($id = false, $table = null, $ds = null)
    {
        parent::__construct($id, $table, $ds);
        $this->virtualFields['response_count'] = sprintf('SELECT count(*) as count FROM evaluation_submissions as sub WHERE sub.event_id = %s.id', $this->alias);
        $this->virtualFields['to_review_count'] = sprintf('SELECT count(*) as count FROM group_events as ge WHERE ge.event_id = %s.id AND marked LIKE "to review"', $this->alias);
        $this->virtualFields['student_count'] = sprintf('SELECT count(*) as count FROM group_events as vge RIGHT JOIN groups_members as vgm ON vge.group_id = vgm.group_id WHERE vge.event_id = %s.id', $this->alias);
        $this->virtualFields['completed_count'] = sprintf('SELECT count(*) as count FROM evaluation_submissions as ves WHERE ves.submitted = 1 AND ves.event_id = %s.id', $this->alias);
    }


    /**
     * beforeSave
     * Overwriting Function - will be called before save operation
     *
     *
     * @access public
     * @return void
     */
    function beforeSave()
    {
        // Ensure the name is not empty
        if (empty($this->data[$this->name]['title'])) {
            $this->errorMessage = "Please enter a new name for this " . $this->name . ".";
            return false;
        }

        // Remove any signle quotes in the name, so that custom SQL queries are not confused.
        $this->data[$this->name]['title'] =
            str_replace("'", "", $this->data[$this->name]['title']);

        $allowSave = true;
        if (empty($this->data[$this->name]['id'])) {
            //check the duplicate title
            $allowSave = $this->__checkDuplicateTitle();
        }
        return $allowSave;
    }

    /**
     * __checkDuplicateTitle
     * Validation check on duplication of title
     *
     * @param bool $title
     *
     * @access protected
     * @return void
     */
    function __checkDuplicateTitle($title = null)
    {
        $duplicate = false;
        $field = 'title';
        $value = null === $title ? $this->data[$this->name]['title'] : $title;
        if ($result =  $this->find('all', array('conditions' => array('title'=>$value), 'fields'=>'title' ))) {
            $duplicate = true;
        }

        if ($duplicate == true) {
            $this->errorMessage='Duplicate Title found. Please change the title of this event.';
            return false;
        } else {
            return true;
        }
    }


    /**
     * prepData
     * parses the grous from the hidden field assigned
     *
     * @param bool $data
     *
     * @access public
     * @return void
     */
    function prepData($data=null)
    {
        $tmp = $data['form']['assigned'];
        $num = null;
        $member_count=0;

        // parse group member id
        for ($i=0; $i<strlen($tmp); $i++) {
            if ($tmp{$i} != ":" ) {<commit_msg>Fixed the error when creating new surveys<commit_after><?php
App::import('Model', 'EvaluationMixeval');
App::import('Model', 'EvaluationMixevalDetail');

/**
 * Event
 *
 * @uses AppModel
 * @package   CTLT.iPeer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 All rights reserved.
 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
 */
class Event extends AppModel
{
    public $name = 'Event';
    /* Accordion's panelHeight - Height various based on the no. of questions and evaluation types*/
    public $SIMPLE_EVAL_HEIGHT = array('2'=>'200', '3'=>'250');
    public $RUBRIC_EVAL_HEIGHT = array('2'=>'200', '3'=>'250');

    public $validate = array(
        'title' => array('rule' => 'notEmpty',
        'message' => 'Title is required.',
        'allowEmpty' => false),
        'due_date' => '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( ([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d)*$/',
        'release_date_begin' => '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( ([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d)*$/',
        'release_date_end' => '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( ([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d)*$/'
    );

    public $actsAs = array('ExtendAssociations', 'Containable', 'Habtamable', 'Traceable');

    /* tables related: events, group_events,
     * evaluation_submissions,
     * evaluation_rubrics, evaluation_rubrics_details,
     * evaluation_simples,
     * evaluation_mixevals, evaluation_mixeval_details
     */

    public $belongsTo = array('EventTemplateType', 'Course');

    public $hasAndBelongsToMany = array('Group' =>
        array('className'    =>  'Group',
            'joinTable'    =>  'group_events',
            'foreignKey'   =>  'event_id',
            'associationForeignKey'    =>  'group_id',
            'conditions'   =>  '',
            'order'        =>  '',
            'limit'        => '',
            'unique'       => true,
            'finderQuery'  => '',
            'deleteQuery'  => '',
            'dependent'    => false,
        ),
    );

    public $hasMany = array(
        'GroupEvent' =>
        array(
            'className' => 'GroupEvent',
            'conditions' => '',
            'order' => '',
            'dependent' => true,
            'foreignKey' => 'event_id'
        ),
        'EvaluationSubmission' =>
        array(
            'className' => 'EvaluationSubmission',
            'conditions' => '',
            'order' => '',
            'dependent' => true,
            'foreignKey' => 'event_id'
        ),
 /*                     'EvaluationRubric' =>
                        array(
                          'className' => 'EvaluationRubric',
                          'conditions' => '',
                          'order' => '',
                          'dependent' => true,
                          'foreignKey' => 'event_id'
                        ),
                      'EvaluationSimple' =>
                        array(
                          'className' => 'EvaluationSimple',
                          'conditions' => '',
                          'order' => '',
                          'dependent' => true,
                          'foreignKey' => 'event_id'
                        ),
                      'EvaluationMixeval' =>
                        array(
                          'className' => 'EvaluationMixeval',
                          'conditions' => '',
                          'order' => '',
                          'dependent' => true,
                          'foreignKey' => 'event_id'
 )*/
    );

    /**
     * __construct
     *
     * @param bool $id    id
     * @param bool $table table
     * @param bool $ds    data source
     *
     * @access protected
     * @return void
     */
    function __construct($id = false, $table = null, $ds = null)
    {
        parent::__construct($id, $table, $ds);
        $this->virtualFields['response_count'] = sprintf('SELECT count(*) as count FROM evaluation_submissions as sub WHERE sub.event_id = %s.id', $this->alias);
        $this->virtualFields['to_review_count'] = sprintf('SELECT count(*) as count FROM group_events as ge WHERE ge.event_id = %s.id AND marked LIKE "to review"', $this->alias);
        $this->virtualFields['student_count'] = sprintf('SELECT count(*) as count FROM group_events as vge RIGHT JOIN groups_members as vgm ON vge.group_id = vgm.group_id WHERE vge.event_id = %s.id', $this->alias);
        $this->virtualFields['completed_count'] = sprintf('SELECT count(*) as count FROM evaluation_submissions as ves WHERE ves.submitted = 1 AND ves.event_id = %s.id', $this->alias);
    }


    /**
     * beforeSave
     * Overwriting Function - will be called before save operation
     *
     *
     * @access public
     * @return void
     */
    function beforeSave()
    {
        // Ensure the name is not empty
        if (empty($this->data[$this->name]['title'])) {
            $this->errorMessage = "Please enter a new name for this " . $this->name . ".";
            return false;
        }

        // Remove any signle quotes in the name, so that custom SQL queries are not confused.
        $this->data[$this->name]['title'] =
            str_replace("'", "", $this->data[$this->name]['title']);

        $allowSave = true;
        if (empty($this->data[$this->name]['id'])) {
            //check the duplicate title
            $allowSave = $this->__checkDuplicateTitle();
        }
        return $allowSave;
    }

    /**
     * __checkDuplicateTitle
     * Validation check on duplication of title
     *
     * @param bool $title
     *
     * @access protected
     * @return void
     */
    function __checkDuplicateTitle($title = null)
    {
        $duplicate = false;
        $field = 'title';

        $value = null === $title ? $this->data[$this->name]['title'] : $title;
        if ($result =  $this->find('all', array('conditions' => array('Event.title'=>$value), 'fields'=>'title' ))) {
            $duplicate = true;
        }

        if ($duplicate == true) {
            $this->errorMessage='Duplicate Title found. Please change the title of this event.';
            return false;
        } else {
            return true;
        }
    }


    /**
     * prepData
     * parses the grous from the hidden field assigned
     *
     * @param bool $data
     *
     * @access public
     * @return void
     */
    function prepData($data=null)
    {
        $tmp = $data['form']['assigned'];
        $num = null;
        $member_count=0;

        // parse group member id
        for ($i=0; $i<strlen($tmp); $i++) {
            if ($tmp{$i} != ":" ) {
{'fraction_non_alphanumeric': 0.16718242886255566, 'fraction_numerical': 0.017057891161597102, 'mean_word_length': 1.7853689299978979, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2716178', 'n_tokens_mistral': 4072, 'n_tokens_neox': 3888, 'n_words': 824}