I am working on a simple event calendar CMP and I am looking for suggestions.
Basically I want to create a modext grid that will allow a manager user update the event calendar that I will display on the front-end.
I am just learning the basics of modext and xpdo, so there is probably a alot better way to do this.
I have the grid working and displaying the events from the calendarEvent table. Now I want to display check boxes or a multiple select field in the grid for the manager user to select what calendar or calendars the event should display in.
Here is my schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="xcal" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="xcal">
<object class="calendarItem" table="calendarItem" extends="xPDOObject">
<field key="eid" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<field key="ename" dbtype="varchar" precision="255" phptype="string" null="false" />
<field key="sDesc" dbtype="varchar" precision="255" phptype="string" null="true" />
<field key="fDesc" dbtype="text" phptype="string" null="true" />
<field key="sdate" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="edate" dbtype="int" precision="11" phptype="integer" null="true" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="eid" length="" collation="A" null="false" />
</index>
<composite alias="Calendars" class="calendarEvent" local="eid" foreign="eid" cardinality="many" owner="local" />
</object>
<object class="calendar" table="calendar" extends="xPDOObject">
<field key="cid" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<field key="calName" dbtype="varchar" precision="255" phptype="string" null="false" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="cid" length="" collation="A" null="false" />
</index>
<composite alias="Calendars" class="calendarEvent" local="cid" foreign="cid" cardinality="many" owner="local" />
</object>
<object class="calendarEvent" table="calendarEvent" extends="xPDOObject">
<field key="keyid" dbtype="int" precision="11" phptype="integer" null="false" index="pk" generated="native" />
<field key="eid" dbtype="int" precision="11" phptype="integer" null="false" />
<field key="cid" dbtype="int" precision="11" phptype="integer" null="false" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="keyid" length="" collation="A" null="false" />
</index>
<aggregate alias="CalendarItem" class="calendarItem" local="eid" foreign="eid" cardinality="one" owner="foreign" />
<aggregate alias="Calendar" class="calendar" local="cid" foreign="cid" cardinality="one" owner="foreign" />
</object>
</model>
Here is my grid:
Xcal.grid.Xcal = function(config) {
config = config || {};
Ext.applyIf(config,{
id: 'xcal-grid-xcal'
,url: Xcal.config.connectorUrl
,baseParams: { action: 'mgr/xcal/getList' }
,fields: [
{ name: 'eid', type: 'int' }
,{ name: 'ename', type: 'string' }
,{ name: 'sDesc', type: 'string' }
,{ name: 'fDesc', type: 'string' }
,{ name: 'sdate', type: 'date', dateFormat: 'timestamp' }
,{ name: 'edate', type: 'date', dateFormat: 'timestamp' }
]
,paging: true
,remoteSort: true
,anchor: '97%'
,autoExpandColumn: 'ename'
,columns: [{
header: _('xcal.eid')
,dataIndex: 'eid'
,sortable: true
,width: 20
},{
header: _('xcal.name')
,dataIndex: 'ename'
,sortable: true
,width: 60
,editor: { xtype: 'textfield' }
},{
header: _('xcal.sdesc')
,dataIndex: 'sDesc'
,sortable: false
,width: 60
,editor: { xtype: 'textarea' }
},{
header: _('xcal.fdesc')
,dataIndex: 'fDesc'
,sortable: false
,width: 200
,editor: { xtype: 'textarea' }
},{
header: _('xcal.sdate')
,renderer: Ext.util.Format.dateRenderer('m/d/Y')
,dataIndex: 'sdate'
,sortable: false
,width: 40
,editor: { xtype: 'textfield' }
},{
header: _('xcal.edate')
,renderer: Ext.util.Format.dateRenderer('m/d/Y')
,dataIndex: 'edate'
,sortable: true
,width: 40
,editor: { xtype: 'textfield' }
}]
});
Xcal.grid.Xcal.superclass.constructor.call(this,config)
};
Ext.extend(Xcal.grid.Xcal,MODx.grid.Grid);
Ext.reg('xcal-grid-xcal',Xcal.grid.Xcal);
Here is my processor script for getlist:
<?php
$isLimit = !empty($scriptProperties['limit']);
$start = $modx->getOption('start',$scriptProperties,0);
$limit = $modx->getOption('limit',$scriptProperties,10);
$sort = $modx->getOption('sort',$scriptProperties,'eid');
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
// working query for only the events
$query = $modx->newQuery('calendarItem');
$count = $modx->getCount('calendarItem',$query);
$query->sortby($sort,$dir);
if ($isLimit) $c->limit($limit,$start);
$events = $modx->getCollection('calendarItem', $query);
$list = array();
foreach ($events as $event) {
$eventArray = $event->toArray();
$list[]= $eventArray;
}
return $this->outputArray($list,$count);
Any hints or suggestions are appreciated.