[Solar-svn] Revision 2840

pmjones at solarphp.com pmjones at solarphp.com
Sat Oct 6 11:35:03 CDT 2007


Solar_App_Bookmarks
-------------------

* [BRK] Updated entire app to match new Model/Record/Collection usage, new Solar_View::partial() usage, and new Solar_Uri::get() usage.

* [BRK] Default area is now 'default' (vice 'Solar_App_Bookmarks').




Modified: trunk/Solar/App/Bookmarks/Layout/_local.php
===================================================================
--- trunk/Solar/App/Bookmarks/Layout/_local.php	2007-10-06 16:32:40 UTC (rev 2839)
+++ trunk/Solar/App/Bookmarks/Layout/_local.php	2007-10-06 16:35:03 UTC (rev 2840)
@@ -38,7 +38,7 @@
         <p><?php
             $uri = Solar::factory('Solar_Uri_Action');
             $uri->set('bookmarks/quick');
-            $href = $uri->fetch(true);
+            $href = $uri->get(true);
             $js = "javascript:location.href='$href?uri='+encodeURIComponent(location.href)+'&subj='+encodeURIComponent(document.title)";
             echo $this->getText('DRAG_THIS') . ': ';
             echo $this->anchor($js, 'ACTION_QUICK');
@@ -54,8 +54,6 @@
             'created_desc' => 'ORDER_CREATED_DESC',
             'pos'          => 'ORDER_POS',
             'pos_desc'     => 'ORDER_POS_DESC',
-            'tags'         => 'ORDER_TAGS',
-            'tags_desc'    => 'ORDER_TAGS_DESC',
             'subj'         => 'ORDER_SUBJ',
             'subj_desc'    => 'ORDER_SUBJ_DESC',
         );
@@ -76,7 +74,7 @@
         }
     ?>
     </ul>
-
+    
     <h3><?php echo $this->getText('HEADING_TAGLIST') ?></h3>
     <ul>
     <?php
@@ -90,9 +88,10 @@
         $uri = Solar::factory('Solar_Uri_Action');
         unset($uri->query['page']);
         $tmp = array();
