PHP Classes

File: examples/cart/app/models/productModel.php

Recommend this page to a friend!
  Classes of Haseeb Ahmad Basil   PHP Skeleton Framework   examples/cart/app/models/productModel.php   Download  
File: examples/cart/app/models/productModel.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Skeleton Framework
Extensive Web application development framework
Author: By
Last change:
Date: 8 years ago
Size: 1,528 bytes
 

Contents

Class file image Download
<?php

class productModel
{
    protected
$data = array();
   
    public function
__construct($locator=null)
    {
       
$this->sizes = array('x-small', 'small', 'medium', 'large', 'x-large');
       
$this->colors = array('red', 'orange', 'yellow', 'green', 'blue');
        for (
$i=0; $i<=4; ++$i) {
           
$id = $i + 1;
           
$this->data[$id] = array(
               
'id' => $id,
               
'sku' => "A$id",
               
'category' => 'One',
               
'name' => "Item $id",
               
'price' => 10.0 + $i,
               
'color' => $this->colors[$i],
               
'size' => '',
            );

           
$id = $i + 6;
           
$this->data[$id] = array(
               
'id' => $id,
               
'sku' => "B$id",
               
'category' => 'Two',
               
'name' => "Item $id",
               
'price' => 10.0 * $id,
               
'color' => '',
               
'size' => $this->sizes[$i],
            );
        }
    }

    public function
findCategories()
    {
       
$data = array();
        foreach (
$this->data as $row) {
           
$data[$row['category']] = 1;
        }
        return
array_keys($data);
    }
   
    public function
findAllProducts()
    {
        return
$this->data;
    }

    public function
findProductsSkus($skus=array())
    {
       
$data = array();
        if (
$skus) {
            foreach (
$this->data as $id => $row) {
                foreach (
$skus as $sku) {
                    if (
$row['sku'] == $sku) {
                       
$data[$id] = $row;
                        break;
                    }
                }
            }
        }
        return
$data;
    }
   
    public function
findProductsInCategory($category)
    {
       
$data = array();
        if (
$category) {
            foreach (
$this->data as $id => $row) {
                if (
$row['category'] == $category) {
                   
$data[$id] = $row;
                }
            }
        }
        return
$data;
    }
}