Exemple #1
0
 /**
  * List all Cache types
  *
  * @return  MageHack_MageConsole_Model_Abstract
  */
 public function listing()
 {
     $collection = new Varien_Data_Collection();
     foreach (Mage::app()->getCacheInstance()->getTypes() as $type) {
         $collection->addItem($type);
     }
     if (!$collection->count()) {
         $message = 'This is strange, we did not find any cache types.';
         $this->setType(self::RESPONSE_TYPE_MESSAGE);
         $this->setMessage($message);
     } else {
         if ($collection->count() > 0) {
             $values = $collection->toArray();
             if (is_array($values) && $values['totalRecords'] > 0) {
                 foreach ($values['items'] as $row) {
                     if (is_array($row)) {
                         $_values[] = array_intersect_key($row, $this->_attrToShow);
                     }
                 }
                 if (Mage::getStoreConfig('admin/mageconsole/html_tables') != 1) {
                     $this->setType(self::RESPONSE_TYPE_MESSAGE);
                     $message = Mage::helper('mageconsole')->createTable($_values, true, $this->_columnWidths);
                     $this->setMessage($message);
                 } else {
                     $this->setMessage($_values);
                     $this->setType(self::RESPONSE_TYPE_LIST);
                 }
             }
         }
     }
     return $this;
 }
Exemple #2
0
 public function getCsv(Varien_Data_Collection $collection, $getAll = false)
 {
     $csv = '';
     $collectionData = $collection->toArray();
     $type = $collection->getEntity()->getType();
     // first pass, collect header
     $_columns = array();
     $_ignoredColumns = array();
     // speedup
     foreach ($collectionData as $item) {
         foreach ($item as $key => $value) {
             if (gettype($value) == 'Array') {
                 $_ignoredColumns[] = $key;
             }
             if ($getAll) {
                 $_columns[] = $key;
             } else {
                 if (!in_array($key, $_columns) && !in_array($key, $_ignoredColumns)) {
                     $attr = Mage::getModel('eav/entity_attribute')->loadByCode($type, $key);
                     // get rid of non-attributes
                     if (!count($attr->getData())) {
                         $_ignoredColumns[] = $key;
                     } else {
                         $_columns[] = $key;
                     }
                 }
             }
         }
     }
     $data = array();
     // add headers as first row
     foreach ($_columns as $column) {
         $data[] = "\"{$column}\"";
     }
     $csv .= implode(',', $data) . "\n";
     // second pass, concatenate data content
     foreach ($collectionData as $item) {
         $data = array();
         foreach ($_columns as $column) {
             $data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), $item[$column]) . '"';
         }
         $csv .= implode(',', $data) . "\n";
     }
     return $csv;
 }
Exemple #3
0
 /**
  *
  * @param Varien_Data_Collection $collection
  * @return array
  */
 protected function _getCollectionData(Varien_Data_Collection $collection)
 {
     return array_values($collection->toArray());
 }