[Solar-svn] Revision 2837
pmjones at solarphp.com
pmjones at solarphp.com
Sat Oct 6 11:26:49 CDT 2007
Solar_Model: complete and total rewrite to replace the previous Solar_Model series *and* the previous Solar_Content series.
Copied: trunk/Solar/Model (from rev 2801, branches/orm/Solar/Model)
Copied: trunk/Solar/Model/Areas (from rev 2801, branches/orm/Solar/Model/Areas)
Deleted: trunk/Solar/Model/Areas/Collection.php
===================================================================
--- branches/orm/Solar/Model/Areas/Collection.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Areas/Collection.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,2 +0,0 @@
-<?php
-class Solar_Model_Areas_Collection extends Solar_Model_Collection {}
\ No newline at end of file
Copied: trunk/Solar/Model/Areas/Collection.php (from rev 2801, branches/orm/Solar/Model/Areas/Collection.php)
===================================================================
--- trunk/Solar/Model/Areas/Collection.php (rev 0)
+++ trunk/Solar/Model/Areas/Collection.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,2 @@
+<?php
+class Solar_Model_Areas_Collection extends Solar_Model_Collection {}
\ No newline at end of file
Deleted: trunk/Solar/Model/Areas/Record.php
===================================================================
--- branches/orm/Solar/Model/Areas/Record.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Areas/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,2 +0,0 @@
-<?php
-class Solar_Model_Areas_Record extends Solar_Model_Record {}
\ No newline at end of file
Copied: trunk/Solar/Model/Areas/Record.php (from rev 2801, branches/orm/Solar/Model/Areas/Record.php)
===================================================================
--- trunk/Solar/Model/Areas/Record.php (rev 0)
+++ trunk/Solar/Model/Areas/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,2 @@
+<?php
+class Solar_Model_Areas_Record extends Solar_Model_Record {}
\ No newline at end of file
Deleted: trunk/Solar/Model/Areas.php
===================================================================
--- branches/orm/Solar/Model/Areas.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Areas.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,60 +0,0 @@
-<?php
-class Solar_Model_Areas extends Solar_Model {
- protected function _setup()
- {
- /**
- * Table name, columns, and indexes.
- */
- $this->_table_name = 'areas';
-
- $this->_table_cols = array(
- 'id' => array(
- 'type' => 'int',
- 'require' => true,
- 'primary' => true,
- 'autoinc' => true,
- ),
- 'created' => 'timestamp',
- 'updated' => 'timestamp',
- 'name' => array(
- 'type' => 'varchar',
- 'size' => 127,
- 'require' => true,
- ),
- 'owner_handle' => array(
- 'type' => 'varchar',
- 'size' => 32,
- ),
- 'subj' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'summ' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'prefs' => 'clob',
- );
-
- $this->_index = array(
- 'created',
- 'updated',
- 'name' => 'unique',
- 'owner_handle',
- );
-
- /**
- * Behaviors (serialize, sequence, filter).
- */
- $this->_serialize_cols[] = 'prefs';
-
- /**
- * Relationships.
- */
- $this->_hasMany('nodes', array(
- 'foreign_class' => 'nodes',
- 'foreign_key' => 'parent_id',
- ));
-
- }
-}
Copied: trunk/Solar/Model/Areas.php (from rev 2801, branches/orm/Solar/Model/Areas.php)
===================================================================
--- trunk/Solar/Model/Areas.php (rev 0)
+++ trunk/Solar/Model/Areas.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,60 @@
+<?php
+class Solar_Model_Areas extends Solar_Model {
+ protected function _setup()
+ {
+ /**
+ * Table name, columns, and indexes.
+ */
+ $this->_table_name = 'areas';
+
+ $this->_table_cols = array(
+ 'id' => array(
+ 'type' => 'int',
+ 'require' => true,
+ 'primary' => true,
+ 'autoinc' => true,
+ ),
+ 'created' => 'timestamp',
+ 'updated' => 'timestamp',
+ 'name' => array(
+ 'type' => 'varchar',
+ 'size' => 127,
+ 'require' => true,
+ ),
+ 'owner_handle' => array(
+ 'type' => 'varchar',
+ 'size' => 32,
+ ),
+ 'subj' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'summ' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'prefs' => 'clob',
+ );
+
+ $this->_index = array(
+ 'created',
+ 'updated',
+ 'name' => 'unique',
+ 'owner_handle',
+ );
+
+ /**
+ * Behaviors (serialize, sequence, filter).
+ */
+ $this->_serialize_cols[] = 'prefs';
+
+ /**
+ * Relationships.
+ */
+ $this->_hasMany('nodes', array(
+ 'foreign_class' => 'nodes',
+ 'foreign_key' => 'parent_id',
+ ));
+
+ }
+}
Deleted: trunk/Solar/Model/Collection.php
===================================================================
--- branches/orm/Solar/Model/Collection.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Collection.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,2 +0,0 @@
-<?php
-class Solar_Model_Collection extends Solar_Sql_Model_Collection {}
\ No newline at end of file
Copied: trunk/Solar/Model/Collection.php (from rev 2801, branches/orm/Solar/Model/Collection.php)
===================================================================
--- trunk/Solar/Model/Collection.php (rev 0)
+++ trunk/Solar/Model/Collection.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,2 @@
+<?php
+class Solar_Model_Collection extends Solar_Sql_Model_Collection {}
\ No newline at end of file
Copied: trunk/Solar/Model/Locale (from rev 2801, branches/orm/Solar/Model/Locale)
Copied: trunk/Solar/Model/Nodes (from rev 2801, branches/orm/Solar/Model/Nodes)
Deleted: trunk/Solar/Model/Nodes/Blogs.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Blogs.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Blogs.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,21 +0,0 @@
-<?php
-class Solar_Model_Nodes_Blogs extends Solar_Model_Nodes {
- protected function _setup()
- {
- parent::_setup();
-
- /**
- * Relationships.
- */
-
- $this->_belongsTo('area', array(
- 'foreign_class' => 'areas',
- 'foreign_key' => 'area_id',
- ));
-
- $this->_hasMany('comments', array(
- 'foreign_class' => 'comments',
- 'foreign_key' => 'parent_id',
- ));
- }
-}
Copied: trunk/Solar/Model/Nodes/Blogs.php (from rev 2801, branches/orm/Solar/Model/Nodes/Blogs.php)
===================================================================
--- trunk/Solar/Model/Nodes/Blogs.php (rev 0)
+++ trunk/Solar/Model/Nodes/Blogs.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,21 @@
+<?php
+class Solar_Model_Nodes_Blogs extends Solar_Model_Nodes {
+ protected function _setup()
+ {
+ parent::_setup();
+
+ /**
+ * Relationships.
+ */
+
+ $this->_belongsTo('area', array(
+ 'foreign_class' => 'areas',
+ 'foreign_key' => 'area_id',
+ ));
+
+ $this->_hasMany('comments', array(
+ 'foreign_class' => 'comments',
+ 'foreign_key' => 'parent_id',
+ ));
+ }
+}
Copied: trunk/Solar/Model/Nodes/Bookmarks (from rev 2801, branches/orm/Solar/Model/Nodes/Bookmarks)
Copied: trunk/Solar/Model/Nodes/Bookmarks/Locale (from rev 2801, branches/orm/Solar/Model/Nodes/Bookmarks/Locale)
Deleted: trunk/Solar/Model/Nodes/Bookmarks/Locale/en_US.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Bookmarks/Locale/en_US.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Bookmarks/Locale/en_US.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,8 +0,0 @@
-<?php
-return array(
- 'LABEL_URI' => 'Location',
- 'LABEL_SUBJ' => 'Title',
- 'LABEL_SUMM' => 'Description',
- 'LABEL_POS' => 'Rank',
- 'LABEL_TAGS_AS_STRING' => 'Tags',
-);
\ No newline at end of file
Copied: trunk/Solar/Model/Nodes/Bookmarks/Locale/en_US.php (from rev 2801, branches/orm/Solar/Model/Nodes/Bookmarks/Locale/en_US.php)
===================================================================
--- trunk/Solar/Model/Nodes/Bookmarks/Locale/en_US.php (rev 0)
+++ trunk/Solar/Model/Nodes/Bookmarks/Locale/en_US.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,8 @@
+<?php
+return array(
+ 'LABEL_URI' => 'Location',
+ 'LABEL_SUBJ' => 'Title',
+ 'LABEL_SUMM' => 'Description',
+ 'LABEL_POS' => 'Rank',
+ 'LABEL_TAGS_AS_STRING' => 'Tags',
+);
\ No newline at end of file
Deleted: trunk/Solar/Model/Nodes/Bookmarks/Record.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Bookmarks/Record.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Bookmarks/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,39 +0,0 @@
-<?php
-class Solar_Model_Nodes_Bookmarks_Record extends Solar_Model_Nodes_Record {
- public function form($cols = null)
- {
- // force the columns to be shown in the form
- $cols = array(
- 'uri' => array(
- 'attribs' => array(
- 'size' => 48,
- ),
- ),
- 'subj' => array(
- 'attribs' => array(
- 'size' => 48,
- ),
- ),
- 'summ' => array(
- 'type' => 'textarea',
- 'attribs' => array(
- 'rows' => 6,
- 'cols' => 48,
- ),
- ),
- 'tags_as_string' => array(
- 'type' => 'text',
- 'attribs' => array(
- 'size' => 48,
- ),
- ),
- 'pos' => array(
- 'attribs' => array(
- 'size' => 3,
- ),
- ),
- );
-
- return parent::form($cols);
- }
-}
\ No newline at end of file
Copied: trunk/Solar/Model/Nodes/Bookmarks/Record.php (from rev 2801, branches/orm/Solar/Model/Nodes/Bookmarks/Record.php)
===================================================================
--- trunk/Solar/Model/Nodes/Bookmarks/Record.php (rev 0)
+++ trunk/Solar/Model/Nodes/Bookmarks/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,39 @@
+<?php
+class Solar_Model_Nodes_Bookmarks_Record extends Solar_Model_Nodes_Record {
+ public function form($cols = null)
+ {
+ // force the columns to be shown in the form
+ $cols = array(
+ 'uri' => array(
+ 'attribs' => array(
+ 'size' => 48,
+ ),
+ ),
+ 'subj' => array(
+ 'attribs' => array(
+ 'size' => 48,
+ ),
+ ),
+ 'summ' => array(
+ 'type' => 'textarea',
+ 'attribs' => array(
+ 'rows' => 6,
+ 'cols' => 48,
+ ),
+ ),
+ 'tags_as_string' => array(
+ 'type' => 'text',
+ 'attribs' => array(
+ 'size' => 48,
+ ),
+ ),
+ 'pos' => array(
+ 'attribs' => array(
+ 'size' => 3,
+ ),
+ ),
+ );
+
+ return parent::form($cols);
+ }
+}
\ No newline at end of file
Deleted: trunk/Solar/Model/Nodes/Bookmarks.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Bookmarks.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Bookmarks.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,9 +0,0 @@
-<?php
-class Solar_Model_Nodes_Bookmarks extends Solar_Model_Nodes {
- protected function _setup()
- {
- parent::_setup();
- $this->_addFilter('uri', 'validateNotBlank');
- $this->_addFilter('tags_as_string', 'validateNotBlank');
- }
-}
Copied: trunk/Solar/Model/Nodes/Bookmarks.php (from rev 2801, branches/orm/Solar/Model/Nodes/Bookmarks.php)
===================================================================
--- trunk/Solar/Model/Nodes/Bookmarks.php (rev 0)
+++ trunk/Solar/Model/Nodes/Bookmarks.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,9 @@
+<?php
+class Solar_Model_Nodes_Bookmarks extends Solar_Model_Nodes {
+ protected function _setup()
+ {
+ parent::_setup();
+ $this->_addFilter('uri', 'validateNotBlank');
+ $this->_addFilter('tags_as_string', 'validateNotBlank');
+ }
+}
Deleted: trunk/Solar/Model/Nodes/Comments.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Comments.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Comments.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,14 +0,0 @@
-<?php
-class Solar_Model_Nodes_Comments extends Solar_Model_Nodes {
- protected function _setup()
- {
- parent::_setup();
- $this->_belongsTo('node', array(
- 'foreign_class' => 'nodes',
- 'foreign_key' => 'parent_id', // normally node_id
- ));
-
- $this->_fetch_cols = array('id', 'created', 'updated', 'subj', 'body',
- 'inherit', 'area_id', 'parent_id', 'moniker', 'email', 'uri', );
- }
-}
Copied: trunk/Solar/Model/Nodes/Comments.php (from rev 2801, branches/orm/Solar/Model/Nodes/Comments.php)
===================================================================
--- trunk/Solar/Model/Nodes/Comments.php (rev 0)
+++ trunk/Solar/Model/Nodes/Comments.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,14 @@
+<?php
+class Solar_Model_Nodes_Comments extends Solar_Model_Nodes {
+ protected function _setup()
+ {
+ parent::_setup();
+ $this->_belongsTo('node', array(
+ 'foreign_class' => 'nodes',
+ 'foreign_key' => 'parent_id', // normally node_id
+ ));
+
+ $this->_fetch_cols = array('id', 'created', 'updated', 'subj', 'body',
+ 'inherit', 'area_id', 'parent_id', 'moniker', 'email', 'uri', );
+ }
+}
Deleted: trunk/Solar/Model/Nodes/Record.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Record.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,130 +0,0 @@
-<?php
-class Solar_Model_Nodes_Record extends Solar_Model_Record {
-
- public function __getTagsAsString()
- {
- // if exactly null, populate for the first time.
- if ($this->_data['tags_as_string'] === null) {
- $text = '';
- foreach ($this->tags as $tag) {
- $text .= "{$tag->name} ";
- }
- $this->_data['tags_as_string'] = rtrim($text);
- }
-
- return $this->_data['tags_as_string'];
- }
-
- public function __setTagsAsString($val)
- {
- $val = preg_replace('/[ ]{2,}/', ' ', $val);
- $this->_data['tags_as_string'] = trim($val);
- $new = explode(' ', $this->_data['tags_as_string']);
- $new = array_unique($new);
-
- // build a new tag collection
- $model = $this->tags->getModel();
- $coll = $model->newCollection();
- foreach ($new as $name) {
- $record = $model->fetchNew();
- $record->name = $name;
- $coll[] = $record;
- }
-
- // reset the tags collection
- $this->tags = $coll;
- }
-
- // work with related values before they get saved.
- // relateds: areas, nodes, taggings, tags
- public function _postSave()
- {
- // -------------------------------------------------------------
- //
- // make sure that each tag actually exists; insert a new tag
- // record for each new one.
- //
-
- // hold on to the tags model
- $tags_model = $this->tags->getModel();
-
- // get the list of tags on the record
- $tag_names = $this->tags->getNames();
- if ($tag_names) {
- // make sure each tag actually exists as a record. tag names
- // that do not exist will not be in this array.
- $params = array(
- 'where' => array(
- 'tags.name IN (?)' => $tag_names,
- ),
- );
- $existing_tags = $tags_model->fetchAll($params);
- } else {
- $existing_tags = $tags_model->newCollection(null);
- }
-
- // loop through the tags
- foreach ($this->tags as $key => $tag) {
-
- // does this tag already exist?
- foreach ($existing_tags as $existing) {
- if ($tag->name == $existing->name) {
- // replace with the existing tag record.
- // this lets us "connect" user-entered tag names
- // with existing records. capture both the tag from
- // the loop and reset the collection value.
- $tag = $existing;
- $this->tags[$key] = $existing;
- break;
- }
- }
-
- // if status is still 'new' then save it
- if ($tag->getStatus() == 'new') {
- $tag->save();
- }
-
- // look for a tagging on this tag
- $found = false;
- foreach ($this->taggings as $tagging) {
- // must match node ID and tag ID
- $match = $tagging->node_id == $this->id &&
- $tagging->tag_id == $tag->id;
- if ($match) {
- $found = true;
- break;
- }
- }
-
- // did we find a tagging for the tag?
- if (! $found) {
- // no, create one ...
- $tagging = $this->taggings->getModel()->fetchNew();
- $tagging->node_id = $this->id;
- $tagging->tag_id = $tag->id;
-
- // ... and add to the collection
- $this->taggings[] = $tagging;
- }
- }
-
- // remove taggings that don't exist any more
- foreach ($this->taggings as $key => $tagging) {
- $found = false;
- foreach ($this->tags as $tag) {
- $match = $tagging->node_id == $this->id &&
- $tagging->tag_id == $tag->id;
- if ($match) {
- $found = true;
- break;
- }
- }
-
- // does the tagging match a tag?
- if (! $found) {
- // no, remove from the taggings
- $tagging->delete();
- }
- }
- }
-}
\ No newline at end of file
Copied: trunk/Solar/Model/Nodes/Record.php (from rev 2801, branches/orm/Solar/Model/Nodes/Record.php)
===================================================================
--- trunk/Solar/Model/Nodes/Record.php (rev 0)
+++ trunk/Solar/Model/Nodes/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,130 @@
+<?php
+class Solar_Model_Nodes_Record extends Solar_Model_Record {
+
+ public function __getTagsAsString()
+ {
+ // if exactly null, populate for the first time.
+ if ($this->_data['tags_as_string'] === null) {
+ $text = '';
+ foreach ($this->tags as $tag) {
+ $text .= "{$tag->name} ";
+ }
+ $this->_data['tags_as_string'] = rtrim($text);
+ }
+
+ return $this->_data['tags_as_string'];
+ }
+
+ public function __setTagsAsString($val)
+ {
+ $val = preg_replace('/[ ]{2,}/', ' ', $val);
+ $this->_data['tags_as_string'] = trim($val);
+ $new = explode(' ', $this->_data['tags_as_string']);
+ $new = array_unique($new);
+
+ // build a new tag collection
+ $model = $this->tags->getModel();
+ $coll = $model->newCollection();
+ foreach ($new as $name) {
+ $record = $model->fetchNew();
+ $record->name = $name;
+ $coll[] = $record;
+ }
+
+ // reset the tags collection
+ $this->tags = $coll;
+ }
+
+ // work with related values before they get saved.
+ // relateds: areas, nodes, taggings, tags
+ public function _postSave()
+ {
+ // -------------------------------------------------------------
+ //
+ // make sure that each tag actually exists; insert a new tag
+ // record for each new one.
+ //
+
+ // hold on to the tags model
+ $tags_model = $this->tags->getModel();
+
+ // get the list of tags on the record
+ $tag_names = $this->tags->getNames();
+ if ($tag_names) {
+ // make sure each tag actually exists as a record. tag names
+ // that do not exist will not be in this array.
+ $params = array(
+ 'where' => array(
+ 'tags.name IN (?)' => $tag_names,
+ ),
+ );
+ $existing_tags = $tags_model->fetchAll($params);
+ } else {
+ $existing_tags = $tags_model->newCollection(null);
+ }
+
+ // loop through the tags
+ foreach ($this->tags as $key => $tag) {
+
+ // does this tag already exist?
+ foreach ($existing_tags as $existing) {
+ if ($tag->name == $existing->name) {
+ // replace with the existing tag record.
+ // this lets us "connect" user-entered tag names
+ // with existing records. capture both the tag from
+ // the loop and reset the collection value.
+ $tag = $existing;
+ $this->tags[$key] = $existing;
+ break;
+ }
+ }
+
+ // if status is still 'new' then save it
+ if ($tag->getStatus() == 'new') {
+ $tag->save();
+ }
+
+ // look for a tagging on this tag
+ $found = false;
+ foreach ($this->taggings as $tagging) {
+ // must match node ID and tag ID
+ $match = $tagging->node_id == $this->id &&
+ $tagging->tag_id == $tag->id;
+ if ($match) {
+ $found = true;
+ break;
+ }
+ }
+
+ // did we find a tagging for the tag?
+ if (! $found) {
+ // no, create one ...
+ $tagging = $this->taggings->getModel()->fetchNew();
+ $tagging->node_id = $this->id;
+ $tagging->tag_id = $tag->id;
+
+ // ... and add to the collection
+ $this->taggings[] = $tagging;
+ }
+ }
+
+ // remove taggings that don't exist any more
+ foreach ($this->taggings as $key => $tagging) {
+ $found = false;
+ foreach ($this->tags as $tag) {
+ $match = $tagging->node_id == $this->id &&
+ $tagging->tag_id == $tag->id;
+ if ($match) {
+ $found = true;
+ break;
+ }
+ }
+
+ // does the tagging match a tag?
+ if (! $found) {
+ // no, remove from the taggings
+ $tagging->delete();
+ }
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Solar/Model/Nodes/Revisions (from rev 2801, branches/orm/Solar/Model/Nodes/Revisions)
Deleted: trunk/Solar/Model/Nodes/Revisions/Record.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Revisions/Record.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Revisions/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,8 +0,0 @@
-<?php
-class Solar_Model_Nodes_Revisions_Record extends Solar_Sql_Model_Record {
- protected function __getId()
- {
- echo "I am the ID!";
- return $this->_data['id'];
- }
-}
Copied: trunk/Solar/Model/Nodes/Revisions/Record.php (from rev 2801, branches/orm/Solar/Model/Nodes/Revisions/Record.php)
===================================================================
--- trunk/Solar/Model/Nodes/Revisions/Record.php (rev 0)
+++ trunk/Solar/Model/Nodes/Revisions/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,8 @@
+<?php
+class Solar_Model_Nodes_Revisions_Record extends Solar_Sql_Model_Record {
+ protected function __getId()
+ {
+ echo "I am the ID!";
+ return $this->_data['id'];
+ }
+}
Deleted: trunk/Solar/Model/Nodes/Revisions.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Revisions.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Revisions.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,16 +0,0 @@
-<?php
-
-class Solar_Model_Nodes_Revisions extends Solar_Model_Nodes {
- protected function _setup()
- {
- parent::_setup();
-
- /**
- * Relationships.
- */
- $this->_belongsTo('node', array(
- 'foreign_class' => 'node',
- 'foreign_key' => 'parent_id',
- ));
- }
-}
Copied: trunk/Solar/Model/Nodes/Revisions.php (from rev 2801, branches/orm/Solar/Model/Nodes/Revisions.php)
===================================================================
--- trunk/Solar/Model/Nodes/Revisions.php (rev 0)
+++ trunk/Solar/Model/Nodes/Revisions.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,16 @@
+<?php
+
+class Solar_Model_Nodes_Revisions extends Solar_Model_Nodes {
+ protected function _setup()
+ {
+ parent::_setup();
+
+ /**
+ * Relationships.
+ */
+ $this->_belongsTo('node', array(
+ 'foreign_class' => 'node',
+ 'foreign_key' => 'parent_id',
+ ));
+ }
+}
Deleted: trunk/Solar/Model/Nodes/Trackbacks.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Trackbacks.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Trackbacks.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,14 +0,0 @@
-<?php
-class Solar_Model_Nodes_Trackbacks extends Solar_Model_Nodes {
- protected function _setup()
- {
- parent::_setup();
- $this->_belongsTo('node', array(
- 'foreign_class' => 'nodes',
- 'foreign_key' => 'parent_id', // normally node_id
- ));
-
- $this->_fetch_cols = array('id', 'created', 'updated', 'subj', 'body',
- 'inherit', 'area_id', 'parent_id', 'moniker', 'email', 'uri', );
- }
-}
Copied: trunk/Solar/Model/Nodes/Trackbacks.php (from rev 2801, branches/orm/Solar/Model/Nodes/Trackbacks.php)
===================================================================
--- trunk/Solar/Model/Nodes/Trackbacks.php (rev 0)
+++ trunk/Solar/Model/Nodes/Trackbacks.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,14 @@
+<?php
+class Solar_Model_Nodes_Trackbacks extends Solar_Model_Nodes {
+ protected function _setup()
+ {
+ parent::_setup();
+ $this->_belongsTo('node', array(
+ 'foreign_class' => 'nodes',
+ 'foreign_key' => 'parent_id', // normally node_id
+ ));
+
+ $this->_fetch_cols = array('id', 'created', 'updated', 'subj', 'body',
+ 'inherit', 'area_id', 'parent_id', 'moniker', 'email', 'uri', );
+ }
+}
Deleted: trunk/Solar/Model/Nodes/Wikis.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Wikis.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes/Wikis.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,21 +0,0 @@
-<?php
-class Solar_Model_Nodes_Wikis extends Solar_Model_Nodes {
- protected function _setup()
- {
- parent::_setup();
-
- /**
- * Relationships.
- */
- $this->_hasMany('revisions', array(
- 'foreign_class' => 'revision',
- 'foreign_key' => 'parent_id',
- 'order' => 'id DESC',
- ));
-
- $this->_hasMany('comments', array(
- 'foreign_class' => 'comment',
- 'foreign_key' => 'parent_id',
- ));
- }
-}
Copied: trunk/Solar/Model/Nodes/Wikis.php (from rev 2801, branches/orm/Solar/Model/Nodes/Wikis.php)
===================================================================
--- trunk/Solar/Model/Nodes/Wikis.php (rev 0)
+++ trunk/Solar/Model/Nodes/Wikis.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,21 @@
+<?php
+class Solar_Model_Nodes_Wikis extends Solar_Model_Nodes {
+ protected function _setup()
+ {
+ parent::_setup();
+
+ /**
+ * Relationships.
+ */
+ $this->_hasMany('revisions', array(
+ 'foreign_class' => 'revision',
+ 'foreign_key' => 'parent_id',
+ 'order' => 'id DESC',
+ ));
+
+ $this->_hasMany('comments', array(
+ 'foreign_class' => 'comment',
+ 'foreign_key' => 'parent_id',
+ ));
+ }
+}
Deleted: trunk/Solar/Model/Nodes.php
===================================================================
--- branches/orm/Solar/Model/Nodes.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Nodes.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,251 +0,0 @@
-<?php
-class Solar_Model_Nodes extends Solar_Model {
- protected function _setup()
- {
- /**
- * Table name, columns, and indexes.
- */
-
- $this->_table_name = 'nodes';
-
- $this->_table_cols = array(
- 'id' => array(
- 'type' => 'int',
- 'require' => true,
- 'primary' => true,
- 'autoinc' => true,
- ),
- 'created' => 'timestamp',
- 'updated' => 'timestamp',
- 'area_id' => array(
- 'type' => 'int',
- 'require' => true,
- ),
- 'inherit' => array(
- 'type' => 'varchar',
- 'size' => 32,
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'size' => 127,
- ),
- 'parent_id' => 'int',
- 'owner_handle' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'editor_handle' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'editor_ipaddr' => array(
- 'type' => 'varchar',
- 'size' => 15,
- ),
- 'assign_handle' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'locale' => array(
- 'type' => 'varchar',
- 'size' => 5,
- ),
- 'rating' => 'int',
- 'email' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'uri' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'moniker' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'pos' => 'int',
- 'status' => array(
- 'type' => 'varchar',
- 'size' => 32,
- ),
- 'mime' => array(
- 'type' => 'varchar',
- 'size' => 64,
- 'default' => 'text/plain',
- ),
- 'subj' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- 'summ' => 'clob',
- 'body' => 'clob',
- 'prefs' => 'clob',
- );
-
- $this->_index = array(
- 'created',
- 'updated',
- 'area_id',
- 'name',
- 'parent_id',
- 'owner_handle',
- 'assign_handle',
- 'inherit',
- 'locale',
- 'pos',
- 'rating',
- 'uri',
- 'email',
- 'status',
- );
-
- /**
- * Special columns
- */
- $this->_serialize_cols[] = 'prefs';
- $this->_calculate_cols[] = 'tags_as_string';
-
- /**
- * Filters
- */
-
- // make sure the name is unique for its area and model
- $where = array(
- 'inherit = :inherit',
- 'area_id = :area_id',
- );
- $this->_addFilter('name', 'validateUnique', $where);
-
- // other filters
- $this->_addFilter('email', 'validateEmail');
- $this->_addFilter('uri', 'validateUri');
- $this->_addFilter('editor_ipaddr', 'validateIpv4');
- $this->_addFilter('locale', 'validateLocaleCode');
- $this->_addFilter('mime', 'validateMimeType');
- $this->_addFilter('tags_as_string', 'validateSepWords');
-
- /**
- * Relationships.
- */
- $this->_belongsTo('area', array(
- 'foreign_class' => 'areas',
- 'foreign_key' => 'area_id',
- 'eager' => false,
- ));
-
- $this->_hasMany('taggings', array(
- 'foreign_class' => 'taggings',
- 'foreign_key' => 'node_id',
- ));
-
- $this->_hasMany('tags', array(
- 'foreign_class' => 'tags',
- 'through' => 'taggings',
- 'through_key' => 'tag_id',
- ));
- }
-
- public function fetchAllByTags($tag_list, $params = null)
- {
- // no tags? fetch all to pre-empt errors related to "IN()" not
- // having a list to work with.
- $tag_list = $this->_fixTagList($tag_list);
- if (! $tag_list) {
- return $this->fetchAll($params);
- }
-
- // fetch
- $select = $this->_newSelectByTags($tag_list, $params);
- return $this->_fetchAll($select, $params);
- }
-
- protected function _fixTagList($tag_list)
- {
- // convert to array
- if (! is_array($tag_list)) {
- $tag_list = preg_split('/\s+/', trim((string) $tag_list));
- }
-
- // no duplicates allowed
- $tag_list = array_unique($tag_list);
-
- // if the string tag-list is empty, the preg-split leaves one empty
- // element in the array.
- if ($tag_list[0] == '') {
- $tag_list = array();
- }
-
- // done!
- return $tag_list;
- }
-
- protected function _newSelectByTags($tag_list, $params)
- {
- // setup
- $params = $this->fixSelectParams($params);
- $select = $this->newSelect($params['eager']);
-
- // catalog entries for joining
- $taggings = $this->_related['taggings'];
- $tags = $this->_related['tags'];
-
- // primary key on the nodes table as an alias; e.g., "nodes.id"
- $native_primary = "{$this->_model_name}.{$this->_primary_col}";
-
- // http://forge.mysql.com/wiki/TagSchema
- // build the select differently from other fetchAll() statements
- $select->distinct($params['distinct'])
- ->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
- // join taggings on nodes
- ->join(
- "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
- "{$taggings->foreign_alias}.node_id = $native_primary"
- )
- // join tags on taggings
- ->join(
- "{$tags->foreign_table} AS {$tags->foreign_alias}",
- "{$tags->foreign_alias}.id = {$taggings->foreign_alias}.tag_id"
- )
- // select for the listed tags
- ->where("{$tags->foreign_alias}.name IN (?)", $tag_list)
- // user-provided WHERE
- ->multiWhere($params['where'])
- // group by nodes.id to collapse multiple nodes (1 for each tag)
- ->group($native_primary)
- // make sure the tag-count matches
- ->having("COUNT($native_primary) = ?", count($tag_list))
- // user-provided ORDER, paging, etc
- ->order($params['order'])
- ->setPaging($params['paging'])
- ->limitPage($params['page'])
- ->bind($params['bind']);
-
- // done!
- return $select;
- }
-
- public function countPagesByTags($tag_list, $params = null)
- {
- $tag_list = $this->_fixTagList($tag_list);
- if (! $tag_list) {
- return $this->countPages($params);
- }
-
- // we need to select the nodes + tags as an "inner" sub-select;
- // clear any limits on it.
- $inner = $this->_newSelectByTags($tag_list, $params);
- $inner->clear('limit');
-
- // set up the outer select, which will wrap the inner sub-select
- $outer = Solar::factory($this->_select_class, array(
- 'sql' => $this->_sql
- ));
-
- // wrap the sub-select and make sure paging is correct
- $outer->fromSelect($inner, $this->_model_name);
- $outer->setPaging($this->_paging);
-
- // *now* get the count of pages with the tags requested
- return $outer->countPages("{$this->_model_name}.{$this->_primary_col}");
- }
-}
Copied: trunk/Solar/Model/Nodes.php (from rev 2801, branches/orm/Solar/Model/Nodes.php)
===================================================================
--- trunk/Solar/Model/Nodes.php (rev 0)
+++ trunk/Solar/Model/Nodes.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,251 @@
+<?php
+class Solar_Model_Nodes extends Solar_Model {
+ protected function _setup()
+ {
+ /**
+ * Table name, columns, and indexes.
+ */
+
+ $this->_table_name = 'nodes';
+
+ $this->_table_cols = array(
+ 'id' => array(
+ 'type' => 'int',
+ 'require' => true,
+ 'primary' => true,
+ 'autoinc' => true,
+ ),
+ 'created' => 'timestamp',
+ 'updated' => 'timestamp',
+ 'area_id' => array(
+ 'type' => 'int',
+ 'require' => true,
+ ),
+ 'inherit' => array(
+ 'type' => 'varchar',
+ 'size' => 32,
+ ),
+ 'name' => array(
+ 'type' => 'varchar',
+ 'size' => 127,
+ ),
+ 'parent_id' => 'int',
+ 'owner_handle' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'editor_handle' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'editor_ipaddr' => array(
+ 'type' => 'varchar',
+ 'size' => 15,
+ ),
+ 'assign_handle' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'locale' => array(
+ 'type' => 'varchar',
+ 'size' => 5,
+ ),
+ 'rating' => 'int',
+ 'email' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'uri' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'moniker' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'pos' => 'int',
+ 'status' => array(
+ 'type' => 'varchar',
+ 'size' => 32,
+ ),
+ 'mime' => array(
+ 'type' => 'varchar',
+ 'size' => 64,
+ 'default' => 'text/plain',
+ ),
+ 'subj' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ 'summ' => 'clob',
+ 'body' => 'clob',
+ 'prefs' => 'clob',
+ );
+
+ $this->_index = array(
+ 'created',
+ 'updated',
+ 'area_id',
+ 'name',
+ 'parent_id',
+ 'owner_handle',
+ 'assign_handle',
+ 'inherit',
+ 'locale',
+ 'pos',
+ 'rating',
+ 'uri',
+ 'email',
+ 'status',
+ );
+
+ /**
+ * Special columns
+ */
+ $this->_serialize_cols[] = 'prefs';
+ $this->_calculate_cols[] = 'tags_as_string';
+
+ /**
+ * Filters
+ */
+
+ // make sure the name is unique for its area and model
+ $where = array(
+ 'inherit = :inherit',
+ 'area_id = :area_id',
+ );
+ $this->_addFilter('name', 'validateUnique', $where);
+
+ // other filters
+ $this->_addFilter('email', 'validateEmail');
+ $this->_addFilter('uri', 'validateUri');
+ $this->_addFilter('editor_ipaddr', 'validateIpv4');
+ $this->_addFilter('locale', 'validateLocaleCode');
+ $this->_addFilter('mime', 'validateMimeType');
+ $this->_addFilter('tags_as_string', 'validateSepWords');
+
+ /**
+ * Relationships.
+ */
+ $this->_belongsTo('area', array(
+ 'foreign_class' => 'areas',
+ 'foreign_key' => 'area_id',
+ 'eager' => false,
+ ));
+
+ $this->_hasMany('taggings', array(
+ 'foreign_class' => 'taggings',
+ 'foreign_key' => 'node_id',
+ ));
+
+ $this->_hasMany('tags', array(
+ 'foreign_class' => 'tags',
+ 'through' => 'taggings',
+ 'through_key' => 'tag_id',
+ ));
+ }
+
+ public function fetchAllByTags($tag_list, $params = null)
+ {
+ // no tags? fetch all to pre-empt errors related to "IN()" not
+ // having a list to work with.
+ $tag_list = $this->_fixTagList($tag_list);
+ if (! $tag_list) {
+ return $this->fetchAll($params);
+ }
+
+ // fetch
+ $select = $this->_newSelectByTags($tag_list, $params);
+ return $this->_fetchAll($select, $params);
+ }
+
+ protected function _fixTagList($tag_list)
+ {
+ // convert to array
+ if (! is_array($tag_list)) {
+ $tag_list = preg_split('/\s+/', trim((string) $tag_list));
+ }
+
+ // no duplicates allowed
+ $tag_list = array_unique($tag_list);
+
+ // if the string tag-list is empty, the preg-split leaves one empty
+ // element in the array.
+ if ($tag_list[0] == '') {
+ $tag_list = array();
+ }
+
+ // done!
+ return $tag_list;
+ }
+
+ protected function _newSelectByTags($tag_list, $params)
+ {
+ // setup
+ $params = $this->fixSelectParams($params);
+ $select = $this->newSelect($params['eager']);
+
+ // catalog entries for joining
+ $taggings = $this->_related['taggings'];
+ $tags = $this->_related['tags'];
+
+ // primary key on the nodes table as an alias; e.g., "nodes.id"
+ $native_primary = "{$this->_model_name}.{$this->_primary_col}";
+
+ // http://forge.mysql.com/wiki/TagSchema
+ // build the select differently from other fetchAll() statements
+ $select->distinct($params['distinct'])
+ ->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
+ // join taggings on nodes
+ ->join(
+ "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
+ "{$taggings->foreign_alias}.node_id = $native_primary"
+ )
+ // join tags on taggings
+ ->join(
+ "{$tags->foreign_table} AS {$tags->foreign_alias}",
+ "{$tags->foreign_alias}.id = {$taggings->foreign_alias}.tag_id"
+ )
+ // select for the listed tags
+ ->where("{$tags->foreign_alias}.name IN (?)", $tag_list)
+ // user-provided WHERE
+ ->multiWhere($params['where'])
+ // group by nodes.id to collapse multiple nodes (1 for each tag)
+ ->group($native_primary)
+ // make sure the tag-count matches
+ ->having("COUNT($native_primary) = ?", count($tag_list))
+ // user-provided ORDER, paging, etc
+ ->order($params['order'])
+ ->setPaging($params['paging'])
+ ->limitPage($params['page'])
+ ->bind($params['bind']);
+
+ // done!
+ return $select;
+ }
+
+ public function countPagesByTags($tag_list, $params = null)
+ {
+ $tag_list = $this->_fixTagList($tag_list);
+ if (! $tag_list) {
+ return $this->countPages($params);
+ }
+
+ // we need to select the nodes + tags as an "inner" sub-select;
+ // clear any limits on it.
+ $inner = $this->_newSelectByTags($tag_list, $params);
+ $inner->clear('limit');
+
+ // set up the outer select, which will wrap the inner sub-select
+ $outer = Solar::factory($this->_select_class, array(
+ 'sql' => $this->_sql
+ ));
+
+ // wrap the sub-select and make sure paging is correct
+ $outer->fromSelect($inner, $this->_model_name);
+ $outer->setPaging($this->_paging);
+
+ // *now* get the count of pages with the tags requested
+ return $outer->countPages("{$this->_model_name}.{$this->_primary_col}");
+ }
+}
Deleted: trunk/Solar/Model/Record.php
===================================================================
--- branches/orm/Solar/Model/Record.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,2 +0,0 @@
-<?php
-class Solar_Model_Record extends Solar_Sql_Model_Record {}
\ No newline at end of file
Copied: trunk/Solar/Model/Record.php (from rev 2801, branches/orm/Solar/Model/Record.php)
===================================================================
--- trunk/Solar/Model/Record.php (rev 0)
+++ trunk/Solar/Model/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,2 @@
+<?php
+class Solar_Model_Record extends Solar_Sql_Model_Record {}
\ No newline at end of file
Deleted: trunk/Solar/Model/Taggings.php
===================================================================
--- branches/orm/Solar/Model/Taggings.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Taggings.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,28 +0,0 @@
-<?php
-class Solar_Model_Taggings extends Solar_Model {
- protected function _setup()
- {
- $this->_table_name = 'taggings';
-
- $this->_table_cols = array(
- 'id' => array(
- 'type' => 'int',
- 'require' => true,
- 'primary' => true,
- 'autoinc' => true,
- ),
- 'node_id' => 'int',
- 'tag_id' => 'int',
- );
-
- $this->_belongsTo('node', array(
- 'foreign_class' => 'nodes',
- 'foreign_key' => 'node_id',
- ));
-
- $this->_belongsTo('tag', array(
- 'foreign_class' => 'tags',
- 'foreign_key' => 'tag_id',
- ));
- }
-}
Copied: trunk/Solar/Model/Taggings.php (from rev 2801, branches/orm/Solar/Model/Taggings.php)
===================================================================
--- trunk/Solar/Model/Taggings.php (rev 0)
+++ trunk/Solar/Model/Taggings.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,28 @@
+<?php
+class Solar_Model_Taggings extends Solar_Model {
+ protected function _setup()
+ {
+ $this->_table_name = 'taggings';
+
+ $this->_table_cols = array(
+ 'id' => array(
+ 'type' => 'int',
+ 'require' => true,
+ 'primary' => true,
+ 'autoinc' => true,
+ ),
+ 'node_id' => 'int',
+ 'tag_id' => 'int',
+ );
+
+ $this->_belongsTo('node', array(
+ 'foreign_class' => 'nodes',
+ 'foreign_key' => 'node_id',
+ ));
+
+ $this->_belongsTo('tag', array(
+ 'foreign_class' => 'tags',
+ 'foreign_key' => 'tag_id',
+ ));
+ }
+}
Copied: trunk/Solar/Model/Tags (from rev 2801, branches/orm/Solar/Model/Tags)
Deleted: trunk/Solar/Model/Tags/Collection.php
===================================================================
--- branches/orm/Solar/Model/Tags/Collection.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Tags/Collection.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,12 +0,0 @@
-<?php
-class Solar_Model_Tags_Collection extends Solar_Model_Collection {
-
- public function getNames()
- {
- $list = array();
- foreach ($this as $tag) {
- $list[] = $tag->name;
- }
- return $list;
- }
-}
\ No newline at end of file
Copied: trunk/Solar/Model/Tags/Collection.php (from rev 2801, branches/orm/Solar/Model/Tags/Collection.php)
===================================================================
--- trunk/Solar/Model/Tags/Collection.php (rev 0)
+++ trunk/Solar/Model/Tags/Collection.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,12 @@
+<?php
+class Solar_Model_Tags_Collection extends Solar_Model_Collection {
+
+ public function getNames()
+ {
+ $list = array();
+ foreach ($this as $tag) {
+ $list[] = $tag->name;
+ }
+ return $list;
+ }
+}
\ No newline at end of file
Deleted: trunk/Solar/Model/Tags/Record.php
===================================================================
--- branches/orm/Solar/Model/Tags/Record.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Tags/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,2 +0,0 @@
-<?php
-class Solar_Model_Tags_Record extends Solar_Model_Record {}
\ No newline at end of file
Copied: trunk/Solar/Model/Tags/Record.php (from rev 2801, branches/orm/Solar/Model/Tags/Record.php)
===================================================================
--- trunk/Solar/Model/Tags/Record.php (rev 0)
+++ trunk/Solar/Model/Tags/Record.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,2 @@
+<?php
+class Solar_Model_Tags_Record extends Solar_Model_Record {}
\ No newline at end of file
Deleted: trunk/Solar/Model/Tags.php
===================================================================
--- branches/orm/Solar/Model/Tags.php 2007-09-29 02:40:28 UTC (rev 2801)
+++ trunk/Solar/Model/Tags.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -1,148 +0,0 @@
-<?php
-class Solar_Model_Tags extends Solar_Model {
- protected function _setup()
- {
- /**
- * Table name, columns, and indexes.
- */
- $this->_table_name = 'tags';
-
- $this->_table_cols = array(
- 'id' => array(
- 'type' => 'int',
- 'require' => true,
- 'primary' => true,
- 'autoinc' => true,
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'size' => 255,
- 'require' => true,
- ),
- 'descr' => array(
- 'type' => 'varchar',
- 'size' => 255,
- ),
- );
-
- $this->_index = array(
- 'name' => 'unique',
- );
-
- /**
- * Behaviors (serialize, sequence, filter).
- */
- $this->_serialize_cols[] = 'prefs';
-
- /**
- * Relationships.
- */
- $this->_hasMany('taggings', array(
- 'foreign_class' => 'taggings',
- 'foreign_key' => 'tag_id',
- ));
-
- $this->_hasMany('nodes', array(
- 'foreign_class' => 'nodes',
- 'through' => 'taggings',
- ));
- }
-
- public function fetchAllWithCount($params = null)
- {
- $params = $this->fixSelectParams($params);
- $select = $this->_newSelectWithCount($params);
- return $this->_fetchAll($select, $params);
- }
-
- public function fetchAllByOwnerHandle($owner_handle, $params = null)
- {
- $owner_handle = trim($owner_handle);
- if (! $owner_handle) {
- return $this->fetchAll($params);
- }
-
- // setup
- $params = $this->fixSelectParams($params);
- $select = $this->newSelect($params['eager']);
-
- // catalog entries for joining
- $taggings = $this->getRelated('taggings');
- $nodes = $this->getRelated('nodes');
-
- // primary key on this table alias; e.g., tags.id
- $native_primary = "{$this->_model_name}.{$this->_primary_col}";
-
- // add a tag-count column
- $params['cols'][] = "COUNT($native_primary) AS count";
-
- // build the select
- $select->distinct($params['distinct'])
- ->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
- // join taggings on tags
- ->join(
- "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
- "{$taggings->foreign_alias}.tag_id = $native_primary"
- )
- // join nodes on taggings
- ->join(
- "{$nodes->foreign_table} AS {$nodes->foreign_alias}",
- "{$nodes->foreign_alias}.id = {$taggings->foreign_alias}.node_id"
- )
- // select for the owner_handle
- ->where("{$nodes->foreign_alias}.owner_handle = ?", $owner_handle)
- // group on primary key for counts
- ->group($native_primary)
- // user-provided ORDER, paging, etc
- ->multiWhere($params['where'])
- ->order($params['order'])
- ->setPaging($params['paging'])
- ->limitPage($params['page'])
- ->bind($params['bind']);
-
- // fetch
- $select = $this->_newSelectWithCount($params);
- $select->where("{$nodes->foreign_alias}.owner_handle = ?", $owner_handle);
- return $this->_fetchAll($select, $params);
- }
-
- protected function _newSelectWithCount($params)
- {
- // params should have been fixed by this point
- $select = $this->newSelect($params['eager']);
-
- // catalog entries for joining
- $taggings = $this->getRelated('taggings');
- $nodes = $this->getRelated('nodes');
-
- // primary key on this table alias; e.g., tags.id
- $native_primary = "{$this->_model_name}.{$this->_primary_col}";
-
- // add a tag-count column
- $params['cols'][] = "COUNT($native_primary) AS count";
-
- // build the select
- $select->distinct($params['distinct'])
- ->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
- // join taggings on tags
- ->join(
- "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
- "{$taggings->foreign_alias}.tag_id = $native_primary"
- )
- // join nodes on taggings
- ->join(
- "{$nodes->foreign_table} AS {$nodes->foreign_alias}",
- "{$nodes->foreign_alias}.id = {$taggings->foreign_alias}.node_id"
- )
- // group on primary key for counts
- ->group($native_primary)
- // user-provided ORDER, paging, etc
- ->multiWhere($params['where'])
- ->order($params['order'])
- ->setPaging($params['paging'])
- ->limitPage($params['page'])
- ->bind($params['bind']);
-
- return $select;
- }
-}
Copied: trunk/Solar/Model/Tags.php (from rev 2801, branches/orm/Solar/Model/Tags.php)
===================================================================
--- trunk/Solar/Model/Tags.php (rev 0)
+++ trunk/Solar/Model/Tags.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,148 @@
+<?php
+class Solar_Model_Tags extends Solar_Model {
+ protected function _setup()
+ {
+ /**
+ * Table name, columns, and indexes.
+ */
+ $this->_table_name = 'tags';
+
+ $this->_table_cols = array(
+ 'id' => array(
+ 'type' => 'int',
+ 'require' => true,
+ 'primary' => true,
+ 'autoinc' => true,
+ ),
+ 'name' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ 'require' => true,
+ ),
+ 'descr' => array(
+ 'type' => 'varchar',
+ 'size' => 255,
+ ),
+ );
+
+ $this->_index = array(
+ 'name' => 'unique',
+ );
+
+ /**
+ * Behaviors (serialize, sequence, filter).
+ */
+ $this->_serialize_cols[] = 'prefs';
+
+ /**
+ * Relationships.
+ */
+ $this->_hasMany('taggings', array(
+ 'foreign_class' => 'taggings',
+ 'foreign_key' => 'tag_id',
+ ));
+
+ $this->_hasMany('nodes', array(
+ 'foreign_class' => 'nodes',
+ 'through' => 'taggings',
+ ));
+ }
+
+ public function fetchAllWithCount($params = null)
+ {
+ $params = $this->fixSelectParams($params);
+ $select = $this->_newSelectWithCount($params);
+ return $this->_fetchAll($select, $params);
+ }
+
+ public function fetchAllByOwnerHandle($owner_handle, $params = null)
+ {
+ $owner_handle = trim($owner_handle);
+ if (! $owner_handle) {
+ return $this->fetchAll($params);
+ }
+
+ // setup
+ $params = $this->fixSelectParams($params);
+ $select = $this->newSelect($params['eager']);
+
+ // catalog entries for joining
+ $taggings = $this->getRelated('taggings');
+ $nodes = $this->getRelated('nodes');
+
+ // primary key on this table alias; e.g., tags.id
+ $native_primary = "{$this->_model_name}.{$this->_primary_col}";
+
+ // add a tag-count column
+ $params['cols'][] = "COUNT($native_primary) AS count";
+
+ // build the select
+ $select->distinct($params['distinct'])
+ ->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
+ // join taggings on tags
+ ->join(
+ "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
+ "{$taggings->foreign_alias}.tag_id = $native_primary"
+ )
+ // join nodes on taggings
+ ->join(
+ "{$nodes->foreign_table} AS {$nodes->foreign_alias}",
+ "{$nodes->foreign_alias}.id = {$taggings->foreign_alias}.node_id"
+ )
+ // select for the owner_handle
+ ->where("{$nodes->foreign_alias}.owner_handle = ?", $owner_handle)
+ // group on primary key for counts
+ ->group($native_primary)
+ // user-provided ORDER, paging, etc
+ ->multiWhere($params['where'])
+ ->order($params['order'])
+ ->setPaging($params['paging'])
+ ->limitPage($params['page'])
+ ->bind($params['bind']);
+
+ // fetch
+ $select = $this->_newSelectWithCount($params);
+ $select->where("{$nodes->foreign_alias}.owner_handle = ?", $owner_handle);
+ return $this->_fetchAll($select, $params);
+ }
+
+ protected function _newSelectWithCount($params)
+ {
+ // params should have been fixed by this point
+ $select = $this->newSelect($params['eager']);
+
+ // catalog entries for joining
+ $taggings = $this->getRelated('taggings');
+ $nodes = $this->getRelated('nodes');
+
+ // primary key on this table alias; e.g., tags.id
+ $native_primary = "{$this->_model_name}.{$this->_primary_col}";
+
+ // add a tag-count column
+ $params['cols'][] = "COUNT($native_primary) AS count";
+
+ // build the select
+ $select->distinct($params['distinct'])
+ ->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
+ // join taggings on tags
+ ->join(
+ "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
+ "{$taggings->foreign_alias}.tag_id = $native_primary"
+ )
+ // join nodes on taggings
+ ->join(
+ "{$nodes->foreign_table} AS {$nodes->foreign_alias}",
+ "{$nodes->foreign_alias}.id = {$taggings->foreign_alias}.node_id"
+ )
+ // group on primary key for counts
+ ->group($native_primary)
+ // user-provided ORDER, paging, etc
+ ->multiWhere($params['where'])
+ ->order($params['order'])
+ ->setPaging($params['paging'])
+ ->limitPage($params['page'])
+ ->bind($params['bind']);
+
+ return $select;
+ }
+}
Copied: trunk/Solar/Model.php (from rev 2801, branches/orm/Solar/Model.php)
===================================================================
--- trunk/Solar/Model.php (rev 0)
+++ trunk/Solar/Model.php 2007-10-06 16:26:49 UTC (rev 2837)
@@ -0,0 +1,3 @@
+<?php
+abstract class Solar_Model extends Solar_Sql_Model {
+}
More information about the Solar-svn
mailing list