Example #1
0
<?php

$owner = elgg_extract('owner', $vars, elgg_get_logged_in_user_entity());
$limit = elgg_extract('limit', $vars, false);
if (!$owner instanceof ElggUser) {
    return;
}
$type_subtypes = quicklinks_get_supported_types();
if (!is_array($type_subtypes)) {
    $type_subtypes = [];
}
// add quicklinks subtype
if (!isset($type_subtypes['object'])) {
    $type_subtypes['object'] = [];
}
if (!in_array(QuickLink::SUBTYPE, $type_subtypes['object'])) {
    $type_subtypes['object'][] = QuickLink::SUBTYPE;
}
// loop though to prevent groups/users from being found because of a bug in Elgg
foreach ($type_subtypes as $type => $subtypes) {
    if (empty($subtypes)) {
        $type_subtypes[$type] = false;
    }
}
$options = ['type_subtype_pairs' => $type_subtypes, 'limit' => false, 'relationship' => QUICKLINKS_RELATIONSHIP, 'relationship_guid' => $owner->getGUID(), 'order_by' => 'r.time_created DESC'];
// @todo fix default time_created by adding an extra field in the select because of relationship created instead of time_created of related entity
elgg_push_context('quicklinks');
$configured_priorities = $owner->getPrivateSetting('quicklinks_order');
if ($configured_priorities) {
    $configured_priorities = json_decode($configured_priorities);
}
Example #2
0
/**
 * Check if a type/subtype can be added to quicklinks
 *
 * @param string $type    the type of the entity
 * @param string $subtype the subtype of the entity
 *
 * @see is_registered_entity_type()
 *
 * @return bool
 */
function quicklinks_can_link($type, $subtype = null)
{
    $supported_types = quicklinks_get_supported_types();
    if (empty($supported_types) || !is_array($supported_types)) {
        return false;
    }
    // is type registered
    $type = strtolower($type);
    if (!isset($supported_types[$type])) {
        return false;
    }
    // check (optional) subtype
    if (!empty($subtype) && !in_array($subtype, $supported_types[$type])) {
        return false;
    }
    return true;
}