Example #1
0
 /**
  * loadList() obtains all the rows from the table
  * Constructs a database query based on the following class variables:
  * @param string $table->table			the table to query
  * @param string $table->parentLink		the table name of the parent link (foreign key table)
  * @param string $table->parentId		the id (foreign key) of the parentLink with which to link
  * @param string $table->list_where		?
  * @param string $table->accessControl	?
  * @param string $table->sort			names of columns, separated by commas to sort by.
  * @return stores result in $list class variable (no actual return result from the method)
  */
 function loadList()
 {
     // check for required variables
     if ($this->table == '') {
         return;
     }
     // build WHERE qualification
     $where = [];
     $join = [];
     $fields = [];
     if ($this->parentLink && $this->parentId) {
         $where[$this->parentLink] = $this->parentId;
     }
     if (!empty($this->list_where)) {
         $where = array_merge($this->list_where, $where);
     }
     if (!empty($this->accessControl)) {
         $where = array_merge($this->accessControl, $where);
     }
     if ($this->action == "autocomplete" && ($field = Request::post('field'))) {
         $this->accessControl[$field] = array('LIKE', Request::post('st') . '%');
     }
     if ($this->accessTable) {
         if ($this->accessTableJoinOn) {
             $join_condition = "ON (" . $this->accessTableJoinOn . ")";
         } else {
             $join_condition = "ON ({$this->accessTable}.{$this->getKey()}={$this->table}.{$this->getKey()})";
         }
         $join[] = array($this->accessTableSchema, $this->accessTable, $join_condition);
         if ($this->accessTableCondition) {
             $where = array_merge($this->accessTableCondition, $where);
         }
     }
     if ($this->cur_subset) {
         if ($this->subset[$this->cur_subset]) {
             $where = array_merge($this->subset[$this->cur_subset], $where);
         }
     }
     if ($this->action == 'list') {
         $this->additional_action_vars['ste'] = Request::get('ste');
         $where[] = Database::getMultiFieldSearch($this->search_fields, explode(' ', Request::get('ste')), $this->searchWildcard);
     }
     // get the page count
     $this->listCount = Database::getInstance()->count(array('from' => $this->table, 'join' => $join), $where);
     $start = (max(1, $this->page_number) - 1) * $this->maxPerPage;
     // validate the sort order
     $sort = !empty($this->sort) ? " ORDER BY " . $this->sort : '';
     if ($this->joins) {
         $join = array_merge($join, $this->joins);
         foreach ($this->joins as $join) {
             // set for every joined table
             $fields[] = [$join[1] => ['*']];
         }
     }
     if ($this->action == "autocomplete") {
         $fields[] = array($this->getKey() => "`{$_POST['field']}`,`{$this->getKey()}`");
         $sort = "ORDER BY `{$_POST['field']}` ASC";
     } else {
         $fields[] = array($this->table => array('*'));
     }
     $this->list = Database::getInstance()->selectIndexed(array('from' => $this->table, 'join' => $join), $this->getKey(), $where, $fields, $sort . ' LIMIT ' . $start . ', ' . $this->maxPerPage);
 }