CREATE TABLE IF NOT EXISTS `tasks` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `userId` int NOT NULL, `title` varchar(300) COLLATE utf8_unicode_ci, `description` varchar(1000) COLLATE utf8_unicode_ci, `startDate` date, `endDate` date, `status` int NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `userId` (`userId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
<?php class Tasks extends Kwf_Model_Db { protected $_table = 'tasks'; }
<?php class TasksController extends Kwf_Controller_Action_Auto_Grid { protected $_modelName = 'Tasks'; protected $_defaultOrder = array('field' => 'id', 'direction' => 'DESC'); protected $_paging = 30; protected $_buttons = array('add'); public function indexAction() { $this->view->ext('Tasks'); } protected function _initColumns() { $this->_columns->add(new Kwf_Grid_Column('title', trl('Title'), 200)); $this->_columns->add(new Kwf_Grid_Column_Date('endDate', trl('End Date'), 100))->setRenderer('checkDate'); } }
protected function _getWhere() { $users = Kwf_Registry::get('userModel'); $ret = parent::_getWhere(); $ret['status = ?'] = 0; $ret['userId = ?'] = $users->getAuthedUserId(); return $ret; }
<?php class TaskController extends Kwf_Controller_Action_Auto_Form { protected $_modelName = 'Tasks'; protected $_permissions = array('save', 'add'); protected $_buttons = array('save'); protected function _initFields() { $this->_form->add(new Kwf_Form_Field_TextField('title', trl('Title'))) ->setWidth(400) ->setAllowBlank(false); $this->_form->add(new Kwf_Form_Field_DateField('startDate', trl('Start Date'))); $this->_form->add(new Kwf_Form_Field_DateField('endDate', trl('End Date'))); $this->_form->add(new Kwf_Form_Field_TextArea('description', trl('Description'))) ->setHeight(70) ->setWidth(400); $this->_form->add(new Kwf_Form_Field_Checkbox('status', trl('Done'))); } }
protected function _beforeInsert(Kwf_Model_Row_Interface $row) { $users = Kwf_Registry::get('userModel'); if ($row->startDate == NULL) { $row->startDate = new DateTime (); } $row->userId = $users->getAuthedUserId(); $row->status = 0; }
var Tasks = Ext.extend(Ext.Panel, { initComponent : function(test) { var form = new Kwf.Auto.FormPanel({ controllerUrl : '/task', region : 'center' }); var grid = new Kwf.Auto.GridPanel({ controllerUrl : '/tasks', region : 'west', width : 400, resizable : true, split : true, collapsible : true, title : trl('Tasks'), bindings: [{ queryParam: 'id', item: form }] }); this.layout = 'border'; this.items = [grid, { layout: 'border', region: 'center', items: [form] }]; Tasks.superclass.initComponent.call(this); } });
<?php class Acl extends Kwf_Acl { public function __construct() { parent::__construct(); $this->remove('default_index'); $this->addResource(new Kwf_Acl_Resource_MenuUrl('default_tasks', array('text'=>trl('Tasks'), 'icon'=>'time.png'), '/tasks')); $this->addResource(new Zend_Acl_Resource('default_task'), 'default_tasks'); $this->addRole(new Zend_Acl_Role('user')); $this->allow('user', 'default_tasks'); $this->allow('admin', 'default_tasks'); $this->allow('admin', 'default_index'); } }
Source: https://habr.com/ru/post/228901/
All Articles