Location: PHPKode > scripts > Piragibe > piragibe/PGBSlaveDefinition.php
<?php
/**
 * A definition for a slave recordset. A slave recordset is a recordset linked to a master
 * record.
 * 
 * This is the slave <b>DEFINITION</b>, not the slave itself. The slave is generated from 
 * the definition for each master record (for instance, the lines of a master invoice). A
 * slave definition is also <b>recursive</b>. So, one slave definition can have its own
 * slaves, and so on.
 * @package Piragibe
 * @author Francisco Piragibe
 * @version 1.00
 * @copyright Copyright &copy; 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 PGBSlaveDefinition {
 
 /**
  * @var string the slave name, for future reference
  */
 var $m_nome;               // nome da definicao
 /**
  * A correspondence definition array, having a series of 'master column name' =>
  * 'child column name' pairs.
  * @var array the correspondence descriptors
  */
 var $m_reldef;             // array com definicao das correspondencias pai x filho
 // [<nome da coluna pai>] => [<nome da coluna filho>]
 /**
  * As slave definitions are recursive entities, a slave definition can have, also, a set of
  * slaves from its own. There is no practical limit to this kind of nesting.
  * @var array slave definitions bound to this slave definition
  */
 var $m_escravos;           // array de PGBSlaveDefinition's que define os escravos de cada
                            // escravo obtido por esta slave definition
                            
 /**
  * Standard constructor.
  * @param string $pNome the definition name
  * @param array $pRelDef the correspondence array (parent field -> child field)
  * @param array $pSubescravos array of child slave definitions (slaves of this slave)
  */
 function PGBSlaveDefinition( $pNome, $pRelDef, $pSubescravos = array() ) {
     $this->m_nome      = $pNome;
     if ( is_array( $pRelDef ) ) {
        $this->m_reldef    = $pRelDef;
     }
     else {
        print 'PGBSlaveDefinition: correspondence definition is not an array';
        die;
     }
     $this->setSlavesOfSlave( $pSubescravos );
 }
 
 /**
  * Getter for the slave definition's name.
  * @return string the slave definition's name
  */
 function getName() {
 // retorna o nome (identificacao) da definicao
     return $this->m_nome;
 }
 
 /**
  * Getter for the whole correspondence array.
  * @return array the correspondence array
  */
 function getRelDefs() {
 // retorna o array completo com as definicoes de relacoes
     return $this->m_reldef;
 }
 
 /**
  * Getter for a child column name, given the parent column name.
  * @return string the child column name
  * @param string $pParent the parent column name
  */
 function getChildColumn( $pParent ) {
 // retorna o nome da coluna correspondente no filho ao pai dado
     return $this->m_reldef[ $pParent ];
 }
 
 /**
  * Getter for the whole array of subslave definitions.
  * @return array the subslave definitions
  */
 function &getSlavesOfSlave() {
 // retorna o array de definicoes dos subescravos
     return $this->m_escravos;
 }
 
 /**
  * Setter for the array of subslaves.
  * @param array $pSubescravos the array of subslave definitions
  */
 function setSlavesOfSlave( $pSubescravos ) {
 // seta o array de definicoes de subescravos
     if ( is_array( $pSubescravos ) ) {
         reset( $pSubescravos );
         $this->m_escravos  = array();
         while( list( $k, $o_sd ) = each( $pSubescravos ) ) {
            if ( is_a( $o_sd, 'PGBSlaveDefinition' ) ) {
                $this->m_escravos[] = $o_sd;
            }
            else {
                print 'PGBSlaveDefinition: slave of slave is not a slave definition';
                die;
            }
         }
     }
     else {
        print 'PGBSlaveDefinition: slaves of slave definition is not an array';
        die;
     }
 }
 
}
?>
Return current item: Piragibe