Source

cruge / models / ui / CrugeAuthItemEditor.php

<?php
/**
CrugeAuthItemEditor

Modelo para editar un CAuthItem.

@author: Christian Salazar H. <christiansalazarh@gmail.com> @salazarchris74
@license protected/modules/cruge/LICENSE
 */
class CrugeAuthItemEditor extends CFormModel
{

    public $name;
    public $businessRule;
    public $description;
    public $categoria;

    public $isNewRecord; // es establecido a true o false directamente desde UiController
    public $deleteConfirmation = false;

    public function onBeforeValidate($event)
    {
        foreach ($this->getIterator() as $atributo => $valor) {
            $this[$atributo] = trim($valor);
        }
    }

    public function rules()
    {
        return array(
            array('name', 'required',),
            array(
                'name',
                'match'
            ,
                'pattern' => '/^([a-zA-Z_-]{3,64})$/'
            ,
                'message' => CrugeTranslator::t(
                    "solo use de 3 a 20 letras (a-z) sin espacios, puede usar caracteres: _-"
                )
            ,
                'on' => 'insert, update'
            ),
            array('name', 'validar_duplicado', 'on' => 'insert'),
            array(
                'description',
                'match'
            ,
                'pattern' => '/^([a-zA-Z0-9.,+\-\_ \{\}\:áéíóúÁÉÍÓÚñÑ]{1,100})$/'
            ,
                'message' => CrugeTranslator::t(
                    "solo use letras A-Z, espacio, digitos o los simbolos .,+-_{}:"
                )
            ),
            array('deleteConfirmation', 'required', 'on' => 'delete'),
            array(
                'deleteConfirmation',
                'compare',
                'compareValue' => '1'
            ,
                'on' => 'delete',
                'message' => CrugeTranslator::t("por favor confirme con la casilla de chequeo")
            ),
            array('businessRule', 'length', 'max' => 512),
        );
    }

    public function validar_duplicado($attr, $param)
    {
        if (Yii::app()->user->rbac->getAuthItem($this[$attr]) !== null) {
            $this->addError($attr, CrugeTranslator::t("este nombre ya esta en uso"));
        }
    }

    public function attributeLabels()
    {
        return array(
            'name' => ucfirst(CrugeTranslator::t('nombre')),
            'description' => ucfirst(CrugeTranslator::t('descripcion corta')),
            'businessRule' => ucfirst(CrugeTranslator::t('regla de negocio')),
            'deleteConfirmation' => ucfirst(CrugeTranslator::t('confirmar eliminacion')),
        );
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.