diff --git a/.idea/tribook.iml b/.idea/tribook.iml deleted file mode 100644 index c956989..0000000 --- a/.idea/tribook.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 220d24e..921e689 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Blog Tribook +# Blog Triboo ## 0.1.1 - 27.03.2019 -- First release of the module tutorial \ No newline at end of file +- First release of the module tutorial diff --git a/app/code/local/Triboo/Blog/Block/Adminhtml/Post.php b/app/code/local/Triboo/Blog/Block/Adminhtml/Post.php new file mode 100644 index 0000000..3519aac --- /dev/null +++ b/app/code/local/Triboo/Blog/Block/Adminhtml/Post.php @@ -0,0 +1,26 @@ +_controller = 'adminhtml_post'; + $this->_blockGroup = 'tbblog'; + #header text label + $this->_headerText = 'Manage the posts'; + #button label + $this->_addButtonLabel = 'Add a post'; + parent::__construct(); + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/Block/Adminhtml/Post/Grid.php b/app/code/local/Triboo/Blog/Block/Adminhtml/Post/Grid.php new file mode 100644 index 0000000..35f6d1c --- /dev/null +++ b/app/code/local/Triboo/Blog/Block/Adminhtml/Post/Grid.php @@ -0,0 +1,61 @@ +setId('tbblog_post_grid'); + $this->setDefaultSort('entity_id'); + $this->setDefaultDir('DESC'); + $this->setSaveParametersInSession(true); + } + + /** + *@return array + */ + public function _prepareCollection(): array + { + $collection = Mage::getModel(Triboo_Blog_Helper_Config::ENTITY_TABLE_POST)->getCollection(); + $this->setCollection($collection); + return parent::_prepareCollection(); + } + + /** + * @return array + */ + public function _prepareColumns(): array + { + $this->addColumn( + 'entity_id', [ + 'header' => 'Entity ID', + 'index' => 'entity_id', + 'type' => 'number' + ]); + $this->addColumn( + 'is_active', [ + 'header' => 'Is Active', + 'index' => 'is_active', + 'type' => 'number' + ]); + $this->addColumn( + 'created_at', [ + 'header' => 'Created At', + 'index' => 'created_at', + 'type' => 'date' + ]); + $this->addColumn( + 'updated_at', [ + 'header' => 'Updated At', + 'index' => 'updated_at', + 'type' => 'date' + ]); + + return parent::_prepareColumns(); + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/Helper/Config.php b/app/code/local/Triboo/Blog/Helper/Config.php new file mode 100644 index 0000000..2e938b6 --- /dev/null +++ b/app/code/local/Triboo/Blog/Helper/Config.php @@ -0,0 +1,23 @@ +isLogEnable = Mage::getStoreConfig(Triboo_Blog_Helper_Config::LOG_ENABLE_CONFIG) ?: false; + } + /** + * @var $message + * @return string + */ + public function log($message): string + { + if ($this->isLogEnable) + { + Mage::log($message, null, self::LOG_FILE); + } + return $message; + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/Model/Post.php b/app/code/local/Triboo/Blog/Model/Post.php new file mode 100644 index 0000000..5e7d64e --- /dev/null +++ b/app/code/local/Triboo/Blog/Model/Post.php @@ -0,0 +1,16 @@ +_init('tbblog/post'); + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/Model/Resource/Post.php b/app/code/local/Triboo/Blog/Model/Resource/Post.php new file mode 100644 index 0000000..cecb664 --- /dev/null +++ b/app/code/local/Triboo/Blog/Model/Resource/Post.php @@ -0,0 +1,36 @@ +setType(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST); + $this->setConnection( + $resource->getConnection(Triboo_Blog_Helper_Config::CONNECTION_READ), + $resource->getConnection(Triboo_Blog_Helper_Config::CONNECTION_WRITE) + ); + } + /** + * Triboo_Blog_Model_Resource_Post getDefaultAttributes. + * @return array + */ + protected function __getDefaultAttributes() + { + return [ + 'entity_type_id', + 'attribute_set_id', + 'created_at', + 'updated_at', + 'increment_id', + 'store_id', + ]; + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/Model/Resource/Post/Collection.php b/app/code/local/Triboo/Blog/Model/Resource/Post/Collection.php new file mode 100644 index 0000000..150ec31 --- /dev/null +++ b/app/code/local/Triboo/Blog/Model/Resource/Post/Collection.php @@ -0,0 +1,16 @@ +_init('tbblog/post'); + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/Model/Resource/Setup.php b/app/code/local/Triboo/Blog/Model/Resource/Setup.php new file mode 100644 index 0000000..d02b721 --- /dev/null +++ b/app/code/local/Triboo/Blog/Model/Resource/Setup.php @@ -0,0 +1,63 @@ + [ + 'entity_model' => Triboo_Blog_Helper_Config::ENTITY_MODEL_POST, + 'attribute_model' => '', + 'table' => Triboo_Blog_Helper_Config::ENTITY_TABLE_POST, + 'attributes' => [ + 'title' => [ + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Title', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ], + 'author' => [ + 'type' => 'varchar', + 'label' => 'Author', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] + ] + ] + ]; + + return $entities; + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/controllers/Adminhtml/PostController.php b/app/code/local/Triboo/Blog/controllers/Adminhtml/PostController.php new file mode 100644 index 0000000..86aa721 --- /dev/null +++ b/app/code/local/Triboo/Blog/controllers/Adminhtml/PostController.php @@ -0,0 +1,37 @@ +loadLayout(); + /* + * output layout + */ + $this->renderLayout(); + } + + /** + * + */ + public function gridAction() + { + $this->loadLayout() + ->getresponse()->setBody( + $this->getLayout()->createBlock('blog/adminhtml_post_grid')->toHtml() + ); + } +} \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/etc/adminhtml.xml b/app/code/local/Triboo/Blog/etc/adminhtml.xml new file mode 100644 index 0000000..352eb65 --- /dev/null +++ b/app/code/local/Triboo/Blog/etc/adminhtml.xml @@ -0,0 +1,47 @@ + + + + + + Blog + 150 + + + Manage Posts + adminhtml/post + + + + + + + + + + + + + + + Triboo log + + + + + + + + Blog + 150 + + + Manage Posts + + + + + + + + + \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/etc/config.xml b/app/code/local/Triboo/Blog/etc/config.xml similarity index 50% rename from app/code/local/Tribook/Blog/etc/config.xml rename to app/code/local/Triboo/Blog/etc/config.xml index 523c122..fbfef71 100644 --- a/app/code/local/Tribook/Blog/etc/config.xml +++ b/app/code/local/Triboo/Blog/etc/config.xml @@ -1,63 +1,63 @@ - + 0.1.1 - + - - Tribook_Blog_Block - + + Triboo_Blog_Block + - - Tribook_Blog_Helper - + + Triboo_Blog_Helper + - - Tribook_Blog_Model - tribook_blog_resource - - - Tribook_Blog_Model_Resource + + Triboo_Blog_Model + triboo_blog_resource + + + Triboo_Blog_Model_Resource - tribook_blog_post_entity
+ tbblog_post_entity
- tribook_blog_post_entity_datetime
+ tbblog_post_entity_datetime
- tribook_blog_post_entity_decimal
+ tbblog_post_entity_decimal
- tribook_blog_post_entity_int
+ tbblog_post_entity_int
- tribook_blog_post_entity_text
+ tbblog_post_entity_text
- tribook_blog_post_entity_varchar
+ tbblog_post_entity_varchar
- tribook_blog_post_entity_char
+ tbblog_post_entity_char
-
+
- + - Tribook_Blog - Tribook_Blog_Model_Resource_Setup + Triboo_Blog + Triboo_Blog_Model_Resource_Setup core_setup - + core_write @@ -72,13 +72,25 @@
- + standard - Tribook_Blog + Triboo_Blog blog - + + + + + admin + + + Triboo_Blog_Adminhtml + + + + +
\ No newline at end of file diff --git a/app/code/local/Tribook/Blog/etc/system.xml b/app/code/local/Triboo/Blog/etc/system.xml similarity index 75% rename from app/code/local/Tribook/Blog/etc/system.xml rename to app/code/local/Triboo/Blog/etc/system.xml index 5461e92..d03fc62 100644 --- a/app/code/local/Tribook/Blog/etc/system.xml +++ b/app/code/local/Triboo/Blog/etc/system.xml @@ -1,16 +1,17 @@ - - - 99999 - + + + 10 + - - - tribook_tab - 1000 + + + + tb_tab + 2 1 1 1 @@ -35,6 +36,7 @@ - + + \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/sql/tbblog_setup/install-0.1.0.php b/app/code/local/Triboo/Blog/sql/tbblog_setup/install-0.1.0.php new file mode 100644 index 0000000..2443fa7 --- /dev/null +++ b/app/code/local/Triboo/Blog/sql/tbblog_setup/install-0.1.0.php @@ -0,0 +1,26 @@ +startSetup(); +/** + * Create all entity tables + */ +$installer->createEntityTables( + $this->getTable(Triboo_Blog_Helper_Config::ENTITY_TABLE_POST) +); +/** + * Add Entity type + */ +$installer->addEntityType(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST, [ + 'entity_model' => Triboo_Blog_Helper_Config::ENTITY_MODEL_POST, + 'attribute_model' => '', + 'table' => Triboo_Blog_Helper_Config::ENTITY_TABLE_POST, + 'increment_model' => '', + 'increment_per_store' => '0' + ] +); +/** + * install Entities with method getDefaultEntities that is in Triboo_Blog_Model_Resource_Setup + */ +$installer->installEntities(); +$installer->endSetup(); \ No newline at end of file diff --git a/app/code/local/Triboo/Blog/sql/tbblog_setup/upgrade-0.1.0-0.1.1.php b/app/code/local/Triboo/Blog/sql/tbblog_setup/upgrade-0.1.0-0.1.1.php new file mode 100644 index 0000000..c013b3c --- /dev/null +++ b/app/code/local/Triboo/Blog/sql/tbblog_setup/upgrade-0.1.0-0.1.1.php @@ -0,0 +1,130 @@ +startSetup(); +/** + * Adding new attribute "created_at" + */ +$installer->addAttribute(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST , 'created_at', [ + 'type' => 'datetime', + 'label' => 'created_at', + 'input' => 'date', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] +); +/** + * Adding new attribute "updated_at" + */ +$installer->addAttribute(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST , 'updated_at', [ + 'type' => 'datetime', + 'label' => 'updated_at', + 'input' => 'date', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '0', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] +); +/** + * Adding new attribute "enable" + */ +$installer->addAttribute(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST , 'enable', [ + 'type' => 'int', + 'label' => 'enable', + 'input' => 'boolean', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '0', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] +); +/** + * Adding new attribute "post_image" + */ +$installer->addAttribute(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST , 'post_image', [ + 'type' => 'varchar', + 'label' => 'post_image', + 'input' => 'media_image', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] +); +/** + * Adding new attribute "description" + */ +$installer->addAttribute(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST , 'description', [ + 'type' => 'varchar', + 'label' => 'description', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] +); +/** + * Adding new attribute "short_description" + */ +$installer->addAttribute(Triboo_Blog_Helper_Config::ENTITY_TYPE_CODE_POST , 'short_description', [ + 'type' => 'varchar', + 'label' => 'description', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => 0, + 'visible' => true, + 'required' => true, + 'user_defined' => true, + 'default' => '', + 'searchable' => false, + 'filterable' => false, + 'comparable' => false, + 'visible_on_front' => true, + 'unique' => false, + ] +); +$installer -> endSetup(); \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/Block/Block.php b/app/code/local/Tribook/Blog/Block/Block.php deleted file mode 100644 index 2084ca3..0000000 --- a/app/code/local/Tribook/Blog/Block/Block.php +++ /dev/null @@ -1,6 +0,0 @@ -isLogEnable = Mage::getStoreConfig(self::LOG_ENABLE_CONFIG) ?: false; - } - - /** - * @param $message - * @return string - */ - public function log($message) - { - if ($this->isLogEnable) - { - Mage::log($message, null, self::LOG_FILE); - } - return $message; - } -} \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/Model/Post.php b/app/code/local/Tribook/Blog/Model/Post.php deleted file mode 100644 index 4612c38..0000000 --- a/app/code/local/Tribook/Blog/Model/Post.php +++ /dev/null @@ -1,8 +0,0 @@ -_init('tribook_blog/post');//Resource model - } -} diff --git a/app/code/local/Tribook/Blog/Model/Resource/Post.php b/app/code/local/Tribook/Blog/Model/Resource/Post.php deleted file mode 100644 index 76838a1..0000000 --- a/app/code/local/Tribook/Blog/Model/Resource/Post.php +++ /dev/null @@ -1,29 +0,0 @@ -setType('tribook_blog_post'); //entity type resource che andrà ad usare. - $this->setConnection( - $resource->getConnection('blog_read'), //connections read/write - $resource->getConnection('blog_write') - ); - } - - protected function __getDefaultAttributes() - { - return [ - 'entity_type_id', - 'attribute_set_id', - 'created_at', - 'updated_at', - 'increment_id', - 'store_id', - ]; - } -} diff --git a/app/code/local/Tribook/Blog/Model/Resource/Post/Collection.php b/app/code/local/Tribook/Blog/Model/Resource/Post/Collection.php deleted file mode 100644 index 97f14fb..0000000 --- a/app/code/local/Tribook/Blog/Model/Resource/Post/Collection.php +++ /dev/null @@ -1,11 +0,0 @@ -_init('tribook_blog/post'); - } -} - - - diff --git a/app/code/local/Tribook/Blog/Model/Resource/Setup.php b/app/code/local/Tribook/Blog/Model/Resource/Setup.php deleted file mode 100644 index 8332770..0000000 --- a/app/code/local/Tribook/Blog/Model/Resource/Setup.php +++ /dev/null @@ -1,51 +0,0 @@ - array( - 'entity_model' => 'tribook_blog/post', - 'attribute_model'=>'', - 'table'=>'tribook_blog/post_entity', - 'attributes' => array( - 'title' => array( - 'type'=>'varchar', - 'backend'=>'', - 'frontend'=>'', - 'label' => 'Title', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => 0, - 'visible' => true, - 'required' => true, - 'user_defined' => true, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => true, - 'unique' => false, - ), - 'author' => array( - 'type'=>'varchar', - 'label' => 'Author', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => 0, - 'visible' => true, - 'required' => true, - 'user_defined' => true, - 'default' => '', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => true, - 'unique' => false, - ), - ), - ) - ); - return $entities; - } -} \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/controllers/IndexController.php b/app/code/local/Tribook/Blog/controllers/IndexController.php deleted file mode 100644 index 92f4b88..0000000 --- a/app/code/local/Tribook/Blog/controllers/IndexController.php +++ /dev/null @@ -1,49 +0,0 @@ -setTitle('Test title'); - $post->setAuthor('Zoran Šalamun'); - $post->setDescription('This is a description'); - $post->setEnable(1); - $post->save(); - - - /* - * Getting posts collection - * -also load collection - * -this will load all post entries but without attributes - * -loaded data is only from tribook_blog_post_entity table - */ - $posts = Mage::getModel('tribook_blog/post')->getCollection(); - $posts->load(); - var_dump($posts); - - /* - * Getting post collection - * -load all posts - * -set attributs to be in collection data - */ - $posts = Mage::getModel('tribook_blog/post')->getCollection() - ->addAttributeToSelect('title') - ->addAttributeToSelect('author') - ->addAttributeToSelect('description') - ->addAttributeToSelect('enable'); - $posts->load(); - var_dump($posts); - - /* - * Load signle post - * -loading single post will get all attributes that we have set for post - */ - $post = Mage::getModel('tribook_blog/post')->load(1); - var_dump($post); - } -} \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/etc/adminhtml.xml b/app/code/local/Tribook/Blog/etc/adminhtml.xml deleted file mode 100644 index 822240d..0000000 --- a/app/code/local/Tribook/Blog/etc/adminhtml.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - Tribook - - - - - - - - - - \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/sql/tribook_blog_setup/install-0.1.0.php b/app/code/local/Tribook/Blog/sql/tribook_blog_setup/install-0.1.0.php deleted file mode 100644 index 43ed74f..0000000 --- a/app/code/local/Tribook/Blog/sql/tribook_blog_setup/install-0.1.0.php +++ /dev/null @@ -1,24 +0,0 @@ -startSetup(); -/* - * Create all entity tables - */ -$installer->createEntityTables( - $this->getTable('tribook_blog/post_entity') -); - -/* - * Add Entity type - */ -$installer->addEntityType('tribook_blog_post', Array( - 'entity_model' => 'tribook_blog/post', - 'attribute_model' =>'', - 'table' =>'tribook_blog/post_entity', - 'increment_model' =>'', - 'increment_per_store' =>'0' -)); - -$installer->installEntities(); - -$installer->endSetup(); \ No newline at end of file diff --git a/app/code/local/Tribook/Blog/sql/tribook_blog_setup/upgrade-0.1.0-0.1.1.php b/app/code/local/Tribook/Blog/sql/tribook_blog_setup/upgrade-0.1.0-0.1.1.php deleted file mode 100644 index 2e69e21..0000000 --- a/app/code/local/Tribook/Blog/sql/tribook_blog_setup/upgrade-0.1.0-0.1.1.php +++ /dev/null @@ -1,41 +0,0 @@ -startSetup(); - -$installer->addAttribute('tribook_blog_post', 'enable', array( - 'type' => 'int', - 'label' => 'enable', - 'input' => 'boolean', - 'class' => '', - 'source' => '', - 'global' => 0, - 'visible' => true, - 'required' => true, - 'user_defined' => true, - 'default' => '0', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => true, - 'unique' => false, - ) -); -$installer->addAttribute('tribook_blog_post', 'description', array( - 'type' => 'varchar', - 'label' => 'description', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => 0, - 'visible' => true, - 'required' => true, - 'user_defined' => true, - 'default' => '0', - 'searchable' => false, - 'filterable' => false, - 'comparable' => false, - 'visible_on_front' => true, - 'unique' => false, - ) -); -$installer -> endSetup(); \ No newline at end of file diff --git a/app/design/adminhtml/default/default/layout/blog.xml b/app/design/adminhtml/default/default/layout/blog.xml new file mode 100644 index 0000000..580ab98 --- /dev/null +++ b/app/design/adminhtml/default/default/layout/blog.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/etc/modules/Tribook_Blog.xml b/app/etc/modules/Triboo_Blog.xml similarity index 75% rename from app/etc/modules/Tribook_Blog.xml rename to app/etc/modules/Triboo_Blog.xml index 86af67f..95f0210 100644 --- a/app/etc/modules/Tribook_Blog.xml +++ b/app/etc/modules/Triboo_Blog.xml @@ -1,9 +1,9 @@ - + true local - + diff --git a/modman b/modman index 9f036a8..99379cd 100644 --- a/modman +++ b/modman @@ -1,2 +1,2 @@ -app/code/local/Tribook app/code/local/Tribook -app/etc/modules/Tribook_Blog.xml app/etc/modules/Tribook_Blog.xml \ No newline at end of file +app/code/local/Triboo app/code/local/Triboo +app/etc/modules/Triboo_Blog.xml app/etc/modules/Triboo_Blog.xml \ No newline at end of file