示例#1
0
 public function __viewIndex()
 {
     $this->setTitle(__('Symphony') . ' – ' . __('Users'));
     $this->appendSubheading(__('Users'), Widget::Anchor(__('Add a User'), Administration::instance()->getCurrentPageURL() . '/new/', array('title' => __('Add a new User'), 'class' => 'create button')));
     $users = new UserIterator();
     $aTableHead = array(array(__('Name'), 'col'), array(__('Email Address'), 'col'), array(__('Last Seen'), 'col'));
     $aTableBody = array();
     $colspan = count($aTableHead);
     if ($users->length() == 0) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), array('class' => 'inactive', 'colspan' => $colspan))), array('class' => 'odd')));
     } else {
         foreach ($users as $u) {
             ## Setup each cell
             $td1 = Widget::TableData(Widget::Anchor($u->getFullName(), Administration::instance()->getCurrentPageURL() . '/edit/' . $u->id . '/', array('title' => $u->username)));
             $td2 = Widget::TableData(Widget::Anchor($u->email, 'mailto:' . $u->email, array('title' => 'Email this user')));
             if ($u->last_seen != NULL) {
                 $td3 = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($u->last_seen)));
             } else {
                 $td3 = Widget::TableData('Unknown', array('class' => 'inactive'));
             }
             $td3->appendChild(Widget::Input('items[' . $u->id . ']', NULL, 'checkbox'));
             ## Add a row to the body array, assigning each cell to the row
             $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3));
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
     $this->Form->appendChild($table);
     $tableActions = $this->createElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(NULL, false, 'With Selected...'), array('delete', false, 'Delete'));
     $tableActions->appendChild(Widget::Select('with-selected', $options));
     $tableActions->appendChild(Widget::Input('action[apply]', 'Apply', 'submit'));
     $this->Form->appendChild($tableActions);
 }
示例#2
0
 public function render(Register $ParameterOutput)
 {
     $result = new XMLDocument();
     $root = $result->createElement($this->parameters()->{'root-element'});
     try {
         ##	User Filtering
         if (is_array($this->parameters()->filters) && !empty($this->parameters()->filters)) {
             $user_ids = NULL;
             $where_clauses = array();
             $query = "SELECT * FROM `tbl_users` WHERE 1 %s ORDER BY `id` ASC";
             foreach ($this->parameters()->filters as $field => $value) {
                 if (!is_array($value) && trim($value) == '') {
                     continue;
                 }
                 $value = self::replaceParametersInString($value, $ParameterOutput);
                 if (!is_array($value)) {
                     $value = preg_split('/,\\s*/', $value, -1, PREG_SPLIT_NO_EMPTY);
                     $value = array_map('trim', $value);
                 }
                 $where_clauses[] = sprintf("`%s` IN ('%s')", str_replace('-', '_', $field), implode(',', $value));
             }
             // Should the $where_clauses array be empty, it means there were no valid filters. I.E. they were all empty strings.
             // If that is the case, we still want Users to get returned, hence the "WHERE 1" part of the SQL to avoid errors.
             if (!empty($where_clauses)) {
                 $where_clauses = 'AND' . implode(' AND ', $where_clauses);
             } else {
                 $where_clauses = NULL;
             }
             $users = Symphony::Database()->query(sprintf($query, $where_clauses), array(), 'UserResult');
         } else {
             $users = new UserIterator();
         }
         if ($users->length() > 0) {
             $included_fields = $this->parameters()->{'included-elements'};
             foreach ($users as $user) {
                 $xUser = $result->createElement('user', null);
                 $xUser->setAttribute('id', $user->id);
                 foreach ($included_fields as $element) {
                     switch ($element) {
                         case 'name':
                             $xUser->appendChild($result->createElement('name', $user->getFullName()));
                             break;
                         case 'email-address':
                             $xUser->appendChild($result->createElement('email-address', $user->email));
                             break;
                         case 'username':
                             $xUser->appendChild($result->createElement('username', $user->username));
                             break;
                         case 'language':
                             if (!is_null($user->language)) {
                                 $xUser->appendChild($result->createElement('language', $user->language));
                             }
                             break;
                         case 'authentication-token':
                             if ($user->isTokenActive()) {
                                 $xUser->appendChild($result->createElement('authentication-token', $user->createAuthToken()));
                             }
                             break;
                         case 'default-section':
                             try {
                                 $section = Section::loadFromHandle($user->default_section);
                                 $default_section = $result->createElement('default-section', $section->name);
                                 $default_section->setAttribute('handle', $section->handle);
                                 $xUser->appendChild($default_section);
                             } catch (SectionException $error) {
                                 // Do nothing, section doesn't exist, but no need to error out about it..
                             }
                             break;
                         default:
                             break;
                     }
                 }
                 $root->appendChild($xUser);
             }
         } else {
             throw new DataSourceException("No records found.");
         }
     } catch (Exception $error) {
         $root->appendChild($result->createElement('error', General::sanitize($error->getMessage())));
     }
     $result->appendChild($root);
     return $result;
 }