<?php
/***************************************************************************
 *																		*
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.	*
 *																		  *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.													*
 *																		  *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.			*
 ****************************************************************************/ //
//$Id: SchemaModel.php, v 1.1 2012/12/24 20:52:11
//
class CategorySchemaModel extends Model {
    public function getSchema($params = array()) {
        extract($params);
        if (!empty($primaryID)) {
            $conditionArry = array(
                'productCategoryID' => $primaryID
            );
        }
        if (!empty($pre_process)) {
            $timeZone = $pre_process['productTimeZone'];
        }
        $conditionArry = isset($conditionArry) ? $conditionArry : '';
        $schema        = array(
            'section' => 'product_categories',
            'name' => 'product_categories',
            'pattern_id' => 'product_categories',
            'key' => array(
                'productCategoryID'
            ),
            'order' => 0,
            'table' => 'product_categories',
            'alt_table' => '',
            'condition' => $conditionArry,
            'references' => array(
                'product_category_details' => array(
                    'reference_fields' => array(
                        'productCategoryID' => '#key',
                        'languageID' => '1'
                    ),
                    'join_type' => 'LEFT'
                )
            ),
            'export_fields' => array(
                'productCategoryID' => array(
                    'db_field' => 'productCategoryID',
                    'alt_key' => true
                ),
                'productCategoryKey' => array(
                    'db_field' => 'productCategoryKey',
                    'pre_insert' => array(
                        'fn_put_checkExists',
                        '#this',
                        'product_categories',
                        'productCategoryKey',
                        " productCategoryStatus!='Deleted'",
                        'productCategoryID',
                        '$productCategoryID'
                    ),
                    'validate' => array(
                        'required'
                    ),
                    'error' => array(
                        'productCategoryKey is required'
                    )
                ),
                'productCategoryParent' => array(
                    'db_field' => 'productCategoryParent',
                    'validate' => array(
                        'required'
                    ),
                    'error' => array(
                        'productCategoryParent is required'
                    )
                ),
                'productCategoryStatus' => array(
                    'db_field' => 'productCategoryStatus',
                    'validate' => array(
                        'required'
                    ),
                    'error' => array(
                        'productCategoryStatus is required'
                    )
                ),
                'productCategorySortOrder' => array(
                    'db_field' => 'productCategorySortOrder'
                ),
                'categoryLevel' => array(
                    'db_field' => 'categoryLevel',
                    'validate' => array(
                        'required'
                    ),
                    'error' => array(
                        'categoryLevel is required'
                    )
                ),
                'languageID' => array(
                    'table' => 'product_category_details',
                    'db_field' => 'languageID',
                    'validate' => array(
                        'required'
                    ),
                    'error' => array(
                        'languageID is required'
                    )
                ),
                'productCategoryName' => array(
                    'table' => 'product_category_details',
                    'db_field' => 'productCategoryName',
                    'process_get' => array(
                        'fn_html_entity_decode',
                        '#this'
                    ),
                    'validate' => array(
                        'required'
                    ),
                    'error' => array(
                        'productCategoryName is required'
                    )
                ),
                'productCategoryDescription' => array(
                    'table' => 'product_category_details',
                    'process_get' => array(
                        'fn_html_entity_decode',
                        '#this'
                    ),
                    'db_field' => 'productCategoryDescription'
                ),
                'productCategoryMetaTitle' => array(
                    'table' => 'product_category_details',
                    'process_get' => array(
                        'fn_html_entity_decode',
                        '#this'
                    ),
                    'db_field' => 'productCategoryMetaTitle'
                ),
                'productCategoryMetaKeywords' => array(
                    'table' => 'product_category_details',
                    'process_get' => array(
                        'fn_html_entity_decode',
                        '#this'
                    ),
                    'db_field' => 'productCategoryMetaKeywords'
                ),
                'productCategoryMetaDescription' => array(
                    'table' => 'product_category_details',
                    'process_get' => array(
                        'fn_html_entity_decode',
                        '#this'
                    ),
                    'db_field' => 'productCategoryMetaDescription'
                )
            )
        );
        $get           = isset($get) ? $get : '';
        $conditionArry = isset($conditionArry) ? $conditionArry : '';
        $schema        = $this->setFilter($get, $conditionArry, $schema);
        return $schema;
    }
    function fn_put_checkKeyExist($data) {
        if ($this->ObjDatabase->checkExist('users', 'userEmail', $data, " userStatus!='Deleted' ") == 'YES') {
            echo 'Email Already Exist';
            exit;
        }
    }
    function setFilter($get, $conditionArry, $schema) {
        if (is_array($get)) {
            extract($get);
        }
        if (!empty($filter)) {
            foreach ($filter as $filtr) {
                if ($filtr['eq'] != '') {
                    $conditionArry[$filtr['key']]['eq'] = $filtr['eq'];
                } else if ($filtr['neq'] != '') {
                    $conditionArry[$filtr['key']]['neq'] = $filtr['neq'];
                } else if ($filtr['lt'] != '') {
                    $conditionArry[$filtr['key']]['lt'] = $filtr['lt'];
                } else if ($filtr['gt'] != '') {
                    $conditionArry[$filtr['key']]['gt'] = $filtr['gt'];
                } else if ($filtr['lteq'] != '') {
                    $conditionArry[$filtr['key']]['lteq'] = $filtr['lteq'];
                } else if ($filtr['gteq'] != '') {
                    $conditionArry[$filtr['key']]['gteq'] = $filtr['gteq'];
                } else if ($filtr['in'] != '') {
                    $conditionArry[$filtr['key']]['in'] = $filtr['in'];
                } else if ($filtr['nin'] != '') {
                    $conditionArry[$filtr['key']]['nin'] = $filtr['nin'];
                } else if ($filtr['llike'] != '') {
                    $conditionArry[$filtr['key']]['llike'] = $filtr['llike'];
                } else if ($filtr['rlike'] != '') {
                    $conditionArry[$filtr['key']]['rlike'] = $filtr['rlike'];
                } else if ($filtr['like'] != '') {
                    $conditionArry[$filtr['key']]['like'] = $filtr['like'];
                }
            }
        }
        $schema['condition']        = $conditionArry;
        $schema['resultPerRequest'] = isset($resultPerRequest) ? $resultPerRequest : '';
        if (isset($page) && $page != '' && $page >= 0) {
            $schema['page'] = $page;
            $schema['from'] = $page * $resultPerRequest;
            $schema['to']   = $resultPerRequest;
        } else if (isset($from) && $from != '' && $to != '') {
            $schema['from'] = $from;
            $schema['to']   = $to;
        } else if (isset($limit) && $limit != '' && $limit >= 0) {
            $schema['limit'] = $limit;
        }
        if (isset($order) && $order != '') {
            $schema['order'] = $order;
            if ($dir != '') {
                $schema['dir'] = $dir;
            } else {
                $schema['dir'] = 'ASC';
            }
        }
        return $schema;
    }
}
	