<commit_before><?php
/**
 * OpenEyes.
 *
 * (C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011
 * (C) OpenEyes Foundation, 2011-2013
 * This file is part of OpenEyes.
 * OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * OpenEyes 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 General Public License for more details.
 * You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see <http://www.gnu.org/licenses/>.
 *
 * @link http://www.openeyes.org.uk
 *
 * @author OpenEyes <<EMAIL>>
 * @copyright Copyright (c) 2008-2011, Moorfields Eye Hospital NHS Foundation Trust
 * @copyright Copyright (c) 2011-2013, OpenEyes Foundation
 * @license http://www.gnu.org/licenses/gpl-3.0.html The GNU General Public License V3.0
 */

namespace OEModule\OphCiExamination\models;

use Yii;

/**
 * This is the model class for table "et_ophciexamination_refraction".
 *
 * The followings are the available columns in table:
 *
 * @property string $id
 * @property int $event_id
 * @property int $eye_id
 * @property decimal $left_sphere
 * @property decimal $left_cylinder
 * @property int $left_axis
 * @property string $left_axis_eyedraw
 * @property string $left_type_id
 * @property string $left_type_other
 * @property decimal $right_sphere
 * @property decimal $right_cylinder
 * @property int $right_axis
 * @property string $right_axis_eyedraw
 * @property string $right_type_id
 * @property string $right_type_other
 */
class Element_OphCiExamination_Refraction extends \SplitEventTypeElement
{
    public $service;

    /**
     * Returns the static model of the specified AR class.
     *
     * @return the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'et_ophciexamination_refraction';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        return array(
            array('left_sphere, left_cylinder, left_axis, left_axis_eyedraw, left_type_id, left_type_other, right_sphere, right_cylinder, right_axis, right_axis_eyedraw, right_type_id, right_type_other, eye_id, left_notes, right_notes', 'safe'),
            array('left_sphere', 'requiredSphere', 'side' => 'left', 'eye_id' => '1'),
            array('left_cylinder', 'requiredCylinder', 'side' => 'left','eye_id' => '1'),
            array('left_axis', 'requiredIfSide', 'side' => 'left'),
            array('left_axis', 'numerical', 'integerOnly' => true),
            array('left_type_other', 'requiredIfRefractionTypeOther', 'side' => 'left'),
            array('right_sphere', 'requiredSphere', 'side' => 'right','eye_id' => '2'),
            array('right_cylinder', 'requiredCylinder', 'side' => 'right','eye_id' => '2'),
            array('right_axis', 'requiredIfSide', 'side' => 'right'),
            array('right_axis', 'numerical', 'integerOnly' => true),
            array('right_type_other', 'requiredIfRefractionTypeOther', 'side' => 'right'),
            array('id, event_id, left_sphere, left_cylinder, left_axis, left_axis_eyedraw, left_type_id, right_sphere, right_cylinder, right_axis, right_axis_eyedraw, right_type_id, eye_id', 'safe', 'on' => 'search'),
        );
    }

    public function requiredSphere( $attribute, $params )
    {

        $eyeID = (int)$_POST['OEModule_OphCiExamination_models_Element_OphCiExamination_Refraction']['eye_id'];

        if(empty($this->{$params['side'].'_sphere'}) && ($params['eye_id'] == $eyeID) && ($eyeID != 3)){
            $this->addError($attribute, ucfirst($params['side']).' sphere cannot be blank. Please specify a valid refraction.');
        }

        if(empty($this->{$params['side'].'_sphere'}) && $eyeID == 3){
            $this->addError($attribute, ucfirst($params['side']).' sphere cannot be blank. Please specify a valid refraction.');
        }

    }

    public function requiredCylinder( $attribute, $params )
    {
        $eyeID = (int)$_POST['OEModule_OphCiExamination_models_Element_OphCiExamination_Refraction']['eye_id'];

        if(empty($this->{$params['side'].'_cylinder'}) && ($params['eye_id'] == $eyeID) && ($eyeID != 3)){
            $this->addError($attribute, ucfirst($params['side']).' cylinder cannot be blank. Please specify a valid refraction.');
        }

        if(empty($this->{$params['side'].'_cylinder'}) && $eyeID == 3){
            $this->addError($attribute, ucfirst($params['side']).' cylinder cannot be blank. Please specify a valid refraction.');
        }
        
    }

    public function requiredIfRefractionTypeOther($attribute, $params)
    {
        if (($params['side'] === 'left' && $this->left_type_id === '') || ($params['side'] === 'right' && $this->right_type_id === '')) {
            if (empty($this->{$params['side'].'_type_other'})) {
                $this->addError($attribute, ucfirst($params['side']).' Other cannot be blank. Please specify a valid refraction.');
            }
        }
    }

    public function sidedFields()
    {
        return array('sphere', 'cylinder', 'axis', 'axis_eyedraw', 'type_id', 'type_other');
    }

    public function sidedDefaults()
    {
        return array('axis' => 0, 'type_id' => 1);
    }

    public function canCopy()
    {
        return true;
    }

    public function setDefaultOptions()
    {
        $this->left_axis = 0;
        $this->right_axis = 0;<commit_msg>Remove _POST from validation functions<commit_after><?php
/**
 * OpenEyes.
 *
 * (C) Moorfields Eye Hospital NHS Foundation Trust, 2008-2011
 * (C) OpenEyes Foundation, 2011-2013
 * This file is part of OpenEyes.
 * OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 * OpenEyes 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 General Public License for more details.
 * You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see <http://www.gnu.org/licenses/>.
 *
 * @link http://www.openeyes.org.uk
 *
 * @author OpenEyes <<EMAIL>>
 * @copyright Copyright (c) 2008-2011, Moorfields Eye Hospital NHS Foundation Trust
 * @copyright Copyright (c) 2011-2013, OpenEyes Foundation
 * @license http://www.gnu.org/licenses/gpl-3.0.html The GNU General Public License V3.0
 */

namespace OEModule\OphCiExamination\models;

use Yii;

/**
 * This is the model class for table "et_ophciexamination_refraction".
 *
 * The followings are the available columns in table:
 *
 * @property string $id
 * @property int $event_id
 * @property int $eye_id
 * @property decimal $left_sphere
 * @property decimal $left_cylinder
 * @property int $left_axis
 * @property string $left_axis_eyedraw
 * @property string $left_type_id
 * @property string $left_type_other
 * @property decimal $right_sphere
 * @property decimal $right_cylinder
 * @property int $right_axis
 * @property string $right_axis_eyedraw
 * @property string $right_type_id
 * @property string $right_type_other
 */
class Element_OphCiExamination_Refraction extends \SplitEventTypeElement
{
    public $service;

