<commit_before><?php
/**
 * Contains a Yii widget for EyeDraw
 * @package EyeDraw
 * @author <NAME> <<EMAIL>>
 * @version 0.9
 * @link http://www.openeyes.org.uk/
 * @copyright Copyright (c) 2012 OpenEyes Foundation
 * @license http://www.yiiframework.com/license/
 * 
 * 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.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * EyeDraw widget for the Yii framework 
 * This widget inserts a canvas element into a view, and registers all required javascript and css files.
 * - When in edit mode, toolbars are displayed with control buttons and the doodle buttons specified in the optional 'doodleToolBarArray'.
 * - Data is stored and loaded from a hidden input element the name of which corresponds to the attribute of the data model
 * - The attribute should be stored as a TEXT data type in the database
 * - If the input element is empty, a template can be produced by placing EyeDraw commands in the optional 'onLoadedCommandArray.'
 *
 * Usage:
 * <code>
 * <?php
 * $this->widget('ext.widgets.eyeDraw.OEEyeDrawWidget', array(
 * 	'identifier'=> 'PS',
 * 	'side'=>'R',
 * 	'mode'=>'edit',
 * 	'size'=>300,
 * 	'model'=>$model,
 * 	'attribute'=>'eyeDraw1',
 * 	'doodleToolBarArray'=>array('RRD', 'UTear'),
 * 	'onLoadedCommandArray'=>array(
 * 		array('addDoodle', array('Fundus')),
 * 		array('deselectDoodles', array()),
 * 		),
 * 	));
 * ?>
 * </code>
 * The ED.Drawing object can be accessed from Javascript in two ways;
 * 1. Using the variable name derived from the side and identifier, for example 'ed_drawing_edit_RPS'
 * 2. Passed as a parameter to the eDparameterListener function as in the following code snippet;
 * <code>
 * function eDparameterListener(_drawing)
 * {
 *	if (_drawing.selectedDoodle != null)
 *	{
 *		console.log(_drawing.IDSuffix);
 *	}
 * }
 * </code> 
 * @package EyeDraw
 * @author <NAME> <<EMAIL>>
 * @version 0.9
 */
class OEEyeDrawWidget extends CWidget
{
	/**
	 * Unique identifier (eg PS for posterior segment drawing)
	 * @var string
	 */
    public $identifier = 'PS';

	/**
	 * Side (R or L)
	 * @var string
	 */
    public $side = "R";

	/**
	 * Mode ('edit' or 'display')
	 * @var string
	 */
	public $mode = 'edit';

	/**
	 * Size of canvas element in pixels
	 * @var int
	 */
    public $size = 400;

	/**
	 * The model possessing an attribute to store JSON data
	 * @var CActiveRecord
	 */
    public $model;

	/**
	 * Name of the attribute, and also of the corresponding hidden input field
	 * @var string
	 */
    public $attribute;

	/**
	 * Array of doodles to appear in doodle selection toolbar
	 * @var array
	 */
    public $doodleToolBarArray = array();

	/**
	 * Array of commands to apply to the drawing object once images have loaded
	 * @var array
	 */
    public $onLoadedCommandArray = array();
	
	/**
	 * URL of the widget directory
	 * @var string
	 */
	private $jsPath;
	private $cssPath;
	private $imgPath;

	/**
	 * Array of EyeDraw script files required
	 * @todo Seach model attribute and contents of doodleToolBarArray to determine subset of files to register
	 * @var array
	 */
    private $scriptArray = array('Adnexal', 'AntSeg', 'Glaucoma', 'MedicalRetina', 'Strabismus', 'VitreoRetinal');
    
	/**
	 * Concatenation of side and idSuffix used to identify control buttons and other related elements
	 * @var string
	 */	
	private $idSuffix;

	/**
	 * Unique name for the EyeDraw drawing object ('ed_drawing_'.$mode.'_'.$side.$identifier).
	 * For example, ed_drawing_edit_RPS
	 * @var string
	 */	
	private $drawingName;

	/**
	 * Unique id of the canvas element
	 * @var string
	 */		
	private $canvasId;

