aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-19 11:30:31 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-19 11:30:31 +0000
commit8a6223ae8a2a3fd32cdef0becb8a8f0eeba684b2 (patch)
tree06f0396220c168fb4c193d543154098f83a518f7 /engine
parent062bc6a5d2b2f9e43a2dab7a3e55905f35f77c3e (diff)
downloadelgg-8a6223ae8a2a3fd32cdef0becb8a8f0eeba684b2.tar.gz
elgg-8a6223ae8a2a3fd32cdef0becb8a8f0eeba684b2.tar.bz2
Introducing archive functionality.
git-svn-id: https://code.elgg.org/elgg/trunk@2803 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/entities.php90
-rw-r--r--engine/lib/users.php12
2 files changed, 97 insertions, 5 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index ebb176feb..002c91358 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1496,9 +1496,11 @@
* @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
* @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
* @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
* @return array A list of entities.
*/
- function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null)
+ function 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;
@@ -1510,6 +1512,8 @@
$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;
@@ -1572,6 +1576,10 @@
$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 ";
@@ -1636,6 +1644,86 @@
}
/**
+ * Returns a list of months containing content specified by the parameters
+ *
+ * @param string $type The type of entity
+ * @param string $subtype The subtype of entity
+ * @param int $container_guid The container GUID that the entinties belong to
+ * @param int $site_guid The site GUID
+ * @return array|false Either an array of timestamps, or false on failure
+ */
+ function get_entity_dates($type = '', $subtype = '', $container_guid = 0, $site_guid = 0) {
+
+ global $CONFIG;
+
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+
+ $where = array();
+
+ if ($type != "") {
+ $type = sanitise_string($type);
+ $where[] = "type='$type'";
+ }
+
+ if (is_array($subtype)) {
+ $tempwhere = "";
+ if (sizeof($subtype))
+ foreach($subtype as $typekey => $subtypearray) {
+ foreach($subtypearray as $subtypeval) {
+ $typekey = sanitise_string($typekey);
+ if (!empty($subtypeval)) {
+ $subtypeval = (int) get_subtype_id($typekey, $subtypeval);
+ } else {
+ $subtypeval = 0;
+ }
+ if (!empty($tempwhere)) $tempwhere .= " or ";
+ $tempwhere .= "(type = '{$typekey}' and subtype = {$subtypeval})";
+ }
+ }
+ if (!empty($tempwhere)) $where[] = "({$tempwhere})";
+
+ } else {
+
+ $subtype = get_subtype_id($type, $subtype);
+
+ if ($subtype!=="")
+ $where[] = "subtype=$subtype";
+
+ }
+
+ if ($container_guid !== 0) {
+ 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 ($site_guid > 0)
+ $where[] = "site_guid = {$site_guid}";
+
+ $where[] = get_access_sql_suffix();
+
+ $sql = "SELECT DISTINCT EXTRACT(YEAR_MONTH FROM FROM_UNIXTIME(time_created)) AS yearmonth FROM {$CONFIG->dbprefix}entities where ";
+ foreach ($where as $w)
+ $sql .= " $w and ";
+ $sql .= "1=1";
+ if ($result = get_data($sql)) {
+ $endresult = array();
+ foreach($result as $res) {
+ $endresult[] = $res->yearmonth;
+ }
+ return $endresult;
+ }
+ return false;
+
+ }
+
+ /**
* Disable an entity but not delete it.
*
* @param int $guid The guid
diff --git a/engine/lib/users.php b/engine/lib/users.php
index f16f5c0f6..f859f9681 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -607,10 +607,12 @@
* @param string $subtype Optionally, the subtype of objects
* @param int $limit The number of results to return (default 10)
* @param int $offset Indexing offset, if any
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
* @return false|array An array of ElggObjects or false, depending on success
*/
- function get_user_objects($user_guid, $subtype = "", $limit = 10, $offset = 0) {
- $ntt = get_entities('object',$subtype, $user_guid, "time_created desc", $limit, $offset,false,0,$user_guid);
+ function get_user_objects($user_guid, $subtype = "", $limit = 10, $offset = 0, $timelower = 0, $timeupper = 0) {
+ $ntt = get_entities('object',$subtype, $user_guid, "time_created desc", $limit, $offset,false,0,$user_guid,$timelower, $timeupper);
return $ntt;
}
@@ -635,14 +637,16 @@
* @param string $subtype The object subtype
* @param int $limit The number of entities to display on a page
* @param true|false $fullview Whether or not to display the full view (default: true)
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
* @return string The list in a form suitable to display
*/
- function list_user_objects($user_guid, $subtype = "", $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true) {
+ function list_user_objects($user_guid, $subtype = "", $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) {
$offset = (int) get_input('offset');
$limit = (int) $limit;
$count = (int) count_user_objects($user_guid, $subtype);
- $entities = get_user_objects($user_guid, $subtype, $limit, $offset);
+ $entities = get_user_objects($user_guid, $subtype, $limit, $offset, $timelower, $timeupper);
return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);