-        foreach ($this->tags_in_use as $tag => $count) {
-            $uri->setPath("$action/$tag");
-            $tmp[] = "<li>" . $this->action($uri, $tag) . " ($count)</li>";
+        foreach ($this->tags_in_use as $tag) {
+            $count = 'x';
+            $uri->setPath("$action/{$tag->name}");
+            $tmp[] = "<li>" . $this->action($uri, $tag->name) . " ({$tag->count})</li>";
         }
         echo implode("\n", $tmp);
     ?>

Modified: trunk/Solar/App/Bookmarks/Locale/pt_BR.php
===================================================================
--- trunk/Solar/App/Bookmarks/Locale/pt_BR.php	2007-10-06 16:32:40 UTC (rev 2839)
+++ trunk/Solar/App/Bookmarks/Locale/pt_BR.php	2007-10-06 16:35:03 UTC (rev 2840)
@@ -1,42 +1,42 @@
 <?php
 /**
- *
+ * 
  * Provides locale strings for the app.
- *
+ * 
  * @category Solar
- *
+ * 
  * @package Solar_App
- *
+ * 
  * @subpackage Solar_App_Bookmarks
- *
+ * 
  * @author Rodrigo Moraes <http://tipos.org>
- *
+ * 
  * @license http://opensource.org/licenses/bsd-license.php BSD
- *
+ * 
  * @version $Id$
- *
+ * 
  */
 
 /**
- *
+ * 
  * Provides locale strings for the app.
- *
+ * 
  * @category Solar
- *
+ * 
  * @package Solar_App
- *
+ * 
  * @subpackage Solar_App_Bookmarks
- *
+ * 
  */
 return array(
-
+    
     'ACTION_ADD'            => 'Novo bookmark.',
     'ACTION_QUICK'          => 'Atalho',
-
+    
     'ERR_NOT_LOGGED_IN'     => 'Você não está logado.',
     'ERR_NOT_OWNER'         => 'Você não é o dono deste bookmark, ou ele não existe.',
     'ERR_NOT_SELECTED'      => 'Nenhum bookmark selecionado.',
-
+    
     'HEADING_BOOKMARKS'     => 'Bookmarks',
     'HEADING_ADD'           => 'Adicionar Bookmark',
     'HEADING_EDIT'          => 'Editar Bookmark',
@@ -45,13 +45,13 @@
     'HEADING_TAGS'          => 'Tags',
     'HEADING_TAGLIST'       => 'Tags em Uso',
     'HEADING_USER'          => 'Usuário',
-
+    
     'LABEL_CREATED'         => 'em',
     'LABEL_OWNER_HANDLE'    => 'por',
     'LABEL_POS'             => 'popularidade',
     'LABEL_TAGS'            => 'com tag',
     'LABEL_URI'             => 'de',
-
+    
     'ORDER_CREATED'         => 'Criação',
     'ORDER_CREATED_DESC'    => 'Criação (desc)',
     'ORDER_POS'             => 'Poluparidade',
@@ -60,7 +60,7 @@
     'ORDER_SUBJ_DESC'       => 'Título (desc)',
     'ORDER_TAGS'            => 'Tags',
     'ORDER_TAGS_DESC'       => 'Tags (desc)',
-
+    
     'BACKLINK'              => 'Voltar',
     'CONFIRM_DELETE'        => 'Quer mesmo apagar este bookmark?',
     'DRAG_THIS'             => 'Arraste este link para a sua barra de ferramentas para adicionar bookmarks rapidamente.',

Modified: trunk/Solar/App/Bookmarks/View/_item.php
===================================================================
--- trunk/Solar/App/Bookmarks/View/_item.php	2007-10-06 16:32:40 UTC (rev 2839)
+++ trunk/Solar/App/Bookmarks/View/_item.php	2007-10-06 16:35:03 UTC (rev 2840)
@@ -15,58 +15,60 @@
  * 
  * @version $Id$
  * 
+ * @var Solar_Model_Nodes_Bookmarks_Record $item
+ * 
  */
 ?>
-
+            
             <li class="bookmark-item">
                 <span><?php
-                    $title = $uri;
+                    $title = $item->uri;
                     if (strlen($title) > 72) {
                         // if longer than 72 chars, only show 64 chars, cut in the middle
                         $title = substr($title, 0, 48) . ' ... ' . substr($title, -16);
                     }
-                    echo $this->anchor($uri, $subj, array('title' => $title));
+                    echo $this->anchor($item->uri, $item->subj, array('title' => $title));
                 ?></span>
-                <ul><?php if (trim($summ) != ''): ?>
+                <ul><?php if (trim($item->summ) != ''): ?>
                     
                     <li class="summ"><?php
-                        echo nl2br(wordwrap($this->escape($summ), 72));
+                        echo nl2br(wordwrap($this->escape($item->summ), 72));
                     ?></li>
                     <?php endif ?>
                     
                     <li class="pos"><span><?php
                             echo $this->getText('LABEL_POS');
-                        ?></span> <?php echo $this->escape($pos);
+                        ?></span> <?php echo $this->escape($item->pos);
                     ?></li>
     
                     <li class="created">
                         <span><?php
                             echo $this->getText('LABEL_CREATED');
-                        ?></span> <?php echo $this->timestamp($created); ?>
+                        ?></span> <?php echo $this->timestamp($item->created); ?>
             
                         <span><?php
                             echo $this->getText('LABEL_OWNER_HANDLE');
                         ?></span> <?php echo $this->action(
-                            "bookmarks/user/$owner_handle",
-                            $owner_handle);
+                            "bookmarks/user/{$item->owner_handle}",
+                            $item->owner_handle);
                         ?>
             
                     </li>
-    
+                    
                     <li class="tags">
-                        <span><?php echo $this->getText('LABEL_TAGS');
-                        ?></span><?php
-                            $tags = explode(' ', $tags);
-                            foreach ($tags as $tag) {
-                                echo ' ' . $this->action("bookmarks/tag/$tag", $tag);
+                        <span><?php echo $this->getText('LABEL_TAGS'); ?></span>
+                        <?php if ($item->tags) {
+                            foreach ($item->tags as $tag) {
+                                echo $this->action("bookmarks/tag/{$tag->name}", $tag->name);
+                                echo "                            \n";
                             }
-                        ?>
-            
-                    </li><?php
-                    if (Solar::registry('user')->auth->handle == $owner_handle): ?>
-                    
+                        } ?>
+                        
+                    </li>
+                        
+                    <?php if (Solar::registry('user')->auth->handle == $item->owner_handle): ?>
                     <li class="edit">
-                        <?php echo $this->action("bookmarks/edit/$id", 'PROCESS_EDIT'); ?>
+                        <?php echo $this->action("bookmarks/edit/{$item->id}", 'PROCESS_EDIT'); ?>
                     </li>
                     <?php endif; ?>
                     

Modified: trunk/Solar/App/Bookmarks/View/browse.php
===================================================================
--- trunk/Solar/App/Bookmarks/View/browse.php	2007-10-06 16:32:40 UTC (rev 2839)
+++ trunk/Solar/App/Bookmarks/View/browse.php	2007-10-06 16:35:03 UTC (rev 2840)
@@ -23,19 +23,19 @@
      */
     $uri = Solar::factory('Solar_Uri_Action');
     $uri->format = 'rss';
-
+    
     if ($this->tags) {
         // there are tags requested, so the RSS should show all pages
         // (i.e., page zero) and ignore the rows-per-page settings.
         $uri->query['page'] = 'all';
         unset($uri->query['rows_per_page']);
     }
-
+    
     $this->layout_head['link'][] = array(
         'rel'   => 'alternate',
         'type'  => 'application/rss+xml',
         'title' => implode('/', $uri->path),
-        'href'  => $uri->fetch(true),
+        'href'  => $uri->get(true),
     );
 ?>
 
@@ -51,7 +51,7 @@
             if ($this->tags) echo $this->getText('HEADING_TAGS') . ': ' . $this->escape($this->tags);
         ?></h2>
     <?php endif ?>
-
+    
     <!-- output the list of results -->
     <?php if (count($this->list)): ?>
         

Modified: trunk/Solar/App/Bookmarks/View/browse.rss.php
===================================================================
--- trunk/Solar/App/Bookmarks/View/browse.rss.php	2007-10-06 16:32:40 UTC (rev 2839)
+++ trunk/Solar/App/Bookmarks/View/browse.rss.php	2007-10-06 16:35:03 UTC (rev 2840)
@@ -36,23 +36,23 @@
 // that date.
 $items = '';
 $updated = ''; // last update
-foreach ($this->list as $key => $val) {
+foreach ($this->list as $item) {
     
     $category = $this->escape(
-        $val['owner_handle'] . '/' . str_replace(' ', '+', $val['tags'])
+        $item->owner_handle . '/' . str_replace(' ', '+', $item->tags_as_string)
     );
     
-    $title = $this->escape($val['subj']);
+    $title = $this->escape($item->subj);
     
-    $pubDate = $this->date($val['updated'], DATE_RSS);
+    $pubDate = $this->date($item->updated, DATE_RSS);
     
-    if ($val['updated'] > $updated) {
-        $updated = $val['updated'];
+    if ($item->updated > $updated) {
+        $updated = $item->updated;
     }
     
-    $description = $this->escape($val['summ']);
+    $description = $this->escape($item->summ);
     
-    $uri = $this->escape($val['uri']);
+    $uri = $this->escape($item->uri);
     
     $items .= <<<ITEM
         
@@ -70,7 +70,7 @@
 <rss version="2.0">
     <channel>
         <title><?php echo $this->escape($this->feed['title']) ?></title>
-        <link><?php echo $this->escape($link->fetch(true)) ?></link>
+        <link><?php echo $this->escape($link->get(true)) ?></link>
         <description><?php echo $this->escape($this->feed['descr']) ?></description>
         <pubDate><?php echo $this->date($updated, DATE_RSS) ?></pubDate>
         <?php echo $items ?>

Modified: trunk/Solar/App/Bookmarks.php
===================================================================
--- trunk/Solar/App/Bookmarks.php	2007-10-06 16:32:40 UTC (rev 2839)
+++ trunk/Solar/App/Bookmarks.php	2007-10-06 16:35:03 UTC (rev 2840)
@@ -1,7 +1,7 @@
 <?php
 /**
  * 
- * Social bookmarking application.
+ * Anti-social bookmarking application.
  * 
  * @category Solar
  * 
@@ -19,7 +19,7 @@
 
 /**
  * 
- * Social bookmarking application.
+ * Anti-social bookmarking application.
  * 
  * @category Solar
  * 
@@ -37,19 +37,14 @@
      * Keys are ...
      * 
      * `area_name`
-     * : (string) The content area for the bookmarks app, default
-     *   'Solar_App_Bookmarks'.  Will be created automatically if it does not
-     *   exist.
+     * : (string) The content area for the bookmarks app, default "default".
+     *   Will be created automatically if it does not exist.
      * 
-     * `content`
-     * : (dependency) A Solar_Content domain model dependency object.
-     * 
      * @var array
      * 
      */
     protected $_Solar_App_Bookmarks = array(
-        'area_name'    => 'Solar_App_Bookmarks',
-        'content'      => 'content',
+        'area_name'    => 'default',
     );
     
     /**
@@ -75,6 +70,15 @@
     
     /**
      * 
+     * The area we're using.
+     * 
+     * @var Solar_Model_Areas_Record
+     * 
+     */
+    public $area;
+    
+    /**
+     * 
      * The total number of pages in the query.
      * 
      * @var int
@@ -84,6 +88,15 @@
     
     /**
      * 
+     * The total number of records in the query.
+     * 
+     * @var int
+     * 
+     */
+    public $count;
+    
+    /**
+     * 
      * The requested bookmark order (subj, tags, created, etc).
      * 
      * @var string
@@ -172,17 +185,12 @@
      * @var Solar_User
      * 
      */
-    protected $_user;
+    public $user;
     
-    /**
-     * 
-     * A bookmarks node interaction manager.
-     * 
-     * @var Solar_Content_Bookmarks
-     * 
-     */
     protected $_bookmarks;
     
+    protected $_tags;
+    
     /**
      * 
      * Extended setup.
@@ -198,28 +206,28 @@
     {
         parent::_setup();
         
-        // make sure a bookmarks area exists
-        $content = Solar::dependency('Solar_Content', $this->_config['content']);
+        // make sure the area exists, and keep it
+        $areas = Solar::factory('Solar_Model_Areas');
         $name = $this->_config['area_name'];
-        $area = $content->areas->fetchByName($name);
-        if (! $area->id) {
+        $this->area = $areas->fetchOneByName($name);
+        if (! $this->area) {
             // area didn't exist, create it.
-            $data = array('name'  => $name);
-            $area = $content->areas->insert($data);
+            $this->area = $areas->fetchNew();
+            $this->area->name = $name;
+            $result = $this->area->save();
+            if (! $result) {
+                throw $this->_exception('ERR_AREA_NOT_CREATED');
+            }
         }
-        
+
         // get a user object for privileges
-        $this->_user = Solar::registry('user');
+        $this->user = Solar::registry('user');
         
-        // get the bookmarks model using the same content
-        // dependency
-        $this->_bookmarks = Solar::factory(
-            'Solar_Content_Bookmarks',
-            array(
-                'content' => $this->_config['content'],
-                'area_id' => $area['id']
-            )
-        );
+        // keep a bookmarks model
+        $this->_bookmarks = Solar::factory('Solar_Model_Nodes_Bookmarks');
+        
+        // keep a tags model
+        $this->_tags = Solar::factory('Solar_Model_Tags');
     }
     
     /**
@@ -229,7 +237,7 @@
      * @return string
      * 
      */
-    protected function _getOrder()
+    protected function _getSqlOrder()
     {
         $tmp = strtolower($this->_query('order'));
         
@@ -238,68 +246,36 @@
         // created timestamp
         case 'created':
         case 'created_asc':
-        case 'ts':
-        case 'ts_asc':
-            $order = 'nodes.created ASC';
+            $order = 'bookmarks.created ASC, bookmarks.id ASC';
             break;
         
         case 'created_desc':
-        case 'ts_desc':
-            $order = 'nodes.created DESC';
+            $order = 'bookmarks.created DESC, bookmarks.id DESC';
             break;
             
         // title
         case 'subj':
         case 'subj_asc':
-        case 'title':
-        case 'title_asc':
-            $order = 'LOWER(nodes.subj) ASC';
+            $order = 'LOWER(bookmarks.subj) ASC, bookmarks.id ASC';
             break;
         
         case 'subj_desc':
-        case 'title_desc':
-            $order = 'LOWER(nodes.subj) DESC';
+            $order = 'LOWER(bookmarks.subj) DESC, bookmarks.id DESC';
             break;
         
-        // tags
-        case 'tag':
-        case 'tag_asc':
-        case 'tags':
-        case 'tags_asc':
-            $order = 'LOWER(nodes.tags) ASC';
-            break;
-            
-        case 'tag_desc':
-        case 'tags_desc':
-            $order = 'LOWER(nodes.tags) DESC';
-            break;
-        
         // pos
         case 'pos':
         case 'pos_asc':
-            $order = 'nodes.pos ASC';
+            $order = 'bookmarks.pos ASC, bookmarks.id ASC';
             break;
         
         case 'pos_desc':
-            $order = 'nodes.pos DESC';
+            $order = 'bookmarks.pos DESC, bookmarks.id DESC';
             break;
         
-        // owner handle (username)
-        case 'owner':
-        case 'owner_asc':
-        case 'user':
-        case 'user_asc':
-            $order = 'LOWER(nodes.owner_handle) ASC';
-            break;
-        
-        case 'owner_desc':
-        case 'user_desc':
-            $order = 'LOWER(nodes.owner_handle) DESC';
-            break;
-        
         // default
         default:
-            $order = 'nodes.created DESC';
+            $order = 'bookmarks.created DESC, bookmarks.id DESC';
             break;
         
         }
@@ -317,76 +293,53 @@
     public function actionAdd()
     {
         // must be logged in to proceed
-        if (! $this->_user->auth->isValid()) {
+        if (! $this->user->auth->isValid()) {
             $this->errors[] = 'ERR_NOT_LOGGED_IN';
             return $this->_forward('error');
         }
-
+        
         // build a link for _redirect() calls and the backlink.
         $href = $this->_session->getFlash('backlink');
         if (! $href) {
             // probably browsed to this page directly.  link to the user's list.
             $uri = Solar::factory('Solar_Uri_Action');
-            $href = $uri->quick("bookmarks/user/{$this->_user->auth->handle}");
+            $href = $uri->quick("bookmarks/user/{$this->user->auth->handle}");
         }
-
+        
         // keep the backlink for the next page load
         $this->_session->setFlash('backlink', $href);
-
-        // build the basic form, populated with the bookmark data
-        // from the database
+        
+        // which record cols do we want to work with?
+        $cols = array('uri', 'subj', 'summ', 'tags_as_string', 'pos');
+        
+        // get a blank bookmark, then populate with submitted data
         $item = $this->_bookmarks->fetchNew();
-        $form = $this->_bookmarks->form($item);
-
-        // now populate the the submitted POST values to the form
-        $form->populate();
-
-
-        // ---------------------------------------------------------------------
-        // 
-        // processes
-        // 
-
-        // Process: save
-        if ($this->_isProcess('save') && $form->validate()) {
-    
-            // load data from the form input
-            $item->load($form->values('bookmark'));
-            
-            // force these values
-            $item->owner_handle = $this->_user->auth->handle;
-            $item->editor_handle = $this->_user->auth->handle;
-    
-            // save the data
+        $data = $this->_request->post('bookmarks', array());
+        $item->load($data, $cols);
+        
+        // force these values
+        $item->area_id = $this->area->id;
+        $item->owner_handle = $this->user->auth->handle;
+        $item->editor_handle = $this->user->auth->handle;
+        
+        // save?
+        if ($this->_isProcess('save')) {
             try {
-                
                 $item->save();
                 $this->_session->setFlash('add_ok', true);
                 $this->_redirect("bookmarks/edit/{$item->id}");
-        
-            } catch (Solar_Exception $e) {
-        
-                // exception on save()
-                // we should not have gotten to this point,
-                // but need to be aware of possible problems.
-                $form->setStatus(false);
-                $form->feedback[] = $e->getClass() . ' -- ' . $e->getMessage();
-        
+            } catch (Solar_Sql_Model_Record_Exception_Invalid $e) {
+                // do nothing, the item form will show invalids
             }
         }
         
-        // OP: Cancel
+        // cancel?
         if ($this->_isProcess('cancel')) {
             $this->_redirect($href);
         }
         
-        // ---------------------------------------------------------------------
-        // 
-        // completion
-        // 
-        
-        // assign data for the view
-        $this->formdata = $form;
+        // assign data for the view, and done
+        $this->formdata = $item->form($cols);
         $this->backlink = $href;
     }
     
@@ -402,108 +355,114 @@
     public function actionEdit($id = null)
     {
         // must be logged in to proceed
-        if (! $this->_user->auth->isValid()) {
+        if (! $this->user->auth->isValid()) {
             $this->errors[] = 'ERR_NOT_LOGGED_IN';
             return $this->_forward('error');
         }
-
-        // get the bookmark ID (0 means a new bookmark)
+        
+        // get the bookmark ID
         $id = (int) $id;
         if (! $id) {
             $this->errors[] = 'ERR_NOT_SELECTED';
             return $this->_forward('error');
         }
-
-        // must be the item owner to edit it
+        
+        // fetch the bookmark
         $item = $this->_bookmarks->fetch($id);
-        if ($this->_user->auth->handle != $item->owner_handle) {
+        
+        // must be in this area
+        if ($item->area_id != $this->area->id) {
+            $this->errors[] = 'ERR_NOT_IN_AREA';
+            return $this->_forward('error');
+        }
+        
+        // must be the item owner to edit it
+        $item = $this->_bookmarks->fetchOneById($id, array(
+            'eager' => array('taggings', 'tags'),
+        ));
+        
+        if ($this->user->auth->handle != $item->owner_handle) {
             $this->errors[] = 'ERR_NOT_OWNER';
             return $this->_forward('error');
         }
-
-        // ---------------------------------------------------------------------
+        
+        // -------------------------------------------------------------------
         // 
         // build a link for _redirect() calls and the backlink.
         // 
-        // if we came from a tag or user page, return there.
-        // otherwise, return the list for the user.
+        // if we came from a tag or user page, link to it.
+        // otherwise, link to the list for the user.
         //
-
+        
         $href = $this->_session->getFlash('backlink');
         if (! $href) {
             // probably browsed directly to this page; return to the user's list
             $uri = Solar::factory('Solar_Uri_Action');
-            $href = $uri->quick("bookmarks/user/{$this->_user->auth->handle}");
+            $href = $uri->quick("bookmarks/user/{$this->user->auth->handle}");
         }
         
         // keep the backlink for the next page load
         $this->_session->setFlash('backlink', $href);
-
-        // ---------------------------------------------------------------------
+        
+        // -------------------------------------------------------------------
         // 
-        // processing
+        // loading
         // 
-
-        // build the basic form, populated with the bookmark data
-        // from the database
-        $form = $this->_bookmarks->form($item);
-
-        // now populate the the submitted POST values to the form
-        $form->populate();
         
-        // was this from a quickmark or an "add" process request?
-        if ($this->_session->getFlash('add_ok')) {
-            $form->setStatus(true);
-            $form->feedback = $this->locale('SUCCESS_ADDED');
-        }
+        // which record cols do we want to work with?
+        $cols = array('uri', 'subj', 'summ', 'tags_as_string', 'pos');
         
-        // Save?
-        if ($this->_isProcess('save') && $form->validate()) {
-    
-            // load the item with form input
-            $item->load($form->values('bookmark'));
-            
-            // force these values
-            $item->owner_handle = $this->_user->auth->handle;
-            $item->editor_handle = $this->_user->auth->handle;
-    
-            // save the data
-            try {
+        // load from posted data
+        $data = $this->_request->post('bookmarks', array());
+        // Solar::dump($data, 'from POST');
+        // Solar::$config['TEST']['BREAK'] = true;
+        // Solar::dump($item);
+        $item->load($data, $cols);
+        // die('postload');
         
-                // attempt the save, may throw an exception
-                $item->save();
+        // force these values
+        $item->area_id = $this->area->id;
+        $item->owner_handle = $this->user->auth->handle;
+        $item->editor_handle = $this->user->auth->handle;
         
-            } catch (Solar_Sql_Table_Exception $e) {
+        // -------------------------------------------------------------------
+        // 
+        // processes
+        // 
         
-                // exception on save()
-                // we should not have gotten to this point,
-                // but need to be aware of possible problems.
-                $form->setStatus(false);
-                $form->feedback[] = $e->getClass() . ' -- ' . $e->getMessage();
-        
-                // add bookmark[*] element feedback
-                $form->addFeedback($e->getInfo(), 'bookmark');
+        if ($this->_isProcess('save')) {
+            try {
+                $item->save();
+            } catch (Solar_Sql_Model_Record_Exception_Invalid $e) {
+                // do nothing, the item form will show invalids
             }
         }
-
-        // Cancel?
+        
+        // cancel
         if ($this->_isProcess('cancel')) {
             $this->_redirect($href);
         }
-
-        // Delete?
+        
+        // delete
         if ($this->_isProcess('delete')) {
-            $values = $form->values();
-            $id = $values['bookmark']['id'];
-            $this->_bookmarks->delete($id);
+            $item->delete();
             $this->_redirect($href);
         }
-
+        
         // ---------------------------------------------------------------------
         // 
         // completion
         // 
-
+        
+        // get the form
+        $form = $item->form($cols);
+        
+        // was this from a quickmark or an "add" process request?
+        if ($this->_session->getFlash('add_ok')) {
+            $form->setStatus(true);
+            $form->feedback = $this->locale('SUCCESS_ADDED');
+        }
+        
         // assign data for the view
         $this->formdata = $form;
         $this->backlink = $href;
@@ -524,69 +483,61 @@
     public function actionQuick($uri = null, $subj = null)
     {
         // must be logged in to proceed
-        if (! $this->_user->auth->isValid()) {
+        if (! $this->user->auth->isValid()) {
             $this->errors[] = 'ERR_NOT_LOGGED_IN';
             return $this->_forward('error');
         }
-
+        
         // get the quickmark info from the query
         $uri = $this->_query('uri');
         $subj = $this->_query('subj');
-
+        
         // we need to see if the user already has the same URI in
         // his bookmarks so that we don't add it twice.
-        $existing = $this->_bookmarks->fetchByOwnerUri(
-            $this->_user->auth->handle,
+        $existing = $this->_bookmarks->fetchOneByOwnerHandleAndUri(
+            $this->user->auth->handle,
             $uri
         );
         
         // if the user *does* already have that URI bookmarked,
         // redirect to the existing bookmark.
-        if (! empty($existing->id)) {
+        if ($existing) {
             $this->_session->setFlash('backlink', $uri);
-            $this->_redirect("bookmarks/edit/{$existing['id']}");
+            $this->_redirect("bookmarks/edit/{$existing->id}");
         }
-
-        // get a blank bookmark item, build the basic form
+        
+        // which record cols do we want to work with?
+        $cols = array('uri', 'subj', 'summ', 'tags_as_string', 'pos');
+        
+        // get a blank bookmark, then populate with submitted data
         $item = $this->_bookmarks->fetchNew();
+        
+        // populate first with query values
         $item->uri = $uri;
         $item->subj = $subj;
-        $form = $this->_bookmarks->form($item);
-
-        // overwrite form defaults with submissions
-        $form->populate();
-
-        // check for a 'Save' process request
-        if ($this->_isProcess('save') && $form->validate()) {
-    
-            // save the data
-            try {
-    
-                // get the form values
-                $item->load($form->values('bookmark'));
-                $item->owner_handle = $this->_user->auth->handle;
-                $item->editor_handle = $this->_user->auth->handle;
         
-                // save
-                $item->save();
+        // overwrite with POST values, if any
+        $data = $this->_request->post('bookmarks', array());
+        $item->load($data, $cols);
         
-                // redirect to the source URI (external)
-                $this->_redirect($item->uri);
+        // force these values
+        $item->area_id = $this->area->id;
+        $item->owner_handle = $this->user->auth->handle;
+        $item->editor_handle = $this->user->auth->handle;
         
-            } catch (Solar_Exception $e) {
-        
-                // exception on save()
-                // we should not have gotten to this point,
-                // but need to be aware of possible problems.
-                $form->setStatus(false);
-                $form->feedback[] = $e->getClass() . ' -- ' . $e->getMessage();
-                echo $e;
-        
+        // save?
+        if ($this->_isProcess('save')) {
+            try {
+                $item->save();
+                $this->_session->setFlash('add_ok', true);
+                $this->_redirect("bookmarks/edit/{$item->id}");
+            } catch (Solar_Sql_Model_Record_Exception_Invalid $e) {
+                // do nothing, the item form will show invalids
             }
         }
-
-        // assign data for the view
-        $this->formdata = $form;
+        
+        // assign data for the view, and done
+        $this->formdata = $item->form($cols);
         $this->backlink = $uri;
     }
     
@@ -600,40 +551,44 @@
      * @return void
      * 
      */
-    public function actionTag($tags = null)
+    public function actionTag($tag_list = null)
     {
-        // allow uri to set the "count" for each page (default 10)
-        $this->_bookmarks->setPaging($this->_query('paging', 10));
-
-        // the requested owner_handle (none)
-        $owner_handle = null;
-
-        // the requested ordering of list results
-        $order = $this->_getOrder();
-
-        // what page-number of the results are we looking for?
-        // (regardless of RSS or HTML)
-        $page = $this->_query('page', 1);
-
-        // get the list of results
-        $this->list = $this->_bookmarks->fetchAll($tags, $owner_handle, $order, $page);
-
+        // params for the query
+        $params = array(
+            'where'  => array(
+                // only this area
+                'bookmarks.area_id = ?'      => $this->area->id,
+            ),
+            'order'  => $this->_getSqlOrder(),
+            'paging' => $this->_query('paging', 10),
+            'page'   => $this->_query('page', 1),
+            'eager'  => array('taggings', 'tags'),
+        );
+        
+        // get the list of bookmarks
+        $this->list = $this->_bookmarks->fetchAllByTags($tag_list, $params);
+        
         // get the total pages and row-count
-        $total = $this->_bookmarks->countPages($tags, $owner_handle);
-
+        $total = $this->_bookmarks->countPagesByTags($tag_list, $params);
+        
         // flash forward the backlink in case we go to edit
         $this->_session->setFlash('backlink', $this->_request->server('REQUEST_URI'));
-
+        
+        // assign the list of tags in use
+        $this->tags_in_use   = $this->_tags->fetchAllWithCount(array(
+            'order' => 'tags.name'
+        ));
+        
         // assign everything else for the view
+        $this->count         = $total['count'];
         $this->pages         = $total['pages'];
-        $this->order         = $this->_request->get('order', 'created_desc');
-        $this->page          = $page;
+        $this->order         = $this->_query('order');
+        $this->page          = $params['page'];
         $this->owner_handle  = null; // requested owner_handle
-        $this->tags          = $tags; // the requested tags
-        $this->tags_in_use   = $this->_bookmarks->fetchTags($owner_handle); // all tags
+        $this->tags          = $tag_list; // the requested tags
         $this->feed['title'] = 'tag';
-        $this->feed['descr'] = $this->tags;
-
+        $this->feed['descr'] = $tag_list;
+        
         // set the view
         $this->_view = 'browse';
     }
@@ -644,41 +599,62 @@
      * 
      * @param string $owner_handle The owner to show bookmarks for.
      * 
-     * @param string|array $tags An optional set of tags to filter by;
+     * @param string|array $tag_list An optional set of tags to filter by;
      * either a space- (or plus-) separated list of tags, or a
      * sequential array of tags.
      * 
      * @return void
      * 
      */
-    public function actionUser($owner_handle = null, $tags = null)
+    public function actionUser($owner_handle = null, $tag_list = null)
     {
+        // must have passed an owner handle
+        if (! $owner_handle) {
+            $this->errors[] = 'ERR_NO_OWNER_HANDLE';
+            return $this->_forward('error');
+        }
         
-        // allow uri to set the "count" for each page (default 10)
-        $this->_bookmarks->setPaging($this->_query('paging', 10));
-
-        // the requested ordering of list results
-        $order = $this->_getOrder();
-
-        // which page number?
-        $page = $this->_query('page', 1);
-
-        // get the list of results
-        $this->list = $this->_bookmarks->fetchAll($tags, $owner_handle, $order, $page);
-
-        // get the total pages and row-count
-        $total = $this->_bookmarks->countPages($tags, $owner_handle);
-
+        // params for the query
+        $params = array(
+            'where'  => array(
+                // only this area
+                'bookmarks.area_id = ?'      => $this->area->id,
+                // only the specified user
+                'bookmarks.owner_handle = ?' => $owner_handle,
+            ),
+            'order'  => $this->_getSqlOrder(),
+            'paging' => $this->_query('paging', 10),
+            'page'   => $this->_query('page', 1),
+            'eager'  => array('taggings', 'tags'),
+        );
+        
+        // tags or no-tags?
+        if ($tag_list) {
+            $this->list = $this->_bookmarks->fetchAllByTags($tag_list, $params);
+            $total = $this->_bookmarks->countPagesByTags($tag_list, $params);
+        } else {
+            $this->list = $this->_bookmarks->fetchAll($params);
+            $total = $this->_bookmarks->countPages($params);
+        }
+        
         // flash forward the backlink in case we go to edit
         $this->_session->setFlash('backlink', $this->_request->server('REQUEST_URI'));
-
-        // assign view vars
+        
+        // assign the list of tags in use
+        $this->tags_in_use = $this->_tags->fetchAllByOwnerHandle(
+            $owner_handle,
+            array(
+            'order' => 'tags.name'
+            )
+        );
+        
+        // assign remaining view vars
+        $this->count         = $total['count'];
         $this->pages         = $total['pages'];
-        $this->order         = $this->_request->get('order', 'created_desc');
-        $this->page          = $page;
+        $this->order         = $this->_query('order');
+        $this->page          = $params['page'];
         $this->owner_handle  = $owner_handle; // requested owner_handle
-        $this->tags          = $tags; // the requested tags
-        $this->tags_in_use   = $this->_bookmarks->fetchTags($owner_handle); // all tags for this user
+        $this->tags          = $tag_list; // the requested tags
         $this->feed['title'] = 'user';
         $this->feed['descr'] = $this->owner_handle . '/' . $this->tags;
         




More information about the Solar-svn mailing list