Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/productcountBox.lib

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of philippe thomassigny  >  Box Model  >  examples/productcountBox.lib  >  Download  
File: examples/productcountBox.lib
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Box Model
Create Web applications based on boxes
Author: By
Last change:
Date: 2012-03-04 13:57
Size: 858 bytes
 

Contents

Class file image Download
<?php

// Gets the quantity of product of the category
// entry: none
// exit: quantity
// params: category of products

class productcountBox extends Box
{
  public function __construct()
  {
    parent::__construct();

    $this->addInput('CATEGORY', Box::STRING, 'main');
    $this->addOutput('quantity', Box::INTEGER);
  }

  public function run()
  {
    // Simulates a connection to a database and gets back
    // 5 products if 'main' category, 3 products if 'other' category

    $CATEGORY = trim($this->getInputData('CATEGORY'));
    if ($CATEGORY != 'main' && $CATEGORY != 'other')
    {
      $CATEGORY = 'main';
    }

    // Here we should make a query like
    // select count(*) from products where category = '$CATEGORY';

    if ($CATEGORY == 'main')
      $q = 5;
    else
      $q = 3;

    $this->setOutputData('quantity', $q);
  }

}

?>