diff --git a/Admin/Installer.php b/Admin/Installer.php index 08ea91e..e39cb1d 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -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; } } diff --git a/Controller.php b/Controller.php index 9b4ffc5..3d0cdfa 100644 --- a/Controller.php +++ b/Controller.php @@ -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; } diff --git a/Models/Promotion.php b/Models/Promotion.php new file mode 100644 index 0000000..054d0dd --- /dev/null +++ b/Models/Promotion.php @@ -0,0 +1,260 @@ +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); + } +} \ No newline at end of file diff --git a/Models/PromotionMapper.php b/Models/PromotionMapper.php new file mode 100644 index 0000000..63dc12c --- /dev/null +++ b/Models/PromotionMapper.php @@ -0,0 +1,134 @@ + ['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; + } +} diff --git a/Theme/Backend/promotion-create.tpl.php b/Theme/Backend/promotion-create.tpl.php index 1a2d5fe..40d1a18 100644 --- a/Theme/Backend/promotion-create.tpl.php +++ b/Theme/Backend/promotion-create.tpl.php @@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>

getHtml('Promotion'); ?>

-
+
diff --git a/Theme/Backend/promotion-list.tpl.php b/Theme/Backend/promotion-list.tpl.php index 6a453c9..ecf0aa7 100644 --- a/Theme/Backend/promotion-list.tpl.php +++ b/Theme/Backend/promotion-list.tpl.php @@ -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(); ?>
- + - - - $value) : $count++; ?> + $value) : $count++; + $url = \phpOMS\Uri\UriFactory::build('{/base}/{/lang}/backend/projectmanagement/profile?{?}&id=' . $value->getId());?> + +
getHtml('Events'); ?>getHtml('Projects'); ?>
getHtml('Status') ?> getHtml('Title') ?> getHtml('Start') ?> - getHtml('End') ?> - getHtml('Expenses') ?> - getHtml('Sales') ?> - getHtml('Budget') ?> + getHtml('Due') ?>
render(); ?> + render(); ?>
printHtml($value->getName()); ?> + printHtml($value->getStart()->format('Y-m-d')); ?> + printHtml($value->getEnd()->format('Y-m-d')); ?> -
getHtml('Empty', 0, 0); ?> +
getHtml('Empty', 0, 0); ?>
-
\ No newline at end of file + diff --git a/Theme/Backend/promotion-profile.tpl.php b/Theme/Backend/promotion-profile.tpl.php index e69de29..1edf999 100644 --- a/Theme/Backend/promotion-profile.tpl.php +++ b/Theme/Backend/promotion-profile.tpl.php @@ -0,0 +1,94 @@ +getData('promotion'); +$tasks = $promotion->getTasks(); + +echo $this->getData('nav')->render(); ?> + +
+
+
+

printHtml($promotion->getName()); ?>

+
+ + + +
+
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+ + + + + + $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'; } ;?> + +
getHtml('Tasks', 'Tasks') ?>
getHtml('Status') ?> + getHtml('Due', 'Tasks') ?> + getHtml('Title') ?> +
getHtml('S' . $task->getStatus(), 'Tasks') ?> + printHtml($task->getDue()->format('Y-m-d H:i')); ?> + printHtml($task->getTitle()); ?> + +
getHtml('Empty', 0, 0); ?> + +
+
+
+
+ +
+
+
+

Calendar

+
+
+ +
+
+

Media

+
+
+
+ +
+
+
+

Finances

+
+
+
\ No newline at end of file