diff --git a/Admin/Installer.php b/Admin/Installer.php index e77b54c..f94b647 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -42,7 +42,43 @@ class Installer extends InstallerAbstract switch ($dbPool->get('core')->getType()) { case DatabaseType::MYSQL: + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'projectmanagement_project` ( + `projectmanagement_project_id` int(11) NOT NULL AUTO_INCREMENT, + `projectmanagement_project_name` varchar(254) NOT NULL, + `projectmanagement_project_description` text NOT NULL, + `projectmanagement_project_calendar` int(11) NOT NULL, + `projectmanagement_project_costs` int(11) NOT NULL, + `projectmanagement_project_budget` int(11) NOT NULL, + `projectmanagement_project_earnings` int(11) NOT NULL, + `projectmanagement_project_start` datetime NOT NULL, + `projectmanagement_project_end` datetime NOT NULL, + PRIMARY KEY (`projectmanagement_project_id`), + KEY `projectmanagement_project_project` (`projectmanagement_project_project`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'projectmanagement_project` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'projectmanagement_project_ibfk_1` FOREIGN KEY (`projectmanagement_project_calendar`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar` (`calendar_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'projectmanagement_task_relation` ( + `projectmanagement_task_relation_id` int(11) NOT NULL AUTO_INCREMENT, + `projectmanagement_task_relation_src` int(11) NULL, + `projectmanagement_task_relation_dst` int(11) NULL, + PRIMARY KEY (`projectmanagement_task_relation_id`), + KEY `projectmanagement_task_relation_src` (`projectmanagement_task_relation_src`), + KEY `projectmanagement_task_relation_dst` (`projectmanagement_task_relation_dst`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'projectmanagement_task_relation` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'projectmanagement_task_relation_ibfk_1` FOREIGN KEY (`projectmanagement_task_relation_src`) REFERENCES `' . $dbPool->get('core')->prefix . 'task` (`task_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'projectmanagement_task_relation_ibfk_2` FOREIGN KEY (`projectmanagement_task_relation_dst`) REFERENCES `' . $dbPool->get('core')->prefix . 'projectmanagement_project` (`projectmanagement_project_id`);' + )->execute(); break; } } diff --git a/Models/Project.php b/Models/Project.php new file mode 100644 index 0000000..394d639 --- /dev/null +++ b/Models/Project.php @@ -0,0 +1,238 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\ProjectManagement\Models; + +/** + * Project class. + * + * @category ProjectManager + * @package Framework + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Project +{ + 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('+1M'); + $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 getTask(int $id) : Task + { + return $this->tasks[$id] ?? new NullTask(); + } + + 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 + * @author Dennis Eichhorn + */ + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + /** + * @param \DateTime $createdAt Calendar created at + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + $this->calendar->setCreatedAt($createdAt); + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedBy() : int + { + return $this->createdBy; + } + + /** + * @param int $createdBy Creator + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedBy(int $createdBy) + { + $this->createdBy = $createdBy; + $this->calendar->setCreatedBy($createdBy); + } +} \ No newline at end of file diff --git a/Models/ProjectMapper.php b/Models/ProjectMapper.php new file mode 100644 index 0000000..9fc3bd7 --- /dev/null +++ b/Models/ProjectMapper.php @@ -0,0 +1,150 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\ProjectManagement\Models; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; + +/** + * Mapper class. + * + * @category Calendar + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @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 = [ + 'projectmanagement_project_id' => ['name' => 'projectmanagement_project_id', 'type' => 'int', 'internal' => 'id'], + 'projectmanagement_project_name' => ['name' => 'projectmanagement_project_name', 'type' => 'string', 'internal' => 'name'], + 'projectmanagement_project_description' => ['name' => 'projectmanagement_project_description', 'type' => 'string', 'internal' => 'description'], + 'projectmanagement_project_calendar' => ['name' => 'projectmanagement_project_calendar', 'type' => 'int', 'internal' => 'calendar'], + 'projectmanagement_project_costs' => ['name' => 'projectmanagement_project_costs', 'type' => 'Serializable', 'internal' => 'costs'], + 'projectmanagement_project_budget' => ['name' => 'projectmanagement_project_budget', 'type' => 'Serializable', 'internal' => 'budget'], + 'projectmanagement_project_earnings' => ['name' => 'projectmanagement_project_earnings', 'type' => 'Serializable', 'internal' => 'earnings'], + 'projectmanagement_project_start' => ['name' => 'projectmanagement_project_start', 'type' => 'DateTime', 'internal' => 'start'], + 'projectmanagement_project_end' => ['name' => 'projectmanagement_project_end', 'type' => 'DateTime', 'internal' => 'end'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasOne = [ + 'project' => [ + 'mapper' => \Modules\Calendar\Models\CalendarMapper::class, + 'src' => 'projectmanagement_project_calendar', + ], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasMany = [ + 'sources' => [ + 'mapper' => \Modules\Tasks\Models\TaskMapper::class, /* mapper of the related object */ + 'relationmapper' => null, /* if the relation itself is a more complex object that has it's own mapper */ + 'table' => 'projectmanager_task_relation', /* table of the related object, null if no relation table is used (many->1) */ + 'dst' => 'projectmanager_task_relation_dst', + 'src' => 'projectmanager_task_relation_src', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'projectmanagement_project'; + + /** + * Create media. + * + * @param project $obj Media + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function create($obj) + { + try { + $objId = parent::create($obj); + $query = new Builder($this->db); + $query->prefix($this->db->getPrefix()) + ->insert( + 'account_permission_account', + 'account_permission_from', + 'account_permission_for', + 'account_permission_id1', + 'account_permission_id2', + 'account_permission_r', + 'account_permission_w', + 'account_permission_m', + 'account_permission_d', + 'account_permission_p' + ) + ->into('account_permission') + ->values($obj->getCreatedBy(), 'calendar_project', 'calendar_project', 1, $objId, 1, 1, 1, 1, 1); + + $this->db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'calendar_project') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('calendar_project.calendar_project_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +}