aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggExtender.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-28 19:17:36 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-10-28 19:17:36 +0000
commit7ddd9521b3f3a397da3b0a6b56238d31414eb4be (patch)
tree6eb6a9a51db5fa0f5d3cc2ec6de29b9e258b12a1 /engine/classes/ElggExtender.php
parentbd3484417d170e62bc94e9db81d4ad37e8ddee6a (diff)
downloadelgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.gz
elgg-7ddd9521b3f3a397da3b0a6b56238d31414eb4be.tar.bz2
Standardized code in all of core, not including language files, tests, or core mods.
git-svn-id: http://code.elgg.org/elgg/trunk@7124 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes/ElggExtender.php')
-rw-r--r--engine/classes/ElggExtender.php117
1 files changed, 102 insertions, 15 deletions
diff --git a/engine/classes/ElggExtender.php b/engine/classes/ElggExtender.php
index 577207c06..cfc8fbf68 100644
--- a/engine/classes/ElggExtender.php
+++ b/engine/classes/ElggExtender.php
@@ -11,11 +11,11 @@
* @tip Plugin authors would probably want to extend either ElggAnnotation
* or ElggMetadata instead of this class.
*
- * @package Elgg.Core
+ * @package Elgg.Core
* @subpackage DataModel.Extender
- * @see ElggAnnotation
- * @see ElggMetadata
- * @link http://docs.elgg.org/DataModel/Extenders
+ * @link http://docs.elgg.org/DataModel/Extenders
+ * @see ElggAnnotation
+ * @see ElggMetadata
*/
abstract class ElggExtender implements
Exportable,
@@ -33,24 +33,31 @@ abstract class ElggExtender implements
/**
* Returns an attribute
*
- * @param string $name
+ * @param string $name Name
+ *
* @return mixed
*/
protected function get($name) {
if (isset($this->attributes[$name])) {
// Sanitise value if necessary
- if ($name=='value') {
+ if ($name == 'value') {
switch ($this->attributes['value_type']) {
case 'integer' :
return (int)$this->attributes['value'];
+ break;
//case 'tag' :
//case 'file' :
case 'text' :
return ($this->attributes['value']);
+ break;
default :
- throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $this->attributes['value_type']));
+ $msg = sprintf(elgg_echo('InstallationException:TypeNotSupported'),
+ $this->attributes['value_type']);
+
+ throw new InstallationException($msg);
+ break;
}
}
@@ -62,9 +69,10 @@ abstract class ElggExtender implements
/**
* Set an attribute
*
- * @param string $name
- * @param mixed $value
- * @param string $value_type
+ * @param string $name Name
+ * @param mixed $value Value
+ * @param string $value_type Value type
+ *
* @return boolean
*/
protected function set($name, $value, $value_type = "") {
@@ -106,11 +114,15 @@ abstract class ElggExtender implements
/**
* Save this data to the appropriate database table.
+ *
+ * @return bool
*/
abstract public function save();
/**
* Delete this data.
+ *
+ * @return bool
*/
abstract public function delete();
@@ -118,10 +130,11 @@ abstract class ElggExtender implements
* Returns if a user can edit this extended data.
*
* @param int $user_guid The GUID of the user (defaults to currently logged in user)
+ *
* @return bool
*/
public function canEdit($user_guid = 0) {
- return can_edit_extender($this->id,$this->type,$user_guid);
+ return can_edit_extender($this->id, $this->type, $user_guid);
}
/**
@@ -160,7 +173,8 @@ abstract class ElggExtender implements
public function export() {
$uuid = get_uuid_from_object($this);
- $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
+ $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'],
+ $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
$meta->setAttribute('published', date("r", $this->time_created));
return $meta;
@@ -228,22 +242,57 @@ abstract class ElggExtender implements
*/
private $valid = FALSE;
+ /**
+ * Iterator interface
+ *
+ * @see Iterator::rewind()
+ *
+ * @return void
+ */
function rewind() {
$this->valid = (FALSE !== reset($this->attributes));
}
+ /**
+ * Iterator interface
+ *
+ * @see Iterator::current()
+ *
+ * @return void
+ */
function current() {
return current($this->attributes);
}
+ /**
+ * Iterator interface
+ *
+ * @see Iterator::key()
+ *
+ * @return void
+ */
function key() {
return key($this->attributes);
}
+ /**
+ * Iterator interface
+ *
+ * @see Iterator::next()
+ *
+ * @return void
+ */
function next() {
$this->valid = (FALSE !== next($this->attributes));
}
+ /**
+ * Iterator interface
+ *
+ * @see Iterator::valid()
+ *
+ * @return void
+ */
function valid() {
return $this->valid;
}
@@ -256,25 +305,63 @@ abstract class ElggExtender implements
* This lets an entity's attributes be accessed like an associative array.
* Example: http://www.sitepoint.com/print/php5-standard-library
*/
+
+ /**
+ * Array access interface
+ *
+ * @see ArrayAccess::offsetSet()
+ *
+ * @param mixed $key Name
+ * @param mixed $value Value
+ *
+ * @return void
+ */
function offsetSet($key, $value) {
- if ( array_key_exists($key, $this->attributes) ) {
+ if (array_key_exists($key, $this->attributes)) {
$this->attributes[$key] = $value;
}
}
+ /**
+ * Array access interface
+ *
+ * @see ArrayAccess::offsetGet()
+ *
+ * @param mixed $key Name
+ *
+ * @return void
+ */
function offsetGet($key) {
- if ( array_key_exists($key, $this->attributes) ) {
+ if (array_key_exists($key, $this->attributes)) {
return $this->attributes[$key];
}
}
+ /**
+ * Array access interface
+ *
+ * @see ArrayAccess::offsetUnset()
+ *
+ * @param mixed $key Name
+ *
+ * @return void
+ */
function offsetUnset($key) {
- if ( array_key_exists($key, $this->attributes) ) {
+ if (array_key_exists($key, $this->attributes)) {
// Full unsetting is dangerious for our objects
$this->attributes[$key] = "";
}
}
+ /**
+ * Array access interface
+ *
+ * @see ArrayAccess::offsetExists()
+ *
+ * @param int $offset Offset
+ *
+ * @return int
+ */
function offsetExists($offset) {
return array_key_exists($offset, $this->attributes);
}