Permalink
Browse files

Add thread tags and slugs

- Add thread tags to group threads logically for an application
- Add slug field to thread and tag
- Introduces dependency on @DASPRiD's Bacon module for now for slugifier
  • Loading branch information...
1 parent d4a5b8e commit e3c47452f2e0559787f166614bad9fd47f37ed48 @EvanDotPro committed Apr 19, 2012
View
@@ -1,20 +1,22 @@
<?php
return array(
'edpdiscuss' => array(
- 'thread_model_class' => 'EdpDiscuss\Model\Thread\Thread',
- 'message_model_class' => 'EdpDiscuss\Model\Message\Message'
+ 'thread_model_class' => 'EdpDiscuss\Model\Thread\Thread',
+ 'message_model_class' => 'EdpDiscuss\Model\Message\Message',
+ 'tag_model_class' => 'EdpDiscuss\Model\Tag\Tag',
),
'di' => array(
'instance' => array(
'alias' => array(
- 'edpdiscuss' => 'EdpDiscuss\Controller\IndexController',
-
+ 'edpdiscuss' => 'EdpDiscuss\Controller\IndexController',
// Default Zend\Db
- 'edpdiscuss_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
- 'edpdiscuss_thread_mapper' => 'EdpDiscuss\Model\Thread\ThreadMapper',
- 'edpdiscuss_message_mapper' => 'EdpDiscuss\Model\Message\MessageMapper',
- 'edpdiscuss_thread_tg' => 'Zend\Db\TableGateway\TableGateway',
- 'edpdiscuss_message_tg' => 'Zend\Db\TableGateway\TableGateway',
+ 'edpdiscuss_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
+ 'edpdiscuss_thread_mapper' => 'EdpDiscuss\Model\Thread\ThreadMapper',
+ 'edpdiscuss_message_mapper' => 'EdpDiscuss\Model\Message\MessageMapper',
+ 'edpdiscuss_tag_mapper' => 'EdpDiscuss\Model\Tag\TagMapper',
+ 'edpdiscuss_thread_tg' => 'Zend\Db\TableGateway\TableGateway',
+ 'edpdiscuss_message_tg' => 'Zend\Db\TableGateway\TableGateway',
+ 'edpdiscuss_tag_tg' => 'Zend\Db\TableGateway\TableGateway',
),
'edpdiscuss' => array(
'parameters' => array(
@@ -25,6 +27,7 @@
'parameters' => array(
'threadMapper' => 'edpdiscuss_thread_mapper',
'messageMapper' => 'edpdiscuss_message_mapper',
+ 'tagMapper' => 'edpdiscuss_tag_mapper',
)
),
'EdpDiscuss\Model\Thread\ThreadMapper' => array(
@@ -37,6 +40,11 @@
'tableGateway' => 'edpdiscuss_message_tg'
),
),
+ 'EdpDiscuss\Model\Tag\TagMapper' => array(
+ 'parameters' => array(
+ 'tableGateway' => 'edpdiscuss_tag_tg'
+ ),
+ ),
'edpdiscuss_thread_tg' => array(
'parameters' => array(
'tableName' => 'discuss_thread',
@@ -49,6 +57,12 @@
'adapter' => 'edpdiscuss_zend_db_adapter',
),
),
+ 'edpdiscuss_tag_tg' => array(
+ 'parameters' => array(
+ 'tableName' => 'discuss_tag',
+ 'adapter' => 'edpdiscuss_zend_db_adapter',
+ ),
+ ),
'Zend\View\Resolver\TemplatePathStack' => array(
'parameters' => array(
'paths' => array(
View
@@ -2,6 +2,7 @@ CREATE TABLE discuss_thread
(
thread_id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
subject VARCHAR(1000) NOT NULL,
+ slug VARCHAR(255) NOT NULL,
first_message_id INTEGER DEFAULT NULL,
latest_message_id INTEGER DEFAULT NULL
) ENGINE=InnoDB;
@@ -37,3 +38,18 @@ CREATE TRIGGER latest_post_time AFTER INSERT ON discuss_message
|
DELIMITER ;
+
+CREATE TABLE discuss_tag
+(
+ tag_id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
+ name VARCHAR(255) NOT NULL,
+ slug VARCHAR(255) NOT NULL
+) ENGINE=InnoDB;
+
+CREATE TABLE discuss_thread_tag
+(
+ thread_id INTEGER NOT NULL,
+ tag_id INTEGER DEFAULT NULL,
+ FOREIGN KEY (thread_id) REFERENCES discuss_thread (thread_id),
+ FOREIGN KEY (tag_id) REFERENCES discuss_tag (tag_id)
+) ENGINE=InnoDB;
@@ -77,11 +77,15 @@ public function getPostTime()
/**
* Set postTime.
*
- * @param DateTime $postTime the value to be set
+ * @param mixed $postTime the value to be set
*/
- public function setPostTime(DateTime $postTime)
+ public function setPostTime($postTime)
{
- $this->postTime = $postTime;
+ if ($postTime instanceof DateTime) {
+ $this->postTime = $postTime;
+ } else {
+ $this->postTime = new DateTime($postTime);
+ }
return $this;
}
@@ -31,9 +31,9 @@ public function getPostTime();
/**
* Set postTime.
*
- * @param DateTime $postTime the value to be set
+ * @param mixed $postTime the value to be set
*/
- public function setPostTime(DateTime $postTime);
+ public function setPostTime($postTime);
/**
* Get authorName.
@@ -0,0 +1,107 @@
+<?php
+
+namespace EdpDiscuss\Model\Tag;
+
+use ZfcBase\Model\ModelAbstract,
+ Bacon\Text\Slugifier\Slugifier;
+
+class Tag extends ModelAbstract implements TagInterface
+{
+ /**
+ * @var int
+ */
+ protected $tagId;
+
+ /**
+ * @var string
+ */
+ protected $name;
+
+ /**
+ * @var string
+ */
+ protected $slug;
+
+ /**
+ * @var Slugifier
+ */
+ protected $slugifier;
+
+ /**
+ * Get tagId.
+ *
+ * @return tagId
+ */
+ public function getTagId()
+ {
+ return $this->tagId;
+ }
+
+ /**
+ * Set tagId.
+ *
+ * @param $tagId the value to be set
+ */
+ public function setTagId($tagId)
+ {
+ $this->tagId = $tagId;
+ return $this;
+ }
+
+ /**
+ * Get name.
+ *
+ * @return name
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set name.
+ *
+ * @param $name the value to be set
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ $this->setSlug($this->getSlugifier()->slugify($name));
+ return $this;
+ }
+
+ /**
+ * Get slug.
+ *
+ * @return slug
+ */
+ public function getSlug()
+ {
+ return $this->slug;
+ }
+
+ /**
+ * Set slug. Protected, use setName() instead
+ *
+ * @param $slug the value to be set
+ */
+ public function setSlug($slug)
+ {
+ $this->slug = $slug;
+ return $this;
+ }
+
+ public function getSlugifier()
+ {
+ if ($this->slugifier === null) {
+ $this->slugifier = new Slugifier;
+ }
+ return $this->slugifier;
+ }
+
+ public function setSlugifier($slugifier)
+ {
+ $this->slugifier = $slugifier;
+ return $this;
+ }
+}
@@ -0,0 +1,48 @@
+<?php
+
+namespace EdpDiscuss\Model\Tag;
+
+interface TagInterface
+{
+ /**
+ * Get tagId.
+ *
+ * @return tagId
+ */
+ public function getTagId();
+
+ /**
+ * Set tagId.
+ *
+ * @param $tagId the value to be set
+ */
+ public function setTagId($tagId);
+
+ /**
+ * Get name.
+ *
+ * @return name
+ */
+ public function getName();
+
+ /**
+ * Set name.
+ *
+ * @param $name the value to be set
+ */
+ public function setName($name);
+
+ /**
+ * Get slug.
+ *
+ * @return slug
+ */
+ public function getSlug();
+
+ /**
+ * Set slug.
+ *
+ * @param $slug the value to be set
+ */
+ public function setSlug($slug);
+}
@@ -0,0 +1,29 @@
+<?php
+
+namespace EdpDiscuss\Model\Tag;
+
+use ZfcBase\Mapper\DbMapperAbstract,
+ EdpDiscuss\Module as EdpDiscuss;
+
+class TagMapper extends DbMapperAbstract implements TagMapperInterface
+{
+ protected $tableName = 'discuss_tag';
+
+ /**
+ * getTagById
+ *
+ * @param int $tagId
+ * @return TagInterface
+ */
+ public function getTagById($tagId)
+ {
+ $rowset = $this->getTableGateway()->select(array('tag_id' => $tagId));
+ $row = $rowset->current();
+ if (!$row) { return false; }
+
+ $tagClass = EdpDiscuss::getOption('tag_model_class');
+ $tag = $tagClass::fromArray($row->getArrayCopy());
+
+ return $tag;
+ }
+}
@@ -0,0 +1,14 @@
+<?php
+
+namespace EdpDiscuss\Model\Tag;
+
+interface TagMapperInterface
+{
+ /**
+ * getTagById
+ *
+ * @param int $tagId
+ * @return TagInterface
+ */
+ public function getTagById($tagId);
+}
Oops, something went wrong.

0 comments on commit e3c4745

Please sign in to comment.