/**
  * Show purchase history of knight
  */
 public function actionPurchasesHistory()
 {
     //Init
     $rowsByPage = 10;
     $data = array('result' => array(), 'armours_list' => array(), 'spears_list' => array(), 'equipment_rarity' => array(), 'total_purchases' => 0, 'rowsByPage' => $rowsByPage, 'page' => 1);
     //Check input
     if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0) {
         $data['page'] = $_GET['page'];
     }
     //Load total of purchases
     $data['total_purchases'] = KnightsPurchases::model()->count('knights_id = :knights_id', array(':knights_id' => Yii::app()->user->knights_id));
     //Load list of purchases
     $criteria = new CDbCriteria();
     $criteria->offset = $rowsByPage * ($data['page'] - 1);
     $criteria->limit = $rowsByPage;
     $criteria->order = 'date DESC';
     $criteria->condition = 'knights_id = :knights_id';
     $criteria->params = array(':knights_id' => Yii::app()->user->knights_id);
     $data['result'] = KnightsPurchases::model()->findAll($criteria);
     //foreach purchase load item
     if (count($data['result'])) {
         $conditions_armours = '1=0 ';
         $conditions_spears = '1=0 ';
         $params_armours = array();
         $params_spears = array();
         foreach ($data['result'] as $row) {
             if ($row->inventory_type_id == Inventory::EQUIPMENT_TYPE_ARMOUR) {
                 $conditions_armours .= ' OR id = :id' . $row->identificator;
                 $params_armours['id' . $row->identificator] = $row->identificator;
             } elseif ($row->inventory_type_id == Inventory::EQUIPMENT_TYPE_SPEAR) {
                 $conditions_spears .= ' OR id = :id' . $row->identificator;
                 $params_spears['id' . $row->identificator] = $row->identificator;
             }
         }
         //Load spears and armours
         $data['armours_list'] = Armours::model()->findAll(array('index' => 'id', 'condition' => $conditions_armours, 'params' => $params_armours));
         $data['spears_list'] = Spears::model()->findAll(array('index' => 'id', 'condition' => $conditions_spears, 'params' => $params_spears));
         //Load equipment rarity table
         $data['equipment_rarity'] = EquipmentRarity::model()->findAll(array('index' => 'id'));
     }
     //Render template
     $this->render('purchasesHistory', $data);
 }
 public function getEquipmentRarityText()
 {
     $model = EquipmentRarity::model()->findByPk($this->equipment_rarity_id);
     return $model->name;
 }