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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Preview: DataObjectManager module


Go to End


379 Posts   95931 Views

Avatar
NickJacobs

Community Member, 148 Posts

29 March 2009 at 7:01pm

Edited: 29/03/2009 7:01pm

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)??

Avatar
Howard

Community Member, 215 Posts

30 March 2009 at 12:15am

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 %>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 March 2009 at 7:31am

Edited: 30/03/2009 7:32am

@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.

Avatar
Howard

Community Member, 215 Posts

30 March 2009 at 9:07am

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.

Avatar
NickJacobs

Community Member, 148 Posts

30 March 2009 at 11:35am

Edited: 30/03/2009 11:37am

@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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 March 2009 at 12:02pm

Why couldn't you just use $TreePageID?

Avatar
NickJacobs

Community Member, 148 Posts

30 March 2009 at 12:14pm

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

Avatar
hu

Community Member, 21 Posts

31 March 2009 at 7:32am

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

Go to Top