Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Preview: DataObjectManager module


Reply

379 Posts   61695 Views

Avatar
drye

20 March 2009 at 4:28am Community Member, 49 Posts

bgribaudo, in my code and all the examples i have seen it is required to have a reference to your page type from the resource object. Are you sure you shouldn't have something like

class QualityPDF extends PDFResource
{
static $has_one = array (
'Page' => 'QualityPDFPage '
);
}


and then you could setParentClass('QualityPDFPage')

Good Luck, I'm no expert.

Avatar
UncleCheese

20 March 2009 at 7:19am (Last edited: 20 March 2009 7:20am), 4085 Posts

Yeah, the parent class has to be the one that's in your has_one relationship. Put it this way.. setParentClass() tells the table which ID field it will update. so setParentClass('Page') means it will try to update PageID on the object. setParentClass('QualityPDFPage') will try to update the field QualityPDFPageID.

@David -- Thanks for these fixes. I've checked them in.

Avatar
Taffy

23 March 2009 at 10:55pm Community Member, 119 Posts

Not sure if this has been posted but here is the link to the module on the unsuported modules page http://silverstripe.org/dataobjectmanager-module/

Avatar
hu

23 March 2009 at 11:57pm Community Member, 21 Posts

There is a "small bug" behind the links on page navigation for lists. The parameters of First, Next, Previous an Last are twice in parameter string.

admin/EditForm/field/Products?ctf[Products][per_page]=10&ctf[Products][showall]=0&ctf[Products][sort]=SortOrder&ctf[Products][sort_dir]=DESC&ctf[Products][search]=&ctf[Products][filter]=&ctf[Products][start]=10&ctf[Products][per_page]=10&ctf[Products][showall]=0&ctf[Products][sort]=SortOrder&ctf[Products][sort_dir]=DESC&ctf[Products][search]=&ctf[Products][filter]=

Avatar
UncleCheese

24 March 2009 at 2:36am 4085 Posts

Hey! Look at that! It got posted. Finally. Still waiting for the ImageGallery to get some love.

@hu - Thanks for the heads up. I'll look at that.

Avatar
Ben Gribaudo

24 March 2009 at 5:16am Community Member, 181 Posts

Uncle Cheese,

I think I'm missing something. I'm setting setParentClass('Page') on the FileDataObjectManager instance, yet PDFResource's PageID column stays set at 0. Any clues?

Ben

Avatar
UncleCheese

24 March 2009 at 5:19am 4085 Posts

Can you show me QualityChildPage?

Avatar
Ben Gribaudo

24 March 2009 at 5:27am Community Member, 181 Posts

Sure thing.

class QualityChildPage extends Page {
   static $db = array('Category' => "Enum('Links, Workplace, Family, Stories, Extras','Links')");
   static $default_parent = 'QualityHomePage';
   static $can_be_root = false;
   static $allowed_children = array();
   static $icon = "themes/memberscf/images/pageicons/cqarticle";

   function getCMSFields() {
      $fields = parent::getCMSFields();

      $fields->addFieldToTab('Root.Content.Metadata', new DropdownField('Category', 'Category', singleton('QualityChildPage')->dbObject('Category')->enumValues()));
      return $fields;
   }
   
   function Quality() {
      return $this->Parent()->Quality;
   }
}

class QualityChildPage_Controller extends Page_Controller {
   protected $sidebar = 'QualitySideBar';

public function CategoryLinks($category) {
return QualityHelper::CategoryLinks($category, $this->Parent());
}
}

class QualityHelper {
   public static function CategoryLinks($category, $quality) {
$results = new DataObjectSet();
foreach($quality->Children() as $child) {
if ($child->Category != $category) continue;
$results->push($child);
}

return $results;
}
}