count() public method

Will return an integer representing the number of rows returned.
public count ( $column = '*' )
Esempio n. 1
0
function render_iterator($class, $page_limit, $template)
{
    list($params, $limit, $page) = build_iterator_where($page_limit);
    $item_count = ORM::count($class, $params);
    $pager_calculator = new PagerCalculator($item_count, $limit);
    $page = $pager_calculator->calculate($page);
    $offset = $pager_calculator->get_offset();
    $limit = $pager_calculator->get_limit();
    $maxpage = $pager_calculator->get_maxpage();
    $items = ORM::all($class, $params, array('ctime', 'desc'), array($offset, $limit));
    $urlparams = array('page' => $page, 'nick' => isset($params['nick']) && $params['nick'] !== null ? rawurlencode($params['nick']) : null, 'day' => isset($params['ctime']) && isset($_GET['day']) ? $_GET['day'] : null, 'week' => isset($params['ctime']) && isset($_GET['week']) ? $_GET['week'] : null, 'url' => isset($params['original_url']) && isset($_GET['url']) ? $_GET['url'] : null, 'limit' => $limit != $page_limit && isset($_GET['limit']) ? $limit : null);
    extract($GLOBALS);
    // since this is an ajax query with only the data included, we can set expires header safely when not on the last page
    if (is_xhr_request() && $page !== $maxpage) {
        header('Expires: ' . date('r', strtotime('+1 week', $_SERVER['REQUEST_TIME'])));
    }
    include APPROOT . '/' . $template;
}
Esempio n. 2
0
<?php

define('APPROOT', dirname(__FILE__)) . '/';
include_once APPROOT . '/lib/constants.php';
include_once APPROOT . '/model/pic.class.php';
include_once APPROOT . '/lib/functions.php';
$dbcnx = new PDO(DB_DSN, DB_USER, DB_PW, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
ORM::set_dbcnx($dbcnx);
$limit = PAGE_LIMIT_PIC;
list($params, $limit, $page) = build_iterator_where(PAGE_LIMIT_PIC);
$item_count = ORM::count('Pic', $params);
$maxpage = max(ceil($item_count / $limit) - 1, 0);
$item_count_on_last_page = $item_count - floor($item_count / $limit) * $limit;
if ($item_count_on_last_page == 0) {
    $maxpage -= 1;
}
$urlparams = $_GET;
$visited_pages = cookie_list('visited_pages');
include APPROOT . '/html/component/pager.html.php';
Esempio n. 3
0
 function validate()
 {
     $this->invalidFields = array();
     $this->errors = array();
     $uniques = array();
     foreach ($this->schema as $field) {
         // Simple required field validation
         $numeric_fields = array('int', 'tinyint', 'bigint', 'float', 'double', 'decimal');
         $field_is_numeric = array_search($field->type, $numeric_fields) !== false;
         if ((!$field_is_numeric && $this->_data[$field->name] === NULL || $field_is_numeric && !is_numeric($this->_data[$field->name])) && $field->required && !$field->primaryKey) {
             $this->invalidFields[$field->name][] = i18n::get('This field is required');
             if (!in_array(self::ERR_REQUIRED, $this->errors)) {
                 $this->errors[] = self::ERR_REQUIRED;
             }
         }
         // Gather unique fields
         if ($field->unique && !$field->primaryKey) {
             $uniques[] = $field->name;
         }
     }
     // Unique field validation only for new model instances
     if (!$this->getPrimaryKey()) {
         // Loop through each unique field and retrieve instances;
         // Could be refactored to reduce the number of queries made
         foreach ($uniques as $field_name) {
             $c = new Criteria($this->model_name);
             $c->add($field_name, $this->_data[$field_name]);
             if (ORM::count($c) > 0) {
                 $this->invalidFields[$field_name][] = i18n::get('Already registered');
                 if (!in_array(self::ERR_UNIQUE, $this->errors)) {
                     $this->errors[] = self::ERR_UNIQUE;
                 }
             }
         }
     }
     if (count($this->invalidFields) > 0) {
         return false;
     } else {
         return true;
     }
 }