* refactor browse method for company module.
This commit is contained in:
@@ -65,35 +65,15 @@ class company extends control
|
||||
$sort = $this->loadModel('common')->appendOrder($orderBy);
|
||||
|
||||
/* Build the search form. */
|
||||
$queryID = $type == 'bydept' ? 0 : (int)$param;
|
||||
$this->config->company->browse->search['actionURL'] = $this->createLink('company', 'browse', "param=myQueryID&type=bysearch");
|
||||
$this->config->company->browse->search['queryID'] = $queryID;
|
||||
$this->config->company->browse->search['params']['dept']['values'] = array('' => '') + $this->dept->getOptionMenu();
|
||||
$queryID = $type == 'bydept' ? 0 : (int)$param;
|
||||
$actionURL = $this->createLink('company', 'browse', "param=myQueryID&type=bysearch");
|
||||
$this->company->buildSearchForm($queryID, $actionURL);
|
||||
$this->loadModel('search')->setSearchParams($this->config->company->browse->search);
|
||||
|
||||
if($type == 'bydept')
|
||||
{
|
||||
$childDeptIds = $this->dept->getAllChildID($deptID);
|
||||
$users = $this->dept->getUsers($childDeptIds, $pager, $sort);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($queryID)
|
||||
{
|
||||
$query = $this->search->getQuery($queryID);
|
||||
if($query)
|
||||
{
|
||||
$this->session->set('userQuery', $query->sql);
|
||||
$this->session->set('userForm', $query->form);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->session->set('userQuery', ' 1 = 1');
|
||||
}
|
||||
}
|
||||
$users = $this->loadModel('user')->getByQuery($this->session->userQuery, $pager, $sort);
|
||||
}
|
||||
/* Get users. */
|
||||
$users = $this->company->getUsers($type, $queryID, $deptID, $sort, $pager);
|
||||
|
||||
/* Set view. */
|
||||
$this->view->title = $this->lang->company->index . $this->lang->colon . $this->lang->dept->common;
|
||||
$this->view->position[] = $this->lang->dept->common;
|
||||
$this->view->users = $users;
|
||||
|
||||
@@ -61,6 +61,48 @@ class companyModel extends model
|
||||
return $this->dao->findById((int)$companyID)->from(TABLE_COMPANY)->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users.
|
||||
*
|
||||
* @param string $type
|
||||
* @param int $queryID
|
||||
* @param int $deptID
|
||||
* @param string $sort
|
||||
* @param object $pager
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getUsers($type, $queryID, $deptID, $sort, $pager)
|
||||
{
|
||||
/* Get users. */
|
||||
if($type == 'bydept')
|
||||
{
|
||||
$childDeptIds = $this->loadModel('dept')->getAllChildID($deptID);
|
||||
$users = $this->dept->getUsers($childDeptIds, $pager, $sort);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($queryID)
|
||||
{
|
||||
$query = $this->loadModel('search')->getQuery($queryID);
|
||||
if($query)
|
||||
{
|
||||
$this->session->set('userQuery', $query->sql);
|
||||
$this->session->set('userForm', $query->form);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->session->set('userQuery', ' 1 = 1');
|
||||
}
|
||||
}
|
||||
$users = $this->loadModel('user')->getByQuery($this->session->userQuery, $pager, $sort);
|
||||
}
|
||||
|
||||
if($users) return $users;
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a company.
|
||||
*
|
||||
@@ -81,4 +123,19 @@ class companyModel extends model
|
||||
->where('id')->eq($companyID)
|
||||
->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build search form.
|
||||
*
|
||||
* @param int $queryID
|
||||
* @param string $actionURL
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function buildSearchForm($queryID, $actionURL)
|
||||
{
|
||||
$this->config->company->browse->search['actionURL'] = $actionURL;
|
||||
$this->config->company->browse->search['queryID'] = $queryID;
|
||||
$this->config->company->browse->search['params']['dept']['values'] = array('' => '') + $this->loadModel('dept')->getOptionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user