Jump to:

7921 Posts in 1359 Topics by 933 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Go to End
Author Topic: 54670 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    @howard - This was a tricky one. Undo your changes and check out the latest version to get a functional setColumnWidths() function. It can be used exactly has you built it:

    $manager->setColumnWidths(array(
    'Name' => 20,
    'Description' => 60,
    'Category' => 20
    ));

    I believe it works best when you pass the values as integers. Make sure they add up to 100. I'll add the error checking later.

    The trick to getting the individual items to draw their widths was to tap into the Fields array of the DataObjectManager_Item class. I actually ended up overloading the Fields() method inherited from TableListField to accomplish this.

    Looks good so far. Please test and let me know what you think.

    @tsunami - Please refer to the documentation in the SS Wiki first, and then write a detailed explanation of the problem you're having so one of us can help you out.

  • Howard
    Avatar
    Forum Moderator
    215 Posts

    Re: Preview: DataObjectManager module Link to this post

    Yea that's brilliant, working well! I tried overloading the Fields method but somehow stuffed it up - your solution looks better I will keep testing, the to-do list looks good - I can't think of anything else to add at the moment.

    Thanks once again.

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    @unclecheese - hi, sorry I know stupid questions must waste your time, but I had been through the wiki stuff and still couldn't get it to work. I've sorted it now after a bit of trial and error, and it works for my purposes but there may be a more elegant way to do it...so I'll post it ..it may help someone else.

    what I had was a series of images using ImageDataObjectManager that needed to have a common identifier , so I wanted to use the parent pageID (because there are multiple child pages output on a pageholder)...the page uses jquery cycle and prettyphoto.

    I ended up with:

    ####TreeImage.php####

    class TreeImage extends DataObject
    {
       static $db = array (
          'TreeImageCaption' => 'Text',      
       );
       
       static $has_one = array (
          'TreeImageFile' => 'Image',
          'TreePage' => 'TreePage'
       );   
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('TreeImageCaption'),
             new ImageField('TreeImageFile')
          );
       }
       
       function theparent()
       {
       $parent = $this->TreePage();
       return $parent;
       }
       
    }

    and in TreeHolder.ss

    <% control Children %>

    ........

    <% if TreeImages %>

    <div class="slider" id="cycle$ID">
    <% control TreeImages %>
    <a rel="prettyPhoto[$theparent.ID]" title="$TreeImageCaption" href="$TreeImageFile.URL">
        <% control TreeImageFile %>
    $CroppedImage(240,180)
    <% end_control %>
    </a>
    <% end_control %>
    </div>

    ...........
    <% end_if %>
    ..........
    <% end_control %>

    final page is here

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Why couldn't you just use $TreePageID?

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    Yes...thats the more elegant solution I was talking about

  • hu
    Avatar
    Community Member
    21 Posts

    Re: Preview: DataObjectManager module Link to this post

    Uncle Cheese, can you please add this code to DataObjectManager.php.
    If you are using get-functions or joined fields in the grid the SQL search string will not execute.

    protected function loadSourceFilter() {
    ...
          if(!empty($this->search)) {
             $search = array();
             $SNG = singleton($this->sourceClass);
             foreach(parent::Headings() as $field) {
                if ($SNG->hasField($field->Name))
                   $search[] = "UPPER($field->Name) LIKE '%".strtoupper($this->search)."%'";
             }
             $search_string = "(".implode(" OR ", $search).")";
          }
    ...
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Great catch. I've added that in.

  • hu
    Avatar
    Community Member
    21 Posts

    Re: Preview: DataObjectManager module Link to this post

    The same problem occurs with sorting by column.

    public function Headings() {
    ...
       foreach($headings as $heading) {
       ...
          $heading->SortLink = $this->RelativeLink(array(
             'sort_dir' => $heading->SortDirection,
             'sort' => $heading->Name
          ));
          $heading->IsSortable = singleton($this->sourceClass)->hasField($heading->Name);
       }
       return $headings;
    }

    DataObjectManager.ss

    <div class="pad">
       <% if IsSortable %>
          <a href="$SortLink">$Title &nbsp;
          <% if IsSorted %>
             <% if SortDirection = ASC %>
             <img src="cms/images/bullet_arrow_up.png" alt="" />
             <% else %>
             <img src="cms/images/bullet_arrow_down.png" alt="" />
             <% end_if %>
          <% end_if %>
          </a>
       <% else %>
        $Title
       <% end_if %>

    </div>

    54670 Views
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.