Skip to content

Commit

Permalink
Merge pull request #1 from bibich/master
Browse files Browse the repository at this point in the history
First release of the module
  • Loading branch information
lunika committed Feb 14, 2015
2 parents a03e7c5 + df8ef31 commit cd81d1a
Show file tree
Hide file tree
Showing 64 changed files with 9,804 additions and 0 deletions.
614 changes: 614 additions & 0 deletions Action/CommentAction.php

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/

namespace Comment;

use Comment\Model\CommentQuery;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Translation\Translator;
use Thelia\Install\Database;
use Thelia\Model\ConfigQuery;
use Thelia\Model\LangQuery;
use Thelia\Model\Message;
use Thelia\Model\MessageQuery;
use Thelia\Module\BaseModule;

/**
* Class Comment
* @package Comment
*
* @author Michaël Espeche <michael.espeche@gmail.com>
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
*/
class Comment extends BaseModule
{
const MESSAGE_DOMAIN = "comment";

/** Use comment */
const CONFIG_ACTIVATED = 1;

/** Use moderation */
const CONFIG_MODERATE = 1;

/** Allowed ref */
const CONFIG_REF_ALLOWED = 'product,content';

/** Only customers are abled to post comment */
const CONFIG_ONLY_CUSTOMER = 1;

/** Allow only verified customer (for product, customers that have bought the product) */
const CONFIG_ONLY_VERIFIED = 1;

/** request customer comment, x days after an order */
const CONFIG_REQUEST_CUSTOMMER_TTL = 15;


public function postActivation(ConnectionInterface $con = null)
{
// Config
if (null === ConfigQuery::read('comment_activated')) {
ConfigQuery::write('comment_activated', Comment::CONFIG_ACTIVATED);
}

if (null === ConfigQuery::read('comment_moderate')) {
ConfigQuery::write('comment_moderate', Comment::CONFIG_MODERATE);
}

if (null === ConfigQuery::read('comment_ref_allowed')) {
ConfigQuery::write('comment_ref_allowed', Comment::CONFIG_REF_ALLOWED);
}

if (null === ConfigQuery::read('comment_only_customer')) {
ConfigQuery::write('comment_only_customer', Comment::CONFIG_ONLY_CUSTOMER);
}

if (null === ConfigQuery::read('comment_only_verified')) {
ConfigQuery::write('comment_only_verified', Comment::CONFIG_ONLY_VERIFIED);
}

if (null === ConfigQuery::read('comment_request_customer_ttl')) {
ConfigQuery::write('comment_request_customer_ttl', Comment::CONFIG_REQUEST_CUSTOMMER_TTL);
}

// Schema
try {
CommentQuery::create()->findOne();
} catch (\Exception $ex) {
$database = new Database($con->getWrappedConnection());
$database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
}

// create new message
if (null === MessageQuery::create()->findOneByName('comment_request_customer')) {

$message = new Message();
$message
->setName('comment_request_customer')
->setHtmlTemplateFileName('request-customer-comment.html')
->setHtmlLayoutFileName('')
->setTextTemplateFileName('request-customer-comment.txt')
->setTextLayoutFileName('')
->setSecured(0);

$languages = LangQuery::create()->find();

foreach ($languages as $language) {
$locale = $language->getLocale();

$message->setLocale($locale);

$message->setTitle(
Translator::getInstance()->trans('Request customer comment', [], self::MESSAGE_DOMAIN)
);
$message->setSubject(
Translator::getInstance()->trans('', [], self::MESSAGE_DOMAIN)
);
}

$message->save();
}
}

public static function getConfig()
{
$config = [
'activated' => (
intval(ConfigQuery::read('comment_activated', self::CONFIG_ACTIVATED)) === 1
),
'moderate' => (
intval(ConfigQuery::read('comment_moderate', self::CONFIG_MODERATE)) === 1
),
'ref_allowed' => explode(
',',
ConfigQuery::read('comment_ref_allowed', self::CONFIG_REF_ALLOWED)
),
'only_customer' => (
intval(ConfigQuery::read('comment_only_customer', self::CONFIG_ONLY_CUSTOMER)) === 1
),
'only_verified' => (
intval(ConfigQuery::read('comment_only_verified', self::CONFIG_ONLY_VERIFIED)) === 1
),
'request_customer_ttl' => (
intval(ConfigQuery::read('comment_request_customer_ttl', self::CONFIG_REQUEST_CUSTOMMER_TTL))
)
];

return $config;
}
}
71 changes: 71 additions & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" ?>

