-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first commit to upload module
- Loading branch information
Showing
25 changed files
with
511 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
namespace Mywork\News\Block; | ||
|
||
|
||
use Magento\Framework\View\Element\Template\Context; | ||
use Mywork\News\Model\Data; | ||
use Magento\Framework\View\Element\Template; | ||
|
||
|
||
class News extends Template | ||
{ | ||
|
||
public function __construct(Context $context, Data $model) | ||
{ | ||
$this->model = $model; | ||
parent::__construct($context); | ||
|
||
} | ||
|
||
public function sayHello() | ||
{ | ||
return __('Hello World'); | ||
} | ||
public function getNewsCollection() | ||
{ | ||
$newsCollection = $this->model->getCollection(); | ||
return $newsCollection; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/code/Mywork/News/Block/adminhtml/Grid/Column/Statuses.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Mywork\News\Block\Adminhtml\Grid\Column; | ||
|
||
/** | ||
* Admin news grid statuses | ||
*/ | ||
class Statuses extends \Magento\Backend\Block\Widget\Grid\Column | ||
{ | ||
/** | ||
* Add to column decorated status | ||
* | ||
* @return array | ||
*/ | ||
public function getFrameCallback() | ||
{ | ||
return [$this, 'decorateStatus']; | ||
} | ||
|
||
/** | ||
* Decorate status column values | ||
* | ||
* @param string $value | ||
* @param \Magento\Framework\Model\AbstractModel $row | ||
* @param \Magento\Backend\Block\Widget\Grid\Column $column | ||
* @param bool $isExport | ||
* @return string | ||
*/ | ||
public function decorateStatus($value, $row, $column, $isExport) | ||
{ | ||
if ($row->getIsActive() || $row->getStatus()) { | ||
if ($row->getStatus() == 2) { | ||
$cell = '<span class="grid-severity-minor"><span>' . $value . '</span></span>'; | ||
} else { | ||
$cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>'; | ||
} | ||
} else { | ||
$cell = '<span class="grid-severity-critical"><span>' . $value . '</span></span>'; | ||
} | ||
return $cell; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace Mywork\News\Block\Adminhtml; | ||
|
||
/** | ||
* Admin news | ||
*/ | ||
class News extends \Magento\Backend\Block\Widget\Grid\Container | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_controller = 'adminhtml_news'; | ||
$this->_blockGroup = 'Mywork_News'; | ||
$this->_headerText = __('News'); | ||
$this->_addButtonLabel = __('Add New News'); | ||
|
||
parent::_construct(); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
protected function _prepareLayout() | ||
{ | ||
|
||
$onClick = "setLocation('" . $this->getUrl('*/import') . "')"; | ||
|
||
$this->getToolbar()->addChild( | ||
'options_button', | ||
\Magento\Backend\Block\Widget\Button::class, | ||
['label' => __('Import News'), 'onclick' => $onClick] | ||
); | ||
|
||
return parent::_prepareLayout(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
namespace Mywork\News\Controller\Index; | ||
|
||
class Index extends \Magento\Framework\App\Action\Action | ||
{ | ||
protected $_pageFactory; | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Framework\View\Result\PageFactory $pageFactory) | ||
{ | ||
$this->_pageFactory = $pageFactory; | ||
return parent::__construct($context); | ||
} | ||
|
||
public function execute() | ||
{ | ||
return $this->_pageFactory->create(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
namespace Mywork\News\Controller\Adminhtml; | ||
|
||
/** | ||
* Admin News news edit controller | ||
*/ | ||
class News extends Actions | ||
{ | ||
/** | ||
* Form session key | ||
* @var string | ||
*/ | ||
protected $_formSessionKey = 'news_post_form_data'; | ||
|
||
/** | ||
* Allowed Key | ||
* @var string | ||
*/ | ||
protected $_allowedKey = 'Mywork_News::post'; | ||
|
||
/** | ||
* Model class name | ||
* @var string | ||
*/ | ||
protected $_modelClass = 'Mywork\News\Model\Post'; | ||
|
||
/** | ||
* Active menu key | ||
* @var string | ||
*/ | ||
protected $_activeMenu = 'Mywork_News::post'; | ||
|
||
/** | ||
* Status field name | ||
* @var string | ||
*/ | ||
protected $_statusField = 'is_active'; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
namespace Mywork\News\Controller\Adminhtml\Post; | ||
|
||
/** | ||
* News post grid controller | ||
*/ | ||
class Grid extends \Mywork\News\Controller\Adminhtml\Post | ||
{ | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace Mywork\News\Controller\Adminhtml\News; | ||
|
||
class Index extends \Magento\Backend\App\Action | ||
{ | ||
/** | ||
* @var \Magento\Framework\View\Result\PageFactory | ||
*/ | ||
protected $resultPageFactory; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Magento\Backend\App\Action\Context $context | ||
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Framework\View\Result\PageFactory $resultPageFactory | ||
) { | ||
parent::__construct($context); | ||
$this->resultPageFactory = $resultPageFactory; | ||
} | ||
|
||
/** | ||
* Load the page defined in view/adminhtml/layout/exampleadminnewpage_helloworld_index.xml | ||
* | ||
* @return \Magento\Framework\View\Result\Page | ||
*/ | ||
public function execute() | ||
{ | ||
return $resultPage = $this->resultPageFactory->create(); | ||
} | ||
} | ||
?> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
namespace Mywork\News\Model; | ||
|
||
use Magento\Framework\Model\AbstractModel; | ||
|
||
class Data extends AbstractModel | ||
{ | ||
protected function _construct() | ||
{ | ||
$this->_init('Mywork\News\Model\ResourceModel\Data'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Mywork\News\Model\ResourceModel; | ||
|
||
|
||
use \Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
|
||
class Data extends AbstractDb | ||
{ | ||
protected function _construct() | ||
{ | ||
$this->_init('news', 'news_id'); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/code/Mywork/News/Model/ResourceModel/Data/Collection.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
namespace Mywork\News\Model\ResourceModel\Data; | ||
|
||
|
||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; | ||
|
||
|
||
class Collection extends AbstractCollection | ||
{ | ||
protected function _construct() | ||
{ | ||
$this->_init( | ||
'Mywork\News\Model\Data', | ||
'Mywork\News\Model\ResourceModel\Data' | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php /** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mywork\News\Setup; | ||
|
||
use Magento\Framework\Setup\InstallDataInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class InstallData implements InstallDataInterface | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||
{ | ||
/** | ||
* Install messages | ||
*/ | ||
$data = [ | ||
['news' => 'news text 1'], | ||
['news' => 'news text 2'] | ||
]; | ||
foreach ($data as $bind) { | ||
$setup->getConnection() | ||
->insertForce($setup->getTable('news'), $bind); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mywork\News\Setup; | ||
use Magento\Framework\Setup\InstallSchemaInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Framework\Setup\SchemaSetupInterface; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class InstallSchema implements InstallSchemaInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) | ||
*/ | ||
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) | ||
{ | ||
/** | ||
* Create table 'news' | ||
*/ | ||
$table = $setup->getConnection() | ||
->newTable($setup->getTable('news')) | ||
->addColumn( | ||
'news_id', | ||
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, | ||
null, | ||
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true], | ||
'News ID' | ||
) | ||
->addColumn( | ||
'news', | ||
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT, | ||
255, | ||
['nullable' => false, 'default' => ''], | ||
'News' | ||
)->setComment("News table"); | ||
$setup->getConnection()->createTable($table); | ||
} | ||
} |
Oops, something went wrong.