code improvements (#3088)
This commit is contained in:
@@ -105,7 +105,7 @@ trait StringAccessibleConfigTrait
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
* @return string|int|bool|float|null|array
|
||||
*/
|
||||
public function find(string $key)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
namespace App\Export;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use App\Utils\FileHelper;
|
||||
|
||||
@@ -19,40 +21,35 @@ final class ExportFilename
|
||||
* @var string
|
||||
*/
|
||||
private $filename;
|
||||
/**
|
||||
* @var Customer|null
|
||||
*/
|
||||
private $customer;
|
||||
/**
|
||||
* @var Project|null
|
||||
*/
|
||||
private $project;
|
||||
/**
|
||||
* @var User|null
|
||||
*/
|
||||
private $user;
|
||||
|
||||
public function __construct(TimesheetQuery $query)
|
||||
{
|
||||
$filename = date('Ymd');
|
||||
$hasName = false;
|
||||
|
||||
$customers = $query->getCustomers();
|
||||
if (\count($customers) === 1) {
|
||||
$filename .= '-' . $this->convert($this->getCustomerName($customers[0]));
|
||||
$hasName = true;
|
||||
$this->customer = $customers[0];
|
||||
}
|
||||
|
||||
$projects = $query->getProjects();
|
||||
if (\count($projects) === 1) {
|
||||
if (!$hasName) {
|
||||
$filename .= '-' . $this->convert($this->getCustomerName($projects[0]->getCustomer()));
|
||||
}
|
||||
$filename .= '-' . $this->convert($projects[0]->getName());
|
||||
$hasName = true;
|
||||
$this->project = $projects[0];
|
||||
}
|
||||
|
||||
$users = $query->getUsers();
|
||||
if (\count($users) === 1) {
|
||||
$filename .= '-' . $this->convert($users[0]->getDisplayName());
|
||||
$hasName = true;
|
||||
$this->user = $users[0];
|
||||
}
|
||||
|
||||
if (!$hasName) {
|
||||
$filename .= '-kimai-export';
|
||||
}
|
||||
|
||||
$filename = str_replace(['/', '\\'], '-', $filename);
|
||||
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
private function getCustomerName(Customer $customer): string
|
||||
@@ -72,6 +69,37 @@ final class ExportFilename
|
||||
|
||||
public function getFilename()
|
||||
{
|
||||
if ($this->filename === null) {
|
||||
$filename = date('Ymd');
|
||||
$hasName = false;
|
||||
|
||||
if ($this->customer !== null) {
|
||||
$filename .= '-' . $this->convert($this->getCustomerName($this->customer));
|
||||
$hasName = true;
|
||||
}
|
||||
|
||||
if ($this->project !== null) {
|
||||
if (!$hasName) {
|
||||
$filename .= '-' . $this->convert($this->getCustomerName($this->project->getCustomer()));
|
||||
}
|
||||
$filename .= '-' . $this->convert($this->project->getName());
|
||||
$hasName = true;
|
||||
}
|
||||
|
||||
if ($this->user !== null) {
|
||||
$filename .= '-' . $this->convert($this->user->getDisplayName());
|
||||
$hasName = true;
|
||||
}
|
||||
|
||||
if (!$hasName) {
|
||||
$filename .= '-kimai-export';
|
||||
}
|
||||
|
||||
$filename = str_replace(['/', '\\'], '-', $filename);
|
||||
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
|
||||
self::$initialized = true;
|
||||
}
|
||||
|
||||
public function getConfigurationByName(string $name): ?Configuration
|
||||
{
|
||||
return $this->findOneBy(['name' => $name]);
|
||||
}
|
||||
|
||||
public function saveConfiguration(Configuration $configuration)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
@@ -59,6 +64,14 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
public function deleteConfiguration(Configuration $configuration)
|
||||
{
|
||||
$entityManager = $this->getEntityManager();
|
||||
$entityManager->remove($configuration);
|
||||
$entityManager->flush();
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $prefix
|
||||
* @return Configuration[]
|
||||
|
||||
Reference in New Issue
Block a user