<?php
/**
* A primary key definition, usually attached to a {@link PGBBaseTable}.
*
* A primary key is merely a set of fields.
* @package Piragibe
* @author Francisco Piragibe
* @version 1.00
* @copyright Copyright © 2006, Francisco Piragibe
* This file is part of The PIRAGIBE Framework.
*
* The PIRAGIBE Framework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The PIRAGIBE Framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with The PIRAGIBE Framework; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class PGBPrimaryKey {
/**
* @var array a set of field names to use as the PK
*/
var $m_pkdef; // definicao da PK, como um array de nomes de campo
/**
* This only makes sense if the PK is a single, numeric field.
*
* <b>ATTENTION:</b> it defaults to YES!!
* @var boolean should the PK be generated "automagically" ?
*/
var $m_pkauto; // indica se a PK e gerada automaticamente pela base de dados ou nao
// ATENCAO!! O DEFAULT E SIM!!
/**
* Standard constructor.
* @param array $pDef array of field names to use as the PK
* @param boolean $pAuto should the PK be auto generated ?
*/
function PGBPrimaryKey( $pDef, $pAuto = true ) {
$this->m_pkdef = $pDef;
$this->m_pkauto = $pAuto;
}
/**
* Getter for the array of PK fields.
* @return array the set of fields that make up the PK
*/
function getDefinition() {
// retorna o array corrente que define a PK
reset( $this->m_pkdef );
return $this->m_pkdef;
}
/**
* Is the given field name part of the PK?
* @return boolean true or false, depending on the answer
* @param string $pNome the field name
*/
function isInPk( $pNome ) {
// verifica se o campo cujo nome e pNome esta na PK, e retorna TRUE ou FAPGBE, dependendo
// do caso
$resp = false;
reset( $this->m_pkdef );
while( list( $k, $c ) = each( $this->m_pkdef ) ) {
if ( $c == $pNome ) {
$resp = true;
break;
}
}
return $resp;
}
/**
* Getter for the auto generated flag.
* @return boolean should the PK be auto generated ?
*/
function getPkAuto() {
// retorna o flag de PK gerada automaticamente pelo SGBD
return $this->m_pkauto;
}
/**
* Setter for the auto generated flag.
* @param boolean $pka the auto generated flag
*/
function setPkAuto( $pka ) {
// seta o flag de PK automatica
$this->m_pkauto = $pka;
}
}
?>