PHP Classes
elePHPant
Icontem

File: classes/database/db-table.php

Recommend this page to a friend!
  Classes of Gonzalo Chumillas  >  Ses Query  >  classes/database/db-table.php  >  Download  
File: classes/database/db-table.php
Role: Class source
Content type: text/plain
Description: DBTable class
Class: Ses Query
Manipulate records retrieved with select queries
Author: By
Last change:
Date: 3 years ago
Size: 3,327 bytes
 

Contents

Class file image Download
<?php
/**
 * This file contains the DBTable class.
 *
 * @author Gonzalo Chumillas <gonzalo@soloproyectos.com>
 * @package database
 */

require_once dirname(__DIR__) . "/database/db-query.php";
require_once
dirname(__DIR__) . "/database/db-column.php";

/**
 * class DBTable
 * @package database
 */
class DBTable {
    const
INNER_JOIN = "inner";
    const
LEFT_JOIN = "left";
   
   
/**
     * Query.
     * @var DBQuery
     */
   
private $query;
   
   
/**
     * Table alias.
     * @var string
     */
   
private $alias = "";
   
   
/**
     * Table name.
     * @var string
     */
   
private $name = "";
   
   
/**
     * Join type.
     * @var string
     */
   
private $join_type = DBTable::LEFT_JOIN;
   
   
/**
     * Primary key column.
     * @var DBColumn
     */
   
private $primary_key;
   
   
/**
     * Table columns.
     * @var array[DBColumn]
     */
   
private $columns = array();
   
   
/**
     * @param DBQuery $query
     * @param string $name
     */
   
public function __construct($query, $alias) {
       
$this->query = $query;
       
$this->alias = $alias;
    }
   
   
/**
     * Gets table name.
     * @return string
     */
   
public function getName() {
        return
$this->name;
    }
   
   
/**
     * Sets table name.
     * @param string $name
     */
   
public function setName($name) {
       
$this->name = $name;
    }
   
    public function
getJoinType() {
        return
$this->join_type;
    }
   
    public function
setJoinType($join_type) {
       
$this->join_type = $join_type;
    }
   
   
/**
     * Gets table alias.
     * @return string
     */
   
public function getAlias() {
        return
$this->alias;
    }
   
   
/**
     * Gets the table columns.
     * @return array[DBColumn]
     */
   
public function getColumns() {
       
$ret = array();
       
        foreach (
$this->columns as $column) {
           
array_push($ret, $column);
        }
       
        return
$ret;
    }
   
   
/**
     * Gets column by name.
     * @param string $name
     * @return DBColumn
     */
   
public function getColumnByName($name) {
       
$ret = NULL;
        foreach (
$this->columns as $column) {
            if (
$column->getName() == $name) {
               
$ret = $column;
                break;
            }
        }
        return
$ret;
    }
   
   
/**
     * Sets the primary key column.
     * @param DBColumn $column
     */
   
public function setPrimaryKey($column) {
       
$this->primary_key = $column;
    }
   
   
/**
     * Gets the primary key column.
     * @return DBColumn
     */
   
public function getPrimaryKey() {
        return
$this->primary_key;
    }
   
   
/**
     * Registers a new columns.
     * @param DBColumn $column
     */
   
public function registerColumn($column) {
       
$pos = array_search($column, $this->columns, TRUE);
       
        if (
$pos === FALSE) {
           
array_push($this->columns, $column);
        }
    }
   
   
/**
     * Has the table changed?
     * @return boolean
     */
   
public function hasChanged() {
       
$ret = FALSE;
       
        foreach (
$this->columns as $column) {
            if (
$column->hasChanged()) {
               
$ret = TRUE;
                break;
            }
        }
       
        return
$ret;
    }
}