本文整理汇总了PHP中Mage_Adminhtml_Block_Widget_Grid::getCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Adminhtml_Block_Widget_Grid::getCollection方法的具体用法?PHP Mage_Adminhtml_Block_Widget_Grid::getCollection怎么用?PHP Mage_Adminhtml_Block_Widget_Grid::getCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Adminhtml_Block_Widget_Grid
的用法示例。
在下文中一共展示了Mage_Adminhtml_Block_Widget_Grid::getCollection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCollection
/**
* Get collection object
*
* @return AntoineK_Slider_Model_Resource_Slider_Collection
*/
public function getCollection()
{
if (!parent::getCollection()) {
$collection = Mage::getResourceModel('antoinek_slider/slider_collection');
$this->setCollection($collection);
}
return parent::getCollection();
}
示例2: countTotals
/**
* Retrieve count totals
*
* @param Mage_Adminhtml_Block_Widget_Grid $grid
* @param string $from
* @param string $to
* @return Varien_Object
*/
public function countTotals($grid, $from, $to)
{
$columns = array();
foreach ($grid->getColumns() as $col) {
$columns[$col->getIndex()] = array("total" => $col->getTotal(), "value" => 0);
}
$count = 0;
$report = $grid->getCollection()->getReportFull($from, $to);
foreach ($report as $item) {
if ($grid->getSubReportSize() && $count >= $grid->getSubReportSize()) {
continue;
}
$data = $item->getData();
foreach ($columns as $field => $a) {
if ($field !== '') {
$columns[$field]['value'] = $columns[$field]['value'] + (isset($data[$field]) ? $data[$field] : 0);
}
}
$count++;
}
$data = array();
foreach ($columns as $field => $a) {
if ($a['total'] == 'avg') {
if ($field !== '') {
if ($count != 0) {
$data[$field] = $a['value'] / $count;
} else {
$data[$field] = 0;
}
}
} else {
if ($a['total'] == 'sum') {
if ($field !== '') {
$data[$field] = $a['value'];
}
} else {
if (strpos($a['total'], '/') !== FALSE) {
if ($field !== '') {
$data[$field] = 0;
}
}
}
}
}
$totals = new Varien_Object();
$totals->setData($data);
return $totals;
}
示例3: getCollection
/**
* Abstract Collection
*
* @return Magpleasure_Common_Model_Resource_Collection_Abstract
*/
public function getCollection()
{
return parent::getCollection();
}
示例4: afterGridPrepareCollection
public function afterGridPrepareCollection(Mage_Adminhtml_Block_Widget_Grid $grid)
{
$blockType = $grid->getType();
$blockId = $grid->getId();
if (!is_null($model = $this->_getGridModel($blockType, $blockId, true)) && !$model->getDisabled()) {
if ($grid->getCollection()) {
// Check grid model against grid columns
$grid->getCollection()->load();
$applyFromCollection = $model->checkColumnsAgainstGridBlock($grid);
// Apply it to grid block (only apply from collection if it could be checked)
$model->applyColumnsToGridBlock($grid, $applyFromCollection);
// Finish to prepare grid collection
$grid->blcg_finishPrepareCollection();
} else {
// If grid has no collection, check and apply directly
$model->checkColumnsAgainstGridBlock($grid);
$model->applyColumnsToGridBlock($grid, false);
}
}
}
示例5: getCollection
/**
* Return collection object
*
* @return Varien_Data_Collection
*/
public function getCollection()
{
$collection = parent::getCollection();
if ($this->_blcg_mustSelectAdditionalAttributes && $collection instanceof Mage_Eav_Model_Entity_Collection_Abstract && count($this->_blcg_additionalAttributes)) {
$this->_blcg_mustSelectAdditionalAttributes = false;
foreach ($this->_blcg_additionalAttributes as $attribute) {
$collection->joinAttribute($attribute['alias'], $attribute['attribute'], $attribute['bind'], $attribute['filter'], $attribute['join_type'], $attribute['store_id']);
}
}
return $collection;
}
示例6: checkColumnsAgainstGridBlock
/**
* Check values against grid block instance, and save up-to-date values
*
* @param Mage_Adminhtml_Block_Widget_Grid $grid Grid block instance
* @return bool Whether we could check collection columns (if false, using them could be "dangerous")
*/
public function checkColumnsAgainstGridBlock(Mage_Adminhtml_Block_Widget_Grid $grid)
{
$foundGridIds = array();
$gridIndexes = array();
// Grid columns
foreach ($grid->getColumns() as $column) {
$columnId = $column->getId();
if (isset($this->_columns[$columnId])) {
// Existing column : update its base values (all values that cannot be changed by user)
$previousOrigin = $this->_columns[$columnId]['origin'];
$this->_columns[$columnId] = array_merge($this->_columns[$columnId], array('id' => $columnId, 'index' => $column->getIndex(), 'origin' => self::GRID_COLUMN_ORIGIN_GRID, 'is_system' => $column->getIsSystem() ? 1 : 0, 'missing' => 0));
if (!$this->isGridColumnOrigin($previousOrigin)) {
// If column did not previously come from grid, refresh origin IDs
unset($this->_originIds[$previousOrigin][array_search($columnId, $this->_originIds[$previousOrigin])]);
$this->_originIds[self::GRID_COLUMN_ORIGIN_GRID][] = $columnId;
}
} else {
// New column
$this->_addColumnFromBlock($column, $this->_getNextOrder());
}
$gridIndexes[] = $column->getIndex();
$foundGridIds[] = $columnId;
}
$foundCollectionIds = array();
$checkedCollection = false;
// Collection columns
if ($grid->getCollection() && $grid->getCollection()->count() > 0) {
// Update collection columns if possible
$item = $grid->getCollection()->getFirstItem();
$checkedCollection = true;
foreach ($item->getData() as $key => $value) {
if (is_scalar($value) || is_null($value)) {
if (isset($this->_columns[$key])) {
// Existing column
$previousOrigin = $this->_columns[$key]['origin'];
if (!in_array($key, $foundGridIds, true)) {
// Existing column that already came from collection, or not found anymore in the grid
if (!in_array($key, $gridIndexes, true)) {
// If it doesnt now collide with a grid index, update its base values
$this->_columns[$key] = array_merge($this->_columns[$key], array('id' => $key, 'index' => $key, 'origin' => self::GRID_COLUMN_ORIGIN_COLLECTION, 'is_system' => 0, 'missing' => 0));
if (!$this->isCollectionColumnOrigin($previousOrigin)) {
// If column did not previously come from collection, remove it from its previous origin
unset($this->_originIds[$previousOrigin][array_search($key, $this->_originIds[$previousOrigin])]);
$this->_originIds[self::GRID_COLUMN_ORIGIN_COLLECTION][] = $key;
}
$foundCollectionIds[] = $key;
} else {
// If it does now collide with a grid index, remove it
unset($this->_columns[$key]);
}
}
// Existing column from the grid, already handled
} else {
if (!in_array($key, $foundGridIds, true) && !in_array($key, $gridIndexes, true)) {
// New column if no collision
$this->_addColumnFromCollection($key, $this->_getNextOrder());
$foundCollectionIds[] = $key;
}
}
}
}
}
// Attributes columns
$foundAttributesIds = array();
if ($this->canHaveAttributeColumns($this->getBlockType())) {
$columnsIds = $this->_originIds[self::GRID_COLUMN_ORIGIN_ATTRIBUTE];
$attributes = $this->getAvailableAttributesCodes();
foreach ($columnsIds as $columnId) {
// Verify attributes existences
if (in_array($this->_columns[$columnId]['index'], $attributes, true)) {
$this->_columns[$columnId]['missing'] = 0;
$foundAttributesIds[] = $columnId;
}
}
}
// Custom columns
$foundCustomIds = array();
if ($this->canHaveCustomColumns()) {
$columnsIds = $this->_originIds[self::GRID_COLUMN_ORIGIN_CUSTOM];
$availableCodes = $this->getAvailableCustomColumnsCodes(true);
foreach ($columnsIds as $columnId) {
// Verify custom columns existence / match
if (in_array($this->_columns[$columnId]['index'], $availableCodes, true)) {
$this->_columns[$columnId]['missing'] = 0;
$foundCustomIds[] = $columnId;
}
}
}
// Mark found to be missing columns as such
$foundIds = array_merge($foundGridIds, $foundCollectionIds, $foundAttributesIds, $foundCustomIds);
$missingIds = array_diff(array_keys($this->_columns), $foundIds);
foreach ($missingIds as $missingId) {
if ($checkedCollection || !$this->isCollectionColumnOrigin($this->_columns[$missingId]['origin'])) {
$this->_columns[$missingId]['missing'] = 1;
//.........这里部分代码省略.........