Hi Nicolaas!
Thanks for your suggestions.
@ //I would add:
//foreach($mixedGalleriesField as $key => $value) {$mixedGalleriesField[$key] = intval(trim($value));}
//for debugging purposes I would write here: print_r($mixedGalleriesField);
I only want to remove $this->ID from the $mixedGalleriesField on StartPage.
(If ! ShowProductImages on this Product remove this ID from $mixedGalleriesField on StartPage )
StartPage :
public function getRandomGalleries() {
$allGalleries = ArrayList::create();
foreach(Dataobject::get('Product')->filter(array('ShowProductImages' => '1')) as $gallery) {
$existingGallery = $gallery;
$allGalleries->merge($existingGallery);
}
return $allGalleries;
}
public function getCMSFields() {
............
$mixedGallery = $this->getRandomGalleries();
$mixedGalleryMap = $mixedGallery->map('ID', 'Title', '(Select one)', true);
if($this->ShowMixedGallery){
$fields->addFieldToTab('Root.GalerieBilder', new ToggleCompositeField('Mixed Galerie', 'Mixed Galerie',
array( new CheckboxSetField( $name = "MixedGalleries", $title = "choose galleries", $source = $mixedGalleryMap, $value = ''))));
//TotalGalleryImages (0-40)
$fields->addFieldToTab('Root.GalerieBilder', new DropdownField('TotalGalleryImages', 'Anzahl Bilder', $this->getNumbers()));
}
...........
AND HERE COMES THE NEXT PROBLEM:
Im trying to merge all Products where ShowProductImages == 1 && checked in CheckboxSetField (on StartPage)
I came up with this but i can not get it working with ->sort('RAND()')->limit($startPage->TotalGalleryImages) :
( I need $gallery->MyImages() AND mylink' => $gallery->Link() )
Page_Controller:
public function getMixedGallery(){
$startPage = StartPage::get()->First();
$mixedGalleriesField = $startPage->MixedGalleries;
$fieldArray = explode(",", $mixedGalleriesField);
$images = ArrayList::create();
foreach($fieldArray as $id){
foreach(Dataobject::get('Product')->filter(array('ID' => $id, 'ShowProductImages' => '1')) as $gallery) {
if($gallery->MyImages()->Count() > 0){
$imagesForGallery = array('myimage' => $gallery->MyImages(), 'mylink' => $gallery->Link());
$images->push($imagesForGallery);
}
}
}
return $images;
StartPage.ss :
<div class="gallery-content" >
<% if $ShowGallery %>
<% if $ShowMixedGallery == 1 %>
<% include Gallery gallery=$MyGallery , mixed=$ShowMixedGallery , Mixed=$getMixedGallery() %>
<% else %>
<% include Gallery gallery=$MyGallery , mixed=$ShowMixedGallery %>
<% end_if %>
<% end_if %>
</div>
Gallery.ss :
<% if $gallery == '1' %>
<div id="gallery-holder" style=" margin: 0px -0px 0px -4px; padding: 0px 0px 0px 0px; ">
<div id="gallery" class="masonry">
<% loop Mixed %>
<% loop myimage %>
<div class="box masonry-brick img-responsive" >
<a href=" $Up.mylink " class="lightbox alpha dark " rel="myscale[$Top.ID]">
<img class="gallery_img img-responsive img-rounded-light" src="<% with $Image %>$CroppedImage(100,100).Link<% end_with %>" alt="$Title" style=""/>
</a>
</div>
<% end_loop %>
<% end_loop %>
</div>
</div>
<% end_if %>
Thanks.timo.