Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » 2.4 - Adding ParentID filter to a custom search - Please help!

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

Page: 1
Go to End
Author Topic: 509 Views
  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    2.4 - Adding ParentID filter to a custom search - Please help! Link to this post

    Hi guys,

    I'm stuck i think it's quite simple, yet i have spend most of my day trying to figure it out.

    I have different CourseHolders, that each have several child pages of the type CoursePage.
    The CourseHolder lists CoursePages that are children of it self, with the following function (pagination is used)

    UPDATE: The code below works - problem is making the CustomSearchCOntext work with the ParentID filter.

       public function getGroupCoursesList() {
          if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
           $SQL_start = (int)$_GET['start'];
          
             $CoursesList = DataObject::get(
                $callerClass = "Course",
                $filter = "ParentID = '". $this->ID . "' AND StartDate > CURDATE()",
                $sort = "StartDate ASC",
                $join = "",
                $limit = "{$SQL_start},10"
             );

          return $CoursesList;
       }

    I have a custom search on the CourseHolder pages, that should allow the user to filter the list by, city and a date.
    The problem is i can not make the custom search context filter the results to only contain children of the current page, it returns all my Courses across all CourseHolder pages.

    I have tried adding hidden fields to the form, modifying the query: $query->where('"ParentID" = 11'); editing the $searchCriteria and everything else i could think of, but no luck - PLEASE HELP!

    Code that generates the form (in the controller of CourseHolder.php): http://www.sspaste.com/paste/show/501be687b44ad
    Complete code of the CoursePage.php: http://www.sspaste.com/paste/show/501be8ecad0b1

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: 2.4 - Adding ParentID filter to a custom search - Please help! Link to this post

    I worked around this problem by modifying the working function, to include the filter for City and Time.

    509 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.