-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProfileFieldModel.class.php
85 lines (69 loc) · 1.92 KB
/
ProfileFieldModel.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
// Copyright 2014 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.
if (!defined("IN_ESOTALK")) exit;
class ProfileFieldModel extends ETModel {
public function __construct()
{
parent::__construct("profile_field", "fieldId");
}
public function getWithSQL($sql)
{
return $sql
->select("f.*")
->from("profile_field f")
->orderBy("f.position ASC")
->exec()
->allRows();
}
public function getData($memberId)
{
$sql = ET::SQL()
->select("d.data")
->from("profile_data d", "d.fieldId=f.fieldId AND d.memberId=:memberId", "left")
->bind(":memberId", $memberId);
return $this->getWithSQL($sql);
}
public function setData($memberId, $fieldId, $data)
{
ET::SQL()
->insert("profile_data")
->set("memberId", $memberId)
->set("fieldId", $fieldId)
->set("data", $data)
->setOnDuplicateKey("data", $data)
->exec();
}
public function delete($wheres = array())
{
return ET::SQL()
->delete("f, d")
->from("profile_field f")
->from("profile_data d", "f.fieldId=d.fieldId", "left")
->where($wheres)
->exec();
}
public function deleteById($id)
{
return $this->delete(array("f.fieldId" => $id));
}
public function update($values, $wheres = array())
{
if (in_array($values["type"], array("select", "radios", "checkboxes")))
$this->validate("options", $values["options"], array($this, "validateOptions"));
if ($this->errorCount()) return false;
return parent::update($values, $wheres);
}
public function create($values, $wheres = array())
{
if (in_array($values["type"], array("select", "radios", "checkboxes")))
$this->validate("options", $values["options"], array($this, "validateOptions"));
if ($this->errorCount()) return false;
return parent::create($values);
}
public function validateOptions($options)
{
$options = trim($options);
if (!strlen($options)) return "empty";
}
}