Mage_Backup_Model_Fs_Collection Class Reference

Inheritance diagram for Mage_Backup_Model_Fs_Collection:

Varien_Data_Collection

List of all members.

Public Member Functions

 __construct ()
 getSize ()
 load ($printQuery=false, $logQuery=false)
 setOrder ($field, $direction= 'desc')
 compareByTypeOrDate (Varien_Object $item1, Varien_Object $item2)
 addFieldToFilter ($fieldName, $condition)

Protected Member Functions

 _loadFiles ()
 _checkCondition ($item)

Protected Attributes

 $_isLoaded = false


Detailed Description

Definition at line 35 of file Collection.php.


Constructor & Destructor Documentation

__construct (  ) 

Constructor

Sets default item object class and default sort order.

Reimplemented from Varien_Data_Collection.

Definition at line 49 of file Collection.php.

00050     {
00051         parent::__construct();
00052         $this->setItemObjectClass(Mage::getConfig()->getModelClassName('backup/backup'))
00053              ->setOrder('time','desc');
00054 
00055     }


Member Function Documentation

_checkCondition ( item  )  [protected]

Definition at line 171 of file Collection.php.

00172     {
00173         foreach ($this->_filters as $field => $condition) {
00174             if (is_array($condition)) {
00175                 if (isset($condition['from']) || isset($condition['to'])) {
00176                     if ($field == 'time_formated') {
00177                         $format = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
00178                         if (isset($condition['from'])) {
00179                             $condition['from'] = Mage::app()->getLocale()->date($condition['from'], $format)->getTimestamp()
00180                                 + Mage::app()->getLocale()->date($condition['from'], $format)->getGmtOffset();
00181                         }
00182                         if (isset($condition['to'])) {
00183                             $condition['to'] = Mage::app()->getLocale()->date($condition['to'], $format)->getTimestamp()
00184                                 + Mage::app()->getLocale()->date($condition['to'], $format)->getGmtOffset();
00185                         }
00186                         $field = 'time';
00187                     }
00188 
00189                     if (isset($condition['from']) && $item->getData($field) < $condition['from']) {
00190                         return false;
00191                     }
00192                     if (isset($condition['to']) && $item->getData($field) > $condition['to']) {
00193                          return false;
00194                     }
00195                 }
00196                 elseif (!empty($condition['neq']) && $item->getData($field) == $condition['neq']) {
00197                     return false;
00198                 }
00199                 elseif (!empty($condition['like']) && strpos($item->getData($field), trim($condition['like'], '%')) === false) {
00200                     return false;
00201                 }
00202                 elseif (!empty($condition['nlike']) && strpos($item->getData($field), trim($condition['nlike'], '%')) !== false) {
00203                     return false;
00204                 }
00205                 elseif (!empty($condition['in'])) {
00206                     $values = $condition['in'];
00207                     if(!is_array($values)) {
00208                         $values =  array($values);
00209                     }
00210                     if(!in_array($item->getData($field), $values)) {
00211                         return false;
00212                     }
00213                 }
00214                 elseif (!empty($condition['nin'])) {
00215                     $values = $condition['in'];
00216                     if(!is_array($values)) {
00217                         $values =  array($values);
00218                     }
00219                     if(in_array($item->getData($field), $values)) {
00220                         return false;
00221                     }
00222                 }
00223             } else if($item->getData($field) != $condition) {
00224                 return false;
00225             }
00226         }
00227 
00228         return true;
00229     }

_loadFiles (  )  [protected]

Definition at line 80 of file Collection.php.

