/** * Return a list of events filtered by required attributes * $attributes is an associative array [field] => [value] * $orderAttribute is a parameter for ordering * $orderDirection is either "asc" or "desc" * If all the parameters are empty, the functions returns the complete list of events stored in database * * @global wpdb $wpdb * @param Array $attributes * @param String $orderAttribute * @param String $orderDirection * @return Array */ public static function getEventsByAttributes($attributes = "", $orderAttribute = "", $orderDirection = "asc") { global $wpdb; if ($attributes == "" || count($attributes) == 0) { return EventDatabaseManager::getEventsList($orderAttribute, $orderDirection); } $query = "SELECT eventID, eventType, title_long, title_short, date_time, duration_min, invitation_text, lecturer_name, booked_participants, max_participants, topicID, mandantID, datr_Locations.name as location, event_visible \n FROM datr_Events JOIN datr_Addresses JOIN datr_Locations \n WHERE datr_Addresses.addressID = datr_Events.addressID \n AND datr_Locations.locationID = datr_Addresses.locationID \n AND"; foreach ($attributes as $field => $value) { if (EventDatabaseManager::isEventFieldInteger($field)) { $query .= EventDatabaseManager::addFilter($field, "int", $value); } else { $query .= EventDatabaseManager::addFilter($field, "string", $value); } $query .= " AND"; } $query = substr($query, 0, strlen($query) - 4); if ($orderAttribute != "") { $query .= " ORDER BY {$orderAttribute} {$orderDirection}"; } $res = $wpdb->get_results($query, ARRAY_A); return $res; }