	/**
	 * Unique name for the input element containing EyeDraw data
	 * @var string
	 */	
	private $inputName;

	/**
	 * Unique id for the input element containing EyeDraw data
	 * @var string
	 */	
	private $inputId;

	/**
	 * Represents the eye using the ED object enumeration (0 = right, 1 = left)
	 * @var int
	 */	
	private $eye;

	/**
	 * Flag indicating whether drawing can be edited
	 * @var bool
	 */
	private $isEditable;
	
	/**
	 * Initializes the widget.
	 * This method registers all needed client scripts and renders the EyeDraw content
	 */
    public function init()
	{
		// Start of widget		
		echo '
<div class="EyeDrawWidget">';
		
        // Set values of derived properties
				$this->cssPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.widgets.eyeDraw.css'));
				$this->jsPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.widgets.eyeDraw.js'));
				$this->imgPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.widgets.eyeDraw.graphics')).'/';
        $this->idSuffix = $this->side.$this->identifier;
        $this->drawingName = 'ed_drawing_'.$this->mode.'_'.$this->idSuffix;
        $this->canvasId = 'ed_canvas_'.$this->mode.'_'.$this->idSuffix;
        if (isset($this->model) && isset($this->attribute))
        {
        	$this->inputName = $this->model->tableName().'['. $this->attribute.']';
        	$this->inputId = $this->model->tableName().'_'. $this->attribute;
        }
        
        $this->eye = $this->side == "R"?0:1;		// ***TODO*** may require additional options
        $this->isEditable = $this->mode == 'edit'?true:false;
        
        // Register the chosen scripts and CSS file
		$this->registerScripts();
        $this->registerCss();
        
        // Show toolbars if in edit mode
        if ($this->isEditable)
        {      
	        // Control toolbar
	        $this->echoControlToolbar();
	        
	        // Doodle toolbar
	        $this->echoDoodleToolbar();<commit_msg>changed the location of eyeDraw to the protected/modules/ directory and updated assetmanager calls appropriately.<commit_after><?php
/**
 * Contains a Yii widget for EyeDraw
 * @package EyeDraw
 * @author <NAME> <<EMAIL>>
 * @version 0.9
 * @link http://www.openeyes.org.uk/
 * @copyright Copyright (c) 2012 OpenEyes Foundation
 * @license http://www.yiiframework.com/license/
 * 
 * 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.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * EyeDraw widget for the Yii framework 
 * This widget inserts a canvas element into a view, and registers all required javascript and css files.
 * - When in edit mode, toolbars are displayed with control buttons and the doodle buttons specified in the optional 'doodleToolBarArray'.
 * - Data is stored and loaded from a hidden input element the name of which corresponds to the attribute of the data model
 * - The attribute should be stored as a TEXT data type in the database
 * - If the input element is empty, a template can be produced by placing EyeDraw commands in the optional 'onLoadedCommandArray.'
 *
 * Usage:
 * <code>
 * <?php
 * $this->widget('application.modules.eyeDraw.OEEyeDrawWidget', array(
 * 	'identifier'=> 'PS',
 * 	'side'=>'R',
 * 	'mode'=>'edit',
 * 	'size'=>300,
 * 	'model'=>$model,
 * 	'attribute'=>'eyeDraw1',
 * 	'doodleToolBarArray'=>array('RRD', 'UTear'),
 * 	'onLoadedCommandArray'=>array(
 * 		array('addDoodle', array('Fundus')),
 * 		array('deselectDoodles', array()),
 * 		),
 * 	));
 * ?>
 * </code>
 * The ED.Drawing object can be accessed from Javascript in two ways;
 * 1. Using the variable name derived from the side and identifier, for example 'ed_drawing_edit_RPS'
 * 2. Passed as a parameter to the eDparameterListener function as in the following code snippet;
 * <code>
 * function eDparameterListener(_drawing)
 * {
 *	if (_drawing.selectedDoodle != null)
 *	{
 *		console.log(_drawing.IDSuffix);
 *	}
 * }
 * </code> 
 * @package EyeDraw
 * @author <NAME> <<EMAIL>>
 * @version 0.9
 */
class OEEyeDrawWidget extends CWidget
{
	/**
	 * Unique identifier (eg PS for posterior segment drawing)
	 * @var string
	 */
    public $identifier = 'PS';

	/**
	 * Side (R or L)
	 * @var string
	 */
    public $side = "R";

	/**
	 * Mode ('edit' or 'display')
	 * @var string
	 */
	public $mode = 'edit';

	/**
	 * Size of canvas element in pixels
	 * @var int
	 */
    public $size = 400;

	/**
	 * The model possessing an attribute to store JSON data
	 * @var CActiveRecord
	 */
    public $model;

	/**
	 * Name of the attribute, and also of the corresponding hidden input field
	 * @var string
	 */
    public $attribute;

	/**
	 * Array of doodles to appear in doodle selection toolbar
	 * @var array
	 */
    public $doodleToolBarArray = array();

	/**
	 * Array of commands to apply to the drawing object once images have loaded
	 * @var array
	 */
    public $onLoadedCommandArray = array();
	
	/**
	 * URL of the widget directory
	 * @var string
	 */
	private $jsPath;
	private $cssPath;
	private $imgPath;

	/**
	 * Array of EyeDraw script files required
	 * @todo Seach model attribute and contents of doodleToolBarArray to determine subset of files to register
	 * @var array
	 */
    private $scriptArray = array('Adnexal', 'AntSeg', 'Glaucoma', 'MedicalRetina', 'Strabismus', 'VitreoRetinal');
    
	/**
	 * Concatenation of side and idSuffix used to identify control buttons and other related elements
	 * @var string
	 */	
	private $idSuffix;

	/**
	 * Unique name for the EyeDraw drawing object ('ed_drawing_'.$mode.'_'.$side.$identifier).
	 * For example, ed_drawing_edit_RPS
	 * @var string
	 */	
	private $drawingName;

	/**
	 * Unique id of the canvas element
	 * @var string
	 */		
	private $canvasId;

	/**
	 * Unique name for the input element containing EyeDraw data
	 * @var string
	 */	
	private $inputName;

	/**
	 * Unique id for the input element containing EyeDraw data
	 * @var string
	 */	
	private $inputId;

	/**
	 * Represents the eye using the ED object enumeration (0 = right, 1 = left)
	 * @var int
	 */	
	private $eye;

	/**
	 * Flag indicating whether drawing can be edited
	 * @var bool
	 */
	private $isEditable;
	
	/**
	 * Initializes the widget.
	 * This method registers all needed client scripts and renders the EyeDraw content
	 */
    public function init()
	{
		// Start of widget		
		echo '
<div class="EyeDrawWidget">';
		
        // Set values of derived properties
				$this->cssPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.eyeDraw.css'));
				$this->jsPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.eyeDraw.js'));
				$this->imgPath = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.modules.eyeDraw.graphics')).'/';
        $this->idSuffix = $this->side.$this->identifier;
        $this->drawingName = 'ed_drawing_'.$this->mode.'_'.$this->idSuffix;
        $this->canvasId = 'ed_canvas_'.$this->mode.'_'.$this->idSuffix;
        if (isset($this->model) && isset($this->attribute))
        {
        	$this->inputName = $this->model->tableName().'['. $this->attribute.']';
        	$this->inputId = $this->model->tableName().'_'. $this->attribute;
        }
        
        $this->eye = $this->side == "R"?0:1;		// ***TODO*** may require additional options
        $this->isEditable = $this->mode == 'edit'?true:false;
        
        // Register the chosen scripts and CSS file
		$this->registerScripts();
        $this->registerCss();
        
        // Show toolbars if in edit mode
        if ($this->isEditable)
        {      
	        // Control toolbar
	        $this->echoControlToolbar();
	        
	        // Doodle toolbar
	        $this->echoDoodleToolbar();
{'fraction_non_alphanumeric': 0.1298980567059573, 'fraction_numerical': 0.003504300732717426, 'mean_word_length': 3.134672374053342, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 121, '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': '4396868', 'n_tokens_mistral': 3984, 'n_tokens_neox': 3694, 'n_words': 1268}