Skip to content
This repository has been archived by the owner on Nov 18, 2017. It is now read-only.
/ fpORMTagging Public archive
forked from imarc/fpORMTagging

Flourish plugin that provides tagging functionality

Notifications You must be signed in to change notification settings

Tatsh/fpORMTagging

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Flourish ORM plugin for tagging

Requires

CREATE TABLE tags (
  tag VARCHAR(255) PRIMARY KEY
);
CREATE TABLE tags_related_table (
  related_table_id INTEGER NOT NULL references related_table(related_table_id) ON DELETE CASCADE,
  tag VARCHAR(255) NOT NULL references tags(tag) ON DELETE RESTRICT ON UPDATE CASCADE,
  PRIMARY KEY (tag, related_table_id)
);

Usage

Add linking table(s) to a tags table (see above tag_related_table for an example).

To initialize, call fpORMTagging::configure() in your init file on whichever tagging class you wish.

Installation on Gentoo

As root:

layman -o http://tatsh.github.com/tatsh-overlay/layman.xml -a tatsh-overlay
emerge --ask --verbose fORMTagging

Example: Tags to blog posts

  • Required table tags
  • Table named blog_posts maps to class BlogPost.
  • Table named blog_post_tags maps to class BlogPostTag
CREATE TABLE tags (
  tag VARCHAR(255) PRIMARY KEY
);

CREATE TABLE blog_posts (
  post_id INTEGER AUTOINCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  content TEXT NOT NULL,
  date_created TIMESTAMP NOT NULL,
  date_updated TIMESTAMP NOT NULL,
  timezone VARCHAR(128) NOT NULL
);

CREATE TABLE blog_post_tags (
  post_id INTEGER NOT NULL REFERENCES blog_posts(post_id) ON DELETE CASCADE ON UPDATE CASCADE,
  tag VARCHAR(255) NOT NULL REFERENCES tags(tag) ON DELETE RESTRICT ON UPDATE CASCADE,
  PRIMARY KEY (tag, post_id)
);
<?php
class Tag extends fActiveRecord {}

class BlogPost extends fActiveRecord {
  protected function configure() {    
    fORMDate::configureDateCreatedColumn($this, 'date_created');
    fORMDate::configureDateUpdatedColumn($this, 'date_updated');
    fORMDate::configureTimezoneColumn($this, 'timezone');
  }
}

class BlogPostTag extends fActiveRecord {
  protected function configure() {
    fORMTagging::configure($this, 'tag', array());
  }
}

Handling a form

<?php // Tags is fRecordSet ?>
<form method="post" action="/blog-post">
  <input type="text" name="title" value="<?php print fRequest::encode('title', 'string', ''); ?>">
  <textarea name="content"></textarea>
  <?php foreach ($tags as $tag): ?>
    <?php $term = $tag->encodeTag(); ?>
    <?php // format for name is underscore_related_table_name::foreign_column_name[] ?>
    <input id="edit-tag-<?php print $term; ?>" type="checkbox" name="blog_post_tags::tag[]" value="<?php print $term; ?>">
    <label for="edit-tag-<?php print $term; ?>"><?php print $term; ?></label>
  <?php endforeach; ?>
  <input type="submit" name="action" value="<?php print fHTML::encode('Create New Blog Post'); ?>">
</form>

Code to handle this request

<?php
$blog_post = new BlogPost;
$blog_post->populate();
$blog_post->linkTags();
$blog_post->store();

About

Flourish plugin that provides tagging functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%