Попытка заставить поиск модуля сбора серебряных полос работать с dataoject

Я создал форму публикации списка классов, чтобы участники могли публиковать свои списки классов на странице внешнего интерфейса, она работает, как и ожидалось, но в данный момент я пытаюсь заставить поля поиска отображать фильтруемую коллекцию страниц. или dataobjects на той же странице, поля поиска есть на странице, но когда я пытаюсь отправить поиск, он ничего не делает, все, что я вижу, URL, кажется, меняется, например: ".../learners/ класс-объявление /?CourseTitle=NZSL+ Уровень +2& Сортировка =Northland&action_%2Flearners%2Fclass-объявление%2F=L"

Для этого я использую модуль сбора Silverstripe: https://github.com/dynamic/silverstripe-collection

Может ли кто-нибудь указать мне правильное направление? или покажи мне, что я сделал неправильно или какие коды мне нужно внести изменения, чтобы поиск работал.

Вот мои коды ниже, я использую SilverStripe 4.2.1.

app.yml:

ClassListingPageController:
   managed_object: ClassListings
   page_size: 20
   extensions:
      - Dynamic\Collection\CollectionExtension

ClassListingPageController.php:

class ClassListingPageController extends PageController {
    private static $allowed_actions = [
        'ClassListingForm',
                'ClassFilterForm',
                'remove',
                'CourseTitle',
                'CourseLocation',
    ];

