PHP Classes

File: prodTypes.php

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

Contents

Class file image Download
<?php

/**
 * @author Prakash Khanchandani
 * @copyright 2013
 * @program prodTypes.php
 * @description product types maintenance
 * @specialities - hiding column(s) in form\
 * - explicitly programming to check if a record can be deleted
 */


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


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


class
prodTypesTable extends mstrTable
{
    function
getListAndColumns()
    {
       
$this->tableName = 'prodTypes';

       
/* ignore the following columns from having text boxes
        for user input. */
       
$this->ignoreInForm = array('active');

       
/* 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] = 'bank';
       
$pair[1] = '412';
       
$var[] = $pair;

       
$this->constraints = $var;

       
$result = parent::getListAndColumns('productCd', 'description', 'basePrdType',
           
'maxCashCr');

        return
$result;
    }


    function
canDelete()
    {
       
/* since there are no foreign keys, implicit or explicit, we will check manually
        whether the selected record is used at all. Let us check in the prodSubTypes
        table for even 1 reference to the productCode. If found, we cannot delete the
        selected prodTypes record.
        */
        // get the value of productCd of the selected record
       
$productCd = $this->getColDefsVal('productCd');
       
/*
        build the where clause for the prodSubTypes table. Note that the column name in
        prodSubTypes is "prdType". */
       
$clause = "prdType = " . $productCd;
       
/*
        read the prodSubTypes record with the above clause. Use limit 1 clause. */
       
$script = new mstrScripts;
       
$result = $script->readMasterRecord("prodSubTypes", $clause, "limit 1");
       
/*
        if the count of result is zero, you can delete the record. Greater than zero (it
        can only be 1), you cannot. */
       
if (count($result) > 0)
            return
"no";
        else
            return
"yes";
    }
}


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


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