]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added get/list_entities_from_access_collection().
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 29 Jul 2009 21:58:15 +0000 (21:58 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 29 Jul 2009 21:58:15 +0000 (21:58 +0000)
git-svn-id: https://code.elgg.org/elgg/trunk@3416 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/access.php

index c971495828fa2f74a7492f5d55c49fe3a446ab02..7120100bbdceb34408c47f2f7f0db86386214018 100644 (file)
@@ -548,6 +548,92 @@ END;
                        \r
                }\r
                \r
+               /**\r
+                * Get entities with the specified access collection id.\r
+                * \r
+                * @param $collection_id\r
+                * @param $entity_type\r
+                * @param $entity_subtype\r
+                * @param $owner_guid\r
+                * @param $limit\r
+                * @param $offset\r
+                * @param $order_by\r
+                * @param $site_guid\r
+                * @param $count\r
+                * @return unknown_type\r
+                */\r
+               function get_entities_from_access_collection($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {\r
+                       global $CONFIG;\r
+                       \r
+                       if (!$collection_id)\r
+                               return false;\r
+                               \r
+                       $entity_type = sanitise_string($entity_type);\r
+                       $entity_subtype = get_subtype_id($entity_type, $entity_subtype);\r
+                       $limit = (int)$limit;\r
+                       $offset = (int)$offset;\r
+                       if ($order_by == "") \r
+                               $order_by = "e.time_created desc";\r
+                       else\r
+                               $order_by = "e.time_created, {$order_by}";\r
+                       $order_by = sanitise_string($order_by);\r
+                       $site_guid = (int) $site_guid;\r
+                       if ((is_array($owner_guid) && (count($owner_guid)))) {\r
+                               foreach($owner_guid as $key => $guid) {\r
+                                       $owner_guid[$key] = (int) $guid;\r
+                               }\r
+                       } else {\r
+                               $owner_guid = (int) $owner_guid;\r
+                       }\r
+                       if ($site_guid == 0)\r
+                               $site_guid = $CONFIG->site_guid;\r
+                               \r
+                       //$access = get_access_list();\r
+                               \r
+                       $where = array("e.access_id = $collection_id");\r
+                       \r
+                       if ($entity_type!=="")\r
+                               $where[] = "e.type='$entity_type'";\r
+                       if ($entity_subtype)\r
+                               $where[] = "e.subtype=$entity_subtype";\r
+                       if ($site_guid > 0)\r
+                               $where[] = "e.site_guid = {$site_guid}";\r
+                       if (is_array($owner_guid)) {\r
+                               $where[] = "e.container_guid in (".implode(",",$owner_guid).")";\r
+                       } else if ($owner_guid > 0)\r
+                               $where[] = "e.container_guid = {$owner_guid}";\r
+                       \r
+                       if (!$count) {\r
+                               $query = "SELECT distinct e.* "; \r
+                       } else {\r
+                               $query = "SELECT count(distinct e.guid) as total ";\r
+                       }\r
+                               \r
+                       $query .= "from {$CONFIG->dbprefix}entities e where";\r
+                       foreach ($where as $w)\r
+                               $query .= " $w and ";\r
+                       $query .= get_access_sql_suffix("e"); // Add access controls\r
+                       //$query .= ' and ' . get_access_sql_suffix("m"); // Add access controls\r
+                       \r
+                       if (!$count) {\r
+                               $query .= " order by $order_by limit $offset, $limit"; // Add order and limit\r
+                               return get_data($query, "entity_row_to_elggstar");\r
+                       } else {\r
+                               if ($row = get_data_row($query))\r
+                                       return $row->total;\r
+                       }\r
+                       return false;\r
+               }\r
+               \r
+               function list_entities_from_access_collection($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true) {\r
+                       $offset = (int) get_input('offset');\r
+                       $limit = (int) $limit;\r
+                       $count = get_entities_from_access_collection($collection_id, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, true);\r
+                       $entities = get_entities_from_access_collection($collection_id, $entity_type, $entity_subtype, $owner_guid, $limit, $offset, "", 0, false);\r
+                       \r
+                       return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);\r
+               }\r
+               \r
                global $init_finished;\r
                $init_finished = false;\r
                \r