PHP Classes

File: bnkCrncy.php

Recommend this page to a friend!
  Classes of Prakash Khanchandani   Table Maintenance   bnkCrncy.php   Download  
File: bnkCrncy.php
Role: Example script
Content type: text/plain
Description: 7th level example
Class: Table Maintenance
Manage forms for CRUD MySQL table records
Author: By
Last change:
Date: 10 years ago
Size: 5,044 bytes
 

Contents

Class file image Download
<?php

/**
 * @author Prakash Khanchandani
 * @copyright 2013
 * @program bnkCrncy.php
 * @description bank currencies maintenance
 * @specialities - column comments displayed in form
 * - explicit foreign key definitions for auto validation of form data
 * - display of data from x-ref tables
 * - additional, table specific validation
 */


session_start();
require_once (
"classes.php");


function
createTableObject()
{
   
$obj = new bnkCrncyTable;
    if (
$obj->getListAndColumns() === false)
        return
false;
    else
        return
$obj;
}


class
bnkCrncyTable extends mstrTable
{
    function
getListAndColumns()
    {
       
$this->tableName = 'bankCurrencies';
       
/*
        set the constraints. Initialise the master class with the constraints.
        setting bank=412 IS FOR THIS DEMO ONLY. In my case in the project in which
        it is used it comes from the session which is set at login. */
       
$var = array();
       
$pair[0] = 'bankCode';
       
$pair[1] = '412';
       
$var[] = $pair;

       
$this->constraints = $var;
       
/*
        create foreign references. For the structure, you can refer the
        checkExplicitForeignReferences() func in the mstrTable class. The set below
        creates 3 references, one to the bnkPrmtrs, another to currencies, and the
        third to generalLedgerMstr. */
       
$this->explicitFrgnRef[] = array("bnkPrmtrs", "bank=bankCode");
       
$this->explicitFrgnRef[] = array("currencies", "currencyCode =currencyCode");
       
$this->explicitFrgnRef[] = array("generalLedgerMstr", "bank = bankCode ",
           
"acNo = cohGLacNo");
       
/*
        no special order or number of columns required in the list. Use the default. */
       
$result = parent::getListAndColumns('currencyCode', 'cohGLacNo',
           
'minRetentionAmt', 'maxRetentionAmt');
        return
$result;
    }


    function
populateRecordValues()
    {
       
/* need to override the master class function since some additional material is
        to be displayed
        */
       
if (parent::populateRecordValues() === false)
            return
false;
       
/*
        having populated all the variables into colValu for the record, get the bankName,
        currencyName, cashOnHandGLacDescription for display in the form. Remember that we
        have given explicit foreign references and therefore the populateRecordValues of
        the parent function would have got the reference records already. */
       
$this->displayXrefDescriptions();

        return
true;
    }


    private function
displayXrefDescriptions()
    {
       
/* populate the adtnlInfo with bankName, currencyName, cashOnHandGLdescription
        for display on the form. Used by populate and validate functions in this file. */
        /*
        We have given explicit foreign references and therefore the reference records
        would be available in the master class. */
        /*
        get the column values that you want to display on the form. */
       
$bankDes = $this->getForeignRefDescription('bnkPrmtrs', 'bankName');
       
$crncyDes = $this->getForeignRefDescription('currencies', 'description');
       
$acName = $this->getForeignRefDescription('generalLedgerMstr', 'acName');
       
/*
        get the ids of the columns where you want the descriptions to be displayed. */
       
$idBank = $this->getColDefsId('bankcode', 'n');
       
$idCrncy = $this->getColDefsId('currencycode', 'n');
       
$idGLacNo = $this->getColDefsId('cohGLacNo', 'n');
       
/*
        display the stuff that you have got in the respective ids. */
       
$this->addAdditionalInfo($idBank, $bankDes);
       
$this->addAdditionalInfo($idCrncy, $crncyDes);
       
$this->addAdditionalInfo($idGLacNo, $acName);
    }


    protected function
validateInput()
    {
       
/* We have used explicit foreign references to validate currency code, bank code, and
        GL code. SO THESE 3 CODES NEED NOT BE VALIDATED HERE. Just get the description details
        from the foreign records to display for user confirmation.
        */
       
$this->displayXrefDescriptions();
       
/*
        Specific validation for retention amount.
        HAS TO BE DONE PROGRAMMATICALLY, THERE IS NO OTHER WAY. */
       
$errors = 0;
       
$minAmt = $this->getColDefsVal('minRetentionAmt') + 0;
       
$maxAmt = $this->getColDefsVal('maxRetentionAmt') + 0;
        if (
$minAmt > $maxAmt) {
           
addToErrorMsg('inconsistent min and max amounts');
           
$errors = $errors + 1;
        }
       
/**
         * maybe there are some other validations that you would like to do?
         * You can do them here.
         */
       
if ($errors > 0)
            return
false;

        return
true;
    }
}


if (!isset(
$_REQUEST['actn'])) {
   
$obj = createTableObject();
} else {
   
/* if the user has taken some action, handle it. */
   
$obj = handleRequestOption();
}


$form = new mstrFH($obj);
$form->setDemoNotes(bnkCrncyNotes());
$form->displayForm();
?>