Stud.IP  5.4
 All Data Structures Namespaces Files Functions Variables Groups
AdminCourseFilter Class Reference

Public Member Functions

 __construct ($reset_settings=false)
 
 storeSettings ()
 
 restoreSettings ()
 
 resetSettings ()
 
 initSettings ()
 
 filterBySemester ($semester_id)
 
 filterByType ($type)
 
 filterByInstitute ($institut_ids)
 
 filterByStgTeil ($stgteil_ids)
 
 filterByDozent ($user_ids)
 
 filterBySearchstring ($text)
 
 orderBy ($attribute, $flag= 'ASC')
 
 where ($where, $parameter=[], $id=null)
 
 getCourses ($grouped=true)
 
 countCourses ()
 
 getCoursesForAdminWidget (string $order_by= 'name')
 
 createQuery ($only_count=false)
 

Static Public Member Functions

static get ($reset_settings=false)
 

Data Fields

 $max_show_courses = 500
 
 $settings = []
 

Static Protected Attributes

static $instance = null
 

Detailed Description

Class AdminCourseFilter

The main class to filter all courses for admins. It's a singleton class, so you better call it with AdminCourseFilter::get(). The whole class is created to provide a nice hook for plugins to add special filters into the admin-area of Stud.IP.

To add a filter with a plugin, listen to the notification "AdminCourseFilterWillQuery" like this:

NotificationCenter::addObserver($this, "addMyFilter", "AdminCourseFilterWillQuery");

Where $this is an object and "addMyFilter" a method. Such a method might look like this:

public function addLectureshipFilter($event, $filter)
{
    if ($GLOBALS['user']->cfg->getValue("LECTURESHIP_FILTER")) {
        $filter->settings['query']['joins']['lehrauftrag'] = array(
            'join' => "INNER JOIN",
            'on' => "seminare.Seminar_id = lehrauftrag.seminar_id"
        );
    }
}

Within this method you alter the public $filter->settings array, because this array describes entirely the big query for the admin-search. In our example above we simple add an INNER JOIN to filter for the course having an entry in the lehrauftrag table.

Description of this array is as follows:

$filter->settings['query'] : The main sql query as a prepared statement. $filter->settings['query']['select'] : An assoc array. $filter->settings['query']['select']['Number_of_teachers'] = "COUNT(DISTINCT dozenten.user_id)" will select the result of COUNT as the variable Number_of_teachers. $filter->settings['query']['joins'] : Example $filter->settings['query']['joins']['dozenten'] = array( 'join' => "INNER JOIN", //default value, else use "LEFT JOIN" 'table' => "seminar_user", //can me omitted if you don't want to use a table-alias 'on' => "dozenten.Seminar_id = seminare.Seminar_id AND dozenten.status = 'dozent'" ) if 'table' differs from the index, the index will be the alias of the table. So normally you don't need to name a table if you don't want it to be aliased. $filter->settings['query']['where'] : You might want to use the method $filter->where($sql, $parameter) instead. $filter->settings['query']['orderby'] : You might want to use $filter->orderBy($attribute, $flag = "ASC") instead. $filter->settings['parameter'] : An assoc array of parameter that will be passed to the prepared statement.

Constructor & Destructor Documentation

__construct (   $reset_settings = false)

Constructor of the singleton-object. The settings might come from the session if $reset_settings is false.

Parameters
bool$reset_settings: should the session settings of the singleton be reset?

Member Function Documentation

countCourses ( )
Returns
integer number of courses that this filter would return
createQuery (   $only_count = false)

Creates the sql-query from the $this->settings['query']

Parameters
boolean$only_count: boolean
Returns
string the big query
filterByDozent (   $user_ids)
Parameters
array | string$user_ids
Returns
AdminCourseFilter
filterByInstitute (   $institut_ids)

Adds a filter for an institut_id or many institut_ids if the parameter is an array.

Parameters
array | integer$institut_ids: id or ids of institutes
Returns
AdminCourseFilter
filterBySearchstring (   $text)

Adds a filter for a textstring, that can be the coursenumber, the name of the course or the last name of one of the dozenten.

Parameters
string$textthe searchstring
Returns
AdminCourseFilter
filterBySemester (   $semester_id)

Adds a filter for all courses of the given semester.

Parameters
string$semester_id: ID of the given semester.
Returns
AdminCourseFilter
Exceptions
Exceptionif semester_id does not exist
filterByStgTeil (   $stgteil_ids)

Adds a filter for an stgteil_id or many stgteil_ids if the parameter is an array.

Parameters
array | integer$stgteil_ids: id or ids of stgteile
Returns
AdminCourseFilter
filterByType (   $type)

Adds a filter for a sem_type or many sem_types if the parameter is an array.

Parameters
array | integer$type: id or ids of sem_types
Returns
AdminCourseFilter
static get (   $reset_settings = false)
static

returns an AdminCourseFilter singleton object

Returns
AdminCourseFilter or derived-class object
getCourses (   $grouped = true)

Returns the data of the resultset of the AdminCourseFilter. Also saves the settings in the session. Note that a notification AdminCourseFilterWillQuery will be posted, before the result is computed. Plugins may register at this event to fully alter this AdminCourseFilter-object and so the resultset.

Returns
array associative array with seminar_ids as keys and seminar-data-arrays as values.
getCoursesForAdminWidget ( string  $order_by = 'name')

Returns the data of the resultset of the AdminCourseFilter.

Parameters
string$order_bypossible values name or number

Note that a notification AdminCourseFilterWillQuery will be posted, before the result is computed. Plugins may register at this event to fully alter this AdminCourseFilter-object and so the resultset.

Returns
array associative array with seminar_ids as keys and seminar-data-arrays as values.
initSettings ( )

initialize settings

orderBy (   $attribute,
  $flag = 'ASC' 
)
Parameters
string$attribute: column, name of the column, yb whcih we should order the results
string$flag: "ASC" or "DESC for ascending order or descending order,
Returns
AdminCourseFilter
Exceptions
Exceptionif $flag does not exist
resetSettings ( )

reset settings

restoreSettings ( )

restore settings from session

storeSettings ( )

store settings in session

where (   $where,
  $parameter = [],
  $id = null 
)

Adds a where filter.

Parameters
string$whereany where condition like "sem_classes.overview = 'CoreOverview'"
array$parameteran array of parameter that appear in the $where query.
null | string$idan id of the where-query. Use this to possibly avoid double where conditions or allow deleting the condition by plugins if necessary. Can be omitted.
Returns
AdminCourseFilter

Field Documentation

$instance = null
staticprotected
$max_show_courses = 500
$settings = []

The documentation for this class was generated from the following file: