Source of file RestaurantPage.php
Size: 8,468 Bytes - Last Modified: 2021-12-24T05:15:50+00:00
/var/www/docs.ssmods.com/process/src/code/pages/RestaurantPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 | <?php /* * MIT License * * Copyright (c) 2016 Hudhaifa Shatnawi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * * @author Hudhaifa Shatnawi <hudhaifa.shatnawi@gmail.com> * @version 1.0, Oct 24, 2016 - 12:55:22 PM */ class RestaurantPage extends Page { private static $db = array( 'Address' => 'Varchar(255)', 'Phone' => 'Varchar(255)', 'Email' => 'Varchar(255)', ); private static $translate = array( 'Address', ); private static $has_one = array( 'About' => 'AboutItem' ); private static $has_many = array( 'OpenTimes' => 'OpenTime', 'MealsMenus' => 'MealsMenu', 'Chefs' => 'Chef', 'GalleryItems' => 'GalleryItem', 'CarouselItems' => 'CarouselItem', ); private static $many_many = array( ); private static $icon = "chef/images/restaurant.png"; /** */ private static $group_code = 'chefs'; private static $group_title = 'Chefs'; private static $group_permission = 'CMS_ACCESS_CMSMain'; public function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); $labels['Address'] = _t('Restaurant.ADDRESS', 'Address'); $labels['Phone'] = _t('Restaurant.PHONE', 'Phone'); $labels['Email'] = _t('Restaurant.EMAIL', 'Email'); $labels['Menus'] = _t('Restaurant.MENUS', 'Menus'); $labels['OpenTimes'] = _t('Restaurant.OPEN_TIMES', 'Open Times'); $labels['Contact'] = _t('Restaurant.CONTACT', 'Contact'); $labels['About'] = _t('Restaurant.ABOUT', 'About'); $labels['Chefs'] = _t('Restaurant.CHEFS', 'Chefs'); $labels['GalleryItems'] = _t('Restaurant.GALLERY_ITEMS', 'Gallery Items'); $labels['CarouselItems'] = _t('Restaurant.CAROUSEL_ITEMS', 'Carousel Items'); return $labels; } public function getCMSFields() { $fields = parent::getCMSFields(); // Removed unnecessary fields $fields->removeByName("Content"); $fields->removeByName("Metadata"); // Meals Menu $fields->addFieldToTab('Root.Menus', GridField::create( 'MealsMenus', // 'MealsMenus', // $this->MealsMenus(), // GridFieldConfig_RecordEditor::create() // )); // Open Times $fields->addFieldToTab('Root.OpenTimes', GridField::create( 'OpenTimes', // 'OpenTimes', // $this->OpenTimes(), // GridFieldConfig_RecordEditor::create() // )); // Contact $fields->addFieldToTab('Root.Contact', TextField::create('Address')); $fields->addFieldToTab('Root.Contact', TextField::create('Phone')); $fields->addFieldToTab('Root.Contact', TextField::create('Email')); // About if ($this->About()->exists()) { $fields->addFieldsToTab("Root.About", array( ReadonlyField::create("add", "About", $this->About()->toString()) )); } $fields->removeByName("AboutID"); $fields->addFieldToTab("Root.About", HasOneButtonField::create("About", "About", $this) //here! ); // Chefs $fields->addFieldToTab('Root.Chefs', GridField::create( 'Chefs', // 'Chefs', // $this->Chefs(), // GridFieldConfig_RecordEditor::create() // )); // Gallery Items $fields->addFieldToTab('Root.GalleryItems', GridField::create( 'GalleryItems', // 'GalleryItems', // $this->GalleryItems(), // GridFieldConfig_RecordEditor::create() // )); // Carousel Items $fields->addFieldToTab('Root.CarouselItems', GridField::create( 'CarouselItems', // 'CarouselItems', // $this->CarouselItems(), // GridFieldConfig_RecordEditor::create() // )); return $fields; } protected function onBeforeWrite() { parent::onBeforeWrite(); $this->getUserGroup(); } /** * Returns/Creates the librarians group to assign CMS access. * * @return Group Librarians group */ protected function getUserGroup() { $code = $this->config()->group_code; $group = Group::get()->filter('Code', $code)->first(); if (!$group) { $group = new Group(); $group->Title = $this->config()->group_title; $group->Code = $code; $group->write(); $permission = new Permission(); $permission->Code = $this->config()->group_permission; $group->Permissions()->add($permission); } return $group; } } class RestaurantPage_Controller extends Page_Controller { private static $allowed_actions = array( // Reservation Actions 'ReservationForm', 'doReservation', 'ContactForm', 'sendContactMessage', 'foodMenu' ); private static $url_handlers = array( ); public function ReservationForm() { // Create fields $fields = new FieldList( TextField::create('Name'), // TextField::create('Email'), // TextField::create('PhoneNo'), // TextField::create('Date'), // TextField::create('Time'), // TextField::create('People'), // TextareaField::create('Message') // ); // Create action $actions = new FieldList( new FormAction('doReservation') ); // Create Validators $validator = new RequiredFields(); $form = new Form($this, 'ReservationForm', $fields, $actions, $validator); $form->setTemplate('Form_Reservation'); return $form; } public function doReservation($data, $form) { die('submited'); $reservation = new Reservation(); $form->saveInto($reservation); $reservation->write(); return $this->redirectBack(); } public function ContactForm() { // Create fields $fields = new FieldList( TextField::create('Name'), // TextField::create('Email'), // TextField::create('Subject'), // TextareaField::create('Message') ); // Create action $actions = new FieldList( new FormAction('sendContactMessage') ); // Create Validators $validator = new RequiredFields(); $form = new Form($this, 'ContactForm', $fields, $actions, $validator); $form->setTemplate('Form_Contact'); return $form; } public function sendContactMessage($data, $form) { // die('submited'); $message = new ContactMessage(); $form->saveInto($message); $message->write(); return $this->redirectBack(); } public function getMeals() { return Meal::get(); } public function getCarousels() { return CarouselItem::get(); } } |