added tags for timesheets (#604)
This commit is contained in:
@@ -11,6 +11,7 @@ namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
@@ -60,6 +61,14 @@ class TimesheetFixtures extends Fixture
|
||||
* @var int
|
||||
*/
|
||||
protected $exported = false;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $useTags = false;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $tags = [];
|
||||
|
||||
/**
|
||||
* @param bool $allowEmptyDescriptions
|
||||
@@ -163,6 +172,28 @@ class TimesheetFixtures extends Fixture
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $useTags
|
||||
* @return TimesheetFixtures
|
||||
*/
|
||||
public function setUseTags(bool $useTags)
|
||||
{
|
||||
$this->useTags = $useTags;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tags
|
||||
* @return TimesheetFixtures
|
||||
*/
|
||||
public function setTags(array $tags)
|
||||
{
|
||||
$this->tags = $tags;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -195,12 +226,15 @@ class TimesheetFixtures extends Fixture
|
||||
$project = $projects[array_rand($projects)];
|
||||
}
|
||||
|
||||
$tags = $this->getTagObjectList($i);
|
||||
|
||||
$entry = $this->createTimesheetEntry(
|
||||
$user,
|
||||
$activity,
|
||||
$project,
|
||||
$description,
|
||||
$this->getDateTime($i)
|
||||
$this->getDateTime($i),
|
||||
$tags
|
||||
);
|
||||
|
||||
$manager->persist($entry);
|
||||
@@ -214,12 +248,15 @@ class TimesheetFixtures extends Fixture
|
||||
$project = $projects[array_rand($projects)];
|
||||
}
|
||||
|
||||
$tags = $this->getTagObjectList($i);
|
||||
|
||||
$entry = $this->createTimesheetEntry(
|
||||
$user,
|
||||
$activity,
|
||||
$project,
|
||||
$faker->text,
|
||||
$this->getDateTime($i),
|
||||
$tags,
|
||||
false
|
||||
);
|
||||
$manager->persist($entry);
|
||||
@@ -228,6 +265,22 @@ class TimesheetFixtures extends Fixture
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cnt
|
||||
* @return array
|
||||
*/
|
||||
protected function getTagObjectList($cnt)
|
||||
{
|
||||
if (true === $this->useTags) {
|
||||
$tagObject = new Tag();
|
||||
$tagObject->setName($this->tags[($cnt % count($this->tags))]);
|
||||
|
||||
return [$tagObject];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $i
|
||||
* @return bool|\DateTime
|
||||
@@ -278,10 +331,11 @@ class TimesheetFixtures extends Fixture
|
||||
* @param Project $project
|
||||
* @param string $description
|
||||
* @param \DateTime $start
|
||||
* @param null|array $tagArray
|
||||
* @param bool $setEndDate
|
||||
* @return Timesheet
|
||||
*/
|
||||
private function createTimesheetEntry(User $user, Activity $activity, Project $project, $description, \DateTime $start, $setEndDate = true)
|
||||
private function createTimesheetEntry(User $user, Activity $activity, Project $project, $description, \DateTime $start, $tagArray = [], $setEndDate = true)
|
||||
{
|
||||
$end = clone $start;
|
||||
$end = $end->modify('+ ' . (rand(1, 86400)) . ' seconds');
|
||||
@@ -299,6 +353,12 @@ class TimesheetFixtures extends Fixture
|
||||
->setRate($rate)
|
||||
->setBegin($start);
|
||||
|
||||
if (count($tagArray) > 0) {
|
||||
foreach ($tagArray as $item) {
|
||||
$entry->addTag($item);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->fixedRate) {
|
||||
$entry->setFixedRate(rand(10, 100));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user