Writing Custom Functions

  • ujCategories_get_audio_genres

    ujCategories_get_audio_genres gets the audio genres from jrAudio datastore and returns them as an array.

    If you are writing a custom function to get your category names and urls it will probably be very similar to this:
    function ujCategories_get_audio_genres() {
        $_search = array(
            'return_keys'    => array('audio_genre','audio_genre_url'),
            'privacy_check'  => false
        );
        $_rt = jrCore_db_search_items('jrAudio', $_search);
        if (isset($_rt['_items']) && is_array($_rt['_items'])) {
        	foreach ($_rt['_items'] as $item) {
        		$_options[$item['audio_genre_url']] = $item['audio_genre'];
        	}
        }
    	return $_options;
    }
  • ujCategories_db_search_items_listener

    The event listener is registered in the ujCategories_init function:
    jrCore_register_event_listener('jrCore', 'db_search_items', 'ujCategories_db_search_items_listener');

    It adds a link to the genre during every audio search, the links are to that category which must be entered as a config setting.
    function ujCategories_db_search_items_listener($_data, $_user, $_conf, $_args, $event)
    {
        if ($_args['module'] == 'jrAudio' && strlen(trim($_conf['ujCategories_link_genres'],', ')) > 1) {
    	$xurl = trim($_conf['ujCategories_link_genres'],', '); // this will be like "categories" or "audio/categories"
    
    	foreach ($_data['_items'] as $k => $item) { // replace the genre with a link to the genre
    
    	$_data['_items'][$k]['audio_genre'] = "<a href='{$_conf['jrCore_base_url']}/{$xurl}/{$item['audio_genre_url']}'>{$item['audio_genre']}</a>";
    	}
        }
        return $_data;
    }

Tags