Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
Go to End
Author Topic: 58344 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hi, I've looked everywhere I can think of, but just can't get this to work...... in my template can I reference the page from inside the dataobject (ie using $Parent or something like that)??

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hi UncleCheese,

    I have had a go at adding adjustable width columns with help from simon in the irc. I can style the heading columns without a problem but for some reason can't set the width of the columns containing the Item values. I was probably trying to do it wrong - any advice? Here is the code I have implemented.

    ## ExamplePage.php ##

          $manager->setColumnWidths(array(
             'Name' => '20',
             'PlanningComment' => '60',
             'Date' => '20'
             ));


    ## DataObjectManager.php ##

    public function setColumnWidths($Widths)
       {
          $this->ColumnWidths = $Widths;
       }

    public function Headings()
       {
          
       $headings = parent::Headings();
    foreach($headings as $heading) {
    $heading->IsSorted = (isset($_REQUEST['ctf'][$this->Name()]['sort'])) && ($_REQUEST['ctf'][$this->Name()]['sort'] == $heading->Name);

    $Widths = $this->ColumnWidths;

    $heading->Width = (isset($Widths[$heading->Name]) ? $Widths[$heading->Name] : self::$default_heading_width);

    if(isset($_REQUEST['ctf'][$this->Name()]['sort_dir']))
    $dir = $_REQUEST['ctf'][$this->Name()]['sort_dir'] == "ASC" ? "DESC" : "ASC";
    else
    $dir = "ASC";
    $heading->SortDirection = $dir;
    $heading->SortLink = $this->RelativeLink(array(
    'sort_dir' => $heading->SortDirection,
    'sort' => $heading->Name
    ));

    }
    return $headings;

       }


    ## DataObjectManager.ss ##

    <% control Headings %>
                   <div class="col $FirstLast" style="width: $Width%">
                      <div class="pad">
                            <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>
                      </div>
                   </div>
                   <% end_control %>

  • 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
    Community Member
    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).")";
          }
    ...
    }

    58344 Views
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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.