* @license PHP License * @package WB * @subpackage content */ /** * Load required class */ WBClass::load('WBContent'); /** * Content component: TableEditor * * @version 0.5.0 * @package WB * @subpackage content * @deprecated in favour of User_Manager */ class WBContent_UserManager extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'action' => 'userlist', 'requiredgroup' => 'admin', 'goto' => '0', 'hideuser' => array(), 'editablecolumns' => array('forename', 'surname'), 'orderfield' => 'surname', 'orderasc' => 1, 'searchfields' => array('nickname', 'forename', 'surname') ); /** * table * @var WBDatasource_Table */ protected $table; /** * user object * @var WBUser */ protected $patron; /** * run * * run component * * @return array parameter list */ public function run() { if (!$this->isUserInGroup($this->config['requiredgroup'])) { $this->loadTemplates('anon'); return $this->config; } // try to load user by id $this->patron = WBClass::create('WBUser'); if ($this->config['action'] != 'userlist' && strncmp($this->config['action'], 'user', 4) == 0) { if ($this->patron->load($this->req->get('user', 0))) { $this->tmpl->addGlobalVars($this->patron->getData()); } else { $this->config['action'] = 'userlist'; } } $this->table = WBClass::create('WBDatasource_Table'); switch ($this->config['action']) { case 'useredit': $data = $this->patron->getData(); $data['groups'] = array_keys($this->patron->getGroups()); $this->processForm('userEdit', $data); break; case 'userrm': $this->tmpl->addGlobalVars($this->patron->getData()); // delete? if ($this->config['action'] == 'userrm') { if ($this->req->get('force', 'no') != 'yes') { $this->loadTemplates('userRm'); return $this->config; break; } $this->table->delete('user', $this->patron->getId()); $this->loadTemplates('userRmDeleted'); $this->config['tmplDir'] = $tmplDir; return $this->config; } break; case 'userdisplay': $this->tmpl->addGlobalVars($this->patron->getData()); $this->loadTemplates('userDisplay'); break; case 'userlist': default: $this->loadTemplates('userList'); break; } $this->displayUserList(); return $this->config; } /** * display list of records in table * * In case there is a template named "list_entry", it will be filled with paged * rows of table */ protected function displayUserList() { if (!$this->tmpl->exists('user_list_entry')) { return; } $clause = array(); if (!empty($this->config['hideuser']) && is_array($this->config['hideuser'])) { $clause[] = array( 'field' => $this->table->getIdentifier('user'), 'relation' => 'not_in', 'value' => $this->config['hideuser'] ); } $this->addSearchQuery($clause); // echo "
" . print_r($clause, true) . ""; $options = array(); if ($this->config['limit'] && intval($this->config['limit']) > 0) { $options['limit'] = intval($this->config['limit']); } // order by if (!empty($this->config['orderfield'])) { $options['order'] = array( 'field' => $this->config['orderfield'], 'asc' => $this->config['orderasc'] ); } $pager = $this->table->getPager($this->part . __CLASS__, 'user', null, $clause, $options); $this->tmpl->addGlobalVars($pager->browse($this->config['goto']), 'pager_'); $this->tmpl->addGlobalVars($this->config, 'config_'); $this->tmpl->addRows('user_list_entry', $pager->get()); } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { return $this->tmpl->getParsedTemplate('snippet'); } /** * Save user's primary data * * Update user's forename and surname * * @param patForms $form * @param array $values */ public function onUserEditValid($form, $values) { // enable, disable user if (isset($values['enabled'])) { if ($values['enabled']) { $this->patron->enable(); } else { $this->patron->disable(); } } if (isset($values['groups'])) { $this->patron->setGroups($values['groups']); } $save = array(); $keys = $this->config['editablecolumns']; foreach ($keys as $key) { if (!isset($values[$key])) { continue; } $save[$key] = $values[$key]; } $this->patron->set($save); return true; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'user/manager'; } /** * Add form rules to just created form * * @param patForms $form object * @param string name of the xml- and template-filename * @param array $elements list of elements current form * @return bool true on success */ protected function insertFormRules(&$form, $name, $elements) { return true; } /** * Add search criteria to clause * * See whether search options are set and add LIKE statements to clause. * Actually check in current request and configuration of search fields * * @param array $clause */ private function addSearchQuery(&$clause) { if (empty($this->config['searchfields'])) { return; } if ('' == $this->req->get('searchsubmit', '')) { return; } $search = array( 'submit' => 1, 'query' => $this->req->get('searchquery') ); if (empty($search['query'])) { return; } // add user input to template $this->tmpl->addGlobalVars($search, 'search_'); // normalize searchfields if (!is_array($this->config['searchfields'])) { $this->config['searchfields'] = array($this->config['searchfields']); } $query = trim($search['query']); $query = array_map('trim', explode(' ', $query)); foreach ($query as $q) { if (strlen($q) < 3) { continue; } $c = array(); foreach ($this->config['searchfields'] as $f) { $c[] = array( 'field' => $f, 'relation' => 'like', 'value' => $q ); } $clause[] = array( 'type' => 'complex', 'bond' => 'or', 'clause' => $c ); } } } ?>