~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Entity/Help.php

  • Committer: Dan Garner
  • Date: 2015-08-11 09:29:02 UTC
  • mto: This revision was merged to the branch mainline in revision 453.
  • Revision ID: git-v1:a86fb4369b7395c13367577d23b14c0ab4528c1a
Transitions fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
namespace Xibo\Entity;
10
10
use Respect\Validation\Validator as v;
11
 
use Xibo\Exception\InvalidArgumentException;
12
 
use Xibo\Service\LogServiceInterface;
13
 
use Xibo\Storage\StorageServiceInterface;
 
11
use Xibo\Storage\PDOConnect;
14
12
 
15
13
/**
16
14
 * Class Help
46
44
     */
47
45
    public $link;
48
46
 
49
 
    /**
50
 
     * Entity constructor.
51
 
     * @param StorageServiceInterface $store
52
 
     * @param LogServiceInterface $log
53
 
     */
54
 
    public function __construct($store, $log)
55
 
    {
56
 
        $this->setCommonDependencies($store, $log);
57
 
    }
58
 
 
59
47
    public function getId()
60
48
    {
61
49
        return $this->helpId;
68
56
 
69
57
    public function validate()
70
58
    {
71
 
        if (!v::stringType()->notEmpty()->length(1, 254)->validate($this->topic))
72
 
            throw new InvalidArgumentException(__('Topic is a required field. It must be between 1 and 254 characters.'), 'topic');
73
 
 
74
 
        if (!v::stringType()->notEmpty()->length(1, 254)->validate($this->category))
75
 
            throw new InvalidArgumentException(__('Category is a required field. It must be between 1 and 254 characters.'), 'category');
76
 
 
77
 
        if (!v::stringType()->notEmpty()->length(1, 254)->validate($this->link))
78
 
            throw new InvalidArgumentException(__('Link is a required field. It must be between 1 and 254 characters.'), 'link');
 
59
        if (!v::string()->notEmpty()->length(1, 254)->validate($this->topic))
 
60
            throw new \InvalidArgumentException(__('Topic is a required field. It must be between 1 and 254 characters.'));
 
61
 
 
62
        if (!v::string()->notEmpty()->length(1, 254)->validate($this->category))
 
63
            throw new \InvalidArgumentException(__('Category is a required field. It must be between 1 and 254 characters.'));
 
64
 
 
65
        if (!v::string()->notEmpty()->length(1, 254)->validate($this->link))
 
66
            throw new \InvalidArgumentException(__('Link is a required field. It must be between 1 and 254 characters.'));
79
67
    }
80
68
 
81
69
    public function save($validate = true)
91
79
 
92
80
    public function delete()
93
81
    {
94
 
        $this->getStore()->update('DELETE FROM `help` WHERE HelpID = :helpid', [
 
82
        PDOConnect::update('DELETE FROM `help` WHERE HelpID = :helpid', [
95
83
            'helpId' => $this->helpId
96
84
        ]);
97
85
    }
98
86
 
99
87
    private function add()
100
88
    {
101
 
        $this->helpId = $this->getStore()->insert('INSERT INTO `help` (Topic, Category, Link) VALUES (:topic, :category, :link)', [
 
89
        $this->helpId = PDOConnect::insert('INSERT INTO `help` (Topic, Category, Link) VALUES (:topic, :category, :link)', [
102
90
            'topic' => $this->topic,
103
91
            'category' => $this->category,
104
92
            'link' => $this->link
107
95
 
108
96
    private function edit()
109
97
    {
110
 
        $this->getStore()->update('UPDATE `help` SET Topic = :topic, Category = :category, Link = :link WHERE HelpID = :helpid', [
 
98
        PDOConnect::update('UPDATE `help` SET Topic = :topic, Category = :category, Link = :link WHERE HelpID = :helpid', [
111
99
            'helpId' => $this->helpId,
112
100
            'topic' => $this->topic,
113
101
            'category' => $this->category,