<?php
require_once MODX_CORE_PATH.'model/modx/modprocessor.class.php';
require_once MODX_CORE_PATH.'model/modx/processors/resource/create.class.php';
require_once MODX_CORE_PATH.'model/modx/processors/resource/update.class.php';
/**
* @package comparejewellery
*/
class JewelleryContainer extends modResource {
public $xpdo;
public $allowListingInClassKeyDropdown = false;
public $showInContextMenu = true;
public $allowChildrenResources = false;
function __construct(xPDO & $xpdo) {
parent :: __construct($xpdo);
$this->set('class_key','JewelleryContainer');
$this->set('hide_children_in_tree',true);
}
public static function getControllerPath(xPDO &$modx) {
return $modx->getOption('comparejewellery.core_path',null,$modx->getOption('core_path').'components/comparejewellery/').'controllers/container/';
}
public function getContextMenuText() {
return array(
'text_create' => 'Jewellery Category',
'text_create_here' => 'Create Jewellery Category here',
);
}
public function getResourceTypeName() {
return 'Jewellery Category';
}
}
class JewelleryContainerCreateProcessor extends modResourceCreateProcessor {
public function beforeSet() {
$beforeSet = parent::beforeSet();
$this->setProperty('cacheable',true);
return $beforeSet;
}
public function beforeSave() {
$beforeSave = parent::beforeSave();
$this->object->set('class_key','JewelleryContainer');
$this->object->set('cacheable',true);
$this->object->set('isfolder',true);
return $beforeSave;
}
public function afterSave() {
$afterSave = parent::afterSave();
$this->setProperty('clearCache',true);
return $afterSave;
}
}
class JewelleryContainerUpdateProcessor extends modResourceUpdateProcessor {
}<?php
require_once $modx->getOption('manager_path',null,MODX_MANAGER_PATH).'controllers/default/resource/create.class.php';
class JewelleryContainerCreateManagerController extends ResourceCreateManagerController {
/** @var JewelleryContainer $resource */
public $resource;
public function loadCustomCssJs() {
$this->prepareResource();
$managerUrl = $this->context->getOption('manager_url', MODX_MANAGER_URL, $this->modx->_userConfig);
$jewelleryAssetsUrl = $this->modx->getOption('comparejewellery.assets_url',null,$this->modx->getOption('assets_url',null,MODX_ASSETS_URL).'components/comparejewellery/');
$connectorUrl = $jewelleryAssetsUrl.'connector.php';
$jewelleryJsUrl = $jewelleryAssetsUrl.'js/';
$this->addJavascript($managerUrl.'assets/modext/util/datetime.js');
$this->addJavascript($managerUrl.'assets/modext/widgets/element/modx.panel.tv.renders.js');
$this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.grid.resource.security.js');
$this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.panel.resource.tv.js');
$this->addJavascript($managerUrl.'assets/modext/widgets/resource/modx.panel.resource.js');
$this->addJavascript($managerUrl.'assets/modext/sections/resource/create.js');
$this->addJavascript($jewelleryJsUrl.'comparejewellery.js');
$this->addJavascript($jewelleryJsUrl.'container/container.common.js');
$this->addJavascript($jewelleryJsUrl.'container/container.jewelleries.grid.js');
$this->addLastJavascript($jewelleryJsUrl.'container/create.js');
$this->addHtml('
<script type="text/javascript">
// <![CDATA[
CompareJewellery.assets_url = "'.$jewelleryAssetsUrl.'";
CompareJewellery.connector_url = "'.$connectorUrl.'";
MODx.config.publish_document = "'.$this->canPublish.'";
MODx.onDocFormRender = "'.$this->onDocFormRender.'";
MODx.ctx = "'.$this->resource->get('context_key').'";
Ext.onReady(function() {
MODx.load({
xtype: "comparejewellery-page-jewellery-container-create"
,resource: "'.$this->resource->get('id').'"
,record: '.$this->modx->toJSON($this->resourceArray).'
,publish_document: "'.$this->canPublish.'"
,canSave: '.($this->canSave ? 1 : 0).'
,canEdit: '.($this->canEdit ? 1 : 0).'
,canCreate: '.($this->canCreate ? 1 : 0).'
,canDuplicate: '.($this->canDuplicate ? 1 : 0).'
,canDelete: '.($this->canDelete ? 1 : 0).'
,show_tvs: '.(!empty($this->tvCounts) ? 1 : 0).'
,mode: "create"
});
});
// ]]>
</script>');
/* load RTE */
$this->loadRichTextEditor();
}
public function prepareResource() {
$settings = $this->resource->getProperties('comparejewellery');
if (empty($settings)) $settings = array();
$defaultContainerTemplate = $this->modx->getOption('comparejewellery.default_container_template',$settings,false);
if (empty($defaultContainerTemplate)) {
/** @var modTemplate $template */
$template = $this->modx->getObject('modTemplate',array('templatename' => 'Jewellery Category'));
if ($template) {
$defaultContainerTemplate = $template->get('id');
}
}
$this->resourceArray['template'] = $defaultContainerTemplate;
$defaultArticleTemplate = $this->modx->getOption('comparejewellery.jewellery_article_template',$settings,false);
if (empty($defaultArticleTemplate)) {
/** @var modTemplate $template */
$template = $this->modx->getObject('modTemplate',array('templatename' => 'Jewellery'));
if ($template) {
$defaultArticleTemplate = $template->get('id');
}
}
$this->resourceArray['setting_jewelleryTemplate'] = $defaultArticleTemplate;
foreach ($settings as $k => $v) {
$this->resourceArray['setting_'.$k] = $v;
}
}
/**
* Return the pagetitle
*
* @return string
*/
public function getPageTitle() {
return 'New Jewellery Category';
}
}Yeah, but it all looks correct. I am not sure why this wouldn't get called. Silly question but have you assigned the Resource to this CRC?
Quote from: easylancer at Apr 04, 2013, 06:24 AMYeah, but it all looks correct. I am not sure why this wouldn't get called. Silly question but have you assigned the Resource to this CRC?
How do you mean? What steps does that involved?
<?xml version="1.0" encoding="UTF-8"?>
<model package="CompareJewellery" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
<object class="JewelleryContainer" extends="modResource">
<composite alias="Jewelleries" class="Jewellery" local="id" foreign="parent" cardinality="many" owner="local" />
</object>
<object class="Jewellery" extends="modResource">
<aggregate alias="Container" class="JewelleryContainer" local="parent" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>Quote from: chrischerrett at Apr 04, 2013, 06:25 AMQuote from: easylancer at Apr 04, 2013, 06:24 AMYeah, but it all looks correct. I am not sure why this wouldn't get called. Silly question but have you assigned the Resource to this CRC?
How do you mean? What steps does that involved?
I have these setup, if that's what you mean?
<!--?xml version="1.0" encoding="UTF-8"?--> <model package="CompareJewellery" baseclass="xPDOObject" platform="mysql" defaultengine="MyISAM"> <object class="JewelleryContainer" extends="modResource"> <composite alias="Jewelleries" class="Jewellery" local="id" foreign="parent" cardinality="many" owner="local"> </composite></object> <object class="Jewellery" extends="modResource"> <aggregate alias="Container" class="JewelleryContainer" local="parent" foreign="id" cardinality="one" owner="foreign"> </aggregate></object> </model>
Keeping in mind that I'm attempting to assign the class_key JewelleryContainer on save. You'll notice this is all VERY similar to Articles. But by not being called, my resource is always being saved as a modDocument...