[Solar-svn] Revision 2747
pmjones at solarphp.com
pmjones at solarphp.com
Sat Sep 8 11:46:11 CDT 2007
branch: Solar_App: [BRK] many breaks to start making Solar_App use the new model system, vice the old content system
Modified: branches/orm/Solar/App/Base.php
===================================================================
--- branches/orm/Solar/App/Base.php 2007-09-08 16:45:19 UTC (rev 2746)
+++ branches/orm/Solar/App/Base.php 2007-09-08 16:46:11 UTC (rev 2747)
@@ -167,11 +167,6 @@
Solar::register('sql', Solar::factory('Solar_Sql'));
}
- // register a Solar_Content object if not already.
- if (! Solar::isRegistered('content')) {
- Solar::register('content', Solar::factory('Solar_Content'));
- }
-
// register a Solar_User object if not already.
// this will trigger the authentication process.
if (! Solar::isRegistered('user')) {
Modified: branches/orm/Solar/App/Bookmarks/Layout/_local.php
===================================================================
--- branches/orm/Solar/App/Bookmarks/Layout/_local.php 2007-09-08 16:45:19 UTC (rev 2746)
+++ branches/orm/Solar/App/Bookmarks/Layout/_local.php 2007-09-08 16:46:11 UTC (rev 2747)
@@ -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',
);
Modified: branches/orm/Solar/App/Bookmarks.php
===================================================================
--- branches/orm/Solar/App/Bookmarks.php 2007-09-08 16:45:19 UTC (rev 2746)
+++ branches/orm/Solar/App/Bookmarks.php 2007-09-08 16:46:11 UTC (rev 2747)
@@ -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
@@ -172,15 +176,8 @@
* @var Solar_User
*
*/
- protected $_user;
+ public $user;
- /**
- *
- * A bookmarks node interaction manager.
- *
- * @var Solar_Content_Bookmarks
- *
- */
protected $_bookmarks;
/**
@@ -198,28 +195,26 @@
{
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');
+
}
/**
@@ -240,12 +235,12 @@
case 'created_asc':
case 'ts':
case 'ts_asc':
- $order = 'nodes.created ASC';
+ $order = 'bookmarks.created ASC';
break;
case 'created_desc':
case 'ts_desc':
- $order = 'nodes.created DESC';
+ $order = 'bookmarks.created DESC';
break;
// title
@@ -253,35 +248,22 @@
case 'subj_asc':
case 'title':
case 'title_asc':
- $order = 'LOWER(nodes.subj) ASC';
+ $order = 'LOWER(bookmarks.subj) ASC';
break;
case 'subj_desc':
case 'title_desc':
- $order = 'LOWER(nodes.subj) DESC';
+ $order = 'LOWER(bookmarks.subj) 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';
break;
case 'pos_desc':
- $order = 'nodes.pos DESC';
+ $order = 'bookmarks.pos DESC';
break;
// owner handle (username)
@@ -289,17 +271,17 @@
case 'owner_asc':
case 'user':
case 'user_asc':
- $order = 'LOWER(nodes.owner_handle) ASC';
+ $order = 'LOWER(bookmarks.owner_handle) ASC';
break;
case 'owner_desc':
case 'user_desc':
- $order = 'LOWER(nodes.owner_handle) DESC';
+ $order = 'LOWER(bookmarks.owner_handle) DESC';
break;
// default
default:
- $order = 'nodes.created DESC';
+ $order = 'bookmarks.created DESC';
break;
}
@@ -317,7 +299,7 @@
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');
}
@@ -327,65 +309,47 @@
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', 'pos');
+
+ // get a blank bookmark, then populate with submitted data
$item = $this->_bookmarks->fetchNew();
- $form = $this->_bookmarks->form($item);
+ $data = $this->_request->post('bookmarks', array());
+ $item->load($data, $cols);
- // now populate the the submitted POST values to the form
- $form->populate();
+ // force these values
+ $item->area_id = $this->area->id;
+ $item->owner_handle = $this->user->auth->handle;
+ $item->editor_handle = $this->user->auth->handle;
- // ---------------------------------------------------------------------
- //
- // processes
- //
-
// Process: save
- if ($this->_isProcess('save') && $form->validate()) {
-
- // load data from the form input
- $item->load($form->values('bookmark'));
+ if ($this->_isProcess('save')) {
- // force these values
- $item->owner_handle = $this->_user->auth->handle;
- $item->editor_handle = $this->_user->auth->handle;
-
- // save the data
- try {
-
- $item->save();
+ // attempt the save; this will also run filters on it
+ if ($item->save()) {
+ // success!
+ // redirect to the "edit" page
$this->_session->setFlash('add_ok', true);
+ die('success');
$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();
-
+ } else {
+ // validation or save failed
}
}
- // OP: Cancel
+ // Process: 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;
}
@@ -401,100 +365,100 @@
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');
}
+ // fetch the bookmark
+ $item = $this->_bookmarks->fetch($id);
+
+ // 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->fetch($id);
- if ($this->_user->auth->handle != $item->owner_handle) {
+ 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);
+ // which record cols do we want to work with?
+ $cols = array('uri', 'subj', 'summ', 'pos');
- // now populate the the submitted POST values to the form
- $form->populate();
+ // load from posted data
+ $data = $this->_request->post('bookmarks', array());
+ $item->load($data, $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');
- }
+ // 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') && $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 {
+ // -------------------------------------------------------------------
+ //
+ // processes
+ //
- // attempt the save, may throw an exception
- $item->save();
-
- } catch (Solar_Sql_Table_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();
-
- // add bookmark[*] element feedback
- $form->addFeedback($e->getInfo(), 'bookmark');
+ // save
+ if ($this->_isProcess('save')) {
+
+ if ($item->save()) {
+ // do nothing
+ } else {
+ // // 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');
}
+
}
- // 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);
}
@@ -503,140 +467,149 @@
// completion
//
- // assign data for the view
- $this->formdata = $form;
- $this->backlink = $href;
- }
-
- /**
- *
- * Handles JavaScript bookmarking requests from offsite.
- *
- * @param string $uri The URI to bookmark.
- *
- * @param string $subj The title for the bookmark, typically the
- * page title from the bookmarked page.
- *
- * @return void
- *
- */
- public function actionQuick($uri = null, $subj = null)
- {
- // must be logged in to proceed
- if (! $this->_user->auth->isValid()) {
- $this->errors[] = 'ERR_NOT_LOGGED_IN';
- return $this->_forward('error');
- }
+ // get the form
+ $form = $item->form($cols);
- // 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,
- $uri
- );
-
- // if the user *does* already have that URI bookmarked,
- // redirect to the existing bookmark.
- if (! empty($existing->id)) {
- $this->_session->setFlash('backlink', $uri);
- $this->_redirect("bookmarks/edit/{$existing['id']}");
+ // 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');
}
- // get a blank bookmark item, build the basic form
- $item = $this->_bookmarks->fetchNew();
- $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();
-
- // redirect to the source URI (external)
- $this->_redirect($item->uri);
-
- } 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;
-
- }
- }
-
// assign data for the view
$this->formdata = $form;
- $this->backlink = $uri;
+ $this->backlink = $href;
}
- /**
- *
- * Shows a list of bookmarks filtered by tag, regardless of owner.
- *
- * @param string|array $tags The tags to show; either a space- (or
- * plus-) separated list of tags, or a sequential array of tags.
- *
- * @return void
- *
- */
- public function actionTag($tags = 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);
-
- // get the total pages and row-count
- $total = $this->_bookmarks->countPages($tags, $owner_handle);
-
- // flash forward the backlink in case we go to edit
- $this->_session->setFlash('backlink', $this->_request->server('REQUEST_URI'));
-
- // assign everything else for the view
- $this->pages = $total['pages'];
- $this->order = $this->_request->get('order', 'created_desc');
- $this->page = $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->feed['title'] = 'tag';
- $this->feed['descr'] = $this->tags;
-
- // set the view
- $this->_view = 'browse';
- }
+ // /**
+ // *
+ // * Handles JavaScript bookmarking requests from offsite.
+ // *
+ // * @param string $uri The URI to bookmark.
+ // *
+ // * @param string $subj The title for the bookmark, typically the
+ // * page title from the bookmarked page.
+ // *
+ // * @return void
+ // *
+ // */
+ // public function actionQuick($uri = null, $subj = null)
+ // {
+ // // must be logged in to proceed
+ // 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,
+ // $uri
+ // );
+ //
+ // // if the user *does* already have that URI bookmarked,
+ // // redirect to the existing bookmark.
+ // if (! empty($existing->id)) {
+ // $this->_session->setFlash('backlink', $uri);
+ // $this->_redirect("bookmarks/edit/{$existing['id']}");
+ // }
+ //
+ // // get a blank bookmark item, build the basic form
+ // $item = $this->_bookmarks->fetchNew();
+ // $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();
+ //
+ // // redirect to the source URI (external)
+ // $this->_redirect($item->uri);
+ //
+ // } 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;
+ //
+ // }
+ // }
+ //
+ // // assign data for the view
+ // $this->formdata = $form;
+ // $this->backlink = $uri;
+ // }
+ // /**
+ // *
+ // * Shows a list of bookmarks filtered by tag, regardless of owner.
+ // *
+ // * @param string|array $tags The tags to show; either a space- (or
+ // * plus-) separated list of tags, or a sequential array of tags.
+ // *
+ // * @return void
+ // *
+ // */
+ // public function actionTag($tags = 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);
+ //
+ // // get the total pages and row-count
+ // $total = $this->_bookmarks->countPages($tags, $owner_handle);
+ //
+ // // flash forward the backlink in case we go to edit
+ // $this->_session->setFlash('backlink', $this->_request->server('REQUEST_URI'));
+ //
+ // // assign everything else for the view
+ // $this->pages = $total['pages'];
+ // $this->order = $this->_request->get('order', 'created_desc');
+ // $this->page = $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->feed['title'] = 'tag';
+ // $this->feed['descr'] = $this->tags;
+ //
+ // // set the view
+ // $this->_view = 'browse';
+ // }
+
/**
*
* Shows all bookmarks for an owner, optionally filtered by tag.
@@ -652,32 +625,41 @@
*/
public function actionUser($owner_handle = null, $tags = null)
{
+ // must have passed an own
+ 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));
+ // params for the query
+ $params = array(
+ 'where' => array(
+ // only this area
+ 'area_id = ?' => $this->area->id,
+ // only the specified user
+ 'owner_handle = ?' => $owner_handle,
+ ),
+ 'order' => $this->_getOrder(),
+ 'paging' => $this->_query('paging', 10),
+ 'page' => $this->_query('page', 1),
+ );
- // the requested ordering of list results
- $order = $this->_getOrder();
+ // get the list of bookmarks
+ $this->list = $this->_bookmarks->fetchAll($params);
- // which page number?
- $page = $this->_query('page', 1);
+ // get the total record-count and pages
+ $total = $this->_bookmarks->countPages($params);
- // 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);
-
// flash forward the backlink in case we go to edit
$this->_session->setFlash('backlink', $this->_request->server('REQUEST_URI'));
// assign view vars
$this->pages = $total['pages'];
$this->order = $this->_request->get('order', 'created_desc');
- $this->page = $page;
+ $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_in_use = array(); // $this->_bookmarks->fetchTags($owner_handle); // all tags for this user
$this->feed['title'] = 'user';
$this->feed['descr'] = $this->owner_handle . '/' . $this->tags;
More information about the Solar-svn
mailing list