Skip to content
Open
30 changes: 29 additions & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function getServiceConfig()
$service = new \EdpDiscuss\Service\Discuss;
$service->setThreadMapper($sm->get('edpdiscuss_thread_mapper'))
->setMessageMapper($sm->get('edpdiscuss_message_mapper'))
->setTagMapper($sm->get('edpdiscuss_tag_mapper'));
->setTagMapper($sm->get('edpdiscuss_tag_mapper'))
->setVisitMapper($sm->get('edpdiscuss_visit_mapper'));
return $service;
},
'edpdiscuss_thread_mapper' => function($sm) {
Expand Down Expand Up @@ -66,6 +67,17 @@ public function getServiceConfig()
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
return $mapper;
},
'edpdiscuss_visit_mapper' => function($sm) {
$mapper = new \EdpDiscuss\Model\Visit\VisitMapper;
$visitModelClass = Module::getOption('visit_model_class');
$mapper->setEntityPrototype(new $visitModelClass);
$mapper->setHydrator(new \Zend\StdLib\Hydrator\ClassMethods);
return $mapper;
},
'edpdiscuss_thread' => function ($sm) {
$thread = new \EdpDiscuss\Model\Thread\Thread;
return $thread;
},
'edpdiscuss_message' => function ($sm) {
$message = new \EdpDiscuss\Model\Message\Message;
return $message;
Expand All @@ -74,6 +86,12 @@ public function getServiceConfig()
$form = new \EdpDiscuss\Form\PostForm;
return $form;
},
'edpdiscuss_visit' => function ($sm) {
$visit = new \EdpDiscuss\Model\Visit\Visit;
$visit->setIpAddress($_SERVER['REMOTE_ADDR'])
->setVisitTime(new \DateTime);
return $visit;
}
),
'initializers' => array(
function($instance, $sm){
Expand Down Expand Up @@ -117,4 +135,14 @@ public static function getOption($option)
}
return static::$options[$option];
}

public function getViewHelperConfig()
{
return array(
'invokables' => array(
'RenderForm' => 'EdpDiscuss\View\Helper\RenderForm'
)
);

}
}
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Requirements
------------

