-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProfilesAdminController.class.php
144 lines (108 loc) · 3.83 KB
/
ProfilesAdminController.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?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 ProfilesAdminController extends ETAdminController {
protected function model()
{
return ET::getInstance("profileFieldModel");
}
protected function plugin()
{
return ET::$plugins["Profiles"];
}
public function action_index()
{
$fields = $this->model()->get();
$this->addCSSFile($this->plugin()->resource("admin.css"));
$this->addJSFile("core/js/lib/jquery.ui.js");
$this->addJSFile($this->plugin()->resource("admin.js"));
$this->addJSLanguage("message.confirmDelete");
$this->data("fields", $fields);
$this->render($this->plugin()->view("admin/fields"));
}
public function action_edit($fieldId = "")
{
// Get this field's details. If it doesn't exist, show an error.
if (!($field = $this->model()->getById((int)$fieldId))) {
$this->render404();
return;
}
// Set up the form.
$form = ETFactory::make("form");
$form->action = URL("admin/profiles/edit/".$field["fieldId"]);
$form->setValues($field);
// Was the cancel button pressed?
if ($form->isPostBack("cancel")) $this->redirect(URL("admin/profiles"));
// Was the save button pressed?
if ($form->validPostBack("save")) {
$data = array(
"name" => $form->getValue("name"),
"description" => $form->getValue("description"),
"type" => $form->getValue("type"),
"options" => $form->getValue("options"),
"showOnPosts" => (bool)$form->getValue("showOnPosts"),
"hideFromGuests" => (bool)$form->getValue("hideFromGuests"),
"searchable" => (bool)$form->getValue("searchable")
);
$model = $this->model();
$model->updateById($field["fieldId"], $data);
// If there were errors, pass them on to the form.
if ($model->errorCount()) $form->errors($model->errors());
// Otherwise, redirect back to the fields page.
else $this->redirect(URL("admin/profiles"));
}
$this->data("form", $form);
$this->data("field", $field);
$this->render($this->plugin()->view("admin/editField"));
}
public function action_create()
{
// Set up the form.
$form = ETFactory::make("form");
$form->action = URL("admin/profiles/create");
// Was the cancel button pressed?
if ($form->isPostBack("cancel")) $this->redirect(URL("admin/profiles"));
// Was the save button pressed?
if ($form->validPostBack("save")) {
$model = $this->model();
$data = array(
"name" => $form->getValue("name"),
"description" => $form->getValue("description"),
"type" => $form->getValue("type"),
"options" => $form->getValue("options"),
"showOnPosts" => (bool)$form->getValue("showOnPosts"),
"hideFromGuests" => (bool)$form->getValue("hideFromGuests"),
"searchable" => (bool)$form->getValue("searchable"),
"position" => $model->count()
);
$model->create($data);
// If there were errors, pass them on to the form.
if ($model->errorCount()) $form->errors($model->errors());
// Otherwise, redirect back to the fields page.
else $this->redirect(URL("admin/profiles"));
}
$this->data("form", $form);
$this->data("field", null);
$this->render($this->plugin()->view("admin/editField"));
}
public function action_delete($fieldId = "")
{
if (!$this->validateToken()) return;
// Get this field's details. If it doesn't exist, show an error.
if (!($field = $this->model()->getById((int)$fieldId))) {
$this->render404();
return;
}
$this->model()->deleteById($field["fieldId"]);
$this->redirect(URL("admin/profiles"));
}
public function action_reorder()
{
if (!$this->validateToken()) return;
$ids = (array)R("ids");
for ($i = 0; $i < count($ids); $i++) {
$this->model()->updateById($ids[$i], array("position" => $i));
}
}
}