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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

how to handle thousands of subpages in admin/cms


Go to End


9 Posts   9734 Views

Avatar
BuddhaSource

Community Member, 57 Posts

26 February 2012 at 8:12pm

I have similar issue.

I have News Holder and News Post. But I Have extended Blog Holder and Blog Entry respectively.
Can I change this to DataObject while inheriting from Blog Entry?

I am a designer who can manage to code with little help :)

Current Code for NewsPost is



class NewsPost extends BlogEntry {
	static $db = array (
     'GalleryImageWidth' => 'Int',
     'Featured' => 'Boolean',
     'UserPost' => 'Boolean',
   );
	
	static $default_parent = 'NewsHolder';
	static $can_be_root = false;
	
	static $has_one = array(
		'Photo' => 'Image'
      
		//'Gallery' => 'ImageGalleryPage' 
		//'GalleryImages' => 'GalleryImage' 
	);
	
	static $has_many = array (
          'GalleryImages' => 'GalleryImage'
    ); 



  public function init() {
    parent::init();

    // Note: you should use SS template require tags inside your templates 
    // instead of putting Requirements calls here.  However these are 
    // included so that our older themes still work   

    Requirements::block("sapphire/thirdparty/behaviour/behaviour.js"); 
	Requirements::block("sapphire/thirdparty/jquery/jquery.js");
	
  }

	function getCMSFields() {
		
	$fields = parent::getCMSFields();
    $fields->addFieldsToTab("Root.Content.Main", new CheckboxField('UserPost', "Post by a Member"));
	$fields->addFieldToTab("Root.Content.Main", new CheckboxField('Featured', "Featured Post"));
	$fields->addFieldToTab("Root.Content.Images", $leadImage= new ImageField('Photo', "Upload your lead image here"));
		$leadImage->setFolderName('Uploads/' .date("Y").'/' .date("m"));
	
	$fields->addFieldToTab("Root.Content.Configuration", $myField= new NumericField('GalleryImageWidth', 'Image Width'));
		/*$fields-> addFieldToTab ("Root.Content.Gallery", new DropdownField("GalleryID", "Gallery", 
			DataObject::get("ImageGalleryPage")->toDropdownMap(),  'Content'));*/
		
		$manager = new ImageDataObjectManager(
         $this, // Controller
        'GalleryImages', // Source name
        'GalleryImage', // Source class
        'MyGalleryImage', // File name on DataObject
         array(
            'GalleryImageTitle' => 'GalleryImageTitle'
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
      $fields->addFieldToTab('Root.Content.GalleryImage', $manager); 
     return $fields;
    }

	
// Function for SideBar
    function GetSidebarContent($num=3) {

      //$randomNumber = 
      $sidebarContent = DataObject::get_one("SidebarContent");

      if(!$sidebarContent)
      {
        return false;
      }

      $contents = array();

      $contents[] =  DBField::create('Varchar', $sidebarContent->Content1);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content2);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content3);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content4);
      $contents[] =  DBField::create('Varchar', $sidebarContent->Content5);

      shuffle($contents);
            
      //return new DataObjectSet(array_rand($contents, $num));      
      return new DataObjectSet(array_slice($contents, 0, $num));   
      //return new DataObjectSet($contents);   
  }

	
}
 
class NewsPost_Controller extends BlogEntry_Controller{


}


/**
 * Replaces Images to a predefined max width and adds a nyroModal class to the image
 * In template use : $Content.Parse(ArticleImageParser)
 */
 
class ArticleImageParser extends TextParser{
	
	public function parse() { 
		
		// match image src
		$pattern = '/<img[^>]+src[\\s=\'"]';
		$pattern .= '+([^"\'>\\s]+)/is';
		if(preg_match_all($pattern,$this->content,$match)){
			$i = 0;
			foreach ($match[0] as $m){	
				//var_dump($m); //"<img class="right" src="assets/Articles/installingsilverstripe/wampserver.jpg"
				
				// get original image url
				$href = preg_replace('/_resampled\/resizedimage[0-9]*-/', '',  $match[1][$i]);
				// add a tag with original image url
				$this->content	= str_replace ($m,'<a class="popImage" rel="grp-all" href="'.$href.'">'.$match[0][$i],$this->content);
				$i++;
			}
			
			// add missing </a> tag after each image
			$this->content = preg_replace('/<img[^>]+>/', '${0}</a>', $this->content);
		}
		
		return $this->content;
	}
}

?>


Go to Top