1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: Yii::import('application.models.X2Model');
38:
39: /**
40: * This is the model class for table "x2_products".
41: * @package application.modules.products.models
42: */
43: class Product extends X2Model {
44:
45: public $supportsWorkflow = false;
46:
47: /**
48: * Returns the static model of the specified AR class.
49: * @return Template the static model class
50: */
51: public static function model($className=__CLASS__) {
52: return parent::model($className);
53: }
54:
55: /**
56: * @return string the associated database table name
57: */
58: public function tableName() {
59: return 'x2_products';
60: }
61:
62: public function behaviors() {
63: return array_merge(parent::behaviors(),array(
64: 'X2LinkableBehavior'=>array(
65: 'class'=>'X2LinkableBehavior',
66: 'module'=>'products'
67: ),
68: 'ERememberFiltersBehavior' => array(
69: 'class'=>'application.components.ERememberFiltersBehavior',
70: 'defaults'=>array(),
71: 'defaultStickOnClear'=>false
72: )
73: ));
74: }
75:
76: /**
77: * @return array relational rules.
78: */
79: public function relations() {
80: return array_merge(parent::relations(),array(
81: 'order'=>array(self::HAS_MANY, 'QuoteProduct', 'productId'),
82: ));
83: }
84:
85: /**
86: * Retrieves a list of models based on the current search/filter conditions.
87: * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
88: */
89: public function search() {
90: // Warning: Please modify the following code to remove attributes that
91: // should not be searched.
92:
93: $criteria=new CDbCriteria;
94:
95: /*
96: $criteria->compare('id',$this->id);
97: $criteria->compare('name',$this->name,true);
98: $criteria->compare('description',$this->description,true);
99: $criteria->compare('createDate',$this->createDate);
100: $criteria->compare('lastUpdated',$this->lastUpdated);
101: $criteria->compare('updatedBy',$this->updatedBy,true);
102:
103: return new CActiveDataProvider(get_class($this), array(
104: 'criteria'=>$criteria,
105: 'pagination'=>array(
106: 'pageSize'=>Profile::getResultsPerPage(),
107: ),
108: ));*/
109: return $this->searchBase($criteria);
110: }
111:
112: /**
113: *
114: */
115: public static function activeProducts() {
116: return Product::model()->findAllByAttributes(array('status'=>'Active'));
117: }
118:
119: /**
120: * Get a list of active product names indexed by id
121: */
122: public static function productNames() {
123: $products = Product::model()->findAll(
124: array(
125: 'select'=>'id, name',
126: 'condition'=>'status=:active',
127: 'params'=>array(':active'=>'Active'),
128: )
129: );
130: $productNames = array(0 => '');
131: foreach($products as $product)
132: $productNames[$product->id] = $product->name;
133:
134: return $productNames;
135: }
136:
137: /**
138: * Get a list of active product currencys indexed by id
139: */
140: public static function productCurrency() {
141: $products = Product::model()->findAll(
142: array(
143: 'select'=>'id, currency',
144: 'condition'=>'status=:active',
145: 'params'=>array(':active'=>'Active'),
146: )
147: );
148: $productCurrency = array(0 => '');
149: foreach($products as $product)
150: $productCurrency[$product->id] = $product->currency;
151:
152: return $productCurrency;
153: }
154:
155: /**
156: * Get a list of active product currencys indexed by id
157: */
158: public static function productPrices() {
159: $products = Product::model()->findAll(
160: array(
161: 'select'=>'id, price',
162: 'condition'=>'status=:active',
163: 'params'=>array(':active'=>'Active'),
164: )
165: );
166: $productPrices = array(0 => '');
167: foreach($products as $product)
168: $productPrices[$product->id] = $product->price;
169:
170: return $productPrices;
171: }
172: }
173: