public static function _validation_check_mail($val)
31 {
32
33 $input = $val->input('id');
$validation = \Validation::active();
public static function _validation_unique($value, $options, $id = 0)
{
list($table, $field) = explode('.', $options);
$val = Validation::active();
$id = $val->input('id');
$check = DB::select('id', $field)->where($field, '=', $value)->from($table)->execute();
$result = $check->current();
if($check->count() > 0)
{
if($result['id'] === $id)
{
return TRUE;
}
else
{
return FALSE;
}
}
else
return true;
}
public static function _validation_unique($val, $options)
{
// Initialize variable
$model = false;
// Is $options an array?
if ( is_array($options) )
{
// Is it associative?
if ( \Arr::is_assoc($options) )
{
// Then the key is the model
$keys = array_keys($options);
$model = reset($keys);
// And the key's value is table.field
$tbl_field = $options[$model];
}
// No associative array, just an array of [table.field, model]
elseif ( count($options) == 2 )
{
$tbl_field = array_shift($options);
$model = array_shift($options);
}
elseif ( count($options) == 1 )
{
$tbl_field = array_shift($options);
}
// Invalid options
else
{
throw new \InvalidArgumentException('Parameter $options must be either an associative array of [model => table.field] or an array of [table.field, model].');
}
}
// Just a string
else
{
$tbl_field = $options;
}
// Get the table and field separately
list($table, $field) = explode('.', $tbl_field);
// Create the query
$query = \DB::select($field)
->where($field, '=', $val)
->from($table);
// Do we have a model?
if ( $model )
{
// Then get it's primary keys
foreach ( $model::primary_key() as $pk )
{
// And see if there is a post value for these
if ( $value = \Input::post($pk, false) )
{
// Then exclude them from the query
$query->and_where($pk, '!=', $value);
}
}
}
// Execute query
$result = $query->execute();
// No results?
if ( $result->count() == 0)
{
// Then it's unique
return true;
}
// Set the message
\Validation::active()->set_message('unique', 'The field :label must be unique');
// And invaldiate it since the value is not unique
return false;
}
protected static $_properties = array(
'name' => array(
'data_type' => 'varchar',
'character_maximum_length' => 255,
'validation' => array(
'required',
'unique' => array(array('table.field', '\\Groups\\Model\\Group'))
),
),
);
protected static $_properties = array(
'name' => array(
'data_type' => 'varchar',
'character_maximum_length' => 255,
'validation' => array(
'required',
'unique' => array(array('\\Groups\\Model\\Group' => 'table.field'))
),
),
);
protected static $_properties = array(
'name' => array(
'data_type' => 'varchar',
'character_maximum_length' => 255,
'validation' => array(
'required',
'unique' => array('table.field')
),
),
);
'unique' => array(array('users.username', '\\Model\\User'))
It looks like you're new here. If you want to get involved, click one of these buttons!