Created
August 13, 2012 22:24
-
-
Save jacquesbh/3344499 to your computer and use it in GitHub Desktop.
[blog] Jbh_Grid (http://jacques.sh/apprendre-a-utiliser-magento-installer.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Init :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
--> | |
<config> | |
<menu> | |
<jbh_grid translate="title" module="jbh_grid"> | |
<title>Manage Foos</title> | |
<sort_order>10</sort_order> | |
<action>jbh_grid_adminhtml/index/grid</action> | |
</jbh_grid> | |
</menu> | |
<acl> | |
<resources> | |
<admin> | |
<children> | |
<jbh_grid translate="title" module="jbh_grid"> | |
<title>Manage Foos</title> | |
<sort_order>10</sort_order> | |
</jbh_grid> | |
</children> | |
</admin> | |
</resources> | |
</acl> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Collection of Foo | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Model_Mysql4_Foo_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
/** | |
* Foo Collection Resource Constructor | |
* @access protected | |
* @return void | |
*/ | |
protected function _construct() | |
{ | |
parent::_construct(); | |
$this->_init('jbh_grid/foo'); | |
} | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
--> | |
<config> | |
<modules> | |
<Jbh_Grid> | |
<version>0.1.0</version> | |
</Jbh_Grid> | |
</modules> | |
<global> | |
<models> | |
<jbh_grid> | |
<class>Jbh_Grid_Model</class> | |
<resourceModel>jbh_grid_mysql4</resourceModel> | |
</jbh_grid> | |
<jbh_grid_mysql4> | |
<class>Jbh_Grid_Model_Mysql4</class> | |
<entities> | |
<foo> | |
<table>jbh_grid_foo</table> | |
</foo> | |
</entities> | |
</jbh_grid_mysql4> | |
</models> | |
<blocks> | |
<jbh_grid> | |
<class>Jbh_Grid_Block</class> | |
</jbh_grid> | |
</blocks> | |
<resources> | |
<jbh_grid_setup> | |
<setup> | |
<module>Jbh_Grid</module> | |
<class>Mage_Core_Model_Resource_Setup</class> | |
</setup> | |
</jbh_grid_setup> | |
</resources> | |
<helpers> | |
<jbh_grid> | |
<class>Jbh_Grid_Helper</class> | |
</jbh_grid> | |
</helpers> | |
</global> | |
<admin> | |
<routers> | |
<jbh_grid_adminhtml> | |
<use>admin</use> | |
<args> | |
<module>Jbh_Grid_Adminhtml</module> | |
<frontName>foo_adminhtml</frontName> | |
</args> | |
</jbh_grid_adminhtml> | |
</routers> | |
</admin> | |
<frontend /> | |
<adminhtml> | |
<translate> | |
<modules> | |
<Jbh_Grid> | |
<files> | |
<default>Jbh_Grid.csv</default> | |
</files> | |
</Jbh_Grid> | |
</modules> | |
</translate> | |
</adminhtml> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://sam.zoy.org/wtfpl/COPYING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Data Helper | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Helper_Data extends Mage_Core_Helper_Abstract | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Foo Grid Container | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Block_Adminhtml_Foo extends Mage_Adminhtml_Block_Widget_Grid_Container | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
/** | |
* Constructor Override | |
* @access protected | |
* @return Jbh_Grid_Block_Adminhtml_Foo | |
*/ | |
protected function _construct() | |
{ | |
parent::_construct(); | |
$this->_blockGroup = 'jbh_grid'; | |
$this->_controller = 'adminhtml_foo'; | |
$this->_headerText = $this->__('Manage Foos'); | |
return $this; | |
} | |
/** | |
* Prepare Layout | |
* @access protected | |
* @return Jbh_Grid_Block_Adminhtml_Foo | |
*/ | |
protected function _prepareLayout() | |
{ | |
$this->_removeButton('add'); | |
return parent::_prepareLayout(); | |
} | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Foo Model | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Model_Foo extends Mage_Core_Model_Abstract | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
/** | |
* Prefix of model events names | |
* @var string | |
*/ | |
protected $_eventPrefix = 'foo'; | |
/** | |
* Parameter name in event | |
* In observe method you can use $observer->getEvent()->getObject() in this case | |
* @var string | |
*/ | |
protected $_eventObject = 'foo'; | |
/** | |
* Foo Constructor | |
* @access protected | |
* @return void | |
*/ | |
protected function _construct() | |
{ | |
parent::_construct(); | |
$this->_init('jbh_grid/foo'); | |
} | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Resource Model of Foo | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Model_Mysql4_Foo extends Mage_Core_Model_Mysql4_Abstract | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
/** | |
* Foo Resource Constructor | |
* @access protected | |
* @return void | |
*/ | |
protected function _construct() | |
{ | |
$this->_init('jbh_grid/foo', 'foo_id'); | |
} | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Foo Grid | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Block_Adminhtml_Foo_Grid extends Mage_Adminhtml_Block_Widget_Grid | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
/** | |
* Get collection object | |
* @access public | |
* @return Jbh_Grid_Model_Mysql4_Foo_Collection | |
*/ | |
public function getCollection() | |
{ | |
if (!parent::getCollection()) { | |
$collection = Mage::getResourceModel('jbh_grid/foo_collection'); | |
$this->setCollection($collection); | |
} | |
return parent::getCollection(); | |
} | |
/** | |
* Prepare columns | |
* @access protected | |
* @return Jbh_Grid_Block_Adminhtml_Foo_Grid | |
*/ | |
protected function _prepareColumns() | |
{ | |
$help = Mage::helper('jbh_grid'); | |
$this->addColumn('foo_id', array( | |
'header' => $help->__('Foo #'), | |
'type' => 'number', | |
'index' => 'foo_id' | |
)); | |
$this->addColumn('text', array( | |
'header' => $help->__('Text'), | |
'type' => 'text', | |
'index' => 'text' | |
)); | |
$this->addColumn('created_at', array( | |
'header' => Mage::helper('adminhtml')->__('Created At'), | |
'type' => 'datetime', | |
'index' => 'created_at' | |
)); | |
$this->addColumn('updated_at', array( | |
'header' => Mage::helper('adminhtml')->__('Updated At'), | |
'type' => 'datetime', | |
'index' => 'updated_at' | |
)); | |
return parent::_prepareColumns(); | |
} | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/** | |
* Adminhtml_Index Controller | |
* @package Jbh_Grid | |
*/ | |
class Jbh_Grid_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action | |
{ | |
// Jacques Bodin-Hullin Tag NEW_CONST | |
// Jacques Bodin-Hullin Tag NEW_VAR | |
/** | |
* Foos grid | |
* @access public | |
* @return void | |
*/ | |
public function gridAction() | |
{ | |
$this->loadLayout(); | |
$this->_addContent($this->getLayout()->createBlock('jbh_grid/adminhtml_foo', 'grid_container')); | |
$this->renderLayout(); | |
} | |
/** | |
* Allowed? | |
* @access protected | |
* @return bool | |
*/ | |
protected function _isAllowed() | |
{ | |
return Mage::getSingleton('admin/session')->isAllowed('jbh_grid'); | |
} | |
// Jacques Bodin-Hullin Tag NEW_METHOD | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Foo # | Foo # | |
---|---|---|
Text | Text | |
Manage Foos | Manage Foos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Foo # | Foo ID | |
---|---|---|
Text | Texte | |
Manage Foos | Gérer les Foos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
--> | |
<config> | |
<modules> | |
<Jbh_Grid> | |
<active>true</active> | |
<codePool>local</codePool> | |
</Jbh_Grid> | |
</modules> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of Jbh_Grid for Magento. | |
* | |
* @license WTFPL (http://sam.zoy.org/wtfpl/COPYING) | |
* @author Jacques Bodin-Hullin <[email protected]> | |
* @category Jbh | |
* @package Jbh_Grid | |
* @copyright Copyright (c) 2012 Jacques Bodin-Hullin (http://jacques.sh/) | |
*/ | |
/* @var $installer Mage_Core_Model_Resource_Setup */ | |
$installer = $this; | |
$installer->startSetup(); | |
try { | |
if (!$installer->tableExists($installer->getTable('jbh_grid/foo'))) { | |
$sql = <<<SQL | |
CREATE TABLE `{$installer->getTable('jbh_grid/foo')}` ( | |
`foo_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The Foo ID', | |
`text` text COMMENT 'The text of our Foo', | |
`created_at` datetime NOT NULL COMMENT 'Creation date', | |
`updated_at` datetime NOT NULL COMMENT 'Update date', | |
PRIMARY KEY (`foo_id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
SQL; | |
$installer->run($sql); | |
} | |
} catch (Exception $e) { | |
// silence is golden | |
} | |
$installer->endSetup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment