From 9f891280a7422c3d4539ef6acd68206045cda66d Mon Sep 17 00:00:00 2001 From: Alex Barth <alex_b@53995.no-reply.drupal.org> Date: Wed, 8 Sep 2010 20:14:36 +0000 Subject: [PATCH] Allow FeedsTermElement to be casted simply to a taxonomy term array. --- plugins/FeedsParser.inc | 51 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index a32c1a49..4128cbf5 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -129,24 +129,63 @@ class FeedsElement { if (is_object($this->value)) { return 'Object'; } - return (string) $this->value; + return (string) $this->getValue(); } } /** * Encapsulates a taxonomy style term object. + * + * Objects of this class can be turned into a taxonomy term style arrays by + * casting them. + * + * @code + * $term_object = new FeedsTermElement($term_array); + * $term_array = (array)$term_object; + * @endcode */ class FeedsTermElement extends FeedsElement { - public $tid, $vid; + public $tid, $vid, $name; + + /** + * @param $term + * An array or a stdClass object that is a Drupal taxonomy term. + */ + public function __construct($term) { + if (is_array($term)) { + parent::__construct($term['name']); + foreach ($this as $key => $value) { + $this->$key = isset($term[$key]) ? $term[$key] : NULL; + } + } + elseif (is_object($term)) { + parent::__construct($term->name); + foreach ($this as $key => $value) { + $this->$key = isset($term->$key) ? $term->$key : NULL; + } + } + } + + /** + * Use $name as $value. + */ + public function getValue() { + return $this->name; + } +} +/** + * A geo term element. + */ +class FeedsGeoTermElement extends FeedsTermElement { + public $lat, $lon, $bound_top, $bound_right, $bound_bottom, $bound_left, $geometry; /** * @param $term - * A stdClass object that is a Drupal taxonomy term. + * An array or a stdClass object that is a Drupal taxonomy term. Can include + * geo extensions. */ public function __construct($term) { - parent::__construct($term->name); - $this->tid = $term->tid; - $this->vid = $term->vid; + parent::__construct($term); } } -- GitLab