Paperyard
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
paperyard
paperyard
frontend
models
rule
Rule.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Paperyard\Models\Rule
;
4
5
use
Illuminate\Database\Eloquent\Model
;
6
use
Valitron\Validator
;
7
8
class
Rule
extends
Model
9
{
11
const
TAG_REGEX
=
'/^([ÄäÜüÖöß\sa-zA-Z0-9]+,)*[ÄäÜüÖöß\sa-zA-Z0-9]+$/'
;
12
14
protected
$attributes
= array(
15
'isActive'
=> 0
16
);
17
19
protected
$rules
;
20
22
protected
$labels
;
23
25
public
$errors
= [];
26
32
public
function
setIsActiveAttribute
($value)
33
{
34
$this->attributes[
'isActive'
] = (int)($value ==
'on'
);
35
}
36
40
private
function
validate
()
41
{
42
// new validator object
43
$validator =
new
Validator($this->getAttributes());
44
45
// pass rules
46
$validator->rules($this->rules);
47
48
// add labels (we dont want to show internal names to the user)
49
$validator->labels($this->labels);
50
51
// check rules
52
if
(!$validator->validate()) {
53
$this->errors = $validator->errors();
54
}
55
}
56
62
public
function
validateAndSave
()
63
{
64
// check rules
65
$this->
validate
();
66
67
// return result
68
if
(empty($this->errors)) {
69
return
$this->save();
70
}
else
{
71
return
false
;
72
}
73
}
74
80
public
function
validateAndUpdate
()
81
{
82
// check rules
83
$this->
validate
();
84
85
// return result
86
if
(empty($this->errors)) {
87
return
$this->update();
88
}
else
{
89
return
false
;
90
}
91
}
92
}
Model
Paperyard\Models\Rule\Rule\$labels
$labels
Definition:
Rule.php:22
Paperyard\Models\Rule\Rule\validateAndUpdate
validateAndUpdate()
Definition:
Rule.php:80
Paperyard\Models\Rule\Rule\validateAndSave
validateAndSave()
Definition:
Rule.php:62
Paperyard\Models\Rule\Rule\validate
validate()
Definition:
Rule.php:40
Paperyard\Models\Rule\Rule\$attributes
$attributes
Definition:
Rule.php:14
Paperyard\Models\Rule\Rule\TAG_REGEX
const TAG_REGEX
Definition:
Rule.php:11
Paperyard\Models\Rule\Rule
Definition:
Rule.php:8
Paperyard\Models\Rule\Rule\$rules
$rules
Definition:
Rule.php:19
Validator
Paperyard\Models\Rule
Definition:
Archive.php:3
Paperyard\Models\Rule\Rule\$errors
$errors
Definition:
Rule.php:25
Paperyard\Models\Rule\Rule\setIsActiveAttribute
setIsActiveAttribute($value)
Definition:
Rule.php:32
Generated by
1.8.11