    public function ClassListingForm() {

                $form = Form::create(
            $this,
          __FUNCTION__,
          FieldList::create(
                            TextField::create('CourseTitle', 'Course title:')
                                ->setAttribute('placeholder', 'NZSL Level 1')
                                ->setCustomValidationMessage('Please enter the course title field')
                ->addExtraClass('requiredField'),
                            DropdownField::create( 'CourseTitleList', 'Or select one from this list:', array(
                  'NZSL Level 1 (beginners)' => 'NZSL Level 1 (beginners)',
                    'NZSL Level 2 (intermediate)' => 'NZSL Level 2 (intermediate)',
                      'NZSL Level 3 (advanced)' => 'NZSL Level 3 (advanced)',
                      'Deaf Culture' => 'Deaf Culture'
                ))->setEmptyString('Select title'),
                                DropdownField::create( 'CourseSubTitleList', 'Select sub category from this list:', array(
                                    'NZSL 1A' => 'NZSL 1A',
                                    'NZSL 1B' => 'NZSL 1B',
                                    'NZSL 1C' => 'NZSL 1C',
                                    'NZSL 1D' => 'NZSL 1D',
                                    'NZSL 2A' => 'NZSL 2A',
                                    'NZSL 2B' => 'NZSL 2B',
                                    'NZSL 2C' => 'NZSL 2C',
                                    'NZSL 2D' => 'NZSL 2D',
                                    'Beginners 1' => 'Beginners 1',
                                    'Beginners 12' => 'Beginners 2',
                                    'Intermediate 1' => 'Intermediate 1',
                                    'Intermediate 2' => 'Intermediate 2',
                                    'Advanced 1' => 'Advanced 1',
                                    'Advanced 2' => 'Advanced 2'
                                ))->setEmptyString('Select title'),
                            GroupedDropdownField::create('CourseLocation','Region', array(
                                    "North" => array(
                                            "Northland" => "Northland",
                                            "North Shore" => "North Shore",
                                            "West Auckland" => "West Auckland",
                                            "Auckland" => "Auckland",
                                            "South Auckland" => "South Auckland",
                                            "Waikato" => "Waikato",
                                            "Rotorua" => "Rotorua",
                                            "Bay of Plenty" => "Bay of Plenty",
                                            "Gisborne" => "Gisborne",
                                            "Taupo" => "Taupo"
                                    ),
                                    "Central" => array(
                                            "Taranaki" => "Taranaki",
                                            "Whanganui-Manawatu" => "Whanganui-Manawatu",
                                            "Hawke's Bay" => "Hawke's Bay",
                                            "Wairarapa" => "Wairarapa",
                                            "Wellington" => "Wellington"
                                    ),
                                    "South" => array(
                                            "Nelson-Tasman" => "Nelson-Tasman",
                                            "West Coast" => "West Coast",
                                            "Christchurch" => "Christchurch",
                                            "Mid-South Canterbury" => "Mid-South Canterbury",
                                            "Otago" => "Otago",
                                            "Southland" => "Southland"
                                    ),
                                    "National" => "National"
                                ))->setEmptyString('Select region')
                                ->setCustomValidationMessage('Please select the region field')
                ->addExtraClass('requiredField'),
                        DateField::create('CourseStartDate', 'Start date:')
                    ->setAttribute('placeholder', 'dd/MM/yyyy'),
                            DateField::create('CourseEndDate', 'End date:')
                    ->setAttribute('placeholder', 'dd/MM/yyyy'),
                            TimeField::create('CourseStartTime', 'Start time:'),
                            TimeField::create('CourseEndTime', 'End time:'),
                    NumericField::create('CourseNumberSessions', 'How many sessions:'),
                            CurrencyField::create('CourseCost', 'Cost:'),
                            DropdownField::create('CourseTuition', 'Type of tuition:', array(
                  'Class' => 'Class',
                  'Online' => 'Online',
                                'Private tutoring' => 'Private tutoring',
                                'Customised' => 'Customised'
                ))->setEmptyString('Select tuition')
                                ->setCustomValidationMessage('Please select the type of tuition field')
                ->addExtraClass('requiredField'),
                    TextField::create('CourseTutorFirstName', 'Tutor\'s first name:')
                                    ->setAttribute('value', Member::CurrentUser()->FirstName)
                                ->setCustomValidationMessage('Please enter the tutor first name field')
                                ->addExtraClass('requiredField'),
                    TextField::create('CourseTutorLastName', 'Tutor\'s last name:')
                                    ->setAttribute('value', Member::CurrentUser()->Surname)
                                ->setCustomValidationMessage('Please enter the tutor last name field')
                                ->addExtraClass('requiredField'),
                                ReadonlyField::create('NzsltaCategory', 'NZSLTA registration category:')
                                    ->setReadonly(true),
                    TextareaField::create('CourseOverview', 'Course overview:'),
                    TextField::create('CourseCoordinatorName', 'Coordinator\'s full name:'),
                    EmailField::create('CourseCoordinatorEmail', 'Coordinator\'s email:'),
                    NumericField::create('CourseCoordinatorPhone', 'Coordinator\'s phone number:'),
                            TextField::create('CourseVenue', 'Course venue:')
                                ->setAttribute('placeholder', 'Victoria University of Wellington'),
                            TextField::create('CourseAddress', 'Address:'),
                    TextField::create('CourseWebsite', 'Course website:')
                                ->setAttribute('placeholder', 'full url http://www...'),
                            LiteralField::create('recaptcha_bubble', '<div class="g-recaptcha" data-sitekey="6LfVXywUAAAAAJSAx-G6xwjfT47JQxR2Qrel54mC"  data-theme="light" data-type="image" data-size="normal" data-form="Form_RegisterForm" data-badge="bottomright"></div>')
          ),
          FieldList::create(
              FormAction::create('handleClassListing')
                                ->setTitle('Post your listing')
                  ->setUseButtonTag(true)
          ),
          RequiredFields::create(
              'CourseTitle',
              'CourseLocation',
              'CourseTuition',
              'CourseTutorFirstName',
              'CourseTutorLastName'
          )

      );

      $form->getSecurityToken()->getValue();

                if ($form->hasExtension('FormSpamProtectionExtension')) {
            $form->enableSpamProtection();
        }

                $data = $this->getRequest()->getSession()->get("FormData.{$form->getName()}.data");
                return $data ? $form->loadDataFrom($data) : $form;
        }

        public function handleClassListing($data, $form) {

                $session = $this->getRequest()->getSession();
                $session->set("FormData.{$form->getName()}.data", $data);
            $class = ClassListings::create();

                $class->CourseTitle = $data['CourseTitle'];
                $class->CourseSubTitleList = $data['CourseSubTitleList'];
          $class->CourseLocation = $data['CourseLocation'];
          $class->CourseStartDate = $data['CourseStartDate'];
          $class->CourseEndDate = $data['CourseEndDate'];
          $class->CourseStartTime = $data['CourseStartTime'];
          $class->CourseEndTime = $data['CourseEndTime'];
          $class->CourseNumberSessions = $data['CourseNumberSessions'];
          $class->CourseCost = $data['CourseCost'];
          $class->CourseTuition = $data['CourseTuition'];
          $class->CourseOverview = $data['CourseOverview'];
          $class->CourseTutorFirstName = $data['CourseTutorFirstName'];
          $class->CourseTutorLastName = $data['CourseTutorLastName'];
          $class->CourseCoordinatorName = $data['CourseCoordinatorName'];
          $class->CourseCoordinatorEmail = $data['CourseCoordinatorEmail'];
          $class->CourseCoordinatorPhone = $data['CourseCoordinatorPhone'];
          $class->CourseVenue = $data['CourseVenue'];
          $class->CourseAddress = $data['CourseAddress'];
          $class->CourseWebsite = $data['CourseWebsite'];

            $class->ClassListingPageID = $this->ID;
                $form->saveInto($class);
            $class->write();

                $session->clear("FormData.{$form->getName()}.data");
                $form->sessionMessage('Your class listing has been posted!','good');
                $session = $this->getRequest()->getSession();

            return $this->redirectBack();
        }

