-
Notifications
You must be signed in to change notification settings - Fork 0
/
PagesModel.class.php
executable file
·68 lines (55 loc) · 1.44 KB
/
PagesModel.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
// Copyright 2014 Aleksandr Tsiolko
if (!defined("IN_ESOTALK")) exit;
class PagesModel extends ETModel {
public function __construct()
{
parent::__construct("page", "pageId");
}
public function getWithSQL($sql)
{
return $sql
->select("f.*")
->from("page f")
->orderBy("f.position ASC")
->exec()
->allRows();
}
public function setData($values)
{
if (!isset($values["title"])) $values["title"] = "";
$this->validate("title", $values["title"], array($this, "validateTitle"));
if (!isset($values["menu"])) $values["menu"] = "user";
$this->validate("menu", $values["menu"], array($this, "validateMenu"));
if (!isset($values["slug"])) $values["slug"] = "";
$this->validate("slug", $values["slug"], array($this, "validateSlug"));
$values["slug"] = slug($values["slug"]);
if ($this->errorCount()) return false;
$pageId = parent::create($values);
return $pageId;
}
public function deleteById($id)
{
return $this->delete(array("pageId" => $id));
}
public function validateTitle($title)
{
if (!strlen($title)) return "empty";
}
public function validateMenu($menu)
{
if (!in_array($menu, array('user','statistics','meta'))) return "empty";
}
public function validateSlug($slug)
{
if (!strlen($slug)) return "empty";
if (ET::SQL()
->select("COUNT(pageId)")
->from("page")
->where("slug=:slug")
->bind(":slug", $slug)
->exec()
->result() > 0)
return "channelSlugTaken";
}
}