e3adf55f272f8fd722749ac7937fd2ff9a50e4aa

Author: Jeff Loiselle

Date: 2008-12-14 20:20:04 -0500

added support for tags

diff --git a/controllers/content_controller.php b/controllers/content_controller.php index 2cffed7..3f7446e 100644 --- a/controllers/content_controller.php +++ b/controllers/content_controller.php @@ -62,9 +62,10 @@ class ContentController extends AppController { } } $categories = $this->Content->Category->find('list'); + $tags = $this->Content->Tag->find('list'); $statuses = $this->Content->Status->find('list'); $commentables = array(1 => 'Yes', 0 => 'No'); - $this->set(compact('categories', 'statuses', 'commentables')); + $this->set(compact('categories', 'statuses', 'commentables', 'tags')); } function admin_edit($id = null) { @@ -84,9 +85,10 @@ class ContentController extends AppController { $this->data = $this->Content->read(null, $id); } $categories = $this->Content->Category->find('list'); + $tags = $this->Content->Tag->find('list'); $statuses = $this->Content->Status->find('list'); $commentables = array(1 => 'Yes', 0 => 'No'); - $this->set(compact('categories', 'statuses', 'commentables')); + $this->set(compact('categories', 'statuses', 'commentables', 'tags')); } function admin_delete($id = null) { diff --git a/controllers/install_controller.php b/controllers/install_controller.php index f0b8186..d43b953 100644 --- a/controllers/install_controller.php +++ b/controllers/install_controller.php @@ -47,6 +47,9 @@ class InstallController extends AppController { // create initital user $this->User->save($this->data['User'], false); + // populate initial status table data + $this->__populateStatusTables(); + $this->redirect('/'); } else { @@ -56,6 +59,18 @@ class InstallController extends AppController { } /** + * fills status tables with data + */ + function __populateStatusTables() { + $data = array( + 1 => 'Published', + 2 => 'Draft' + ); + $this->Status = ClassRegistry::init('Status'); + $this->Status->save($data); + } + + /** * creates database.php files */ function index() { diff --git a/controllers/tags_controller.php b/controllers/tags_controller.php new file mode 100644 index 0000000..e19e8dd --- /dev/null +++ b/controllers/tags_controller.php @@ -0,0 +1,66 @@ +<?php + +class TagsController extends AppController { + + var $helpers = array('Paginator'); + + /** + * shows all tags + */ + function admin_index() { + $this->set('tags', $this->paginate()); + } + + /** + * creates a tag + */ + function admin_add() { + if (!empty($this->data)) { + if ($this->Tag->save($this->data)) { + $this->Session->setFlash(__('Successfully saved tag', true)); + $this->redirect('/admin/tags'); + } else { + $this->Session->setFlash(__('Failed to save tags', true), null, null, 'error'); + } + } + } + + /** + * deletes a tag + */ + function admin_delete($id) { + if (!$id) { + $this->Session->setFlash(__('That tag does not exist', true), null, null, 'error'); + $this->redirect($this->referer()); + } + if ($this->Tag->del($id)) { + $this->Session->setFlash(__('Successfully deleted tag', true)); + $this->redirect($this->referer()); + } else { + $this->Session->setFlash(__('Failed to delete tag', true), null, null, 'error'); + } + } + + /** + * edits a tag + */ + function admin_edit($id = null) { + if (!$id && empty($this->data['Category']['id'])) { + $this->Session->setFlash(__('That tag does not exist', true), null, null, 'error'); + $this->redirect($this->referer()); + } + if (!empty($this->data)) { + if ($this->Tag->save($this->data)) { + $this->Session->setFlash(__('Successfully saved tag', true)); + $this->redirect('/admin/tags'); + } else { + $this->Session->setFlash(__('Failed to save tag', true), null, null, 'error'); + } + } else { + $this->data = $this->Tag->read(null, $id); + } + } + +} + +?> \ No newline at end of file diff --git a/models/content.php b/models/content.php index 579e7ec..126a851 100644 --- a/models/content.php +++ b/models/content.php @@ -5,7 +5,7 @@ class Content extends AppModel { var $actsAs = array('Sluggable'); var $hasMany = array('Comment'); var $belongsTo = array('Status', 'User'); - var $hasAndBelongsToMany = array('Category'); + var $hasAndBelongsToMany = array('Category', 'Tag'); var $validate = array( 'title' => array( diff --git a/models/tag.php b/models/tag.php new file mode 100644 index 0000000..428722e --- /dev/null +++ b/models/tag.php @@ -0,0 +1,14 @@ +<?php + +class Tag extends AppModel { + + var $validate = array( + 'name' => array( + 'rule' => array('custom', '/^[A-Za-z\- ]+$/'), + 'message' => 'Only letters, spaces, and hyphens allowed' + ) + ); + +} + +?> \ No newline at end of file diff --git a/tmp/cache/models/empty b/tmp/cache/models/empty old mode 100644 new mode 100755 diff --git a/tmp/cache/persistent/empty b/tmp/cache/persistent/empty old mode 100644 new mode 100755 diff --git a/tmp/cache/views/empty b/tmp/cache/views/empty old mode 100644 new mode 100755 diff --git a/tmp/logs/empty b/tmp/logs/empty old mode 100644 new mode 100755 diff --git a/views/content/admin_add.ctp b/views/content/admin_add.ctp index aa7d3a1..928f0ce 100644 --- a/views/content/admin_add.ctp +++ b/views/content/admin_add.ctp @@ -10,6 +10,7 @@ echo $form->input('redirect_code'); echo $form->input('redirect_url'); echo $form->input('Category'); + echo $form->input('Tag'); ?> </fieldset> <?php echo $form->end('Create');?> diff --git a/views/content/admin_edit.ctp b/views/content/admin_edit.ctp index 7da05fa..397d371 100644 --- a/views/content/admin_edit.ctp +++ b/views/content/admin_edit.ctp @@ -11,6 +11,7 @@ echo $form->input('redirect_code'); echo $form->input('redirect_url'); echo $form->input('Category'); + echo $form->input('Tag'); ?> </fieldset> <?php echo $form->end('Update');?> diff --git a/views/layouts/admin.ctp b/views/layouts/admin.ctp index d9f49ea..98ba3ed 100644 --- a/views/layouts/admin.ctp +++ b/views/layouts/admin.ctp @@ -106,7 +106,17 @@ </ul> </div> </div> - </li> + </li> + <li class="yuimenuitem"><a class="yuimenuitemlabel" href="#">Tags</a> + <div id="" class="yuimenu"> + <div class="bd"> + <ul class="first-of-type"> + <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<?php print Router::url('/admin/tags/add') ?>">Create Tag</a></li> + <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<?php print Router::url('/admin/tags/') ?>">Manage Tags</a></li> + </ul> + </div> + </div> + </li> </ul> </div> </div> diff --git a/views/tags/admin_add.ctp b/views/tags/admin_add.ctp new file mode 100644 index 0000000..1923fb9 --- /dev/null +++ b/views/tags/admin_add.ctp @@ -0,0 +1,6 @@ +<fieldset> + <legend><?php __('Add Tag') ?></legend> + <?php print $form->create('Tag', array('url' => '/admin/tags/add')) ?> + <?php print $form->input('name')?> + <?php print $form->end('Add') ?> +</fieldset> \ No newline at end of file diff --git a/views/tags/admin_edit.ctp b/views/tags/admin_edit.ctp new file mode 100644 index 0000000..084025e --- /dev/null +++ b/views/tags/admin_edit.ctp @@ -0,0 +1,7 @@ +<fieldset> + <legend><?php __('Edit Tag') ?></legend> + <?php print $form->create('Tag', array('url' => '/admin/tags/edit')) ?> + <?php print $form->hidden('id') ?> + <?php print $form->input('name')?> + <?php print $form->end('Update ') ?> +</fieldset> \ No newline at end of file diff --git a/views/tags/admin_index.ctp b/views/tags/admin_index.ctp new file mode 100644 index 0000000..3a396c5 --- /dev/null +++ b/views/tags/admin_index.ctp @@ -0,0 +1,27 @@ +<h2><?php __('Tags') ?></h2> +<p> +<?php +echo $paginator->counter(array( +'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) +)); +?></p> +<table> + <tr> + <th><?php print $paginator->sort('name') ?></th> + <th></th> + </tr> + <?php foreach ($tags as $l) { ?> + <tr> + <td><?php print $l['Tag']['name']?></td> + <td> + <?php print $html->link('Edit', '/admin/tags/edit/'.$l['Tag']['id']) ?> + <?php print $html->link('Delete', '/admin/tags/delete/'.$l['Tag']['id'], null, 'Are you sure?') ?> + </td> + </tr> + <?php } ?> +</table> +<div class="paging"> + <?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> + | <?php echo $paginator->numbers();?> + <?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?> +</div> \ No newline at end of file