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

How to get image


Go to End
Reply


2 Posts   1532 Views

Avatar
T3nD4n

Community Member, 16 Posts

16 July 2011 at 3:07pm

Edited: 16/07/2011 3:07pm

hi, mi English in to poor, but im going to try you understand me.

i have a gallery holder whitch contains multiple gallerys with images.

In my galery holder i want to show the title and an image of each galery, the image linked to the gallery.

The Link an Name of each galery y can get with control children.
but the problen comes when i want to show a image of the gallery, i cant figured how to get this image.

here are my classes:
HolderGalerias

class holderGalerias extends Page {
   static $db = array(
   );
   static $has_one = array(
   );
   
   static $allowed_children = array('Galeria');
}
 
class holderGalerias_Controller extends Page_Controller {
    function getGalerias(){
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) 
			$_GET['start'] = 0;
		$SQL_start = (int)$_GET['start'];
		$doSet = DataObject::get(
		$callerClass = "Galeria",
		$filter = "", 
		$sort = "",
		$join = "",
		$limit = "{$SQL_start},2"
		);
		return $doSet ? $doSet : false;
		//return $doSet->fotos();
	}	
}

Galeria
class Galeria extends Page {
	
	static $has_many = array (
		'FotosGal' => 'imagenesGaleria',
    );
	
	static $db = array(
	);
   
	static $has_one = array(
	
	);
	
	 public function getCMSFields(){
        $f = parent::getCMSFields();
        $manager = new ImageDataObjectManager(
            $this, // Controller
            'FotosGal', // Source name
            'imagenesGaleria', // Source class
            'Photo', // File name on DataObject
            array(
            ), // Headings 
            'getCMSFields_forPopup' // Detail fields
            // Filter clause
            // Sort clause
            // Join clause
        );
        $f->addFieldToTab("Root.Content.Fotos",$manager);
        return $f;
    }
}
 
class Galeria_Controller extends Page_Controller {

	function fotos() {
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
		$SQL_start = (int)$_GET['start'];
		$doSet = DataObject::get(
			$callerClass = "imagenesGaleria",
			$filter = "`GaleriaID` = '".$this->ID."'",
			$sort = "",
			$join = "",
			$limit = "{$SQL_start},8"
		);
		return $doSet ? $doSet : false;
	} 
}

imagenesGaleria
class imagenesGaleria extends DataObject{
	static $db = array (
		'Title' => 'Varchar(250)',
	);
	
	static $has_one = array (
		'Galeria' => 'Galeria',
		'Photo' => 'Imagen',
	);
	
	 public function getCMSFields_forPopup(){
        return new FieldSet(
			new TextField('Title'),
            new FileIFrameField('Photo')
        );
    }
}

any help would be apreciate!

Avatar
T3nD4n

Community Member, 16 Posts

17 July 2011 at 7:52am

Edited: 17/07/2011 7:56am

[SOLVED]

this may help someone.

I find the way to render one Image (DataObject) of a gallery from the holder gallerys

My Class ImagenesGaleria:

class imagenesGaleria extends DataObject{
	static $db = array (
		'Title' => 'Varchar(250)',
	);
	
	static $has_one = array (
		'Galeria' => 'Galeria',
		'Photo' => 'Imagen',
	);
	
	public function getCMSFields_forPopup(){
		return new FieldSet(
			new TextField('Title'),
			new FileIFrameField('Photo')
		);
	}
}

My Class Galeria:

class Galeria extends Page {
	
	static $has_many = array (
		'FotosGal' => 'imagenesGaleria',
    );
	
	static $db = array(
	);
   
	static $has_one = array(
	);

	public function getCMSFields(){
        $f = parent::getCMSFields();
        $manager = new ImageDataObjectManager(
            $this, // Controller
            'FotosGal', // Source name
            'imagenesGaleria', // Source class
            'Photo', // File name on DataObject
            array(
            ), // Headings 
            'getCMSFields_forPopup' // Detail fields
            // Filter clause
            // Sort clause
            // Join clause
        );
        $f->addFieldToTab("Root.Content.Fotos",$manager);
        return $f;
    }
	
	function forTemplate() {
		$galeria = DataObject::get_one('imagenesGaleria', "GaleriaID = $this->ID");
		return $galeria->renderWith('imagenesGaleria'); 
	}
}
 
class Galeria_Controller extends Page_Controller {

	function fotos() { // to render al the images in the template Galeria.ss in the page type Galeria.
		if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
		$SQL_start = (int)$_GET['start'];
		$doSet = DataObject::get(
			$callerClass = "imagenesGaleria",
			$filter = "`GaleriaID` = '".$this->ID."'",
			$sort = "",
			$join = "",
			$limit = "{$SQL_start},8"
		);
		return $doSet ? $doSet : false;
	}
}

My Class imagenesGaleria:

class imagenesGaleria extends DataObject{
	static $db = array (
		'Title' => 'Varchar(250)',
	);
	
	static $has_one = array (
		'Galeria' => 'Galeria',
		'Photo' => 'Imagen',
	);
	
	public function getCMSFields_forPopup(){
		return new FieldSet(
			new TextField('Title'),
			new FileIFrameField('Photo')
		);
	}
}

And here is my holderGalerias.ss

<% control Children %> 	
	<div class="thumb">
		<a  href="$Link" title="$Title"><img  src="$Me" alt="" border="0" /></a>
		<div class="title">$Title</div>
	</div>	
<% end_control %>

Exist Me() method that returns $this, but if we use it in this case we will get this error.
Object->__call(): the method 'fortemplate' does not exist on 'Galeria'
for that i create the function forTemplate() inside the class Galeria:

function forTemplate() { 
	$galeria = DataObject::get_one('imagenesGaleria', "GaleriaID = $this->ID");
	return $galeria->renderWith('imagenesGaleria'); 
}

witch get one image of the galeria and render with imagenesGaleria.ss, found in templates/Includes, with the following code:

$Photo.URL

Hopefully someone will understand my poor English

Bye.