December 17, 2010 par Facyla
Commentaires (0)
Ce bug ne devrait pas être gênant dans la grande majorité des cas : il n'apparaît que si vous avez besoin de lister les objets d'un owner particulier, mais dont le container est différent (en général on fait le listing de tous les objets et la question ne se pose pas)
Bref, la fonction get_entities ne filtre pas sur l'owner_guid ( (jamais: ce n'est pas dans la clause SQL), mais, lorsqu'il n'y a pas de container précisé, prend la valeur de l'owner_guid spécifiée à la place. Résultat, une liste vide lorsque tous les objets d'un owner sont dans un container dont il n'est pas lui-même owner (sinon on les a quand même, par héritage des droits d'accès).
Fonction de remplacement si vous voulez éviter un patch :
function alternate_get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null, $timelower = 0, $timeupper = 0)
{
global $CONFIG;
if ($subtype === false || $subtype === null || $subtype === 0)
return false;
if ($order_by == "") $order_by = "time_created desc";
$order_by = sanitise_string($order_by);
$limit = (int)$limit;
$offset = (int)$offset;
$site_guid = (int) $site_guid;
$timelower = (int) $timelower;
$timeupper = (int) $timeupper;
if ($site_guid == 0)
$site_guid = $CONFIG->site_guid;
$where = array();
if (is_array($subtype)) {
$tempwhere = "";
if (sizeof($subtype))
foreach($subtype as $typekey => $subtypearray) {
foreach($subtypearray as $subtypeval) {
$typekey = sanitise_string($typekey);
if (!empty($subtypeval)) {
if (!$subtypeval = (int) get_subtype_id($typekey, $subtypeval))
return false;
} else {
// @todo: Setting subtype to 0 when $subtype = '' returns entities with
// no subtype. This is different to the non-array behavior
// but may be required in some cases.
$subtypeval = 0;
}
if (!empty($tempwhere)) $tempwhere .= " or ";
$tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
}
}
if (!empty($tempwhere)) $where[] = "({$tempwhere})";
} else {
$type = sanitise_string($type);
if ($subtype !== "" AND !$subtype = get_subtype_id($type, $subtype))
return false;
if ($type != "")
$where[] = "type='$type'";
if ($subtype!=="")
$where[] = "subtype=$subtype";
}
if ($owner_guid != "") {
if (!is_array($owner_guid)) {
$owner_array = array($owner_guid);
$owner_guid = (int) $owner_guid;
$where[] = "owner_guid = '$owner_guid'";
} else if (sizeof($owner_guid) > 0) {
$owner_array = array_map('sanitise_int', $owner_guid);
// Cast every element to the owner_guid array to int
$owner_guid = array_map("sanitise_int", $owner_guid);
$owner_guid = implode(",",$owner_guid);
$where[] = "owner_guid in ({$owner_guid})";
}
if (is_null($container_guid)) {
$container_guid = $owner_array;
}
}
if ($site_guid > 0)
$where[] = "site_guid = {$site_guid}";
if (!is_null($container_guid)) {
if (is_array($container_guid)) {
foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
$where[] = "container_guid in (" . implode(",",$container_guid) . ")";
} else {
$container_guid = (int) $container_guid;
$where[] = "container_guid = {$container_guid}";
}
}
if ($timelower)
$where[] = "time_created >= {$timelower}";
if ($timeupper)
$where[] = "time_created <= {$timeupper}";
if (!$count) {
$query = "SELECT * from {$CONFIG->dbprefix}entities where ";
} else {
$query = "SELECT count(guid) as total from {$CONFIG->dbprefix}entities where ";
}
foreach ($where as $w)
$query .= " $w and ";
$query .= get_access_sql_suffix(); // Add access controls
if (!$count) {
$query .= " order by $order_by";
if ($limit) $query .= " limit $offset, $limit"; // Add order and limit
$dt = get_data($query, "entity_row_to_elggstar");
return $dt;
} else {
$total = get_data_row($query);
return $total->total;
}
}
April 29, 2009 par Facyla
Commentaires (4)
Pour ajouter les événements de l'agenda dans une partie de l'interface (par exemple le "projecteur" / "spolight", il faut insérer le code suivant à l'emplacement voulu :
<?php if(is_plugin_enabled('event_calendar')) {
$events = event_calendar_get_events_between( mktime(0,0,0,date("m"),date("d"),date("Y")), mktime(0,0,0,date("m") + 1,date("d"),date("Y")), false) ?>
<h2><?php echo elgg_echo("event_calendar:settings:site_calendar:title"); ?></h2>
<?php if ($events && count($events) > 0) { echo elgg_view_entity_list($events, 10, 0, 10, true, false);
} else { echo '<p>'.elgg_echo('event_calendar:no_events_found').'</p>'; } ?>
<?php } ?>