/** * prepare array of notification objects * * @param array|null $access * @param array|null $filtering * @param array|null $ordering * @param int|array|null $limits * @param bool $list * @return array|cbgjNotification */ static public function getNotifications( $access = array(), $filtering = array(), $ordering = array(), $limits = 0, $list = true ) { global $_CB_database; static $cache = array(); if ( ! $access ) { $access = array(); } if ( ! $filtering ) { $filtering = array(); } if ( ! $ordering ) { $ordering = array(); } $id = cbgjClass::getStaticID( $filtering, $ordering ); if ( ( ! isset( $cache[$id] ) ) || cbgjClass::resetCache() ) { $where = array(); $join = array(); if ( $filtering ) { cbgjData::where( $where, $join, $filtering, 'a' ); } $orderBy = array(); if ( $ordering ) { cbgjData::order( $orderBy, $join, $ordering, 'a' ); } $query = 'SELECT a.*' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_notifications' ) . " AS a"; if ( count( $join ) ) { if ( in_array( 'b', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_categories' ) . " AS b" . ' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'item' ) . ' AND a.' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'category' ); } if ( array_intersect( array( 'c', 'd' ), $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_groups' ) . " AS c" . ' ON c.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'item' ) . ' AND a.' . $_CB_database->NameQuote( 'type' ) . ' = ' . $_CB_database->Quote( 'group' ); } if ( in_array( 'd', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__groupjive_users' ) . " AS d" . ' ON d.' . $_CB_database->NameQuote( 'group' ) . ' = c.' . $_CB_database->NameQuote( 'id' ) . ' AND d.' . $_CB_database->NameQuote( 'user_id' ) . ' = a.' . $_CB_database->NameQuote( 'user_id' ); } if ( in_array( 'e', $join ) ) { $query .= "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS e" . ' ON e.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'user_id' ); } } $query .= ( count( $where ) ? "\n WHERE " . implode( "\n AND ", $where ) : null ) . ( count( $orderBy ) ? "\n ORDER BY " . implode( ', ', $orderBy ) : null ); $_CB_database->setQuery( $query ); $cache[$id] = $_CB_database->loadObjectList( 'id', 'cbgjNotification', array( &$_CB_database ) ); } $rows = $cache[$id]; if ( $rows ) { if ( $access ) { cbgjData::access( $rows, $access ); } if ( $limits ) { cbgjData::limit( $rows, $limits ); } } if ( ! $rows ) { $rows = array(); } if ( $list ) { return $rows; } else { $rows = array_shift( $rows ); if ( ! $rows ) { $rows = new cbgjNotification( $_CB_database ); } return $rows; } }