/** * Get the value of this Record's title column. * @return string */ public function getTitle() { $title_col = $this->table->getTitleColumn(); if ($title_col !== $this->table->getPkColumn()) { $title_col_name = $title_col->getName(); return $this->data->{$title_col_name}; } else { $title_parts = array(); foreach ($this->table->getColumns() as $col) { $col_name = $col->getName() . self::FKTITLE; $title_parts[] = $this->{$col_name}(); } return '[ ' . join(' | ', $title_parts) . ' ]'; } }
/** * Get the record count of this table. Will use a cached value only for base * tables and where there are no filters. * @return integer The record count. */ public function getCount() { // Only cache if this is a base table and there are no filters. $canCache = $this->table->isTable() && count($this->table->get_filters()) === 0; if ($canCache) { if (isset($_SESSION[$this->sessionKey()])) { return $_SESSION[$this->sessionKey()]; } } // Otherwise, run the COUNT() query. $pkCol = $this->table->getPkColumn(); if ($pkCol instanceof Column) { $count_col = '`' . $this->table->getName() . '`.`' . $pkCol->getName() . '`'; } else { $count_col = '*'; } $sql = 'SELECT COUNT(' . $count_col . ') as `count` FROM `' . $this->table->getName() . '`'; $params = $this->table->applyFilters($sql); $count = $this->table->getDatabase()->query($sql, $params)->fetchColumn(); if ($canCache) { $_SESSION[$this->sessionKey()] = $count; } return (int) $count; }