Created
March 28, 2013 15:32
-
-
Save Cyberschorsch/5264112 to your computer and use it in GitHub Desktop.
The get argument function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function controls what to return to the contextual filter. | |
*/ | |
function get_argument() { | |
// Get available flag types from the system. | |
$flags = flag_get_flags('taxonomy_term'); | |
// Get all User flags. | |
$user_flags = flag_get_user_flags('taxonomy_term'); | |
// This array will collect all Term IDs which will be filtered. | |
$tids = array(); | |
// Get the vocab foreach flag. | |
foreach ($flags as $flagname => $flag) { | |
// We only proceed with this flag, if it has been selected and the current | |
// user has flagged terms with that flag. | |
if (!empty($this->options['flags'][$flagname]) && !empty($user_flags[$flagname])) { | |
// Get all tids from the user flags. | |
$user_tids = array_keys($user_flags[$flagname]); | |
$vocabs = array(); | |
// Check which vocabularies are valid for this handler. | |
foreach ($flag->types as $vocab) { | |
if (!empty($this->options['vocabularies'][$vocab])) { | |
$vocabs[] = $vocab; | |
} | |
} | |
// We add the valid terms of the flag set to our default argument list. | |
$valid_tids = _views_flag_context_filter_tids_on_vocabularies($user_tids, $vocabs); | |
$tids = array_merge($tids, $valid_tids); | |
} | |
} | |
// If no tids are valid, we can fallback to a given value. | |
if (empty($tids)) { | |
// Fall back to the exception value (by default this is 'all') | |
return $this->options['fallback']; | |
} | |
// If there are term ids available we return them by concating the terms | |
// with the multiple operator (AND or OR). | |
else { | |
return implode($this->options['multiple_operator'], $tids); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment