Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Order Class Reference

Public Member Functions

 tableName ()
 rules ()
 relations ()
 scopes ()
 attributeLabels ()
 search ()
 getItems ()

Static Public Member Functions

static model ($className=__CLASS__)
static getOrder ($id_only=false)
static getUser ($id_only=false)
static getItemIsAdded ()
static getUserCacheId ($user_id)
static getOrderCacheId ($user_id)
static getOrderItemsCacheId ($user_id)
static flushOrder ()
static cleaning ()

Public Attributes

const ORDERED = 1
const PROCESS = 0
 $verifyCode

Detailed Description

Definition at line 20 of file Order.php.

Member Function Documentation

Order::attributeLabels ( )
Returns
array customized attribute labels (name=>label)

Definition at line 94 of file Order.php.

References WebCustModule\t().

{
return array(
'id' => ShoppingcartModule::t('ID'),
'ordered' => ShoppingcartModule::t('Ordered'),
'user_id' => ShoppingcartModule::t('User'),
'shipping_info' => ShoppingcartModule::t('Shipping Info'),
'payment_info' => ShoppingcartModule::t('Payment Info'),
'verifyCode' => ShoppingcartModule::t('Verify Code'),
);
}
static Order::cleaning ( )
static

The function that deletes unnecessary items, orders and users lifetime of which has already gone

Returns
void

Definition at line 258 of file Order.php.

References model().

{
$max_lifetime = Yii::app()->getModule('shoppingcart')->max_lifetime;
$connection = Yii::app()->db;
//Find all process orders which should be removed
Yii::beginProfile('garbageCollector');
$ordersToRemove = $command=$connection
->createCommand(
"SELECT ProcessOrder.id AS order_id,
ProcessOrder.user_id,
IF((DATE_ADD(IFNULL(MAX(Item.ordered_at),ProcessOrder.started_at), INTERVAL :max_lifetime MINUTE) < NOW()) , TRUE , FALSE) AS order_to_remove,
IF((COUNT(OrderedOrder.id) < 1) , TRUE, FALSE) AS user_to_remove
FROM {{order}} AS ProcessOrder
LEFT JOIN {{item}} AS Item
ON ProcessOrder.id = Item.order_id
LEFT JOIN {{order}} AS OrderedOrder
ON ProcessOrder.user_id = OrderedOrder.user_id AND OrderedOrder.ordered = :ordered
WHERE ProcessOrder.ordered=:process GROUP BY ProcessOrder.id
HAVING order_to_remove = TRUE")
->bindValues(array(
':max_lifetime' => $max_lifetime,
':ordered' => Order::ORDERED,
':process' => Order::PROCESS
))->queryAll();
$orderIds = array();
$userIds = array();
foreach($ordersToRemove as $order){
$orderIds[] = $order['order_id'];
if($order['user_to_remove']){
$userIds[] = $order['user_id'];
}
}
$orderIds = array_unique($orderIds);
$userIds = array_unique($userIds);
//Delete items
if(count($orderIds)){
$criteria=new CDbCriteria;
$criteria->addInCondition('order_id', $orderIds);
Item::model()->deleteAll($criteria);
}
//Delete orders
if(count($orderIds)){
$criteria=new CDbCriteria;
$criteria->addInCondition('id', $orderIds);
Order::model()->deleteAll($criteria);
}
//Delete users
if(count($orderIds)){
$criteria=new CDbCriteria;
$criteria->addInCondition('id', $userIds);
TmpUser::model()->deleteAll($criteria);
}
Yii::endProfile('garbageCollector');
}
Order::getItems ( )

The function performs caching of the order items

Returns
array order items

Definition at line 321 of file Order.php.

{
$user_id = self::getUser(true);
$cacheId = self::getOrderItemsCacheId($user_id);
if (!($data = Yii::app()->cache->get($cacheId, false))) {
$data = $this->order_items;
Yii::app()->cache->set($cacheId, $data, Yii::app()->getModule('shoppingcart')->cacheTime);
}
return $data;
}
static Order::model (   $className = __CLASS__)
static

Returns the static model of the specified AR class.

Parameters
string$classNameactive record class name.
Returns
Order the static model class

Definition at line 34 of file Order.php.

Referenced by cleaning(), and ShoppingcartTest\setUp().

{
return parent::model($className);
}
Order::relations ( )
Returns
array relational rules.

Definition at line 68 of file Order.php.

{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'order_items' => array(self::HAS_MANY, 'Item', 'order_id'),
);
}
Order::rules ( )
Returns
array validation rules for model attributes.

Definition at line 50 of file Order.php.

{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('ordered', 'numerical', 'integerOnly'=>true),
array('shipping_info, payment_info', 'length', 'max'=>1024),
array('user_id', 'length', 'max'=>10),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, ordered, user_id, tmp_user_id, shipping_info, payment_info', 'safe', 'on'=>'search'),
array('verifyCode','captcha','allowEmpty'=>!Yii::app()->user->isGuest || !CCaptcha::checkRequirements() || !Yii::app()->getModule('shoppingcart')->captchaEnabled, 'captchaAction' => '/shoppingcart/shoppingcart/captcha'),
);
}
Order::scopes ( )
Returns
array named scopes.

Definition at line 79 of file Order.php.

{
return array(
'ordered'=>array(
'condition'=>'ordered='.self::ORDERED,
),
'process'=>array(
'condition'=>'ordered='.self::PROCESS,
),
);
}
Order::search ( )

Retrieves a list of models based on the current search/filter conditions.

Returns
CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

Definition at line 234 of file Order.php.

{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('ordered',$this->ordered);
$criteria->compare('user_id',$this->user_id,true);
$criteria->compare('shipping_info',$this->shipping_info,true);
$criteria->compare('payment_info',$this->order_info,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Order::tableName ( )
Returns
string the associated database table name

Definition at line 42 of file Order.php.

{
return '{{order}}';
}

The documentation for this class was generated from the following file: