Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Default disable object in DataObject

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

Page: 1
Go to End
Author Topic: 379 Views
  • Craftnet
    Avatar
    Community Member
    58 Posts

    Default disable object in DataObject Link to this post

    Hi,
    I have a problem.

    On my site I have a registration form for mail confirmation.
    Each user after registration has a subsite with form to report new objectsleep .

    The form requires the name object, address, etc. ...
    Form application write in the DataObject.
    How to make an application which is stored in the database was set by default to not display on the page

    otherwise:
    My point is that the notification sent by member in the database which to save the "ObjectSleep" it was turned off for as long as admin does not approve it.

    At the moment member send the form saves the object in the database but it is automatically visible to others.

    My code:

    class Obiekt extends DataObject {

    //--------------- BAZA DANYCH --------------- //
    static $db = array(
    'Title' => 'Varchar(255)',
    'NazwaObiektu' => 'Varchar(255)',
    'KodPocztowy' => 'Varchar(6)',
    'Miejscowosc' => 'Varchar(255)',
    'Ulica' => 'Varchar(255)',
    'NrDomu' => 'Varchar(6)',
    'Telefon' => 'Int',
    'TelefonDodatkowy' => 'Int',
    'Email' => 'Varchar(255)',
    'Strona' => 'Varchar(255)',
    'DostepnoscObiektu' => 'Boolean',
    'Pokoj1' => 'Boolean',
    'Pokoj2' => 'Boolean',
    'Pokoj3' => 'Boolean',
    'Pokoj4' => 'Boolean',
    'Pokoj5' => 'Boolean',
    'SrCenaMin' => 'Int',
    'SrCenaMax' => 'Int',
    'IloscMiejsc' => 'Int',
    );
    //--------------- ŁĄCZENIA BAZ DANYCH --------------- //
    static $has_one = array(
    'Wojewodztwo' => 'Wojewodztwo',
    'Uzytkownik' => 'Uzytkownik',
    'Region' => 'Region',
    'Nocleg' => 'Nocleg',
    );
       
    //--------------- NAZWA --------------- //   
       static $singular_name = 'Obiekt';
       static $plural_name = 'Obiekty';
       
       function getTitle() {
       return "{$this->NazwaObiektu}";
       }
       
    //--------------- NAZWY POLA FORMULARZA --------------- //      
       static $field_labels = array(
          'Title' => 'NazwaObiektu',
          'NazwaObiektu' => 'Nazwa Obiektu:',
          'KodPocztowy' => 'Kod pocztowy:',
          'Miejscowosc' => 'Miejscowosc:',
          'Ulica' => 'Ulica:',
          'NrDomu' => 'Numer domu / lokalu:',
          'Telefon' => 'Telefon:',
          'TelefonDodatkowy' => 'Telefon dodatkowy:',
          'Email' => 'Email:',
          'Strona' => 'Strona www (bez http://):',
          'DostepnoscObiektu' => 'Obiekt dostepny całorocznie:',
          'SrCenaMin' => 'Średnia cena noclegu za osobę od:',
       'SrCenaMax' => 'do:',
       );
       
          
    //--------------- NAZWY POLA WYSZUKIWANIA --------------- //   
       static $searchable_fields = array(
        'Miejscowosc' => array (
           'title' => 'Nazwa miejscowosci',
           'field' => 'TextField',
           'filter' => 'PartialMatchFilter',
        ),
        'Wojewodztwo.ID' => array(
           'title' => 'Województwo',
        ),
        'Region.ID' => array (
           'title' => 'Region',
        ),
        'Nocleg.ID' => array (
           'title' => 'Kategoria noclegu',
        ),
        'SrCenaMin' => array(
    'field' => 'TextField',
    'filter' => 'GreaterThanFilter',
    'title' => 'Cena / od'
    ),
    'SrCenaMax' => array(
    'field' => 'TextField',
    'filter' => 'LessThanFilter',
    'title' => 'do / osoba'
    ),
    );
       
       public function getDefaultSearchContext() {
          $context = parent::getDefaultSearchContext();      
          return $context;
       }
       
       
       //--------------- UPRAWNIENIA --------------- //
    public function canView($member = null) {
          return true;
       }
       
       public function canCreate($member = null) {
          return true;
       }
       
       public function canEdit($member = null) {
          if(!$member) $member = Member::currentUser();
          return (
             Permission::checkMember($member, 'ADMIN')
             || ($member && $member->ID == $this->ID)
          );
       }
       
       public function canDelete($member = null) {
          return $this->canEdit($member);
       }

    }

    I think i must use

    'Status' => "Enum('Active,Disabled','Disabled')",

    and

    'defaults' => array(
              'Status' => 'Disabled'
             )

    but i know idea where i must use this code and

    what must be in ContentController which be blocked this object

    unless you have a different idea

    Sorry for my bad English

    379 Views
Page: 1
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.