Implement draft promotions

This commit is contained in:
Dennis Eichhorn 2017-09-25 19:53:07 +02:00
parent b5e450934d
commit 0c60c9f1c7
7 changed files with 572 additions and 23 deletions

View File

@ -40,17 +40,49 @@ class Installer extends InstallerAbstract
switch ($dbPool->get()->getType()) {
case DatabaseType::MYSQL:
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'marketing_promotion` (
`marketing_promotion_id` int(11) NOT NULL AUTO_INCREMENT,
`marketing_promotion_name` varchar(30) NOT NULL,
`marketing_promotion_description` text DEFAULT NULL,
`marketing_promotion_start` datetime DEFAULT NULL,
`marketing_promotion_end` datetime DEFAULT NULL,
`marketing_promotion_type` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`marketing_promotion_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'marketing_promotion` (
`marketing_promotion_id` int(11) NOT NULL AUTO_INCREMENT,
`marketing_promotion_name` varchar(255) NOT NULL,
`marketing_promotion_description` text NOT NULL,
`marketing_promotion_calendar` int(11) NOT NULL,
`marketing_promotion_costs` int(11) NOT NULL,
`marketing_promotion_budget` int(11) NOT NULL,
`marketing_promotion_earnings` int(11) NOT NULL,
`marketing_promotion_start` datetime NOT NULL,
`marketing_promotion_end` datetime NOT NULL,
`marketing_promotion_progress` int NOT NULL,
`marketing_promotion_progress_type` int NOT NULL,
`marketing_promotion_created_at` datetime NOT NULL,
`marketing_promotion_created_by` int(11) NOT NULL,
PRIMARY KEY (`marketing_promotion_id`),
KEY `marketing_promotion_calendar` (`marketing_promotion_calendar`),
KEY `marketing_promotion_created_by` (`marketing_promotion_created_by`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'marketing_promotion`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'marketing_promotion_ibfk_1` FOREIGN KEY (`marketing_promotion_calendar`) REFERENCES `' . $dbPool->get()->prefix . 'calendar` (`calendar_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'marketing_promotion_ibfk_2` FOREIGN KEY (`marketing_promotion_created_by`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'marketing_promotion_task_relation` (
`marketing_promotion_task_relation_id` int(11) NOT NULL AUTO_INCREMENT,
`marketing_promotion_task_relation_src` int(11) NULL,
`marketing_promotion_task_relation_dst` int(11) NULL,
PRIMARY KEY (`marketing_promotion_task_relation_id`),
KEY `marketing_promotion_task_relation_src` (`marketing_promotion_task_relation_src`),
KEY `marketing_promotion_task_relation_dst` (`marketing_promotion_task_relation_dst`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'marketing_promotion_task_relation`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'marketing_promotion_task_relation_ibfk_1` FOREIGN KEY (`marketing_promotion_task_relation_src`) REFERENCES `' . $dbPool->get()->prefix . 'task` (`task_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'marketing_promotion_task_relation_ibfk_2` FOREIGN KEY (`marketing_promotion_task_relation_dst`) REFERENCES `' . $dbPool->get()->prefix . 'marketing_promotion` (`marketing_promotion_id`);'
)->execute();
break;
}
}

View File

@ -23,6 +23,8 @@ use phpOMS\Module\ModuleAbstract;
use phpOMS\Module\WebInterface;
use phpOMS\Views\View;
use phpOMS\Views\ViewLayout;
use Modules\Marketing\Models\Promotion;
use Modules\Marketing\Models\PromotionMapper;
/**
* Marketing controller class.
@ -100,6 +102,30 @@ class Controller extends ModuleAbstract implements WebInterface
$view->setTemplate('/Modules/Marketing/Theme/Backend/promotion-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1001902001, $request, $response));
$promotions = PromotionMapper::getNewest(25);
$view->addData('promotions', $promotions);
return $view;
}
/**
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return RenderableInterface
*
* @since 1.0.0
*/
public function viewMarketingPromotionProfile(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
{
$view = new View($this->app, $request, $response);
$view->setTemplate('/Modules/Marketing/Theme/Backend/promotion-profile');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1001701001, $request, $response));
$promotion = PromotionMapper::get((int) $request->getData('id'));
$view->addData('promotion', $promotion);
return $view;
}

260
Models/Promotion.php Normal file
View File

@ -0,0 +1,260 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace Modules\Marketing\Models;
use Modules\Calendar\Models\Calendar;
use Modules\Tasks\Models\Task;
use phpOMS\Localization\Money;
/**
* Project class.
*
* @category ProjectManager
* @package Framework
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Promotion
{
private $id = 0;
private $start = null;
private $end = null;
private $name = '';
private $description = '';
private $calendar = null;
private $costs = null;
private $budget = null;
private $earnings = null;
/**
* Created at.
*
* @var \Datetime
* @since 1.0.0
*/
private $createdAt = null;
/**
* Created by.
*
* @var int
* @since 1.0.0
*/
private $createdBy = 0;
private $tasks = [];
public function __construct(string $name = '')
{
$this->start = new \DateTime('now');
$this->end = new \DateTime('now');
$this->end->modify('+1 month');
$this->createdAt = new \DateTime('now');
$this->calendar = new Calendar();
$this->costs = new Money();
$this->budget = new Money();
$this->earnings = new Money();
$this->setName($name);
}
public function getId() : int
{
return $this->id;
}
public function addTask(Task $task)
{
if($task->getId() !== 0) {
$this->tasks[$task->getId()] = $task;
} else {
$this->tasks[] = $task;
}
}
public function removeTask(int $id) : bool
{
if(isset($this->tasks[$id])) {
unset($this->tasks[$id]);
return true;
}
return false;
}
public function getProgress() : int
{
return $this->progress;
}
public function setProgress(int $progress) /* : void */
{
$this->progress = $progres;
}
public function getProgressType() : int
{
return $this->progressType;
}
public function setProgressType(int $type) /* : void */
{
$this->progressType = $type;
}
public function getTask(int $id) : Task
{
return $this->tasks[$id] ?? new Task();
}
public function getTasks() : array
{
return $this->tasks;
}
public function countTasks() : int
{
return count($this->tasks);
}
public function getStart() : \DateTime
{
return $this->start;
}
public function setStart(\DateTime $start)
{
$this->start = $start;
}
public function setEnd(\DateTime $end)
{
$this->end = $end;
}
public function getEnd() : \DateTime
{
return $this->end;
}
public function getCalendar() : Calendar
{
return $this->calendar;
}
public function getName() : string
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
$this->calendar->setName($name);
}
public function getDescription() : string
{
return $this->description;
}
public function setDescription(string $description)
{
$this->description = $description;
}
public function getCosts() : Money
{
return $this->costs;
}
public function getBudget() : Money
{
return $this->budget;
}
public function getEarnings() : Money
{
return $this->earnings;
}
public function setCosts(Money $costs)
{
$this->costs = $costs;
}
public function setBudget(Money $budget)
{
$this->budget = $budget;
}
public function setEarnings(Money $earnings)
{
$this->earnings = $earnings;
}
/**
* @return \DateTime
*
* @since 1.0.0
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt Calendar created at
*
* @since 1.0.0
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
$this->calendar->setCreatedAt($createdAt);
}
/**
* @return int
*
* @since 1.0.0
*/
public function getCreatedBy() : int
{
return $this->createdBy;
}
/**
* @param int $createdBy Creator
*
* @since 1.0.0
*/
public function setCreatedBy(int $createdBy)
{
$this->createdBy = $createdBy;
$this->calendar->setCreatedBy($createdBy);
}
}

134
Models/PromotionMapper.php Normal file
View File

@ -0,0 +1,134 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace Modules\ProjectManagement\Models;
use Modules\Calendar\Models\CalendarMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
use phpOMS\DataStorage\Database\RelationType;
use Modules\Tasks\Models\TaskMapper;
/**
* Mapper class.
*
* @category Calendar
* @package Modules
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ProjectMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array
* @since 1.0.0
*/
protected static $columns = [
'marketing_promotion_id' => ['name' => 'marketing_promotion_id', 'type' => 'int', 'internal' => 'id'],
'marketing_promotion_name' => ['name' => 'marketing_promotion_name', 'type' => 'string', 'internal' => 'name'],
'marketing_promotion_description' => ['name' => 'marketing_promotion_description', 'type' => 'string', 'internal' => 'description'],
'marketing_promotion_calendar' => ['name' => 'marketing_promotion_calendar', 'type' => 'int', 'internal' => 'calendar'],
'marketing_promotion_costs' => ['name' => 'marketing_promotion_costs', 'type' => 'Serializable', 'internal' => 'costs'],
'marketing_promotion_budget' => ['name' => 'marketing_promotion_budget', 'type' => 'Serializable', 'internal' => 'budget'],
'marketing_promotion_earnings' => ['name' => 'marketing_promotion_earnings', 'type' => 'Serializable', 'internal' => 'earnings'],
'marketing_promotion_start' => ['name' => 'marketing_promotion_start', 'type' => 'DateTime', 'internal' => 'start'],
'marketing_promotion_end' => ['name' => 'marketing_promotion_end', 'type' => 'DateTime', 'internal' => 'end'],
'marketing_promotion_created_by' => ['name' => 'marketing_promotion_created_by', 'type' => 'int', 'internal' => 'createdBy'],
'marketing_promotion_created_at' => ['name' => 'marketing_promotion_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'],
];
/**
* Has many relation.
*
* @var array
* @since 1.0.0
*/
protected static $hasMany = [
'tasks' => [
'mapper' => TaskMapper::class,
'table' => 'projectmanagement_task_relation',
'dst' => 'projectmanagement_task_relation_dst',
'src' => 'projectmanagement_task_relation_src',
],
];
/**
* Has one relation.
*
* @var array
* @since 1.0.0
*/
protected static $ownsOne = [
'calendar' => [
'mapper' => CalendarMapper::class,
'src' => 'marketing_promotion_calendar',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static $table = 'marketing_promotion';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'marketing_promotion_created_at';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $primaryField = 'marketing_promotion_id';
/**
* Create object.
*
* @param mixed $obj Object
* @param int $relations Behavior for relations creation
*
* @return mixed
*
* @since 1.0.0
*/
public static function create($obj, int $relations = RelationType::ALL)
{
try {
$objId = parent::create($obj, $relations);
if($objId === null || !is_scalar($objId)) {
return $objId;
}
} catch (\Exception $e) {
var_dump($e->getMessage());
return false;
}
return $objId;
}
}

View File

@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>
<section class="box wf-100">
<header><h1><?= $this->getHtml('Promotion'); ?></h1></header>
<div class="inner">
<form action="<?= \phpOMS\Uri\UriFactory::build('{/base}/{/lang}/api/reporter/template'); ?>" method="post">
<form action="<?= \phpOMS\Uri\UriFactory::build('{/base}/{/lang}/api/marketing/promotion'); ?>" method="post">
<table class="layout wf-100">
<tbody>
<tr><td colspan="2"><label for="iTitle"><?= $this->getHtml('Type'); ?></label>

View File

@ -12,37 +12,40 @@
* @link http://orange-management.com
*/
$footerView = new \Web\Views\Lists\PaginationView($this->app, $this->request, $this->response);
$footerView = new \Web\Views\Lists\PaginationView($this->app, $this->request, $this->response);
$footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig');
$footerView->setPages(20);
$footerView->setPage(1);
$list = $this->getData('promotions');
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12">
<div class="box wf-100">
<table class="table red">
<caption><?= $this->getHtml('Events'); ?></caption>
<caption><?= $this->getHtml('Projects'); ?></caption>
<thead>
<tr>
<td><?= $this->getHtml('Status') ?>
<td class="wf-100"><?= $this->getHtml('Title') ?>
<td><?= $this->getHtml('Start') ?>
<td><?= $this->getHtml('End') ?>
<td><?= $this->getHtml('Expenses') ?>
<td><?= $this->getHtml('Sales') ?>
<td><?= $this->getHtml('Budget') ?>
<td><?= $this->getHtml('Due') ?>
<tfoot>
<tr>
<td colspan="7"><?= $footerView->render(); ?>
<td colspan="5"><?= $footerView->render(); ?>
<tbody>
<?php $count = 0; foreach([] as $key => $value) : $count++; ?>
<?php $count = 0; foreach($list as $key => $value) : $count++;
$url = \phpOMS\Uri\UriFactory::build('{/base}/{/lang}/backend/projectmanagement/profile?{?}&id=' . $value->getId());?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getName()); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getStart()->format('Y-m-d')); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getEnd()->format('Y-m-d')); ?></a>
<?php endforeach; ?>
<?php if($count === 0) : ?>
<tr><td colspan="7" class="empty"><?= $this->getHtml('Empty', 0, 0); ?>
<tr><td colspan="5" class="empty"><?= $this->getHtml('Empty', 0, 0); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,94 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
$promotion = $this->getData('promotion');
$tasks = $promotion->getTasks();
echo $this->getData('nav')->render(); ?>
<div class="row">
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1><?= $this->printHtml($promotion->getName()); ?></h1></header>
<div class="inner">
<form id="fProject" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('{/base}/{/lang}/api/marketing/promotion?{?}&csrf={$CSRF}'); ?>">
<table class="layout wf-100">
<tbody>
<tr><td colspan="2"><label for="iName"><?= $this->getHtml('Name') ?></label>
<tr><td colspan="2"><input type="text" id="iName" name="name" placeholder="&#xf007; Name" value="<?= $this->printHtml($promotion->getName()); ?>" required>
<tr><td><label for="iStart"><?= $this->getHtml('Start') ?></label>
<td><label for="iEnd"><?= $this->getHtml('End') ?></label>
<tr><td><input type="datetime-local" id="iStart" name="start" value="<?= $this->printHtml($promotion->getStart()->format('Y-m-d\TH:i:s')); ?>">
<td><input type="datetime-local" id="iEnd" name="end" value="<?= $this->printHtml($promotion->getEnd()->format('Y-m-d\TH:i:s')); ?>">
<tr><td colspan="2"><label for="iDescription"><?= $this->getHtml('Description') ?></label>
<tr><td colspan="2"><textarea id="iDescription" name="desc"><?= $this->printHtml($promotion->getDescription()); ?></textarea>
<tr><td><label for="iBudget"><?= $this->getHtml('Budget') ?></label><td><label for="iActual"><?= $this->getHtml('Actual') ?></label>
<tr><td><input type="text" id="iBudget" name="budget" placeholder=""><td><input type="text" id="iActual" name="actual">
<tr><td colspan="2"><input type="submit" value="<?= $this->getHtml('Save', 0, 0); ?>">
</table>
</form>
</div>
</section>
</div>
<div class="col-xs-12 col-md-6">
<div class="box wf-100">
<table class="table red">
<caption><?= $this->getHtml('Tasks', 'Tasks') ?></caption>
<thead>
<td><?= $this->getHtml('Status') ?>
<td><?= $this->getHtml('Due', 'Tasks') ?>
<td class="full"><?= $this->getHtml('Title') ?>
<tfoot>
<tbody>
<?php $c = 0; foreach($tasks as $key => $task) : $c++;
$url = \phpOMS\Uri\UriFactory::build('{/base}/{/lang}/backend/task/single?{?}&id=' . $task->getId());
$color = 'darkred';
if($task->getStatus() === \Modules\Tasks\Models\TaskStatus::DONE) { $color = 'green'; }
elseif($task->getStatus() === \Modules\Tasks\Models\TaskStatus::OPEN) { $color = 'darkblue'; }
elseif($task->getStatus() === \Modules\Tasks\Models\TaskStatus::WORKING) { $color = 'purple'; }
elseif($task->getStatus() === \Modules\Tasks\Models\TaskStatus::CANCELED) { $color = 'red'; }
elseif($task->getStatus() === \Modules\Tasks\Models\TaskStatus::SUSPENDED) { $color = 'yellow'; } ;?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><span class="tag <?= $this->printHtml($color); ?>"><?= $this->getHtml('S' . $task->getStatus(), 'Tasks') ?></span></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($task->getDue()->format('Y-m-d H:i')); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($task->getTitle()); ?></a>
<?php endforeach; if($c == 0) : ?>
<tr><td colspan="6" class="empty"><?= $this->getHtml('Empty', 0, 0); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1>Calendar</h1></header>
</section>
</div>
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1>Media</h1></header>
</section>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-6">
<section class="box wf-100">
<header><h1>Finances</h1></header>
</section>
</div>
</div>