public this repo is viewable by everyone
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
Started playing with attribute handling.  Both for content specifically 
and as an acts_as plugin for orm'd objects.
Added try/cache handling to save() and delete() in the orm.  Made those 
functions also return a true boolean.
Added Portuguese to the langages list

Signed-off-by: Ted Kulp <ted@cmsmadesimple.org>
tedkulp (author)
about 1 month ago
commit  76a27552eec217235635b66823a973156e333c73
tree    80ae35722af9c9b190bd8af4524058bae5dd54e9
parent  996445f762f191e7b68d0e7cb78026e17f5571cf
...
284
285
286
 
 
287
288
289
...
284
285
286
287
288
289
290
291
0
@@ -284,6 +284,8 @@ $smarty->assign('include_templates', $page_object->add_template($smarty, $curren
0
 //Other fields that aren't easily done with smarty
0
 $smarty->assign('metadata_box', create_textarea(false, $page_object->metadata, 'content[metadata]', 'pagesmalltextarea', 'content_metadata', '', '', '80', '6'));
0
 
0
+$smarty->assign('attribute_defns', cms_orm('CmsAttributeDefinition')->find_all_by_module_and_extra_attr('Core', 'Content'));
0
+
0
 //extra buttons
0
 $ExtraButtons = array(
0
   array(
...
416
417
418
 
 
419
420
421
...
416
417
418
419
420
421
422
423
0
@@ -416,6 +416,8 @@ $smarty->assign('metadata_box', create_textarea(false, $page_object->metadata, '
0
 
0
 $smarty->assign('start_tab', $start_tab);
0
 
0
+$smarty->assign('attribute_defns', cms_orm('CmsAttributeDefinition')->find_all_by_module_and_extra_attr('Core', 'Content'));
0
+
0
 $ExtraButtons = array(
0
   array(
0
     'name' => 'applybutton',
...
117
118
119
 
 
 
 
 
 
120
121
122
...
117
118
119
120
121
122
123
124
125
126
127
128
0
@@ -117,6 +117,12 @@
0
    {if $page_object->field_used('alias')}
0
       {admin_input type='input' label='pagealias' id='content_alias' name='content[alias]' value=$page_object->alias useentities='true'}            
0
    {/if}
0
+  
0
+    {foreach item='defn' from=$attribute_defns}
0
+      {if $defn.attribute_type eq 'textbox'}
0
+        {admin_input type='input' label="`$defn.name`" id="attr_def-`$defn.id`" name="content[property][attr_def-`$defn->id`]" value=$page_object->get_property_value("attr_def-`$defn.id`", $orig_current_language) useentities='true' }
0
+      {/if}
0
+    {/foreach}
0
    <div class="clearb"></div>
0
 
0
   </div> <!-- End advanced -->
...
37
38
39
40
 
41
42
43
...
37
38
39
 
40
41
42
43
0
@@ -37,7 +37,7 @@ while($__shell->input()) {
0
             $__shell->resetCode();
0
         }
0
     } catch(Exception $__shell_exception) {
0
- print $__shell_exception->getMessage();
0
+ print $__shell_exception->getTraceAsString();
0
         
0
         $__shell->resetCode();
0
 
...
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
54
55
...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
0
@@ -50,6 +50,31 @@ CmsInstallOperations::create_table($db, 'admin_recent_pages', "
0
   access_time T
0
 ");
0
 
0
+CmsInstallOperations::create_table($db, 'attribute_defns', "
0
+  id I KEY AUTO,
0
+  module C(100),
0
+  extra_attr C(50),
0
+  name C(50),
0
+  attribute_type C(50),
0
+  optional X,
0
+  user_generated I1 default 1,
0
+  create_date T,
0
+  modified_date T
0
+");
0
+
0
+CmsInstallOperations::create_table($db, 'attributes', "
0
+  id I KEY AUTO,
0
+  attribute_id I,
0
+  object_id I,
0
+  language C(50),
0
+  content XL,
0
+  create_date T,
0
+  modified_date T
0
+");
0
+CmsInstallOperations::create_index($db, 'attributes', 'object_id', 'object_id');
0
+CmsInstallOperations::create_index($db, 'attributes', 'attribute_id', 'attribute_id');
0
+CmsInstallOperations::create_index($db, 'attributes', 'attribute_and_object', 'attribute_id,object_id');
0
+
0
 CmsInstallOperations::create_table($db, 'content', "
0
   id I KEY AUTO,
0
   content_name C(255),
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
0
@@ -0,0 +1,45 @@
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
+#CMS - CMS Made Simple
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
+#This project's homepage is: http://cmsmadesimple.org
0
+#
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
+#
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
+#
0
+#$Id$
0
+
0
+/**
0
+ * Stores and attribute definition for another class to link to. Stores
0
+ * things like the attribute type and optional parameters (items in a dropdown,
0
+ * for instance).
0
+ *
0
+ * @author Ted Kulp
0
+ * @since 2.0
0
+ * @version $Revision$
0
+ * @modifiedby $LastChangedBy$
0
+ * @lastmodified $Date$
0
+ * @license GPL
0
+ **/
0
+class CmsAttribute extends CmsObjectRelationalMapping
0
+{
0
+  var $params = array('id' => -1);
0
+  var $table = 'attributes';
0
+  
0
+  public function __construct()
0
+  {
0
+    parent::__construct();
0
+  }
0
+}
0
+
0
+# vim:ts=4 sw=4 noet
0
+?>
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
0
@@ -0,0 +1,45 @@
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
+#CMS - CMS Made Simple
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
+#This project's homepage is: http://cmsmadesimple.org
0
+#
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
+#
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
+#
0
+#$Id$
0
+
0
+/**
0
+ * Stores and attribute definition for another class to link to. Stores
0
+ * things like the attribute type and optional parameters (items in a dropdown,
0
+ * for instance).
0
+ *
0
+ * @author Ted Kulp
0
+ * @since 2.0
0
+ * @version $Revision$
0
+ * @modifiedby $LastChangedBy$
0
+ * @lastmodified $Date$
0
+ * @license GPL
0
+ **/
0
+class CmsAttributeDefinition extends CmsObjectRelationalMapping
0
+{
0
+  var $params = array('id' => -1);
0
+  var $table = 'attribute_defns';
0
+  
0
+  public function __construct()
0
+  {
0
+    parent::__construct();
0
+  }
0
+}
0
+
0
+# vim:ts=4 sw=4 noet
0
+?>
0
\ No newline at end of file
...
34
35
36
 
 
 
37
38
39
 
40
41
42
...
34
35
36
37
38
39
40
41
42
43
44
45
46
0
@@ -34,9 +34,13 @@ class CmsUser extends CmsObjectRelationalMapping
0
   var $field_maps = array('first_name' => 'firstname', 'last_name' => 'lastname', 'admin_access' => 'adminaccess', 'username' => 'name');
0
   var $table = 'users';
0
   
0
+  var $attr_module = 'Core';
0
+  var $attr_extra = 'User';
0
+  
0
   public function __construct()
0
   {
0
     parent::__construct();
0
+    $this->assign_acts_as('Attributed');
0
   }
0
 
0
   public function validate()
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
0
@@ -0,0 +1,85 @@
0
+<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
0
+#CMS - CMS Made Simple
0
+#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
0
+#This project's homepage is: http://cmsmadesimple.org
0
+#
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
+#
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
+#
0
+#$Id$
0
+
0
+/**
0
+ * Class to easily add attributes to your ORM class.
0
+ * To use this 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
+ *
0
+ * @package default
0
+ * @author Ted Kulp
0
+ **/
0
+class CmsActsAsAttributed extends CmsActsAs
0
+{
0
+  function __construct()
0
+  {
0
+    parent::__construct();
0
+  }
0
+  
0
+  function check_variables_are_set(&$obj)
0
+  {
0
+    if (!isset($obj->attr_module) || !isset($obj->attr_extra))
0
+    {
0
+      die('Must set the $attr_module and $attr_extra variables to use CmsActsAsAttributed');
0
+    }
0
+  }
0
+  
0
+  function get_attribute_defnitions(&$obj)
0
+  {
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
+  }
0
+  
0
+  function get_attribute_by_name(&$obj, $attribute_name)
0
+  {
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
+  }
0
+  
0
+  function get_attribute_value(&$obj, $attribute_name)
0
+  {
0
+    $attribute = $this->get_attribute_by_name($obj, $attribute_name);
0
+
0
+    if ($attribute != null)
0
+      return $attribute->content;
0
+
0
+    return null;
0
+  }
0
+  
0
+  function set_attribute_value(&$obj, $attribute_name, $attribute_value)
0
+  {
0
+    $attribute = $this->get_attribute_by_name($obj, $attribute_name);
0
+
0
+    if ($attribute != null)
0
+    {
0
+      $attribute->content = $attribute_value;
0
+      return $attribute->save();
0
+    }
0
+
0
+    return false;
0
+  }
0
+
0
+}
0
+
0
+# vim:ts=4 sw=4 noet
0
+?>
0
\ No newline at end of file
...
830
831
832
833
 
 
 
 
 
 
 
 
834
835
836
...
898
899
900
901
 
 
 
 
 
 
 
 
902
903
904
...
949
950
951
952
 
953
954
955
...
830
831
832
 
833
834
835
836
837
838
839
840
841
842
843
...
905
906
907
 
908
909
910
911
912
913
914
915
916
917
918
...
963
964
965
 
966
967
968
969
0
@@ -830,7 +830,14 @@ abstract class CmsObjectRelationalMapping extends CmsObject implements ArrayAcce
0
           $queryparams[] = $id;
0
         }
0
       
0
-        $result = $db->Execute($query, $queryparams);
0
+        try
0
+        {
0
+          $result = $db->Execute($query, $queryparams) ? true : false;
0
+        }
0
+        catch (Exception $e)
0
+        {
0
+          $result = false;
0
+        }
0
         
0
         if ($result)
0
         {
0
@@ -898,7 +905,14 @@ abstract class CmsObjectRelationalMapping extends CmsObject implements ArrayAcce
0
         $query .= ')';
0
       }
0
       
0
-      $result = $db->Execute($query, $queryparams);
0
+      try
0
+      {
0
+        $result = $db->Execute($query, $queryparams) ? true : false;
0
+      }
0
+      catch (Exception $e)
0
+      {
0
+        $result = false;
0
+      }
0
       
0
       if ($result)
0
       {
0
@@ -949,7 +963,7 @@ abstract class CmsObjectRelationalMapping extends CmsObject implements ArrayAcce
0
       $new_map = array_flip($this->field_maps); //Flip the keys, since this is the reverse operation
0
       if (array_key_exists($id_field, $new_map)) $id_field = $new_map[$id_field];
0
 
0
-      $result = cms_db()->Execute("DELETE FROM {$table} WHERE ".$this->get_table($id_field)." = {$id}");
0
+      $result = cms_db()->Execute("DELETE FROM {$table} WHERE ".$this->get_table($id_field)." = {$id}") ? true : false;
0
     
0
       if ($result)
0
         $this->after_delete_caller();
...
290
291
292
293
294
 
 
295
296
297
298
299
300
 
 
 
 
 
 
 
 
 
301
302
303
...
290
291
292
 
 
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
0
@@ -290,14 +290,23 @@
0
   </language>
0
   <language>
0
     <code>pt_BR</code>
0
-    <native_name>Português do Brasil</native_name>
0
-    <english_name>Brazilian Portuguese</english_name>
0
+    <native_name>Português Brasileiro</native_name>
0
+    <english_name>Portuguese [Brazilian]</english_name>
0
     <aliases>
0
       <alias>pt-BR</alias>
0
     </aliases>
0
     <flag_image>pt_BR.png</flag_image>
0
   </language>
0
   <language>
0
+    <code>pt_PT</code>
0
+    <native_name>Português</native_name>
0
+    <english_name>Portuguese</english_name>
0
+    <aliases>
0
+      <alias>pt-PT</alias>
0
+    </aliases>
0
+    <flag_image>pt_PT.png</flag_image>
0
+  </language>
0
+  <language>
0
     <code>ru_RU</code>
0
     <native_name>Русский</native_name>
0
     <english_name>Russian</english_name>

Comments

    No one has commented yet.