* Adjust account methods.
This commit is contained in:
@@ -1,15 +1,30 @@
|
||||
<?php
|
||||
global $app;
|
||||
$config->account->form = new stdclass();
|
||||
$config->account->form->create = array();
|
||||
$config->account->form->create['name'] = array('type' => 'string', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['provider'] = array('type' => 'string', 'required' => true, 'default' => '');
|
||||
$config->account->form->create['adminURI'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['account'] = array('type' => 'string', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['password'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['email'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['mobile'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['type'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['status'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['extra'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['name'] = array('type' => 'string', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['provider'] = array('type' => 'string', 'required' => true, 'default' => '');
|
||||
$config->account->form->create['adminURI'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['account'] = array('type' => 'string', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['password'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['email'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['mobile'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['type'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['status'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['extra'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->create['createdBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account);
|
||||
$config->account->form->create['createdDate'] = array('type' => 'string', 'required' => false, 'default' => helper::now());
|
||||
|
||||
$config->account->form->edit = $config->account->form->create;;
|
||||
$config->account->form->edit = array();
|
||||
$config->account->form->edit['name'] = array('type' => 'string', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['provider'] = array('type' => 'string', 'required' => true, 'default' => '');
|
||||
$config->account->form->edit['adminURI'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['account'] = array('type' => 'string', 'required' => true, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['password'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['email'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['mobile'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['type'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['status'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['extra'] = array('type' => 'string', 'required' => false, 'default' => '', 'filter' => 'trim');
|
||||
$config->account->form->edit['editedBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account);
|
||||
$config->account->form->edit['editedDate'] = array('type' => 'string', 'required' => false, 'default' => helper::now());
|
||||
|
||||
+18
-15
@@ -7,12 +7,12 @@ declare(strict_types=1);
|
||||
* @license ZPL (http://zpl.pub/page/zplv11.html)
|
||||
* @author Xiying Guan <guanxiying@xirangit.com>
|
||||
* @package account
|
||||
* @version $Id$
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class account extends control
|
||||
{
|
||||
/**
|
||||
* 查看账号列表。
|
||||
* Browse accouts page.
|
||||
*
|
||||
* @param string $browseType
|
||||
@@ -53,6 +53,7 @@ class account extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个账号。
|
||||
* Create account.
|
||||
*
|
||||
* @access public
|
||||
@@ -62,7 +63,7 @@ class account extends control
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$account = $this->accountZen->buildDataForCreate();
|
||||
$account = form::data($this->config->account->form->create)->get();
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
$this->account->create($account);
|
||||
@@ -78,61 +79,63 @@ class account extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑一个账号。
|
||||
* Edit one account.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $from parent|self
|
||||
* @param int $accountID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function edit(int $id, string $from = 'parent')
|
||||
public function edit(int $accountID)
|
||||
{
|
||||
if($_POST)
|
||||
{
|
||||
$account = $this->accountZen->buildDataForEdit();
|
||||
$account = form::data($this->config->account->form->edit)->get();
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
$changes = $this->account->update($id, $account);
|
||||
$this->account->update($accountID, $account);
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'), 'closeModal' => true));
|
||||
}
|
||||
|
||||
$this->view->title = $this->lang->account->edit;
|
||||
$this->view->account = $this->account->getById($id);
|
||||
$this->view->account = $this->account->fetchByID($accountID);
|
||||
$this->view->rooms = $this->loadModel('serverroom')->getPairs();
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看账号信息。
|
||||
* View account.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $accountID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function view(int $id)
|
||||
public function view(int $accountID)
|
||||
{
|
||||
$this->view->title = $this->lang->account->view;
|
||||
$this->view->account = $this->account->getById($id);
|
||||
$this->view->account = $this->account->fetchByID($accountID);
|
||||
$this->view->rooms = $this->loadModel('serverroom')->getPairs();
|
||||
$this->view->actions = $this->loadModel('action')->getList('account', $id);
|
||||
$this->view->actions = $this->loadModel('action')->getList('account', $accountID);
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noletter');
|
||||
$this->view->optionMenu = $this->loadModel('tree')->getOptionMenu(0, 'account');
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个账号。
|
||||
* Delete Account.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $accountID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function delete(int $id)
|
||||
public function delete(int $accountID)
|
||||
{
|
||||
$this->account->delete(TABLE_ACCOUNT, $id);
|
||||
$this->account->delete(TABLE_ACCOUNT, $accountID);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
|
||||
@@ -7,24 +7,12 @@ declare(strict_types=1);
|
||||
* @license ZPL (http://zpl.pub/page/zplv11.html)
|
||||
* @author Xiying Guan <guanxiying@xirangit.com>
|
||||
* @package account
|
||||
* @version $Id$
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class accountModel extends model
|
||||
{
|
||||
/**
|
||||
* Get account by id.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByID(int $id): object|false
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_ACCOUNT)->where('id')->eq($id)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账号列表。
|
||||
* Get account list.
|
||||
*
|
||||
* @param string $browseType
|
||||
@@ -34,7 +22,7 @@ class accountModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getList(string $browseType = 'all', string $param = '', string $orderBy = 'id_desc', object|null $pager = null)
|
||||
public function getList(string $browseType = 'all', string $param = '', string $orderBy = 'id_desc', object|null $pager = null): array
|
||||
{
|
||||
$query = '';
|
||||
if($browseType == 'bysearch')
|
||||
@@ -67,7 +55,8 @@ class accountModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account pairs
|
||||
* 获取账号的id:name键值对。
|
||||
* Get account pairs.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
@@ -78,7 +67,8 @@ class accountModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Create account
|
||||
* 创建一个账号。
|
||||
* Create account.
|
||||
*
|
||||
* @param object $account
|
||||
* @access public
|
||||
@@ -99,6 +89,7 @@ class accountModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个账号。
|
||||
* Update one account.
|
||||
*
|
||||
* @param int $id
|
||||
@@ -108,7 +99,7 @@ class accountModel extends model
|
||||
*/
|
||||
public function update(int $id, object $account): bool
|
||||
{
|
||||
$oldAccount = $this->getByID($id);
|
||||
$oldAccount = $this->fetchByID($id);
|
||||
$this->dao->update(TABLE_ACCOUNT)->data($account)->autoCheck()
|
||||
->batchCheck($this->config->account->edit->requiredFields, 'notempty')
|
||||
->checkIf($account->email, 'email', 'email')
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
zdTable('account')->gen(10);
|
||||
|
||||
/**
|
||||
|
||||
title=accountModel->getByID();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$accountModel = $tester->loadModel('account');
|
||||
r($accountModel->getByID(0)) && p() && e('0'); // 获取空数据。
|
||||
r((array)$accountModel->getByID(1)) && p('id,name,provider') && e('1,运维账号1,qingyun'); // 获取id=1的数据。
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The zen file of account module of ZenTaoPMS.
|
||||
*
|
||||
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
|
||||
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
|
||||
* @author Yidong Wang <yidong@easycorp.ltd>
|
||||
* @package account
|
||||
* @link https://www.zentao.net
|
||||
*/
|
||||
class accountZen extends account
|
||||
{
|
||||
/**
|
||||
* Build account data for create method.
|
||||
*
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function buildDataForCreate(): object
|
||||
{
|
||||
return form::data()->add('createdBy', $this->app->user->account)
|
||||
->add('createdDate', helper::now())
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build account data for edit method.
|
||||
*
|
||||
* @access protected
|
||||
* @return object
|
||||
*/
|
||||
protected function buildDataForEdit(): object
|
||||
{
|
||||
return form::data()->add('editedBy', $this->app->user->account)
|
||||
->add('editedDate', helper::now())
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user