<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">

<loops>
<loop name="comment" class="Comment\Loop\CommentLoop" />
</loops>

<forms>
<form name="comment.add.form" class="Comment\Form\AddCommentForm" />
<form name="comment.abuse.form" class="Comment\Form\CommentAbuseForm" />
<form name="comment.configuration.form" class="Comment\Form\ConfigurationForm" />
<form name="admin.comment.modification.form" class="Comment\Form\CommentModificationForm" />
</forms>

<commands>
<!--
<command class="MyModule\Command\MySuperCommand" />
-->
</commands>

<services>

<service id="comment.action" class="Comment\Action\CommentAction" scope="request">
<argument type="service" id="thelia.translator" />
<argument type="service" id="thelia.parser" />
<argument type="service" id="mailer"/>

<tag name="kernel.event_subscriber"/>
</service>

<service id="comment.form.type.field.comment_id" class="Comment\Form\Field\CommentIdType">
<argument type="service" id="thelia.translator" />
<tag name="thelia.form.type" />
</service>

</services>

<!--
<exports>
</exports>
-->

<!--
<imports>
</imports>
-->

<hooks>
<!-- front -->
<hook id="comment.hook.front" class="Comment\Hook\FrontHook" scope="request">
<tag name="hook.event_listener" event="product.additional" method="onShowBlockComment" />
<tag name="hook.event_listener" event="content.main-bottom" method="onShowComment" />
<tag name="hook.event_listener" event="main.javascript-initialization" method="jsComment" />
</hook>
<!-- back -->
<hook id="comment.hook.back" class="Comment\Hook\BackHook" scope="request">
<tag name="hook.event_listener" event="module.configuration" type="back" />
<tag name="hook.event_listener" event="main.top-menu-tools" type="back" />
<tag name="hook.event_listener" event="product.tab-content" type="back" method="onProductTabContent" />
<tag name="hook.event_listener" event="product.edit-js" type="back" method="onJsTabContent" />
<tag name="hook.event_listener" event="content.tab-content" type="back" method="onContentTabContent" />
<tag name="hook.event_listener" event="content.edit-js" type="back" method="onJsTabContent" />
</hook>

</hooks>
</config>
24 changes: 24 additions & 0 deletions Config/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="http://thelia.net/schema/dic/module"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_1.xsd">
<fullnamespace>Comment\Comment</fullnamespace>
<descriptive locale="en_US">
<title>Comment system</title>
</descriptive>
<descriptive locale="fr_FR">
<title>Système de commentaire</title>
</descriptive>
<languages>
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>0.1</version>
<author>
<name>Julien Chanséaume</name>
<email>jchanseaume@openstudio.fr</email>
</author>
<type>classic</type>
<thelia>2.1.0</thelia>
<stability>alpha</stability>
</module>
69 changes: 69 additions & 0 deletions Config/routing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<!-- Front -->

<route id="front.comment.get" path="/comment/get">
<default key="_controller">Comment\Controller\Front\CommentController::getAction</default>
</route>

<route id="front.comment.add" path="/comment/add" methods="post">
<default key="_controller">Comment\Controller\Front\CommentController::createAction</default>
</route>

<route id="front.comment.delete" path="/comment/delete/{commentId}">
<default key="_controller">Comment\Controller\Front\CommentController::deleteAction</default>
<requirement key="commentId">\d+</requirement>
</route>

