Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .idea/tribook.iml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Blog Tribook
# Blog Triboo

## 0.1.1 - 27.03.2019
- First release of the module tutorial
- First release of the module tutorial
26 changes: 26 additions & 0 deletions app/code/local/Triboo/Blog/Block/Adminhtml/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Class Triboo_Blog_Block_Adminhtml_Post
*/
class Triboo_Blog_Block_Adminhtml_Post extends Mage_Adminhtml_Block_Widget_Grid_Container
{
/**
* Triboo_Blog_Block_Adminhtml_Post constructor.
* @var _controller
* @var _blockGroup
* @var _headerText
* @var _addButtonLabel
*/
public function __construct()
{
#where you can find the controller
$this->_controller = 'adminhtml_post';
$this->_blockGroup = 'tbblog';
#header text label
$this->_headerText = 'Manage the posts';
#button label
$this->_addButtonLabel = 'Add a post';
parent::__construct();
}
}
61 changes: 61 additions & 0 deletions app/code/local/Triboo/Blog/Block/Adminhtml/Post/Grid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/**
* Class Triboo_Blog_Block_Adminhtml_Post_Grid
*/
class Triboo_Blog_Block_Adminhtml_Post_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->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();
}
}
23 changes: 23 additions & 0 deletions app/code/local/Triboo/Blog/Helper/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Class Triboo_Blog_Helper_Config for constants' configuration
*/
class Triboo_Blog_Helper_Config
{
/**
* enable log
*/
const LOG_ENABLE_CONFIG = 'tbblog/log/enable';
/**
* connection with db
*/
const CONNECTION_READ = 'blog_read';
const CONNECTION_WRITE = 'blog_write';
/**
* EAV's configuration
*/
const ENTITY_TYPE_CODE_POST = 'tbblog_post';
const ENTITY_MODEL_POST = 'tbblog/post';
const ENTITY_TABLE_POST = 'tbblog/post_entity';
}
35 changes: 35 additions & 0 deletions app/code/local/Triboo/Blog/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/**
* Class Triboo_Blog_Helper_Data
*/
class Triboo_Blog_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* log file
*/
const LOG_FILE = 'tribooBlog.log';
/**
* @var bool
*/
protected $isLogEnable;

public function __construct()
{
$this->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;
}
}
16 changes: 16 additions & 0 deletions app/code/local/Triboo/Blog/Model/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* Class Triboo_Blog_Model_Post
*/
class Triboo_Blog_Model_Post extends Mage_Core_Model_Abstract
{
/**
* Triboo_Blog_Model_Post construct
* that initialize resource model post
*/
public function _construct()
{
$this->_init('tbblog/post');
}
}
36 changes: 36 additions & 0 deletions app/code/local/Triboo/Blog/Model/Resource/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Class Triboo_Blog_Model_Resource_Post
*/
class Triboo_Blog_Model_Resource_Post extends Mage_Eav_Model_Entity_Abstract
{
/**
* Triboo_Blog_Model_Resource_Post constructor.
* @var $resource
*/
public function _construct()
{
$resource = Mage::getSingleton('core/resource');
$this->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',
];
}
}
16 changes: 16 additions & 0 deletions app/code/local/Triboo/Blog/Model/Resource/Post/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* Class Triboo_Blog_Model_Resource_Post_Collection
*/
class Triboo_Blog_Model_Resource_Post_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{
/**
* Triboo_Blog_Model_Resource_Post_Collection construct.
* that initialize resource model post
*/
protected function _construct()
{
$this->_init('tbblog/post');
}
}
63 changes: 63 additions & 0 deletions app/code/local/Triboo/Blog/Model/Resource/Setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* Class Triboo_Blog_Model_Resource_Setup
*/
class Triboo_Blog_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
/**
* Method Triboo_Blog_Model_Resource_Setup getDefaultEntities.
* @var $entities
* @return array
*/
public function getDefaultEntities() : array
{
$entities = [
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,
'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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* Class Triboo_Blog_Adminhtml_PostController
*/
class Triboo_Blog_Adminhtml_PostController extends Mage_Adminhtml_Controller_Action
{

/**
*
*/
public function indexAction()
{
/*
* For adminhtml menù
* load the layout
*/
$this->loadLayout();
/*
* output layout
*/
$this->renderLayout();
}

/**
*
*/
public function gridAction()
{
$this->loadLayout()
->getresponse()->setBody(
$this->getLayout()->createBlock('blog/adminhtml_post_grid')->toHtml()
);
}
}
47 changes: 47 additions & 0 deletions app/code/local/Triboo/Blog/etc/adminhtml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<config>
<menu>
<!--Start Blog admin-->
<tbblog translate="title" module="tbblog">
<title>Blog</title>
<sort_order>150</sort_order>
<children>
<manage module="tbblog">
<title>Manage Posts</title>
<action>adminhtml/post</action>
</manage>
</children>
</tbblog>
<!--End Blog admin-->
</menu>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<tbblog>
<title>Triboo log</title>
</tbblog>
</children>
</config>
</children>
</system>
<!--Start Blog admin-->
<tbblog translate="title" module="tbblog">
<title>Blog</title>
<sort_order>150</sort_order>
<children>
<manage>
<title>Manage Posts</title>
</manage>
</children>
</tbblog>
<!--End Blog admin-->
</children>
</admin>
</resources>
</acl>
</config>
Loading