0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
+#This project's homepage is: http://cmsmadesimple.org
0
+#This program is free software; you can redistribute it and/or modify
0
+#it under the terms of the GNU General Public License as published by
0
+#the Free Software Foundation; either version 2 of the License, or
0
+#(at your option) any later version.
0
+#This program is distributed in the hope that it will be useful,
0
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
0
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0
+#GNU General Public License for more details.
0
+#You should have received a copy of the GNU General Public License
0
+#along with this program; if not, write to the Free Software
0
+#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0
+ * Class to easily add attributes to your ORM class.
0
+ * 1. Create variables named $attr_module and $attr_extra in your class.
0
+ * 2. Set them to the name of your module and an optional "namespace"
0
+ * (ex. $attr_module = 'MyModule'; $attr_extra = 'Widget';)
0
+class CmsActsAsAttributed extends CmsActsAs
0
+ function __construct()
0
+ parent::__construct();
0
+ function check_variables_are_set(&$obj)
0
+ if (!isset($obj->attr_module) || !isset($obj->attr_extra))
0
+ die('Must set the $attr_module and $attr_extra variables to use CmsActsAsAttributed');
0
+ function get_attribute_defnitions(&$obj)
0
+ $this->check_variables_are_set($obj);
0
+ return cms_orm('CmsAttributeDefinition')->find_all_by_module_and_extra_attr($obj->attr_module, $obj->attr_extra);
0
+ function get_attribute_by_name(&$obj, $attribute_name)
0
+ $this->check_variables_are_set($obj);
0
+ $prefix = CMS_DB_PREFIX;
0
+ return cms_orm('CmsAttribute')->find(array('joins' => "INNER JOIN {$prefix}attribute_defns ON {$prefix}attribute_defns.id = {$prefix}attributes.attribute_id", 'conditions' => array("{$prefix}attribute_defns.module = ? AND {$prefix}attribute_defns.extra_attr = ? AND {$prefix}attribute_defns.name = ? AND {$prefix}attributes.object_id = ?", $obj->attr_module, $obj->attr_extra, $attribute_name, $obj->id)));
0
+ function get_attribute_value(&$obj, $attribute_name)
0
+ $attribute = $this->get_attribute_by_name($obj, $attribute_name);
0
+ if ($attribute != null)
0
+ return $attribute->content;
0
+ function set_attribute_value(&$obj, $attribute_name, $attribute_value)
0
+ $attribute = $this->get_attribute_by_name($obj, $attribute_name);
0
+ if ($attribute != null)
0
+ $attribute->content = $attribute_value;
0
+ return $attribute->save();
0
\ No newline at end of file
Comments
No one has commented yet.