* [Zend Framework 2](https://github.com/zendframework/zf2) (latest master)
* [ZfcBase](https://github.com/ZF-Commons/ZfcBase) (latest master).
* [ZfcBase](https://github.com/ZF-Commons/ZfcBase) (latest master)
* [BaconStringUtils] (https://github.com/Bacon/BaconStringUtils)

Installation
------------
Expand All @@ -17,16 +18,44 @@ Installation

1. Install the [ZfcBase](https://github.com/ZF-Commons/ZfcBase) ZF2 module
by cloning it into `./vendor/`.
2. Clone this project into your `./vendor/` directory.
2. Install the [BaconStringUtils] (https://github.com/Bacon/BaconStringUtils) ZF2 module
by cloning it into `./vendor/`.
3. Clone this project into your `./vendor/` directory.


Post Installation
-----------------

Import the SQL schema located in `./vendor/EdpDiscuss/data/schema.sql`.
1. Enabling the modules in your `application.config.php` file.

```php
<?php
return array(
'modules' => array(
// ...
'ZfcBase',
'BaconStringUtils',
'EdpDiscuss',
),
// ...
);
```
2. Import the SQL schema located in `./vendor/EdpDiscuss/data/schema.sql`.


Introduction
------------
EdpDiscuss is a module for Zend Framework 2.


Options
-------

The EdpDiscuss module has various options to allow you to quickly customize the basic functionality.

The following options are available:

- **thread_model_class** - Name of Thread entity class to use.
- **message_model_class** - Name of Message entity class to use.
- **tag_model_class** - Name of Tag entity class to use.
- **visit_model_class** - Name of Visit Entity class to use.
1 change: 1 addition & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'thread_model_class' => 'EdpDiscuss\Model\Thread\Thread',
'message_model_class' => 'EdpDiscuss\Model\Message\Message',
'tag_model_class' => 'EdpDiscuss\Model\Tag\Tag',
'visit_model_class' => 'EdpDiscuss\Model\Visit\Visit'
),
'service_manager' => array(
'aliases' => array(
Expand Down
27 changes: 18 additions & 9 deletions data/schema.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
CREATE TABLE discuss_thread
(
thread_id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
thread_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL,
subject VARCHAR(1000) NOT NULL,
slug VARCHAR(255) NOT NULL
) ENGINE=InnoDB;

CREATE TABLE discuss_message
(
message_id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
message_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL,
post_time DATETIME NOT NULL,
author_user_id INTEGER DEFAULT NULL,
author_user_id INT UNSIGNED DEFAULT NULL,
author_email VARCHAR(255) DEFAULT NULL UNIQUE,
author_name VARCHAR(50) DEFAULT NULL,
thread_id INTEGER NOT NULL,
parent_message_id INTEGER DEFAULT NULL,
subject VARCHAR(100) DEFAULT NOT NULL,
thread_id INT UNSIGNED NOT NULL,
parent_message_id INT UNSIGNED DEFAULT NULL,
subject VARCHAR(100) NOT NULL,
message TEXT NOT NULL,
FOREIGN KEY (author_user_id) REFERENCES user (user_id),
FOREIGN KEY (thread_id) REFERENCES discuss_thread (thread_id) ON DELETE CASCADE,
Expand All @@ -23,15 +23,24 @@ CREATE TABLE discuss_message

CREATE TABLE discuss_tag
(
tag_id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
tag_id INT UNSIGNED 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,
thread_id INT UNSIGNED NOT NULL,
tag_id INT UNSIGNED DEFAULT NULL,
FOREIGN KEY (thread_id) REFERENCES discuss_thread (thread_id),
FOREIGN KEY (tag_id) REFERENCES discuss_tag (tag_id)
) ENGINE=InnoDB;

CREATE TABLE discuss_visit
(
ip_address VARCHAR(45) NOT NULL,
thread_id INT UNSIGNED NOT NULL,
visit_time DATETIME NOT NULL,
PRIMARY KEY(ip_address, thread_id),
FOREIGN KEY (thread_id) REFERENCES discuss_thread(thread_id)
) ENGINE=InnoDB;
7 changes: 6 additions & 1 deletion src/EdpDiscuss/Form/PostForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function __construct()
),
'attributes' => array(
'type' => 'text',
'class' => 'form-control',
),

));

$this->add(array(
Expand All @@ -36,8 +38,11 @@ public function __construct()
'label' => 'Message',
),
'attributes' => array(
'type' => 'text',
'type' => 'textarea',
'class' => 'form-control',
'rows' => '6',
),

));

// Submit button.
Expand Down
8 changes: 0 additions & 8 deletions src/EdpDiscuss/Model/Message/MessageHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ public function extract($object)
$thread = $object->getThread();
$data['thread_id'] = (int)$thread->getThreadId();
unset($data['thread']);


$data['post_time'] = $data['post_time']->format('Y-m-d H:i:s');

//die(var_dump($data));

// Example of how to map fields.
//$data = $this->mapField('id', 'user_id', $data);

return $data;
}

Expand Down
118 changes: 118 additions & 0 deletions src/EdpDiscuss/Model/Tag/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EdpDiscuss\Model\Tag;

use BaconStringUtils\Slugifier;
use DateTime;

class Tag implements TagInterface
{
Expand All @@ -15,6 +16,11 @@ class Tag implements TagInterface
* @var string
*/
protected $name;

/**
* @var string
*/
protected $description;

/**
* @var string
Expand All @@ -26,6 +32,21 @@ class Tag implements TagInterface
*/
protected $slugifier;

/**
* @var integer
*/
protected $threadCount;

/**
* @var integer
*/
protected $messageCount;

/**
* @var Date
*/
protected $lastPost;

/**
* Get tagId.
*
Expand Down Expand Up @@ -69,6 +90,27 @@ public function setName($name)
return $this;
}

/**
* Get description.
*
* @return description
*/
public function getDescription()
{
return $this->description;
}

/**
* Set description.
*
* @param $description the value to be set
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}

/**
* Get slug.
*
Expand All @@ -90,6 +132,11 @@ public function setSlug($slug)
return $this;
}

/**
* Get Slugifier.
*
* @return Slugifier
*/
public function getSlugifier()
{
if ($this->slugifier === null) {
Expand All @@ -98,9 +145,80 @@ public function getSlugifier()
return $this->slugifier;
}

/**
* Set Slugifier.
*
* @param Slugifier
*/
public function setSlugifier($slugifier)
{
$this->slugifier = $slugifier;
return $this;
}

/**
* Set thread count.
* @param integer $threadCount
*/
public function setThreadCount($threadCount)
{
$this->threadCount = $threadCount;
return $this;
}

/**
* Get thread count.
*
* @return integer
*/
public function getThreadCount()
{
return $this->threadCount;
}

/**
* Set Message Count.
*
* @param integer $messageCount
*/
public function setMessageCount($messageCount)
{
$this->messageCount = $messageCount;
return $this;
}

/**
* Get Message Count.
*
* @return integer
*/
public function getMessageCount()
{
return $this->messageCount;
}

/**
* Set Last Post
*
* @param Date $lastPost
*/
public function setLastPost($lastPost)
{
if ($lastPost instanceof DateTime) {
$this->lastPost = $lastPost;
} else {
$this->lastPost = new DateTime($lastPost);
}
return $this;
}

/**
* Get Last Post.
*
* @return Date
*/
public function getLastPost()
{
return $this->lastPost;
}
}
Loading