Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Emmanuel Fringant committed Apr 15, 2009
0 parents commit 1a42bd3
Show file tree
Hide file tree
Showing 21 changed files with 2,228 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/sql/tagging.sql
@@ -0,0 +1,19 @@
CREATE TABLE `tags` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci NOT NULL,
`slug` varchar(255) collate utf8_unicode_ci NOT NULL,
`count` int(10) unsigned NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE `tagged` (
`id` int(10) unsigned NOT NULL auto_increment,
`tag_id` int(10) unsigned NOT NULL,
`model` varchar(255) collate utf8_unicode_ci NOT NULL,
`assoc_key` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `tag_id` (`tag_id`),
KEY `model` (`model`),
KEY `assoc_key` (`assoc_key`)
);
13 changes: 13 additions & 0 deletions controllers/tagging_controller.php
@@ -0,0 +1,13 @@
<?php
class TaggingController extends TaggingAppController
{
var $name = 'Tagging';

var $uses = array();

function admin_index()
{

}
}
?>
151 changes: 151 additions & 0 deletions controllers/tags_controller.php
@@ -0,0 +1,151 @@
<?php
class TagsController extends TaggingAppController
{
var $name = 'Tags';

var $paginate = array(
'Tag' => array(
'order' => 'Tag.name ASC',
'limit' => 20
)
);

var $components = array('RequestHandler');

/**
* JSON format tag suggestions based on first letters of tag name
*/
function suggest()
{
if($this->RequestHandler->isAjax() && $this->RequestHandler->isPost())
{
App::import('Core', 'Sanitize');

$first_letters = Sanitize::clean($this->params['form']['tag']);

$this->set('matches', $this->Tag->suggest($first_letters));
}
}

/**
* List Tags
* You have to create a view for this action in {your_app}/views/tags/index.ctp
*/
function index()
{
$this->set('data', $this->paginate());
}

/**
* View Tag
* Checks $this->params['pass'] for tag slug or tag id
* You have to create a view for this action in {your_app}/views/tags/view.ctp
*/
function view()
{
if(!isset($this->params['pass'][0]))
{
$this->cakeError('error404', array(array('url' => $this->action)));
}

$param = $this->params['pass'][0];

if(preg_match('/^\d+$/', $param))
{
$findMethod = 'findById';
}
else
{
$findMethod = 'findBySlug';
}

if(!$data = $this->Tag->{$findMethod}($param))
{
$this->cakeError('error404', array(array('url' => $this->action)));
}

$this->set(compact('data'));
}

/**
* List Tags
*/
function admin_index()
{
$this->set('data', $this->paginate());
}

/**
* Add Tag
*/
function admin_add()
{
if(!empty($this->data))
{
$this->Tag->create();

if($this->Tag->save($this->data))
{
$this->Session->setFlash(__('The Tag has been saved', true));
$this->redirect(array('action'=>'index'));
}
else
{
$this->Session->setFlash(__('The Tag could not be saved. Please, try again.', true));
}
}
}

/**
* Edit Tag
*
* @param int $id Tag id
*/
function admin_edit($id = null)
{
if(!$id && empty($this->data))
{
$this->Session->setFlash(__('Invalid Tag', true));
$this->redirect(array('action'=>'index'));
}

if(!empty($this->data))
{
if($this->Tag->save($this->data))
{
$this->Session->setFlash(__('The Tag has been saved', true));
$this->redirect(array('action' => 'index'));
}
else
{
$this->Session->setFlash(__('The Tag could not be saved. Please, try again.', true));
}
}

if(empty($this->data))
{
$this->data = $this->Tag->read(null, $id);
}
}

/**
* Delete Tag
*
* @param int $id Tag id
*/
function admin_delete($id = null)
{
if(!$id)
{
$this->Session->setFlash(__('Invalid id for Tag', true));
}

if($this->Tag->del($id))
{
$this->Session->setFlash(__('Tag deleted', true));
}

$this->redirect(array('action' => 'index'));
}
}
?>

0 comments on commit 1a42bd3

Please sign in to comment.