Ejemplo n.º 1
0
 public function prepareList($page_size = 5)
 {
     if ($page_size) {
         $sql = "SELECT COUNT(*)\n\t\t\t\t\tFROM `" . BackupOldDataTx::model()->tableName() . "` \n\t\t\t\t\tORDER BY `backup_date` DESC";
         $total = Yii::app()->db->createCommand($sql)->queryScalar();
         $pages = new CPagination($total);
         $pages->pageSize = $page_size;
         //$pages->applyLimit($criteria);
     }
     $sql = "SELECT *\n\t\t\t\tFROM `" . BackupOldDataTx::model()->tableName() . "` \n\t\t\t\tORDER BY `backup_date` DESC";
     if ($page_size) {
         $sql .= " LIMIT " . $pages->currentPage * $pages->pageSize . ", " . $pages->pageSize;
     }
     $res = Yii::app()->db->createCommand($sql)->queryAll();
     if ($res) {
         $ids = array();
         foreach ($res as $key => $value) {
             $ids[] = $value['id'];
         }
         $sql = "SELECT * \n\t\t\t\t\tFROM `" . BackupOldDataTxLog::model()->tableName() . "` \n\t\t\t\t\tWHERE `backup_id` IN (" . implode(',', $ids) . ") \n\t\t\t\t\tORDER BY `created` ASC";
         $res2 = Yii::app()->db->createCommand($sql)->queryAll();
         if ($res2) {
             foreach ($res2 as $key => $value) {
                 $res2prepared[$value['backup_id']][] = $value;
             }
             foreach ($res as $key => $value) {
                 $res[$key]['logs'] = $res2prepared[$value['id']] ? $res2prepared[$value['id']] : array();
             }
         }
     }
     return array('list' => $res, 'pages' => $pages);
 }
Ejemplo n.º 2
0
 public static function getLastBackupInfo()
 {
     $criteria = new CDbCriteria();
     $criteria->order = 'backup_date DESC';
     $criteria->limit = 1;
     return BackupOldDataTx::model()->find($criteria);
 }