Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 7 commits
  • 13 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 30, 2012
@bjyoungblood bjyoungblood update/create thread/message methods in service 2329502
@bjyoungblood bjyoungblood added phpdoc d29546c
@bjyoungblood bjyoungblood events for message and thread creation 5dad116
@bjyoungblood bjyoungblood create methods should return updated thread/message, and create threa…
…d should also create a message (the initial message)
1a823ff
@bjyoungblood bjyoungblood have to extend EventProvider in ZfcBase a5d5a61
Commits on Apr 03, 2012
@EvanDotPro Merge remote-tracking branch 'bjyoungblood/master' d4a5b8e
Commits on Apr 19, 2012
@EvanDotPro 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
e3c4745
View
5 Module.php
@@ -4,9 +4,10 @@
use Zend\Module\Manager,
Zend\EventManager\StaticEventManager,
- Zend\Module\Consumer\AutoloaderProvider;
+ Zend\Module\Consumer\AutoloaderProvider,
+ ZfcBase\EventManager\EventProvider;
-class Module implements AutoloaderProvider
+class Module extends EventProvider implements AutoloaderProvider
{
protected static $options;
View
32 config/module.config.php
@@ -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
16 data/schema.sql
@@ -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;
View
10 src/EdpDiscuss/Model/Message/Message.php
@@ -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;
}
View
4 src/EdpDiscuss/Model/Message/MessageInterface.php
@@ -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.
View
107 src/EdpDiscuss/Model/Tag/Tag.php
@@ -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;
+ }
+}
View
48 src/EdpDiscuss/Model/Tag/TagInterface.php
@@ -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);
+}
View
29 src/EdpDiscuss/Model/Tag/TagMapper.php
@@ -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;
+ }
+}
View
14 src/EdpDiscuss/Model/Tag/TagMapperInterface.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace EdpDiscuss\Model\Tag;
+
+interface TagMapperInterface
+{
+ /**
+ * getTagById
+ *
+ * @param int $tagId
+ * @return TagInterface
+ */
+ public function getTagById($tagId);
+}
View
47 src/EdpDiscuss/Model/Thread/Thread.php
@@ -3,6 +3,7 @@
namespace EdpDiscuss\Model\Thread;
use ZfcBase\Model\ModelAbstract,
+ Bacon\Text\Slugifier\Slugifier,
EdpDiscuss\Model\Message\MessageInterface;
class Thread extends ModelAbstract implements ThreadInterface
@@ -18,6 +19,11 @@ class Thread extends ModelAbstract implements ThreadInterface
protected $subject;
/**
+ * @var string
+ */
+ protected $slug;
+
+ /**
* @var MessageInterface
*/
protected $originalMessage;
@@ -28,6 +34,11 @@ class Thread extends ModelAbstract implements ThreadInterface
protected $latestMessage;
/**
+ * @var Slugifier
+ */
+ protected $slugifier;
+
+ /**
* Get threadId.
*
* @return threadId
@@ -66,6 +77,28 @@ public function getSubject()
public function setSubject($subject)
{
$this->subject = $subject;
+ $this->setSlug($this->getSlugifier()->slugify($subject));
+ return $this;
+ }
+
+ /**
+ * Get slug.
+ *
+ * @return slug
+ */
+ public function getSlug()
+ {
+ return $this->slug;
+ }
+
+ /**
+ * Set slug.
+ *
+ * @param $slug the value to be set
+ */
+ public function setSlug($slug)
+ {
+ $this->slug = $slug;
return $this;
}
@@ -110,4 +143,18 @@ public function setLatestMessage(MessageInterface $latestMessage)
$this->latestMessage = $latestMessage;
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;
+ }
}
View
14 src/EdpDiscuss/Model/Thread/ThreadInterface.php
@@ -35,6 +35,20 @@ public function getSubject();
public function setSubject($subject);
/**
+ * Get slug.
+ *
+ * @return slug
+ */
+ public function getSlug();
+
+ /**
+ * Set slug.
+ *
+ * @param $slug the value to be set
+ */
+ public function setSlug($slug);
+
+ /**
* Get originalMessage.
*
* @return MessageInterface
View
27 src/EdpDiscuss/Model/Thread/ThreadMapper.php
@@ -3,7 +3,8 @@
namespace EdpDiscuss\Model\Thread;
use ZfcBase\Mapper\DbMapperAbstract,
- EdpDiscuss\Module as EdpDiscuss;
+ EdpDiscuss\Module as EdpDiscuss,
+ Zend\Db\Sql\Select;
class ThreadMapper extends DbMapperAbstract implements ThreadMapperInterface
{
@@ -19,10 +20,15 @@ class ThreadMapper extends DbMapperAbstract implements ThreadMapperInterface
public function getThreadById($threadId)
{
$rowset = $this->getTableGateway()->select(array($this->threadIDField => $threadId));
+
+ if (count($rowset) === 0) {
+ return false;
+ }
+
$row = $rowset->current();
$threadClass = EdpDiscuss::getOption('thread_model_class');
- $thread = $threadClass::fromArray($row);
+ $thread = $threadClass::fromArray($row->getArrayCopy());
return $thread;
}
@@ -34,9 +40,22 @@ public function getThreadById($threadId)
* @param int $offset
* @return array of ThreadInterface's
*/
- public function getLatestThreads($limit = 25, $offset = 0)
+ public function getLatestThreads($limit = 25, $offset = 0, $tagId = false)
{
- $rowset = $this->getTableGateway()->select();
+ if ($tagId) {
+ $select = new Select();
+ // @TODO: Join the original and latest messages
+ $select->from('discuss_thread')
+ ->join('discuss_thread_tag', 'discuss_thread_tag.thread_id = discuss_thread.thread_id')
+ ->where(array('tag_id = ?' => $tagId));
+ $rowset = $this->getTableGateway()->selectWith($select);
+ } else {
+ $rowset = $this->getTableGateway()->select();
+ }
+
+ if (count($rowset) === 0) {
+ return false;
+ }
$threadClass = EdpDiscuss::getOption('thread_model_class');
$threads = $threadClass::fromArraySet($rowset->toArray());
View
125 src/EdpDiscuss/Service/Discuss.php
@@ -6,6 +6,8 @@
EdpDiscuss\Model\Message\MessageMapperInterface,
EdpDiscuss\Model\Thread\ThreadInterface,
EdpDiscuss\Model\Thread\ThreadMapperInterface,
+ EdpDiscuss\Model\Tag\TagInterface,
+ EdpDiscuss\Model\Tag\TagMapperInterface,
ZfcUser\Module as ZfcUser;
class Discuss {
@@ -20,15 +22,111 @@ class Discuss {
*/
protected $messageMapper;
- public function getLatestThreads($limit = 25, $offset = 0)
+ /**
+ * @var TagMapperInterface
+ */
+ protected $tagMapper;
+
+ /**
+ * getLatestThreads
+ *
+ * @param int $limit
+ * @param int $offset
+ * @param int $tagId
+ * @return array
+ */
+ public function getLatestThreads($limit = 25, $offset = 0, $tagId = false)
{
- return $this->threadMapper->getLatestThreads($limit, $offset);
+ return $this->threadMapper->getLatestThreads($limit, $offset, $tagId);
}
- public function getMessagesByThread($thread, $limit = 25, $offset = 0)
+ /**
+ * getMessagesByThread
+ *
+ * @param ThreadInterface $thread
+ * @param int $limit
+ * @param int $offset
+ * @return array
+ */
+ public function getMessagesByThread(ThreadInterface $thread, $limit = 25, $offset = 0)
{
return $this->messageMapper->getMessagesByThread($thread->getThreadId(), $limit, $offset);
}
+
+ /**
+ * createThread
+ *
+ * @param ThreadInterface $thread
+ * @return ThreadInterface
+ */
+ public function createThread(ThreadInterface $thread, MessageInterface $message)
+ {
+ $message = $this->messageMapper->persist($message);
+
+ $thread->setOriginalMessage($message);
+ $thread = $this->threadMapper->persist($thread);
+
+ $this->events()->trigger(__FUNCTION__, $this, array('thread' => $thread));
+
+ return $thread;
+ }
+
+ /**
+ * updateThread
+ *
+ * @param ThreadInterface $thread
+ * @return ThreadInterface
+ */
+ public function updateThread(ThreadInterface $thread)
+ {
+ return $this->threadMapper->persist($thread);
+ }
+
+ /**
+ * createMessage
+ *
+ * @param MessageInterface $message
+ * @return MessageInterface
+ */
+ public function createMessage(MessageInterface $message)
+ {
+ $message = $this->messageMapper->persist($message);
+ $this->events()->trigger(__FUNCTION__, $this, array('message' => $message));
+ return $message;
+ }
+
+ /**
+ * updateMessage
+ *
+ * @param MessageInterface $message
+ * @return MessageInterface
+ */
+ public function updateMessage(MessageInterface $message)
+ {
+ return $this->messageMapper->persist($message);
+ }
+
+ /**
+ * getTagById
+ *
+ * @param int $tagId
+ * @return TagInterface
+ */
+ public function getTagById($tagId)
+ {
+ return $this->tagMapper->getTagById($tagId);
+ }
+
+ /**
+ * getThreadById
+ *
+ * @param int $threadId
+ * @return ThreadInterface
+ */
+ public function getThreadById($threadId)
+ {
+ return $this->threadMapper->getThreadById($threadId);
+ }
/**
* getThreadMapper
@@ -73,4 +171,25 @@ public function setMessageMapper($messageMapper)
$this->messageMapper = $messageMapper;
return $this;
}
+
+ /**
+ * Get tagMapper.
+ *
+ * @return tagMapper
+ */
+ public function getTagMapper()
+ {
+ return $this->tagMapper;
+ }
+
+ /**
+ * Set tagMapper.
+ *
+ * @param TagMapperInterface $tagMapper the value to be set
+ */
+ public function setTagMapper(TagMapperInterface $tagMapper)
+ {
+ $this->tagMapper = $tagMapper;
+ return $this;
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.