Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

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


Reply

2 Posts   519 Views

Avatar
Nobrainer Web

4 August 2012 at 2:51am (Last edited: 4 August 2012 10:09am), Community Member, 135 Posts

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

Avatar
Nobrainer Web

6 August 2012 at 9:20pm Community Member, 135 Posts

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