Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » how to handle thousands of subpages in admin/cms

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

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

Page: 1 2
Go to End
Author Topic: 3403 Views
  • BuddhaSource
    Avatar
    Community Member
    57 Posts

    Re: how to handle thousands of subpages in admin/cms Link to this post

    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;
       }
    }

    ?>

    3403 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.