From 55ac11d517d78279c2a2c4a875d23e18577df21e Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Thu, 27 Oct 2016 08:13:59 +0200 Subject: [PATCH] improvements --- app/Resources/translations/messages.de.xliff | 24 +++ app/Resources/views/macros/widgets.html.twig | 21 +++ src/AppBundle/Entity/User.php | 19 +- .../DataFixtures/ORM/LoadFixtures.php | 164 +++++++++++++++--- src/TimesheetBundle/Entity/Activity.php | 41 ++++- src/TimesheetBundle/Entity/Project.php | 36 +++- src/TimesheetBundle/Entity/Timesheet.php | 50 ++---- src/TimesheetBundle/EventListener/Menu.php | 2 +- .../Repository/ProjectRepository.php | 15 +- .../Resources/views/admin/activity.html.twig | 16 +- .../Resources/views/admin/project.html.twig | 16 +- .../Resources/views/admin/timesheet.html.twig | 2 +- 12 files changed, 297 insertions(+), 109 deletions(-) diff --git a/app/Resources/translations/messages.de.xliff b/app/Resources/translations/messages.de.xliff index 3000e936..a7264d80 100644 --- a/app/Resources/translations/messages.de.xliff +++ b/app/Resources/translations/messages.de.xliff @@ -161,6 +161,14 @@ label.budget Budget + + label.activity + Aktivität + + + label.project + Projekt + + + more.info.link + Mehr Infos + + + badge.visible + Ja + + + badge.invisible + Nein + + diff --git a/app/Resources/views/macros/widgets.html.twig b/app/Resources/views/macros/widgets.html.twig index a9e2fe68..b699ee00 100644 --- a/app/Resources/views/macros/widgets.html.twig +++ b/app/Resources/views/macros/widgets.html.twig @@ -1,4 +1,25 @@ +{% macro badge_visible(visible) %} + {% import _self as macro %} + {% if visible %} + {{ macro.badge('badge.visible', 'green') }} + {% else %} + {{ macro.badge('badge.invisible', 'red') }} + {% endif %} +{% endmacro %} + +{% macro badge_counter(count, url) %} + {% if url %} + {{ count }} + {% else %} + {{ count }} + {% endif %} +{% endmacro %} + +{% macro badge(title, color) %} + {{ title|trans }} +{% endmacro %} + {% macro alert(type, description, title, icon) %}
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php index 19ad2fb1..fb23e24f 100644 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -68,23 +68,6 @@ class User implements UserInterface */ private $passwordresethash; - /** - * FIXME remove me - * - * @var integer - * - * @ORM\Column(name="ban", type="integer", nullable=false) - */ - private $ban = '0'; - - /** - * FIXME remove me - * @var integer - * - * @ORM\Column(name="banTime", type="integer", nullable=false) - */ - private $bantime = '0'; - /** * @var string * @@ -111,6 +94,8 @@ class User implements UserInterface private $lastactivity = '1'; /** + * FIXME manytoone + * * @var integer * * @ORM\Column(name="lastRecord", type="integer", nullable=false) diff --git a/src/TimesheetBundle/DataFixtures/ORM/LoadFixtures.php b/src/TimesheetBundle/DataFixtures/ORM/LoadFixtures.php index 053cd721..43b5ede9 100644 --- a/src/TimesheetBundle/DataFixtures/ORM/LoadFixtures.php +++ b/src/TimesheetBundle/DataFixtures/ORM/LoadFixtures.php @@ -12,6 +12,8 @@ namespace TimesheetBundle\DataFixtures\ORM; use AppBundle\Entity\User; +use TimesheetBundle\Entity\Activity; +use TimesheetBundle\Entity\Project; use TimesheetBundle\Entity\Timesheet; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; @@ -29,27 +31,72 @@ use AppBundle\DataFixtures\ORM\LoadFixtures as AppBundleLoadFixtures; */ class LoadFixtures extends AppBundleLoadFixtures { - const AMOUNT_ACTIVITIES = 20; - const AMOUNT_TIMESHEET = 1000; - const AMOUNT_PROJECTS = 10; - const AMOUNT_CUSTOMER = 10; + const AMOUNT_ACTIVITIES = 10; // maximum activites per project + const AMOUNT_TIMESHEET = 1000; // timesheet entries total + const AMOUNT_PROJECTS = 20; // projects entries total + const AMOUNT_CUSTOMER = 10; // customer entries total /** * {@inheritdoc} */ public function load(ObjectManager $manager) { + $this->loadProjects($manager); + $this->loadActivities($manager); $this->loadTimesheet($manager); } + /** + * @param ObjectManager $manager + * @return User[] + */ + protected function getAllUsers(ObjectManager $manager) + { + $all = []; + /* @var User[] $entries */ + $entries = $manager->getRepository(User::class)->findAll(); + foreach ($entries as $temp) { + $all[$temp->getId()] = $temp; + } + return $all; + } + + /** + * @param ObjectManager $manager + * @return Project[] + */ + protected function getAllProjects(ObjectManager $manager) + { + $all = []; + /* @var Project[] $entries */ + $entries = $manager->getRepository(Project::class)->findAll(); + foreach ($entries as $temp) { + $all[$temp->getId()] = $temp; + } + return $all; + } + /** + * @param ObjectManager $manager + * @return Activity[] + */ + protected function getAllActivities(ObjectManager $manager) + { + $all = []; + /* @var Activity[] $entries */ + $entries = $manager->getRepository(Activity::class)->findAll(); + foreach ($entries as $temp) { + $all[$temp->getId()] = $temp; + } + return $all; + } + private function loadTimesheet(ObjectManager $manager) { - $allUsers = []; - $users = $manager->getRepository(User::class)->findAll(); - foreach ($users as $user) { - $allUsers[$user->getId()] = $user; - } - $amountUsers = count($allUsers); + $allUser = $this->getAllUsers($manager); + $amountUser = count($allUser); + + $allActivity = $this->getAllActivities($manager); + $amountActivity = count($allActivity); for ($i = 0; $i <= self::AMOUNT_TIMESHEET; $i++) { @@ -60,29 +107,101 @@ class LoadFixtures extends AppBundleLoadFixtures $end = $end->modify('+ '.(rand(1, 43200)).' seconds'); $entry = new Timesheet(); - $entry->setProjectid(rand(1, self::AMOUNT_PROJECTS)); - $entry->setActivityid(rand(1, self::AMOUNT_ACTIVITIES)); - $entry->setStatusid(1); // TODO - $entry->setBillable(true); + $entry->setActivity($allActivity[array_rand($allActivity)]); + $entry->setStatusid(1); // TODO + $entry->setBillable($i % 2 == 0); $entry->setBudget(0); - $entry->setCleared(false); + $entry->setCleared($i % 7 == 0); $entry->setComment($this->getRandomPhrase()); $entry->setDescription($this->getRandomPhrase()); $entry->setLocation($this->getRandomLocation()); $entry->setStart($start->getTimestamp()); $entry->setEnd($end->getTimestamp()); $entry->setDuration($end->modify('- ' . $start->getTimestamp() . ' seconds')->getTimestamp()); - $entry->setUser($allUsers[rand(1, $amountUsers)]); - //$entry->setApproved(false); // TODO - //$entry->setFixedrate(); // TODO - //$entry->setRate(); // TODO - //$entry->setTrackingnumber(); // TODO + $entry->setUser($allUser[rand(1, $amountUser)]); + //$entry->setApproved(false); // TODO + //$entry->setFixedrate(); // TODO + //$entry->setRate(); // TODO + //$entry->setTrackingnumber(); // TODO $manager->persist($entry); } $manager->flush(); } + private function loadProjects(ObjectManager $manager) + { + for ($i = 0; $i <= self::AMOUNT_PROJECTS; $i++) { + + $entry = new Project(); + $entry->setName($this->getRandomProject()); + $entry->setBudget(rand(1000, 100000)); + $entry->setComment($this->getRandomPhrase()); + $entry->setCustomerId(rand(1, self::AMOUNT_CUSTOMER)); // TODO + $entry->setVisible($i % 3 != 0); + + $manager->persist($entry); + } + $manager->flush(); + } + + private function loadActivities(ObjectManager $manager) + { + $allProject = $this->getAllProjects($manager); + + foreach ($allProject as $projectId => $project) { + $activityCount = rand(1, self::AMOUNT_ACTIVITIES); + for ($i = 0; $i < $activityCount; $i++) { + $entry = new Activity(); + $entry->setProject($project); + $entry->setName($this->getRandomActivity()); + $entry->setComment($this->getRandomPhrase()); + $entry->setVisible($i % 3 != 0); + + $manager->persist($entry); + } + } + $manager->flush(); + } + + private function getActivities() + { + return [ + 'Design', + 'Programming', + 'Testing', + 'Documentation', + 'Pause', + 'Internal', + 'Research', + 'Meeting', + ]; + } + + private function getRandomActivity() + { + $all = $this->getActivities(); + return $all[array_rand($all)]; + } + + private function getProjects() + { + return [ + 'FooBar', + 'Relaunch', + 'Refactoring', + 'Test Automatisation', + 'Website redesign', + 'Services', + ]; + } + + private function getRandomProject() + { + $all = $this->getProjects(); + return $all[array_rand($all)]; + } + private function getLocations() { return [ @@ -103,8 +222,7 @@ class LoadFixtures extends AppBundleLoadFixtures private function getRandomLocation() { - $titles = $this->getLocations(); - - return $titles[array_rand($titles)]; + $all = $this->getLocations(); + return $all[array_rand($all)]; } } diff --git a/src/TimesheetBundle/Entity/Activity.php b/src/TimesheetBundle/Entity/Activity.php index 79221e47..da068120 100644 --- a/src/TimesheetBundle/Entity/Activity.php +++ b/src/TimesheetBundle/Entity/Activity.php @@ -27,11 +27,18 @@ class Activity /** * @var integer * - * @ORM\Column(name="activityID", type="integer") + * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ - private $activityid; + private $id; + + /** + * @var Project + * + * @ORM\ManyToOne(targetEntity="TimesheetBundle\Entity\Project", inversedBy="activities") + */ + private $project; /** * @var string @@ -52,7 +59,23 @@ class Activity * * @ORM\Column(name="visible", type="boolean", nullable=false) */ - private $visible = '1'; + private $visible = true; + + /** + * @return Project + */ + public function getProject() + { + return $this->project; + } + + /** + * @param int $project + */ + public function setProject($project) + { + $this->project = $project; + } /** * Set name @@ -131,8 +154,16 @@ class Activity * * @return integer */ - public function getActivityId() + public function getId() { - return $this->activityid; + return $this->id; + } + + /** + * @return string + */ + public function __toString() + { + return $this->getName(); } } diff --git a/src/TimesheetBundle/Entity/Project.php b/src/TimesheetBundle/Entity/Project.php index 817ecf13..417a2b17 100644 --- a/src/TimesheetBundle/Entity/Project.php +++ b/src/TimesheetBundle/Entity/Project.php @@ -27,13 +27,14 @@ class Project /** * @var integer * - * @ORM\Column(name="projectID", type="integer") + * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ - private $projectid; + private $id; /** + * FIXME * @var integer * * @ORM\Column(name="customerID", type="integer", nullable=false) @@ -59,14 +60,21 @@ class Project * * @ORM\Column(name="visible", type="boolean", nullable=false) */ - private $visible = '1'; + private $visible = true; /** * @var string * * @ORM\Column(name="budget", type="decimal", precision=10, scale=2, nullable=true) */ - private $budget = '0.00'; + private $budget = 0.00; + + /** + * @var Activity[] + * + * @ORM\OneToMany(targetEntity="TimesheetBundle\Entity\Activity", mappedBy="project") + */ + private $activities; /** * Set customerid @@ -193,8 +201,24 @@ class Project * * @return integer */ - public function getProjectId() + public function getId() { - return $this->projectid; + return $this->id; + } + + /** + * @return Activity[] + */ + public function getActivities() + { + return $this->activities; + } + + /** + * @return string + */ + public function __toString() + { + return $this->getName(); } } diff --git a/src/TimesheetBundle/Entity/Timesheet.php b/src/TimesheetBundle/Entity/Timesheet.php index 0c1b8ec5..e49f9e48 100644 --- a/src/TimesheetBundle/Entity/Timesheet.php +++ b/src/TimesheetBundle/Entity/Timesheet.php @@ -18,7 +18,7 @@ use Doctrine\ORM\Mapping as ORM; * Timesheet entity. * * @ORM\Entity(repositoryClass="TimesheetBundle\Repository\TimesheetRepository") - * @ORM\Table(name="timeSheet", indexes={@ORM\Index(columns={"userID"}), @ORM\Index(columns={"projectID"}), @ORM\Index(name="activityID", columns={"activityID"})}) + * @ORM\Table(name="timeSheet", indexes={@ORM\Index(columns={"userID"}), @ORM\Index(name="activity", columns={"activity"})}) * * @author Kevin Papst */ @@ -46,7 +46,7 @@ class Timesheet private $duration = '0'; /** - * @var integer + * @var User * * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User") * @ORM\JoinColumn(name="userID", referencedColumnName="userID") @@ -56,16 +56,10 @@ class Timesheet /** * @var integer * - * @ORM\Column(name="projectID", type="integer", nullable=false) + * @ORM\ManyToOne(targetEntity="TimesheetBundle\Entity\Activity") + * @ORM\JoinColumn(name="activity", referencedColumnName="id") */ - private $projectid; - - /** - * @var integer - * - * @ORM\Column(name="activityID", type="integer", nullable=false) - */ - private $activityid; + private $activity; /** * @var string @@ -258,40 +252,16 @@ class Timesheet return $this->user; } - /** - * Set projectid - * - * @param integer $projectid - * - * @return Timesheet - */ - public function setProjectid($projectid) - { - $this->projectid = $projectid; - - return $this; - } - - /** - * Get projectid - * - * @return integer - */ - public function getProjectid() - { - return $this->projectid; - } - /** * Set activityid * - * @param integer $activityid + * @param integer $activity * * @return Timesheet */ - public function setActivityid($activityid) + public function setActivity($activity) { - $this->activityid = $activityid; + $this->activity = $activity; return $this; } @@ -301,9 +271,9 @@ class Timesheet * * @return integer */ - public function getActivityid() + public function getActivity() { - return $this->activityid; + return $this->activity; } /** diff --git a/src/TimesheetBundle/EventListener/Menu.php b/src/TimesheetBundle/EventListener/Menu.php index 18794159..167859a2 100644 --- a/src/TimesheetBundle/EventListener/Menu.php +++ b/src/TimesheetBundle/EventListener/Menu.php @@ -62,7 +62,7 @@ class Menu $menu->addChild( new MenuItemModel('timesheet_admin', 'menu.admin_timesheet', 'admin_timesheet', [], 'fa fa-clock-o') )->addChild( - new MenuItemModel('project_admin', 'menu.admin_project', 'admin_project', [], 'fa fa-object-group') + new MenuItemModel('project_admin', 'menu.admin_project', 'admin_project', [], 'fa fa-book') )->addChild( new MenuItemModel('activity_admin', 'menu.admin_activity', 'admin_activity', [], 'fa fa-tasks') ) diff --git a/src/TimesheetBundle/Repository/ProjectRepository.php b/src/TimesheetBundle/Repository/ProjectRepository.php index 7ef5e220..29f88a79 100644 --- a/src/TimesheetBundle/Repository/ProjectRepository.php +++ b/src/TimesheetBundle/Repository/ProjectRepository.php @@ -36,7 +36,18 @@ class ProjectRepository extends EntityRepository $qb->select('p') ->from('TimesheetBundle:Project', 'p') - ->orderBy('p.name', 'DESC'); + ->orderBy('p.id', 'DESC'); + + return $qb->getQuery(); + } + + public function queryAll($orderBy = 'id') + { + $qb = $this->getEntityManager()->createQueryBuilder(); + + $qb->select('p') + ->from('TimesheetBundle:Project', 'p') + ->orderBy('p.' . $orderBy, 'ASC'); return $qb->getQuery(); } @@ -58,7 +69,7 @@ class ProjectRepository extends EntityRepository */ public function findAll($page = 1) { - return $this->getPager($this->queryLatest(), $page); + return $this->getPager($this->queryAll(), $page); } /** diff --git a/src/TimesheetBundle/Resources/views/admin/activity.html.twig b/src/TimesheetBundle/Resources/views/admin/activity.html.twig index 3a500ef4..4a5058e3 100644 --- a/src/TimesheetBundle/Resources/views/admin/activity.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/activity.html.twig @@ -9,26 +9,28 @@ - - - - + + + + + {% for entry in entries %} + + - - + {% endfor %}
{{ 'label.name'|trans }} {{ 'label.comment'|trans }} {{ 'label.visible'|trans }} {{ 'label.id'|trans }}{{ 'label.id'|trans }} {{ 'label.name'|trans }} {{ 'label.project'|trans }} {{ 'label.comment'|trans }} {{ 'label.visible'|trans }}
{{ entry.id }} {{ entry.name }}{{ entry.project }} {{ entry.comment }}{{ entry.visible }}{{ entry.activityId }}{{ widgets.badge_visible(entry.visible) }}
{% else %} {{ widgets.callout('warning', 'error.no_entries_found') }} diff --git a/src/TimesheetBundle/Resources/views/admin/project.html.twig b/src/TimesheetBundle/Resources/views/admin/project.html.twig index e1a5a76a..14a0c0a9 100644 --- a/src/TimesheetBundle/Resources/views/admin/project.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/project.html.twig @@ -9,20 +9,22 @@ - - - - + + + + + {% for entry in entries %} + - - + + {% endfor %} @@ -30,7 +32,7 @@
{{ 'label.name'|trans }} {{ 'label.comment'|trans }} {{ 'label.visible'|trans }} {{ 'label.id'|trans }}{{ 'label.id'|trans }} {{ 'label.name'|trans }} {{ 'label.comment'|trans }} {{ 'label.visible'|trans }} {{ 'label.activity'|trans }} {{ 'label.budget'|trans }}
{{ entry.id }} {{ entry.name }} {{ entry.comment }}{{ entry.visible }}{{ entry.projectId }}{{ widgets.badge_visible(entry.visible) }}{{ widgets.badge_counter(entry.activities.count) }} {{ entry.budget}}
{% else %} {{ widgets.callout('warning', 'error.no_entries_found') }} diff --git a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig index 92134e08..1ab5b626 100644 --- a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig @@ -32,7 +32,7 @@ {% else %} {{ widgets.callout('warning', 'error.no_entries_found') }}