<route id="front.comment.abuse" path="/comment/abuse" methods="post">
<default key="_controller">Comment\Controller\Front\CommentController::abuseAction</default>
</route>

<!-- Admin -->
<route id="admin.comment.configuration" path="/admin/module/comment/configuration" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::saveConfiguration</default>
</route>

<!-- crud -->

<route id="admin.comment.comments.default" path="/admin/module/comments">
<default key="_controller">Comment\Controller\Back\CommentController::defaultAction</default>
</route>

<route id="admin.comment.comments.create" path="/admin/module/comment/create">
<default key="_controller">Comment\Controller\Back\CommentController::createAction</default>
</route>

<route id="admin.comment.comments.update" path="/admin/module/comment/update/{comment_id}">
<default key="_controller">Comment\Controller\Back\CommentController::updateAction</default>
<requirement key="comment_id">\d+</requirement>
</route>

<route id="admin.comment.comments.save" path="/admin/module/comment/save/{comment_id}" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::processUpdateAction</default>
<requirement key="comment_id">\d+</requirement>
</route>

<route id="admin.comment.comments.delete" path="/admin/module/comment/delete" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::deleteAction</default>
</route>

<route id="admin.comment.comments.status" path="/admin/module/comment/status" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::changeStatusAction</default>
</route>

<route id="admin.comment.comments.activation" path="/admin/module/comment/activation/{ref}/{refId}" methods="post">
<default key="_controller">Comment\Controller\Back\CommentController::activationAction</default>
<requirement key="ref">.*</requirement>
<requirement key="refId">\d+</requirement>
</route>

<route id="admin.comment.comments.activation" path="/admin/module/comment/request-customer">
<default key="_controller">Comment\Controller\Back\CommentController::requestCustomerCommentAction</default>
</route>

</routes>
28 changes: 28 additions & 0 deletions Config/schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia" namespace="Comment\Model">

<table name="comment">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER" />
<column name="username" size="255" type="VARCHAR" />
<column name="customer_id" type="INTEGER" />
<column name="ref" size="255" type="VARCHAR" />
<column name="ref_id" type="INTEGER" />
<column name="email" size="255" type="VARCHAR" />
<column name="title" size="255" type="VARCHAR" />
<column name="content" type="CLOB" />
<column name="rating" type="TINYINT" />
<column name="status" type="TINYINT" default="0" />
<column name="verified" type="TINYINT" />
<column name="abuse" type="INTEGER" />
<column name="locale" size="10" type="VARCHAR" />
<behavior name="timestampable" />
<foreign-key foreignTable="customer" name="fk_comment_customer_id" onDelete="CASCADE" onUpdate="RESTRICT">
<reference foreign="id" local="customer_id" />
</foreign-key>
<index name="idx_comment_user_id">
<index-column name="customer_id" />
</index>
</table>

<external-schema filename="local/config/schema.xml" referenceOnly="true" />
</database>
39 changes: 39 additions & 0 deletions Config/thelia.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

-- ---------------------------------------------------------------------
-- comment
-- ---------------------------------------------------------------------

DROP TABLE IF EXISTS `comment`;

CREATE TABLE `comment`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`username` VARCHAR(255),
`customer_id` INTEGER,
`ref` VARCHAR(255),
`ref_id` INTEGER,
`email` VARCHAR(255),
`title` VARCHAR(255),
`content` LONGTEXT,
`rating` TINYINT,
`status` TINYINT DEFAULT 0,
`verified` TINYINT,
`abuse` INTEGER,
`locale` VARCHAR(10),
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `idx_comment_user_id` (`customer_id`),
CONSTRAINT `fk_comment_customer_id`
FOREIGN KEY (`customer_id`)
REFERENCES `customer` (`id`)
ON UPDATE RESTRICT
ON DELETE CASCADE
) ENGINE=InnoDB;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
Loading

0 comments on commit cd81d1a

Please sign in to comment.