Jump to:

22977 Posts in 11806 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Restricting visibility of database items

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 3
Go to End
Author Topic: 1696 Views
  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Restricting visibility of database items Link to this post

    So I have decided to go back to the original method I was using, based on tutorial 5, after finding a line of code to help filter out the tracks that aren't relevant to that page - "TrackProductID=$this->ID".

    However because you can't check the checkbox which is how a TrackProductID gets assigned until after you have created a new entry they are lost. I therefore need to find a way to either add in an 'OR is NULL' argument to the above line or automatically check the checkbox so that the TrackProductID is assigned by default. And then remove the checkbox so that it can't be accidentally unchecked and lost. Does that make sense?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Restricting visibility of database items Link to this post

    I'd say that the follwing is fine is all that is required to edit the data within ModelAdmin... with the has_many automatically scaffolded...

    TrackAdmin.php:

    class TrackAdmin extends ModelAdmin {
    public static $managed_models = array(
    'CDTracks',
    );
    static $url_segment = 'cdtracks';
    static $menu_title = 'Track Admin';
    }

    CDVolumes.php:

    class CDVolumes extends DataObject {
    static $db = array(
    'Volume' => 'Text'
    );
    static $has_many= array(
    'CDTracks' => 'CDTracks'
    );
    }

    CDTracks.php:

    class CDTracks extends DataObject {
    static $db = array(
    'TrackName' => 'Varchar',
    'TrackNumber' => 'Varchar',
    'TrackDescription' => 'Text'
    );

    static $has_one = array(
    'CDVolumes' => 'CDVolumes'
    );
    }

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Restricting visibility of database items Link to this post

    if you want those attached, or not at all...

    "TrackProductID IN (".$this->ID.",0)"

  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Restricting visibility of database items Link to this post

    Got it! Thank you so much for all your help.

    One last question. How would I add an AND statement to the query below?

    "TrackProductID IN (".$this->ID.",0) AND ($AnotherID = XXXXXX)"

    Thanks again.

    Marc

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Restricting visibility of database items Link to this post

    sure, just add the extra SQL required as in any other where clause...
    joins need special attention though

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: Restricting visibility of database items Link to this post

    Reading all this I was just wondering whether you were ever going to use the same cdtrack for different cdvolumes? Since you are using a one-to-many relationship I suppose not, in which case you could just use a ComplexTableField instead of the HasManyComplexTableField (or even the DataObjectManager) that will let you create CDTracks for each CDVolume individually and then automatically add the correct page ID to the track, meaning you could even just use <% control CDTracks %> in your template?

    You probably wouldn't need ModelAdmin... But maybe I just completely missed the point, in which case just forget I posted

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Restricting visibility of database items Link to this post

    hahe - yeah I push model admin loads

    Mainly because I like it loads!

    I do think that security is very easy for cms menu items, harder for page items. So if I wanted to have someone only have access to maintain CD data - it takes 2 seconds. Plus ModelAdmin scaffolds the entire data object, no need to create extra code (while silverSmith isn't available ;) ).

  • marc79
    Avatar
    Community Member
    65 Posts

    Re: Restricting visibility of database items Link to this post

    Yeah. Looking at it I think, currently, the only thing I'd be using the ModelAdmin for is the CSV upload but I guess I can add this in on the product page?

    1696 Views
Page: 1 2 3
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.