Skip to content

Commit

Permalink
Modules files
Browse files Browse the repository at this point in the history
first commit to upload module
  • Loading branch information
upma17 authored Aug 9, 2019
1 parent 8830067 commit 555dfc7
Show file tree
Hide file tree
Showing 25 changed files with 511 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/code/Mywork/News/Block/News.php
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 app/code/Mywork/News/Block/adminhtml/Grid/Column/Statuses.php
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;
}
}
40 changes: 40 additions & 0 deletions app/code/Mywork/News/Block/adminhtml/News.php
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();
}
}
19 changes: 19 additions & 0 deletions app/code/Mywork/News/Controller/Index/Index.php
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();
}
}
38 changes: 38 additions & 0 deletions app/code/Mywork/News/Controller/adminhtml/News.php
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';
}
10 changes: 10 additions & 0 deletions app/code/Mywork/News/Controller/adminhtml/News/Grid.php
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
{

}
36 changes: 36 additions & 0 deletions app/code/Mywork/News/Controller/adminhtml/News/index.php
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();
}
}
?>

12 changes: 12 additions & 0 deletions app/code/Mywork/News/Model/Data.php
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');
}
}
14 changes: 14 additions & 0 deletions app/code/Mywork/News/Model/ResourceModel/Data.php
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 app/code/Mywork/News/Model/ResourceModel/Data/Collection.php
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'
);
}
}
38 changes: 38 additions & 0 deletions app/code/Mywork/News/Setup/InstallData.php
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);
}
}
}
44 changes: 44 additions & 0 deletions app/code/Mywork/News/Setup/InstallSchema.php
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);
}
}
Loading

0 comments on commit 555dfc7

Please sign in to comment.