public function getList(array $data = array())
    {
        $sql = 'SELECT b.*, u.name AS user_name';

        if (!empty($data['count'])) {
            $sql = 'SELECT COUNT(b.backup_id)';
        }

        $sql .= ' FROM backup b
                  LEFT JOIN user u ON(b.user_id = u.user_id)
                  WHERE b.backup_id > 0';

        $where = array();

        if (isset($data['user_id'])) {
            $sql .= ' AND b.user_id = ?';
            $where[] = $data['user_id'];
        }

        if (isset($data['id'])) {
            $sql .= ' AND b.id = ?';
            $where[] = $data['id'];
        }

        if (isset($data['version'])) {
            $sql .= ' AND b.version = ?';
            $where[] = $data['version'];
        }

        if (isset($data['name'])) {
            $sql .= ' AND b.name LIKE ?';
            $where[] = "%{$data['name']}%";
        }

        $allowed_order = array('asc', 'desc');
        $allowed_sort = array('name', 'user_id', 'version',
            'id', 'backup_id', 'type', 'created');

        if (isset($data['sort'])
            && in_array($data['sort'], $allowed_sort)
            && isset($data['order'])
            && in_array($data['order'], $allowed_order)
        ) {
            $sql .= " ORDER BY b.{$data['sort']} {$data['order']}";
        } else {
            $sql .= ' ORDER BY b.created DESC';
        }

        if (!empty($data['limit'])) {
            $sql .= ' LIMIT ' . implode(',', array_map('intval', $data['limit']));
        }

        if (!empty($data['count'])) {
            return (int) $this->db->fetchColumn($sql, $where);
        }

        $results = $this->db->fetchAll($sql, $where, array('index' => 'backup_id'));
        $this->hook->attach('module.backup.list', $results, $this);
        return $results;
    }
public function getList(array $data = array())
    {
        $sql = 'SELECT b.*, u.name AS user_name';

        if (!empty($data['count'])) {
            $sql = 'SELECT COUNT(b.backup_id)';
        }

        $sql .= ' FROM backup b
                  LEFT JOIN user u ON(b.user_id = u.user_id)
                  WHERE b.backup_id > 0';

        $where = array();

        if (isset($data['user_id'])) {
            $sql .= ' AND b.user_id = ?';
            $where[] = $data['user_id'];
        }

        if (isset($data['id'])) {
            $sql .= ' AND b.id = ?';
            $where[] = $data['id'];
        }

        if (isset($data['version'])) {
            $sql .= ' AND b.version = ?';
            $where[] = $data['version'];
        }

        if (isset($data['name'])) {
            $sql .= ' AND b.name LIKE ?';
            $where[] = "%{$data['name']}%";
        }

        $allowed_order = array('asc', 'desc');
        $allowed_sort = array('name', 'user_id', 'version',
            'id', 'backup_id', 'type', 'created');

        if (isset($data['sort'])
            && in_array($data['sort'], $allowed_sort)
            && isset($data['order'])
            && in_array($data['order'], $allowed_order)
        ) {
            $sql .= " ORDER BY b.{$data['sort']} {$data['order']}";
        } else {
            $sql .= ' ORDER BY b.created DESC';
        }

        if (!empty($data['limit'])) {
            $sql .= ' LIMIT ' . implode(',', array_map('intval', $data['limit']));
        }

        if (!empty($data['count'])) {
            return (int) $this->db->fetchColumn($sql, $where);
        }

        $results = $this->db->fetchAll($sql, $where, array('index' => 'backup_id'));
        $this->hook->attach('module.backup.list', $results, $this);
        return $results;
    }
public function getList ( array $ data = array ( ) ) { $ sql = 'SELECT b.*, u.name AS user_name' ; if ( ! empty ( $ data [ 'count' ] ) ) { $ sql = 'SELECT COUNT(b.backup_id)' ; } $ sql .= ' FROM backup b
                  LEFT JOIN user u ON(b.user_id = u.user_id)
                  WHERE b.backup_id > 0' ; $ where = array ( ) ; if ( isset ( $ data [ 'user_id' ] ) ) { $ sql .= ' AND b.user_id = ?' ; $ where [ ] = $ data [ 'user_id' ] ; } if ( isset ( $ data [ 'id' ] ) ) { $ sql .= ' AND b.id = ?' ; $ where [ ] = $ data [ 'id' ] ; } if ( isset ( $ data [ 'version' ] ) ) { $ sql .= ' AND b.version = ?' ; $ where [ ] = $ data [ 'version' ] ; } if ( isset ( $ data [ 'name' ] ) ) { $ sql .= ' AND b.name LIKE ?' ; $ where [ ] = "%{$data['name']}%" ; } $ allowed_order = array ( 'asc' , 'desc' ) ; $ allowed_sort = array ( 'name' , 'user_id' , 'version' , 'id' , 'backup_id' , 'type' , 'created' ) ; if ( isset ( $ data [ 'sort' ] ) && in_array ( $ data [ 'sort' ] , $ allowed_sort ) && isset ( $ data [ 'order' ] ) && in_array ( $ data [ 'order' ] , $ allowed_order ) ) { $ sql .= " ORDER BY b.{$data['sort']} {$data['order']}" ; } else { $ sql .= ' ORDER BY b.created DESC' ; } if ( ! empty ( $ data [ 'limit' ] ) ) { $ sql .= ' LIMIT ' . implode ( ',' , array_map ( 'intval' , $ data [ 'limit' ] ) ) ; } if ( ! empty ( $ data [ 'count' ] ) ) { return ( int ) $ this -> db -> fetchColumn ( $ sql , $ where ) ; } $ results = $ this -> db -> fetchAll ( $ sql , $ where , array ( 'index' => 'backup_id' ) ) ; $ this -> hook -> attach ( 'module.backup.list' , $ results , $ this ) ; return $ results ; }
Returns an array of backups or counts them
@param array $data
@return array|integer
Returns an array of backups or counts them