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

Show images in ArticleHolder


Reply

21 Posts   3130 Views

Avatar
frabraha

26 November 2009 at 9:33pm Community Member, 49 Posts

No no.. this isn't in ArticlePage.ss its in ArticleHolder.ss. The function works just fine in ArticlePage.ss

Maybe I didn't explain it clear enough..:)
Well here's how it is..

I have Article 1, Article 2 and article 3, each with images and text.

In ArticleHolder.ss I'm trying to list out those 3 article's with the first image.

Image - Article 1
Image - Article 2
Image - Article 3
..and so on..

Avatar
frabraha

2 December 2009 at 10:18pm Community Member, 49 Posts

I still can't get this thing to work..
Can't find any help with this on the forum either..

Avatar
UncleCheese

3 December 2009 at 3:44am 4085 Posts

So the code you're using is

<% control Children %>
<% control ArticleBilder.First %>
$Attachment
<% end_control %>
<% end_control %>

Avatar
frabraha

3 December 2009 at 9:43pm Community Member, 49 Posts

Here is all of the code for the images:

In ArticleHolder.ss

       <% if GetArticleFirstImage %>
         <% control GetArticleFirstImage %>   
            <% control Attachment.First %>
               $Attachment
            <% end_control %>
         <% end_control %>
         <% else %>
            <a href="$Link"><img src="themes/tutorial/images/blank.jpg" /></a>
         <% end_if %>

In ArticleHolder.php

   function GetArticleFirstImage($num=1){
   $manager = DataObject::get_one("ArticlePage");
   return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder", "", $num) : false;
   }

In ArticlePage.php

$manager = new ImageDataObjectManager(
         $this,
         'ArticleBilder',
         'ArticleBilde',
         'Attachment',
         array(
            'Name' => 'Bildenavn',
            'Description' => 'Beskrivelse'
         ),
         'getCMSFields_forPopup_articlebilder'
   );
$fields->addFieldToTab("Root.Content.Bilder",$manager);   

Avatar
UncleCheese

4 December 2009 at 2:35am 4085 Posts

And your ArticleBilde class?

Avatar
frabraha

4 December 2009 at 2:41am Community Member, 49 Posts

Forgot that one..

Here:

In ArticleBilde.php

<?php
class ArticleBilde extends DataObject
{
   static $db = array (
      'Name' => 'Text',
      'Description' => 'Text',
   );
   
   static $has_one = array (
      'Attachment' => 'File',
      'ArticlePage' => 'ArticlePage'
   );
   
   public function getCMSFields_forPopup_articlebilder()
   {
      return new FieldSet(
         new TextField('Name'),
         new TextareaField('Description'),
         new FileIFrameField('Attachment')
      );
   }
}

?>

Avatar
frabraha

9 December 2009 at 1:40am Community Member, 49 Posts

I have tried to get this to work with a fresh install of SS and just starting from scratch, but I still can't get the images to show up in the articleHolder.ss.

I've done this before, the only different is that I used DataObjectManager to manage a simple list of urls, and used this function to output it to the template:

   function GetLinksInternal(){
   $LinksPage = DataObject::get_one("LinksPage");
   return ($LinksPage) ? DataObject::get("InternalLink", "LinksPageID = {$LinksPage->ID}") : false;
   }

And this works perfectly anywhere on the website, but when I do the same when I use imagedataobjectmanager or the filedataobjectmanager it only shows the content added in the imagedataobjectmanager or the filedataobjectmanager when you are on the right page.

Avatar
frabraha

15 December 2009 at 11:49pm Community Member, 49 Posts

I think I have found out why this isn't working.
Its the Get function, this part isnt right: ArticlePageID = $this->ID. When I just have ArticlePageID, all of the ArticleBilde are showing in a list. SS doesn't know what do get and doesn't output anything..

I'm not that good at programming this kind of things, so how should I do this when I have an articleholder with serveral ArticlePages with images added to them, something like this:

Articleholder -> ArticlePage1 -> ArticleBilde1,ArticleBilde2,ArticleBilde2,
-> ArticlePage2 -> ArticleBilde1,ArticleBilde2,
-> ArticlePage3 -> ArticleBilde1,ArticleBilde2,

Heres the function:

function GetArticleFirstImage(){
$manager = DataObject::get_one("ArticlePage");
return ($manager) ? DataObject::get("ArticleBilde", "ArticlePageID = $this->ID", "SortOrder") : false;
}