|
@@ -80,4 +80,88 @@ class UserPower extends Backend
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ */
|
|
|
+ public function add()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+ if (!$params) {
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $result = false;
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
+ $this->model->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
|
|
|
+ $params['private_messages_time'] = strtotime($params['private_messages_time']);
|
|
|
+ }
|
|
|
+ if (isset($params['speak_time']) && !empty($params['speak_time'])) {
|
|
|
+ $params['speak_time'] = strtotime($params['speak_time']);
|
|
|
+ }
|
|
|
+ $result = $this->model->allowField(true)->save($params);
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result == false) {
|
|
|
+ $this->error(__('No rows were inserted'));
|
|
|
+ }
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ */
|
|
|
+ public function edit($ids = null)
|
|
|
+ {
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if (!$params) {
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+ $result = false;
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
+ $row->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ if (isset($params['private_messages_time']) && !empty($params['private_messages_time'])) {
|
|
|
+ $params['private_messages_time'] = strtotime($params['private_messages_time']);
|
|
|
+ }
|
|
|
+ if (isset($params['speak_time']) && !empty($params['speak_time'])) {
|
|
|
+ $params['speak_time'] = strtotime($params['speak_time']);
|
|
|
+ }
|
|
|
+ $result = $row->allowField(true)->save($params);
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result == false) {
|
|
|
+ $this->error(__('No rows were updated'));
|
|
|
+ }
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+ $this->view->assign("row", $row);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
}
|