Ebents.grid.Organizers = function(config) {
config = config || {};
Ext.applyIf(config,{
url: Ebents.config.connectorUrl
,baseParams: { action: 'mgr/organizers/getlist' }
,fields: ['organizer.id','organizer.name','organizer.description']//<- notice the dot style naming - these are required for the post submission to the rest gateway
,trackMouseOver:true
,disableSelection:true
,loadMask: true
,save_action: 'mgr/organizers/updateFromGrid'
,autosave: true
,paging: true
,remoteSort: false
,anchor: '97%'
,columns: [{
header: _('ebents.organizer_id')
,dataIndex: 'organizer.id'//<-- rendered fine when it was just "id"
,sortable: true
,width: 70
},{
header: _('ebents.organizer_name')
,dataIndex: 'organizer.name'//<-- rendered fine when it was just "name"
,sortable: true
,width: 150
,editor: { xtype: 'textfield' }
},{
header: _('ebents.organizer_description')
,dataIndex: 'organizer.description'//<-- rendered fine when it was just "description"
,sortable: false
,width: 250
,editor: { xtype: 'textarea' }
}
]
,tbar:[{
text: _('ebents.organizer_create')
,handler: { xtype: 'ebents-window-organizer-create' ,blankValues: true }
}]
});
Ebents.grid.Organizers.superclass.constructor.call(this,config)class GetOrganizersListProcessor extends modProcessor {
public function initialize() {
$this->setDefaultProperties(array(
'start' => 0,
'limit' => 10,
));
return true;
}
public function process() {
// call to main class to retrieve my organizers from theEventbrite API
$this->mgr_client = new Ebents($this->modx);
$this->args = array('id' => 'me', 'data' => 'organizers');
$this->output = $this->mgr_client->getData('users', $this->args);
//error_log(print_r($this->output), true);
//lazy convert results from stdClass to array as the api returns a stdClass object
$organizers = array();
$organizers = json_decode(json_encode($this->output->organizers), true);
$count = count($organizers);
$organizers = array_slice($organizers,$this->getProperty('start'),$this->getProperty('limit'),true);
$list = array();
/* process output data for grid columns */
foreach ($organizers as $organizer) {
$entryArray = array(
'organizer.id' => $organizer['id'],
'organizer.name' => $organizer['name'],
'organizer.description' => $organizer['description']['text'],
);
$list[] = $entryArray;
}
//convert to JSON for grid consumption
return $this->outputArray($list,$count);
}
}
return 'GetOrganizersListProcessor';{"success":true,"total":"1","results":[{"organizer.id":"8310024813","organizer.name":"Joe Organizer","organizer.description":"Joe is the Organizerest Organizer."}]}class UpdateOrganizerFromGridProcessor extends modProcessor {
public $id;
public $params = array();
public $args = array();
public function initialize() {
$data = $this->getProperty('data');
if (empty($data)) return $this->modx->lexicon('invalid_data');
$data = $this->modx->fromJSON($data);
if (empty($data)) return $this->modx->lexicon('invalid_data');
$this->id = $data['id'];
//error_log($data);
//error_log("Org ID : " . $this->id);
$this->params = array (
'organizer.name' => $data['organizer.name'],
'organizer.description' => $data['organizer.description'],
);
$this->args = array('id' => $this->id, 'params' => $this->params);
error_log(print_r($this->args, true));
return parent::initialize();
}
public function process() {
// call to main class to save changes to theEventbrite API
$this->mgr_client = new Ebents($this->modx);
$this->output = $this->mgr_client->postData('organizers', $this->args);
$response = json_decode(json_encode($this->output), true);
//convert to JSON
error_log($this->outputArray($response));
return $this->outputArray($response);
}
}
return 'UpdateOrganizerFromGridProcessor';This question has been answered by harveyev. See the first response.
$entryArray = array(
'organizer' => array(
'id' => $organizer['id'],
'name' => $organizer['name'],
'description' => $organizer['description'],
)
);
,fields: [{name: 'organizer', type: 'object'}]
class UpdateOrganizerFromGridProcessor extends modProcessor {
public function initialize() {
$data = $this->getProperty('data');
if (empty($data)) return $this->modx->lexicon('invalid_data');
$data = $this->modx->fromJSON($data);
if (empty($data)) return $this->modx->lexicon('invalid_data');
$this->id = $data['id'];
$this->params = array ();
// build JSON content for form submission...cooking key names
$this->formData = array (
'organizer.name' => $data['name'],
'organizer.description' => $data['description'],
);
$this->formJSON = $this->modx->toJSON($this->formData);
$this->args = array('id' => $this->id, 'params' => $this->params);
return parent::initialize();
}
public function process() {
// call to main class to save changes to the Eventbrite API
$this->mgr_client = new Ebents($this->modx);
$this->output = $this->mgr_client->postData('organizers', $this->args, $this->formJSON);
$response = json_decode(json_encode($this->output), true);
return $this->outputArray($response);
}
}
return 'UpdateOrganizerFromGridProcessor';
function postData($method, $args, $JSONdata) {
error_log("JSON Payload : " . $JSONdata);
// Get the URI we need.
$uri = $this->build_uri($method, $args);
// Construct the full URL.
$request_url = $this->endpoint . $uri;
// This array is used to authenticate our request.
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $JSONdata,
'header' => "Authorization: Bearer " . $this->token
)
);
// Call the URL and get the data.
error_log("URL: " . $request_url);
error_log("Content: " . $options['http']['content']);
$resp = file_get_contents($request_url, false, stream_context_create($options));
// parse our response
if($resp){
$resp = json_decode( $resp );
if( isset( $resp->error ) && isset($resp->error->error_message) ){
error_log( $resp->error->error_message );
}
}
// Return it as arrays/objects.
return $resp;
}{"organizer.name":"Joe Organizer","organizer.description":"Joe is the Uberest Organizer."}class UpdateOrganizerFromGridProcessor extends modProcessor {
public function initialize() {
$data = $this->getProperty('data');
if (empty($data)) return $this->modx->lexicon('invalid_data');
$data = $this->modx->fromJSON($data);
if (empty($data)) return $this->modx->lexicon('invalid_data');
$this->id = $data['id'];
$this->params = array (
'organizer.name' => $data['name'],
'organizer.description.html' => $data['description'],
'organizer.logo.id' => $data['logo_id'],
);
$this->args = array('id' => $this->id, 'data'=> '', 'params' => $this->params);
return parent::initialize();
}
public function process() {
// call to main class to save changes to the Eventbrite API
$this->mgr_client = new Ebents($this->modx);
$this->output = $this->mgr_client->postData('organizers', $this->args);
$response = json_decode(json_encode($this->output), true);
return $this->outputArray($response);
}
}
return 'UpdateOrganizerFromGridProcessor';
UpdateOrganizerProcessor extends modObjectUpdateProcessor {
/// more code
}
UpdateOrganizerFromGridProcessor extends UpdateOrganizerProcessor {
// @example https://github.com/goldsky/Lingua/blob/master/core/components/lingua/processors/mgr/langs/updatefromgrid.class.php#L27
}
I think I need to chime in because this is related with your other issue in ExtJs's grid.
Why don't you extend:
- GetOrganizersListProcessor from modObjectGetListProcessor?
- UpdateOrganizerFromGridProcessor from UpdateOrganizerProcessor?
modProcessor is somewhat an abstract class, a raw class.
Then modObjectProcessor extends it.
You better use modObjectProcessor's child classes to do the common jobs:
- modObjectCreateProcessor
- modObjectUpdateProcessor
- modObjectRemoveProcessor
- modObjectGetProcessor
- modObjectGetListProcessor
By doing that, you standardize the output of the processors.
You only need to direct extend the modObjectProcessor for other task, like: batch action, etc.
Example: https://github.com/virtudraft/CrossContextsSettings/blob/master/core/components/crosscontextssettings/processors/mgr/settings/updatefromgrid.class.php#L28
MODx's grid in ExtJs expects values with the format of modObjectGetListProcessor's response.
Back to your update-from-grid processor.
You better try to do this:
update.class.php
UpdateOrganizerProcessor extends modObjectUpdateProcessor { /// more code }
updatefromgrid.class.php
UpdateOrganizerFromGridProcessor extends UpdateOrganizerProcessor { // @example https://github.com/goldsky/Lingua/blob/master/core/components/lingua/processors/mgr/langs/updatefromgrid.class.php#L27 }
Thanks for the info. But, I'm not using the MODX db and only interfacing with a 3rd party API. Not sure what I gain by using objectProcessors for that.
<?php
require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config.core.php';
require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
require_once MODX_CONNECTORS_PATH . 'index.php';
$corePath = $modx->getOption('ebents.core_path', null, $modx->getOption('core_path') . 'components/ebents/');
require_once $corePath . 'model/ebents.class.php';
$modx->ebents = new Ebents($modx);
$modx->lexicon->load('ebents:processor', 'ebents:cmp');
/* handle request */
$path = $modx->getOption('processorsPath', $modx->ebents->config, $corePath . 'processors/');
$modx->request->handleRequest(array(
'processors_path' => $path,
'location' => '',
));
public function process() {
// call to main class to save changes to the Eventbrite API
$this->output = $this->modx->ebents->postData('organizers', $this->args);
$response = json_decode(json_encode($this->output), true);
return $this->outputArray($response);
}
class CreateOrganizerProcessor extends modProcessor {
public function initialize() {
//formats the nvpairs used in the query string for submit
$this->params = array (
'organizer.name' => $_POST['name'],
'organizer.description.html' => $_POST['description'],
);
$this->args = array('data'=> '', 'params' => $this->params);
return parent::initialize();
}
public function process() {
$this->output = $this->modx->ebents->postData('organizers', $this->args);
return $this->output;
}
}
return 'CreateOrganizerProcessor';