private function addToGalleryArtworkCount() {
$galleryName = $this->getProperty('galleryname');
$artwork = $this->modx->getObject('artworks', array('galleryname' => $galleryName));
$gallery = $artwork->getOne('Gallery'); // WORKING IF VERY FIRST ENTRY INTO TABLE
$gallery->set('artworktotal', $gallery->get('artworktotal')+1); // adds one to the total
$this->modx->log(modX::LOG_LEVEL_DEBUG, 'CURRENT VALUE OF ARTWORK TOTAL: ' . $gallery->get('artworktotal'));
$gallery->save();
}
<?xml version="1.0" encoding="UTF-8"?>
<model package="sovereign" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="artworks" table="mycomponent_artworks" extends="xPDOSimpleObject">
<field key="galleryname" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="filename" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="aname" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="pname" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="createdby" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0" />
<aggregate alias="Gallery" class="galleries" local="id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="galleries" table="mycomponent_galleries" extends="xPDOSimpleObject">
<field key="galleryname" dbtype="varchar" precision="250" phptype="string" null="true" default="" />
<field key="artworktotal" dbtype="int" precision="10" phptype="integer" null="true" default="0" />
<field key="url" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="year" dbtype="varchar" precision="6" phptype="string" null="true" default="" />
<field key="enabled" dbtype="int" precision="1" phptype="integer" null="true" default="0" />
<field key="vote_on" dbtype="int" precision="1" phptype="integer" attributes="unsigned" null="true" default="" />
<field key="votes" dbtype="int" precision="10" phptype="integer" null="true" default="0" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="createdby" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="true" default="0" />
<composite alias="Artworks" class="artworks" local="id" foreign="id" cardinality="many" owner="local" />
<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
This question has been answered by Bruno17. See the first response.
<?xml version="1.0" encoding="UTF-8"?>
<model package="sovereign" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="artworks" table="mycomponent_artworks" extends="xPDOSimpleObject">
<field key="aname" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="pname" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="createdby" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0" />
<field key="gallery_id" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0" />
<aggregate alias="Gallery" class="galleries" local="gallery_id" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="galleries" table="mycomponent_galleries" extends="xPDOSimpleObject">
<field key="galleryname" dbtype="varchar" precision="250" phptype="string" null="true" default="" />
<field key="artworktotal" dbtype="int" precision="10" phptype="integer" null="true" default="0" />
<field key="url" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
<field key="year" dbtype="varchar" precision="6" phptype="string" null="true" default="" />
<field key="enabled" dbtype="int" precision="1" phptype="integer" null="true" default="0" />
<field key="vote_on" dbtype="int" precision="1" phptype="integer" attributes="unsigned" null="true" default="" />
<field key="votes" dbtype="int" precision="10" phptype="integer" null="true" default="0" />
<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
<field key="createdby" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="true" default="0" />
<composite alias="Artworks" class="artworks" local="id" foreign="gallery_id" cardinality="many" owner="local" />
<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
<?php
$galleryId = $scriptProperties['galleryId'];
$artworkCount = $modx->getCount('artworks', $galleryId);
$data['artworktotal'] = $artworkCount;
$response['success'] = true;
$response['msg'] = 'count returned';
$response['data'] = $data;
return $modx->toJSON($response);

,{
header: _('mycomponent.artwork_total')
,dataIndex: 'artworktotal'
,sortable: true
,editable: false
,width: 30
,renderer: function(){
var grid = Ext.getCmp('mycomponent-grid-galleries');
var galleryId = grid.getStore().get('id');
var artworkCount = MODx.load({
url: MyComponent.config.connectorUrl
,params: {action: 'mgr/mycomponent/getArtworkCount'}
,'galleryId': galleryId
});
return artworkCount;
}
}
,{
header: _('mycomponent.artwork_total')
,dataIndex: 'artworktotal'
,sortable: true
,editable: false
,width: 30
,renderer: function(){
var grid = Ext.getCmp('mycomponent-grid-galleries');
var galleryId = grid.store.getAt(0).get('id');
var artworkCount = MODx.load({
url: MyComponent.config.connectorUrl
,params: {action: 'mgr/mycomponent/getArtworkCount'}
,'galleryId': galleryId
});
return artworkCount;
}
}
private function getArtworkCount() {
$count = $this->modx->getCount('artworks');
$this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of count:' . $count);
return $count;
}
<?php
class GalleryGetListProcessor extends modObjectGetListProcessor {
public $classKey = 'galleries';
public $languageTopics = array('mycomponent:default');
public $defaultSortField = 'id';
public $defaultSortDirection = 'DESC';
public $objectType = 'mycomponent';
public function prepareQueryBeforeCount(xPDOQuery $c) {
$query = $this->getProperty('query'); // Search box
if (!empty($query)) {
$c->where(array(
'galleryname:LIKE' => '%'.$query.'%',
'OR:description:LIKE' => '%'.$query.'%',
));
}
$this->setProperty('artworktotal', $this->getArtworkCount()); // get count of artworks
return $c;
}
private function getArtworkCount() {
$count = $this->modx->getCount('artworks');
$this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of count:' . $count);
return $count;
}
}
return 'GalleryGetListProcessor';
public function afterIteration(array $list) {
$rows = array();
foreach ($list as $row){
$row['artworktotal'] = $this->getArtworkCount();
$rows[] = $row;
}
return $rows;
}
$count = $this->modx->getCount('artworks');
private function getArtworkCount() {
$galleryName = $this->getProperty('galleryname');
$this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of $galleryName:' . $galleryName); // log shows no value!
$count = $this->modx->getCount('artworks', array('galleryname' => $galleryName));
$this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of count:' . $count); // count is zero if this criteria is specified
return $count;
}
$count = $this->modx->getCount('artworks', array('galleryname' => 'Gallery 1'));
public function afterIteration(array $list) {
$rows = array();
foreach ($list as $row){
$row['artworktotal'] = $this->getArtworkCount($row['id']);
$rows[] = $row;
}
return $rows;
}
private function getArtworkCount($gallery_id) {
$count = $this->modx->getCount('artworks', array('gallery_id' => $gallery_id));
$this->modx->log(modX::LOG_LEVEL_DEBUG, 'The current value of count:' . $count); // count is zero if this criteria is specified
return $count;
}