    /**
     * Returns the static model of the specified AR class.
     *
     * @return the static model class
     */
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'et_ophciexamination_refraction';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        return array(
            array('left_sphere, left_cylinder, left_axis, left_axis_eyedraw, left_type_id, left_type_other, right_sphere, right_cylinder, right_axis, right_axis_eyedraw, right_type_id, right_type_other, eye_id, left_notes, right_notes', 'safe'),
            array('left_sphere', 'requiredSphere', 'side' => 'left', 'eye_id' => '1'),
            array('left_cylinder', 'requiredCylinder', 'side' => 'left','eye_id' => '1'),
            array('left_axis', 'requiredIfSide', 'side' => 'left'),
            array('left_axis', 'numerical', 'integerOnly' => true),
            array('left_type_other', 'requiredIfRefractionTypeOther', 'side' => 'left'),
            array('right_sphere', 'requiredSphere', 'side' => 'right','eye_id' => '2'),
            array('right_cylinder', 'requiredCylinder', 'side' => 'right','eye_id' => '2'),
            array('right_axis', 'requiredIfSide', 'side' => 'right'),
            array('right_axis', 'numerical', 'integerOnly' => true),
            array('right_type_other', 'requiredIfRefractionTypeOther', 'side' => 'right'),
            array('id, event_id, left_sphere, left_cylinder, left_axis, left_axis_eyedraw, left_type_id, right_sphere, right_cylinder, right_axis, right_axis_eyedraw, right_type_id, eye_id', 'safe', 'on' => 'search'),
        );
    }

    public function requiredSphere( $attribute, $params )
    {

        $eyeID = (int)$this->eye_id;

        if(empty($this->{$params['side'].'_sphere'}) && ($params['eye_id'] == $eyeID) && ($eyeID != 3)){
            $this->addError($attribute, ucfirst($params['side']).' sphere cannot be blank. Please specify a valid refraction.');
        }

        if(empty($this->{$params['side'].'_sphere'}) && $eyeID == 3){
            $this->addError($attribute, ucfirst($params['side']).' sphere cannot be blank. Please specify a valid refraction.');
        }
    }

    public function requiredCylinder( $attribute, $params )
    {

        $eyeID = (int)$this->eye_id;
        if(empty($this->{$params['side'].'_cylinder'}) && ($params['eye_id'] == $eyeID) && ($eyeID != 3)){
            $this->addError($attribute, ucfirst($params['side']).' cylinder cannot be blank. Please specify a valid refraction.');
        }

        if(empty($this->{$params['side'].'_cylinder'}) && $eyeID == 3){
            $this->addError($attribute, ucfirst($params['side']).' cylinder cannot be blank. Please specify a valid refraction.');
        }

    }

    public function requiredIfRefractionTypeOther($attribute, $params)
    {
        if (($params['side'] === 'left' && $this->left_type_id === '') || ($params['side'] === 'right' && $this->right_type_id === '')) {
            if (empty($this->{$params['side'].'_type_other'})) {
                $this->addError($attribute, ucfirst($params['side']).' Other cannot be blank. Please specify a valid refraction.');
            }
        }
    }

    public function sidedFields()
    {
        return array('sphere', 'cylinder', 'axis', 'axis_eyedraw', 'type_id', 'type_other');
    }

    public function sidedDefaults()
    {
        return array('axis' => 0, 'type_id' => 1);
    }

    public function canCopy()
    {
        return true;
    }

    public function setDefaultOptions()
    {
        $this->left_axis = 0;
        $this->right_axis = 0;
{'fraction_non_alphanumeric': 0.14182692307692307, 'fraction_numerical': 0.008413461538461538, 'mean_word_length': 3.44279176201373, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '3637079', 'n_tokens_mistral': 3606, 'n_tokens_neox': 3412, 'n_words': 955}