class PositionGetListProcessor extends modObjectGetListProcessor {
public $classKey = 'rtPositions';
public $languageTopics = array('recroot:default');
public $defaultSortField = 'title';
public $defaultSortDirection = 'ASC';
public $objectType = 'recroot.position';
public function prepareQueryBeforeCount(xPDOQuery $c) {
$query = $this->getProperty('query');
if (!empty($query)) {
$c->where(array(
'title:LIKE' => '%'.$query.'%',
'OR:description:LIKE' => '%'.$query.'%',
'OR:company:LIKE' => '%'.$query.'%',
));
}
return $c;
}
//return existing position categories per position from rtPositionCategoriesMap
public function prepareRow(xPDOObject $object) {
$ps = $object->toArray('', false, true);
$position_id = $object->getProperty('id');
//this is referencing the alias to rtPositionCategoriesMap
$criteria = $this->modx->newQuery('PositionCategories');
$criteria->where(array('position_id' => $position_id));
$categories= $this->modx->getCollection('PositionCategories', $criteria);
if ($categories) {
foreach ($categories as $obj) {
$cats[] = $obj->get('category_id');
}
}
$ps['categories'] = $cats;
return $ps;
}
}
return 'PositionGetListProcessor';includeRelated: Describes if and how to include loaded related object fields. * As an integer all loaded related objects in the graph up to that level of depth will be included. * As a string, only loaded related objects matching the JSON graph representation will be included. * As an array, only loaded related objects matching the graph array will be included. * As boolean true, all currently loaded related objects will be included.
This question has been answered by harveyev. See the first response.
$position_id = $object->get('id');$position_id = $this->getProperty('id');//return existing position categories per position from rtPositionCategoriesMap
public function prepareRow(xPDOObject $object) {
$ps = parent::prepareRow($object); //<- this sets the array to be modified and returned
$position_id = $ps['id'];
$criteria = $this->modx->newQuery('rtPositionCategoriesMap');
$criteria->where(array('position_id' => $position_id,));
$categories = $this->modx->getCollection('rtPositionCategoriesMap', $criteria);
if ($categories) {
$cats = array();
foreach ($categories as $obj) {
$cats[] = $obj->get('category_id');
}
}
$ps['categories'] = $cats;
return $ps;
}One issue could be in line 22. It is just a try to solve it, since I don't know the model:
Use the following if you refer to the ID of the object.
$position_id = $object->;get('id');
Or use this if you have a property 'id' in the getlist processor call that is different to $object->get('id');
$position_id = $this->getProperty('id');