00081     {
00082         if (!$this->_isLoaded) {
00083 
00084             $readPath = Mage::getBaseDir('var') . DS . "backups";
00085 
00086             $ioProxy = new Varien_Io_File();
00087 
00088             try {
00089                 $ioProxy->open(array('path'=>$readPath));
00090             }
00091             catch (Exception $e) {
00092                 $ioProxy->mkdir($readPath, 0777);
00093                 $ioProxy->chmod($readPath, 0777);
00094                 $ioProxy->open(array('path'=>$readPath));
00095             }
00096 
00097             if (!is_file($readPath . DS . ".htaccess")) {
00098                 // Deny from reading in browser
00099                 $ioProxy->write(".htaccess","deny from all", 0644);
00100             }
00101 
00102 
00103             $list = $ioProxy->ls(Varien_Io_File::GREP_FILES);
00104 
00105             $fileExtension = constant($this->_itemObjectClass . "::BACKUP_EXTENSION");
00106 
00107             foreach ($list as $entry) {
00108                 if ($entry['filetype'] == $fileExtension) {
00109                     $item = new $this->_itemObjectClass();
00110                     $item->load($entry['text'], $readPath);
00111                     $item->setSize($entry['size']);
00112                     if ($this->_checkCondition($item)) {
00113                         $this->addItem($item);
00114                     }
00115                 }
00116             }
00117 
00118 
00119             $this->_totalRecords = count($this->_items);
00120 
00121             if ($this->_totalRecords > 1) {
00122                 usort($this->_items, array(&$this, 'compareByTypeOrDate'));
00123             }
00124 
00125             $this->_isLoaded = true;
00126         }
00127 
00128         return $this;
00129     }

addFieldToFilter ( fieldName,
condition 
)

Definition at line 165 of file Collection.php.

00166     {
00167         $this->_filters[$fieldName] = $condition;
00168         return $this;
00169     }

compareByTypeOrDate ( Varien_Object item1,
Varien_Object item2 
)

Function for comparing two items in collection

Parameters:
Varien_Object $item1
Varien_Object $item2
Returns:
boolean

Definition at line 152 of file Collection.php.

00153     {
00154         if (is_string($item1->getData($this->_orders[0]))) {
00155             return strcmp($item1->getData($this->_orders[0]),$item2->getData($this->_orders[0]))*(-1*$this->_orders[1]);
00156         } else if ($item1->getData($this->_orders[0]) < $item2->getData($this->_orders[0])) {
00157             return 1*(-1*$this->_orders[1]);
00158         } else if ($item1->getData($this->_orders[0]) > $item2->getData($this->_orders[0])) {
00159             return -1*(-1*$this->_orders[1]);
00160         } else {
00161             return 0;
00162         }
00163     }

getSize (  ) 

Loads data from backup directory

Returns:
Mage_Backup_Model_Fs_Collection

Reimplemented from Varien_Data_Collection.

Definition at line 62 of file Collection.php.

00063     {
00064         $this->_loadFiles();
00065         return $this->_totalRecords;
00066     }

load ( printQuery = false,
logQuery = false 
)

Load data

Returns:
Varien_Data_Collection

Reimplemented from Varien_Data_Collection.

Definition at line 68 of file Collection.php.

00069     {
00070         if (!$this->_isLoaded) {
00071             $this->_loadFiles();
00072             if($this->getPageSize()) {
00073                 $this->_items = array_slice($this->_items, ($this->getCurPage()-1)*$this->getPageSize(), $this->getPageSize());
00074             }
00075         }
00076 
00077         return $this;
00078     }

setOrder ( field,
direction = 'desc' 
)

Set sort order for items

Parameters:
string $field
string $direction
Returns:
Mage_Backup_Model_Fs_Collection

Reimplemented from Varien_Data_Collection.

Definition at line 138 of file Collection.php.

00139     {
00140         $direction = (strtoupper($direction)=='ASC') ? 1 : -1;
00141         $this->_orders = array($field, $direction);
00142         return $this;
00143     }


Member Data Documentation

$_isLoaded = false [protected]

Definition at line 41 of file Collection.php.


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

Generated on Sat Jul 4 17:23:33 2009 for Magento by  doxygen 1.5.8