Aaron Cooper

Thanks Joe. That should be a simple in between

Aaron Cooper

I've got a simple DataObject in a $has_many on a Page Type. But I want two collections of the same DataObject and shown in two separate GridFields

  1. private static $has_many = [
  2. 'MonthlyStatements' => 'StatementType',
  3. 'AnnualStatements' => 'StatementType'
  4. ];

The only difference between them is a "Type": Monthly or Annual. But I don't have a field in the DO for this. So as it stands, both GridFileds show the same collection of data of course.

What's the best way of dealing with something like this? I can only think of making two idential DOs so they have separate tables, or adding a Type field to the existing DO and have the user set it. The first seems a bit DRY. The second is OK, but is also an extra step for the user since they are clicking the Add button for either Monthly or Annual, so it it should just be set for them (and hidden on the CMS form)

Aaron Cooper

@Firesphere FYI it wasn't StaffCategory, it was the class that was next in line to run. I went to the other environment to see what the next class is and found that class did a Xero application init on __construct. Commenting that out works.

Aaron Cooper

I'll give that a stab mate. Just waiting for a VM reboot. Cheers.

Aaron Cooper

Haha. If you're right I'll take it as a sign that I need to work with Whiskey more often

Aaron Cooper

Just found that my local here is running PHP 7.2 and the other env is 7.1. Checking that out

Aaron Cooper
  1. class StaffCategory extends DataObject {
  2.  
  3. private static $db = array (
  4. 'SortID' => 'Int',
  5. 'Title' => 'Varchar(75)',
  6. 'Description' => 'HTMLText'
  7. );
  8.  
  9. private static $has_one = array (
  10. 'StaffPage' => StaffPage::class
  11. );
  12.  
  13. private static $has_many = array (
  14. "Staff" => Staff::class
  15. );
  16.  
  17. private static $summary_fields = array (
  18. 'Title' => 'Title',
  19. 'DescriptionExcerpt' => 'Description'
  20. );
  21.  
  22. private static $default_sort = 'SortID Asc';
  23. private static $table_name = 'StaffCategory';
  24.  
  25. public function canCreate($Member = null, $context = array()) { return true; }
  26. public function canEdit($Member = null, $context = array()) { return true; }
  27. public function canView($Member = null, $context = array()) { return true; }
  28. public function canDelete($Member = null, $context = array()) { return true; }
  29.  
  30. public function getCMSFields() {
  31. return new FieldList(
  32. TextField::create("Title"),
  33. HTMLEditorField::create("Description")
  34. );
  35. }
  36.  
  37. public function DescriptionExcerpt($length = 300) {
  38. $text = strip_tags($this->Description);
  39. $length = abs((int)$length);
  40. if(strlen($text) > $length) {
  41. $text = preg_replace("/^(.{1,$length})(\s.*|$)/s", '\\1...', $text);
  42. }
  43. return $text;
  44. }
  45.  
  46. }
Aaron Cooper

Doesn't look like it. StaffCategory just extends DataObject and has little to it