        public function remove() {
            $ClassListingPageID = $this->request->param('ID');
            if ($ClassListingPageID && $class = ClassListings::get()->byID($ClassListingPageID)) {
                $class->delete();
            }

            return array();
        }
}

ClassListingPage.php:

class ClassListingPage extends Page {

        private static $description = 'Generic content of the class listing page for learners';

        private static $table_name = 'ClassListingPage';

        private static $icon = "images/page.png";

        private static $has_many = [
        'Classlisting' => ClassListings::class,
    ];

}

ClassListings.php:

class ClassListings extends DataObject {

private static $db = [
    'CourseTitle' => 'Varchar(255)',
    'CourseTitleList' => 'Varchar(255)',
    'CourseSubTitleList' => 'Varchar(255)',
    'CourseLocation' => 'Varchar(255)',
    'CourseStartDate' => 'Date',
    'CourseEndDate' => 'Date',
    'CourseStartTime' => 'Time',
    'CourseEndTime' => 'Time',
    'CourseNumberSessions' => 'Int(2)',
    'CourseCost' => 'Currency',
    'CourseTuition' => 'Varchar(255)',
    'CourseTutorFirstName' => 'Varchar(255)',
    'CourseTutorLastName' => 'Varchar(255)',
    'CourseOverview' => 'Text',
    'CourseCoordinatorName' => 'Varchar(255)',
    'CourseCoordinatorEmail' => 'Varchar(255)',
    'CourseCoordinatorPhone' => 'Int(11)',
    'CourseVenue' => 'Varchar(255)',
    'CourseAddress' => 'Varchar(255)',
    'CourseWebsite' => 'Varchar(255)'
];

private static $has_one = [
    'ClassListingPage' => ClassListingPage::class,
];

private static $searchable_fields = [
    'CourseTitle',
];

public function getSortOptions(){
    return array(
        "Northland" => "Northland",
        "North Shore" => "North Shore",
        "West Auckland" => "West Auckland",
        "Auckland" => "Auckland",
        "South Auckland" => "South Auckland",
        "Waikato" => "Waikato",
        "Rotorua" => "Rotorua",
        "Bay of Plenty" => "Bay of Plenty",
        "Gisborne" => "Gisborne",
        "Taupo" => "Taupo",
        "Taranaki" => "Taranaki",
        "Whanganui-Manawatu" => "Whanganui-Manawatu",
        "Hawke's Bay" => "Hawke's Bay",
        "Wairarapa" => "Wairarapa",
        "Wellington" => "Wellington",
        "Nelson-Tasman" => "Nelson-Tasman",
        "West Coast" => "West Coast",
        "Christchurch" => "Christchurch",
        "Mid-South Canterbury" => "Mid-South Canterbury",
        "Otago" => "Otago",
        "Southland" => "Southland",
        "National" => "National",
    );
}

public function updateCollectionForm(&$form){
        $sortOptions->setEmptyString('Select region');
        $CourseTitle->setAttribute('placeholder', 'i.e. NZSL Level 1');
}

}

ClassListingPage.ss:

<div class="searchDrawings">
    $CollectionSearchForm
</div>

<div class="content">
    <p>There are $ClassListing.Count class listings available:</p>
    <% loop $ClassListing %>
      $Collection
        <% if CourseTutorFirstName %>
        <a href="{$Top.Link}remove/{$ID}">Remove class listing</a>
        <% else %>
        <% end_if %>
      $PaginatedList
    <% end_loop %>
    <% if CurrentMember %>
      <hr>
      <h2>Add your class listing here:</h2>
      $ClassListingForm
    <% else %>
    <% end_if %>
  </div>

0 ответов

Другие вопросы по тегам