aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-06 14:17:47 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-06 14:17:47 +0000
commit674205a2651af6f7e611dc001f6efc349580df55 (patch)
tree30a08037a08c04e2e12b5319f2089269db04e252
parentf933424c18201eb0daa38b1c554228bd7dbfd835 (diff)
downloadelgg-674205a2651af6f7e611dc001f6efc349580df55.tar.gz
elgg-674205a2651af6f7e611dc001f6efc349580df55.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Initial annotations and metadata get/sets functional, combined with site test git-svn-id: https://code.elgg.org/elgg/trunk@98 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/annotations.php1
-rw-r--r--engine/lib/metadata.php1
-rw-r--r--engine/lib/sites.php39
-rw-r--r--index.php27
4 files changed, 51 insertions, 17 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 11473c498..2b398fc61 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -136,7 +136,6 @@
$value = sanitise_string(trim($value));
$owner_id = (int)$owner_id;
- if ($owner_id=0) $owner_id = $_SESSION['id'];
$limit = (int)$limit;
$offset = (int)$offset;
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 19c2e2298..a02ff1ad7 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -234,7 +234,6 @@
$value = sanitise_string(trim($value));
$owner_id = (int)$owner_id;
- if ($owner_id==0) $owner_id = $_SESSION['id'];
$limit = (int)$limit;
$offset = (int)$offset;
diff --git a/engine/lib/sites.php b/engine/lib/sites.php
index 1c011f05c..7182e6060 100644
--- a/engine/lib/sites.php
+++ b/engine/lib/sites.php
@@ -165,7 +165,7 @@
* @param int $limit
* @param int $offset
*/
- function getAnnotations($name, $limit = 50, $offset = 0) { return get_site_annotations($name, $limit, $offset); }
+ function getAnnotations($name, $limit = 50, $offset = 0) { return get_site_annotations($name, $this->id, $limit, $offset); }
/**
* Return the annotations for the site.
@@ -360,8 +360,14 @@
*/
function set_site_metadata($name, $value, $access_id, $site_id, $vartype = "")
{
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
+ $name = sanitise_string($name);
+ $value = sanitise_string($value);
+ $access_id = (int)$access_id;
+ $site_id = (int)$site_id;
+ $vartype = sanitise_string($vartype);
+
+ $id = create_metadata($site_id, 'site', $name, $value, $vartype, $owner_id, $access_id);
+ return $id;
}
/**
@@ -372,8 +378,10 @@
*/
function get_site_metadata($name, $site_id)
{
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
+ $name = sanitise_string($name);
+ $site_id = (int)$site_id;
+
+ return get_metadatas($site_id, 'site');
}
/**
@@ -401,8 +409,16 @@
*/
function add_site_annotation($name, $value, $access_id, $owner_id, $site_id, $vartype)
{
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
+ $name = sanitise_string($name);
+ $value = sanitise_string($value);
+ $access_id = (int)$access_id;
+ $owner_id = (int)$owner_id; if ($owner_id==0) $owner_id = $_SESSION['id'];
+ $site_id = (int)$site_id;
+ $vartype = sanitise_string($vartype);
+
+ $id = create_annotation($site_id, 'site', $name, $value, $vartype, $owner_id, $access_id);
+
+ return $id;
}
/**
@@ -415,8 +431,13 @@
*/
function get_site_annotations($name, $site_id, $limit, $offset)
{
- // TODO : Writeme
- throw new NotImplementedException("Writeme!");
+ $name = sanitise_string($name);
+ $site_id = (int)$site_id;
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ $owner_id = (int)$owner_id; if ($owner_id==0) $owner_id = $_SESSION['id']; // Consider adding the option to change in param?
+
+ return get_annotations($site_id, 'site', $owner_id, "created desc", $limit, $offset);
}
/**
diff --git a/index.php b/index.php
index ae8dc5e51..2ba68800d 100644
--- a/index.php
+++ b/index.php
@@ -30,9 +30,12 @@
// Testing ///////
+ if ($_SESSION['id']==-1) $_SESSION['id'] = 1;
// Create / load a site
$site = get_site(1);
+error_log("GETTIGN SITE " . print_r($site, true));
+
if (!$site)
{
$site = new ElggSite();
@@ -43,31 +46,43 @@
$site->owner_id = 1;
$site->access_id = 0;
- error_log("LOADED NEW SITE: Saving");
+ error_log("LOADED NEW SITE: Saving" . print_r($site,true));
$site->save();
}
else
+ {
$site = new ElggSite($site);
+
+ $site->title = "Test title " . time();
+ $site->save();
+ error_log("UPDATING SITE " . print_r($site, true));
+ }
// annotate site
-
-
+ $site->annotate("Test","TestValue");
+
// add meta data
+ $site->setMetadata("Metaname", "Value");
+
- // get site
- // get site metadata
// change site metadata
+ $site->setMetadata("Metaname", "Value2");
- // get site metadata
+
// get site annotations
+ error_log("SITE Annotations : " . print_r($site->getAnnotations("Test"), true));
+
+
+ // get site metadata
+ error_log("SITE Metadata : " . print_r($site->getMetadata("Metaname"), true));
?> \ No newline at end of file