Hallo zusammen,
my first post here on the forums. First of all, i'm really impressed with SilverStripe and all the work that you guys have put into this.. I've come quite a long way looking for a flexible (and pretty : ) CMS, and although right now i feel a little dizzy from crash-coursing myself into the system i think it'll be perfect for my next projects. So i thought a thanks would be in order here..
My question relates to the DOM (which seems to be a great tool by the way, UncleCheese), and is somewhat related to this post
http://www.silverstripe.org/dataobjectmanager-module-forum/show/267254#post267254
as well as this one
http://www.silverstripe.org/dataobjectmanager-module-forum/show/275956#post275956
I'm trying to create an "Affiliates" Page Class which stores affiliates (for now, only name & URL) divided into categories, so much like the Resource Pages from the Tutorial. Only should the categories also come from a DataObject, so the website owner can add/remove categories dynamically.
Here's my code so far
### AffiliateDataObject.php
<?php
class AffiliateDataObject extends DataObject {
static $db = array (
'Name' => 'Text',
'Url' => 'Text'
);
static $has_one = array (
'AffiliatePage' => 'AffiliatePage',
'AffiliateCategory' => 'AffiliateCategory'
);
// Testing, obsolete?
function getMyCategoryName() {
return $this->AffiliateCategory()->Name;
}
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Name', 'Name' ) );
$fields->push( new TextField( 'Url', 'Url' ) );
$oData = (DataObject::get('AffiliateCategory'));
if ($oData) $CategoriesSource = $oData->toDropDownMap('ID','Name');
$dropdown = new DropdownField('AffiliateCategoryID','Category',$CategoriesSource);
$dropdown->setEmptyString('-- Select category --');
$fields->push ( $dropdown );
return $fields;
}
}
### AffiliateCategory.php
<?php
class AffiliateCategory extends DataObject {
static $db = array (
'Name' => 'Varchar(100)'
);
static $has_one = array (
'AffiliatePage' => 'AffiliatePage'
);
static $has_many = array (
'AffiliateDataObjects' => 'AffiliateDataObject'
);
public function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Name', 'Name')
);
}
}
### AffiliatePage.php
<?php
class AffiliatePage extends Page {
static $db = array (
);
static $has_many = array (
'AffiliateDataObjects' => 'AffiliateDataObject',
'AffiliateCategories' => 'AffiliateCategory'
);
function getCMSFields() {
$f = parent::getCMSFields();
$affiliate_manager = new DataObjectManager(
$this,
'AffiliateDataObjects',
'AffiliateDataObject',
array('Name' => 'Name','Url'=>'Url','AffiliateCategory.Name'=>'Category'),
'getCMSFields_forPopup'
);
$affiliate_manager->setPerPageMap(array('50'));
$f->addFieldToTab("Root.Content.Affiliates", $affiliate_manager);
$f->addFieldToTab("Root.Content.Categories", new DataObjectManager(
$this,
'AffiliateCategories',
'AffiliateCategory',
array('Name'=>'Name'),
'getCMSFields_forPopup'
));
return $f;
}
}
class AffiliatePage_Controller extends Page_Controller {
}
Everything seems to be working just fine, i can add categories and get a dropdown menu showing the categories name when i add a new "Affiliate" Data Object.
However there's no sorting by category in the DOM. If I click the header area in DOM for "Category" the loading animation appears and disappears, but no sorting occurs.
In an ideal case, what i'm trying to achieve is alphabetcal ordering by category name (which has to be pulled from the AffiliateCategory DataObject)
I tried changing
### AffiliatePage.php
array('Name' => 'Name','Url'=>'Url','MyCategoryName'=>'Category'),
to
array('Name' => 'Name','Url'=>'Url','AffiliateCategory.Name'=>'Category'),
which also outputs the categories column correctly, but renders the table header unclickable, so also no sorting.
Could this possibly have to do with naming conventions for relationships that (while unbeknownst to me) make the whole thing work automagically?
I've also been trying to gather more documentation about working with related field values in DOM, does anybody have some tutorial or working module recommendations for this kind of thing?
Any help would be greatly appreciated.. Thanks and all the best,
Andi