Commit 45e3939e authored by Tino Goratsch's avatar Tino Goratsch

add the basic infrastructure for the content ratings

parent 74477be3
......@@ -74,8 +74,10 @@ class PollsModel extends AbstractModel implements UpdatedAtAwareModelInterface
* @param int $pollId
*
* @return bool|int
*
* @throws \Doctrine\DBAL\ConnectionException
*/
public function saveAnswers(array $answers, $pollId)
public function saveAnswers(array $answers, int $pollId)
{
$bool = false;
foreach ($answers as $row) {
......@@ -104,8 +106,10 @@ class PollsModel extends AbstractModel implements UpdatedAtAwareModelInterface
* @param int $pollId
*
* @return bool|int
*
* @throws \Doctrine\DBAL\ConnectionException
*/
public function resetVotesByPollId($pollId)
public function resetVotesByPollId(int $pollId)
{
return $this->voteRepository->delete($pollId, 'poll_id');
}
......
......@@ -39,6 +39,8 @@ class SaveSharingInfoOnModelAfterSaveListener
/**
* @param ModelSaveEvent $event
*
* @throws \Doctrine\DBAL\DBALException
*/
public function execute(ModelSaveEvent $event)
{
......@@ -49,7 +51,8 @@ class SaveSharingInfoOnModelAfterSaveListener
$this->socialSharingManager->saveSharingInfo(
\sprintf($formData['share_uri_pattern'], $event->getEntryId()),
$formData['share_active'],
$formData['share_customize_services'] == 1 ? $formData['share_services'] : []
$formData['share_customize_services'] == 1 ? $formData['share_services'] : [],
$formData['share_ratings_active']
);
}
}
......
......@@ -85,6 +85,17 @@ class ValidateSharingInfoOnValidationInfo
'haystack' => $this->socialServices->getActiveServices(),
],
]
)
->addConstraint(
InArrayValidationRule::class,
[
'data' => $event->getFormData(),
'field' => 'share_ratings_active',
'message' => $this->translator->t('share', 'select_ratings_active'),
'extra' => [
'haystack' => [0, 1],
],
]
);
}
}
......
......@@ -86,6 +86,10 @@ class ShareFormFields
$this->getAvailableServices(),
$this->getCurrentServices(\unserialize($sharingInfo['services']))
),
'ratings_active' => $this->formsHelper->yesNoCheckboxGenerator(
'share_ratings_active',
$sharingInfo['ratings_active']
),
];
}
......
......@@ -68,18 +68,24 @@ class SocialSharingManager
* @param string $path
* @param bool $active
* @param array $services
* @param bool $ratingsActive
*
* @return bool
*
* @throws \Doctrine\DBAL\DBALException
*/
public function saveSharingInfo(string $path, bool $active = false, array $services = []): bool
public function saveSharingInfo(
string $path,
bool $active = false,
array $services = [],
bool $ratingsActive = false): bool
{
$path .= $this->preparePath($path);
$data = [
'uri' => $path,
'share_active' => $active,
'share_services' => $services,
'share_ratings_active' => $ratingsActive,
];
$sharingInfo = $this->shareRepository->getOneByUri($path);
......
......@@ -13,18 +13,27 @@ class Migration implements Modules\Installer\MigrationInterface
{
/**
* {@inheritdoc}
*
* @return array
*/
public function schemaUpdates()
{
return [];
return [
2 => [
'ALTER TABLE `{pre}share` ADD COLUMN `ratings_active` TINYINT(1) UNSIGNED NOT NULL AFTER `services`;',
'CREATE TABLE IF NOT EXISTS `{pre}share_ratings` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`stars` TINYINT(1) UNSIGNED NOT NULL,
`ip` VARCHAR(40) NOT NULL,
`share_id` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX(`share_id`),
FOREIGN KEY (`share_id`) REFERENCES `{pre}share` (`id`) ON DELETE CASCADE
) {ENGINE} {CHARSET};',
],
];
}
/**
* {@inheritdoc}
*
* @return array
*/
public function renameModule()
{
......
......@@ -55,7 +55,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 1;
return 2;
}
/**
......@@ -69,7 +69,18 @@ class Schema implements Modules\Installer\SchemaInterface
`uri` VARCHAR(255) NOT NULL,
`active` TINYINT(1) UNSIGNED NOT NULL,
`services` TEXT NOT NULL,
PRIMARY KEY (`id`), UNIQUE(`uri`)
`ratings_active` TINYINT(1) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE(`uri`)
) {ENGINE} {CHARSET};',
'CREATE TABLE IF NOT EXISTS `{pre}share_ratings` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`stars` TINYINT(1) UNSIGNED NOT NULL,
`ip` VARCHAR(40) NOT NULL,
`share_id` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
INDEX(`share_id`),
FOREIGN KEY (`share_id`) REFERENCES `{pre}share` (`id`) ON DELETE CASCADE
) {ENGINE} {CHARSET};',
];
}
......@@ -80,6 +91,7 @@ class Schema implements Modules\Installer\SchemaInterface
public function removeTables()
{
return [
'DROP TABLE IF EXISTS `{pre}share_ratings`;',
'DROP TABLE IF EXISTS `{pre}share`;',
];
}
......
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Modules\ACP3\Share\Model\Repository;
use ACP3\Core\Model\Repository\AbstractRepository;
class ShareRatingsRepository extends AbstractRepository
{
const TABLE_NAME = 'share_ratings';
}
......@@ -36,6 +36,7 @@ class ShareModel extends AbstractModel
$keys = [
'active' => 'share_active',
'services' => 'share_services',
'ratings_active' => 'share_ratings_active',
];
foreach ($keys as $column => $formField) {
if (isset($data[$formField])) {
......@@ -55,6 +56,7 @@ class ShareModel extends AbstractModel
'uri' => DataProcessor\ColumnTypes::COLUMN_TYPE_RAW,
'active' => DataProcessor\ColumnTypes::COLUMN_TYPE_BOOLEAN,
'services' => DataProcessor\ColumnTypes::COLUMN_TYPE_SERIALIZABLE,
'ratings_active' => DataProcessor\ColumnTypes::COLUMN_TYPE_BOOLEAN,
];
}
}
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Modules\ACP3\Share\Model;
use ACP3\Core\Model\AbstractModel;
use ACP3\Core\Model\DataProcessor\ColumnTypes;
use ACP3\Modules\ACP3\Share\Installer\Schema;
class ShareRatingModel extends AbstractModel
{
const EVENT_PREFIX = Schema::MODULE_NAME;
/**
* {@inheritdoc}
*/
protected function getAllowedColumns()
{
return [
'stars' => ColumnTypes::COLUMN_TYPE_INT,
'share_id' => ColumnTypes::COLUMN_TYPE_INT,
'ip' => ColumnTypes::COLUMN_TYPE_TEXT,
];
}
}
......@@ -5,6 +5,7 @@
{include file="asset:System/Partials/form_group.select.tpl" options=$share.services multiple=true required=true label={lang t="share|active_services"}}
</div>
</div>
{include file="asset:System/Partials/form_group.button_group.tpl" options=$share.ratings_active required=true label={lang t="share|activate_ratings"}}
{if !empty($share.uri_pattern)}
<input type="hidden" name="share_uri_pattern" value="{$share.uri_pattern}">
{/if}
......
......@@ -4,6 +4,11 @@ services:
arguments:
- '@core.db'
share.model.share_ratings_repository:
class: ACP3\Modules\ACP3\Share\Model\Repository\ShareRatingsRepository
arguments:
- '@core.db'
share.model.share_repository:
class: ACP3\Modules\ACP3\Share\Model\Repository\ShareRepository
arguments:
......@@ -15,3 +20,10 @@ services:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@share.model.share_repository'
share.model.share_rating_model:
class: ACP3\Modules\ACP3\Share\Model\ShareRatingModel
arguments:
- '@core.event_dispatcher'
- '@core.model.data_processor'
- '@share.model.share_ratings_repository'
......@@ -5,6 +5,7 @@
-->
<language>
<keys>
<item key="activate_ratings">Bewertung aktivieren</item>
<item key="activate_sharing">Social sharing aktivieren</item>
<item key="active">Aktiv</item>
<item key="active_services">Aktivierte Dienste</item>
......@@ -16,6 +17,9 @@
<item key="fb_app_id">Facebook App-ID</item>
<item key="fb_secret">Facebook Secret</item>
<item key="mod_description">Ermöglicht die Einbindung diverser sozialer Netzwerke zum Teilen von Inhalten, etc.</item>
<item key="select_active">Bitte wählen aus, ob dieser Datensatz bei sozialen Netzwerken geteilt werden können soll oder nicht.</item>
<item key="select_customize_services">Bitte wählen aus ob Sie die verfügbaren sozialen Netzwerke für diesen Datensatz anpassen möchten oder nicht.</item>
<item key="select_ratings_active">Bitte wählen aus, ob dieser Datensatz von Benutzern bewertet werden können soll oder nicht.</item>
<item key="select_services">Bitte wählen aus, welche Dienste aktiviert werden sollen. Es muss mindestens ein Dienst aktiv sein.</item>
<item key="service_addthis">AddThis</item>
<item key="service_diaspora">diaspora</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment