<?php 
class isUnique extends CValidator{

    /**
    * Validates the attribute of the object.
    * If there is any error, the error message is added to the object.
    * @param CModel $object the object being validated
    * @param string $attribute the attribute being validated
    */
    protected function validateAttribute($object,$attribute)
    {

        //FIXME: Check with the ExtensionManager if this extension already exists (e.g. Queues, IVR's, Conference Rooms etc)
        
        $model = $object->findByAttributes(array($attribute=>$object->$attribute));

        if (!$model) {
            return true;
        }
         
        if ($object->isNewRecord() && $object->$attribute!=$model->$attribute){
            return true;

        } else if (!$object->isNewRecord() && $model->id == $object->id) {
            return true;
        }
        $object->addError($attribute, __('PHONALISA_VALIDATORS_ISUNIQUE_ERROR_MESSAGE'));
        return false;
    }
} 
?>