Merge branch 'master' into dist/eole/2.7.0/master

This commit is contained in:
2020-05-12 11:35:36 +02:00
6 changed files with 207 additions and 2 deletions

View File

@@ -6,7 +6,8 @@
<containers> <containers>
<container name='web'> <container name='web'>
<!-- <package>schedule-apps</package> --> <package>schedule-apps</package>
<!-- service de configuration apache --> <!-- service de configuration apache -->
<service method="apache" servicelist="schedule">schedule</service> <service method="apache" servicelist="schedule">schedule</service>

View File

@@ -40,6 +40,7 @@ app_logoutcas:
path: /logoutcas path: /logoutcas
defaults: { _controller: App\Controller\SecurityController:logoutcas } defaults: { _controller: App\Controller\SecurityController:logoutcas }
#== Crop ========================================================================================================= #== Crop =========================================================================================================
app_crop01: app_crop01:
path: /user/crop01 path: /user/crop01
@@ -350,4 +351,9 @@ app_customer_report:
app_customer_planning: app_customer_planning:
path: /customer/planning/{key} path: /customer/planning/{key}
defaults: { _controller: App\Controller\ReportController:planning, access: 'customer' } defaults: { _controller: App\Controller\ReportController:planning, access: 'customer' }
#== API ===========================================================================================================
app_api:
path: /api/{key}
defaults: { _controller: App\Controller\ApiController:api }

View File

@@ -41,6 +41,10 @@ services:
public: true public: true
class: App\Service\passwordEncoder class: App\Service\passwordEncoder
app.ics.service:
public: true
class: App\Service\icsService
app.upload.listener: app.upload.listener:
public: true public: true
class: App\Service\uploadListener class: App\Service\uploadListener

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\FormError;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use App\Service\icsService;
class ApiController extends AbstractController
{
public function api($key,Request $request)
{
$em = $this->getDoctrine()->getManager();
$user=$em->getRepository("App:User")->findBy(["apikey"=>$key]);
if(!$user) {
return new Response("Accès refusé", 403);
}
$ics = new icsService();
$ics->debug(false);
$content=$ics->writeheader();
$events=$em->getRepository("App:Event")->findBy(["user"=>$user]);
foreach($events as $event) {
$task=$event->getTask();
$project=$task->getProject();
$customer=$project->getCustomer();
$ics->set(
[
'allday' => $event->getAllday(),
'description' => $event->getDescription(),
'dtstart' => $event->getStart()->format("Y-m-d H:i:s"),
'dtend' => $event->getEnd()->format("Y-m-d H:i:s"),
'summary' => $customer->getName()."-".$project->getName()."-".$task->getName(),
'uid' => "schedule".$event->getId()
]
);
$content.=$ics->writeevent();
}
$content.=$ics->writefooter();
return new Response($content);
}
}

View File

@@ -116,6 +116,13 @@ class UserType extends AbstractType
] ]
); );
$builder->add('apikey',
TextType::class, [
"label" =>"Clé Accès",
"required" => false
]
);
$builder->add('avatar',HiddenType::class, array("empty_data" => "noavatar.png")); $builder->add('avatar',HiddenType::class, array("empty_data" => "noavatar.png"));
} }

View File

@@ -0,0 +1,135 @@
<?php
namespace App\Service;
class icsService
{
const DT_FORMAT = 'Ymd\THis';
const DT_FORMATDAY = 'Ymd';
protected $properties = array();
private $fgdebug;
private $available_properties = array(
'description',
'dtend',
'dtstart',
'location',
'summary',
'url',
'allday',
'uid'
);
public function __construct() {
}
public function debug($fgdebug = false) {
$this->fgdebug=$fgdebug;
}
public function set($key, $val = false) {
if (is_array($key)) {
foreach ($key as $k => $v) {
if($k=="allday"&&(is_null($v)||$v=="")) $v=0;
if($k!="allday"&&(is_null($v)||$v=="")) unset( $this->properties[$k]);
else $this->set($k, $v);
}
}
else {
if (in_array($key, $this->available_properties)) {
if($key=="allday")
$this->properties[$key] = $this->sanitize_val($val, $key, false);
else
$this->properties[$key] = $this->sanitize_val($val, $key,$this->properties["allday"]);
}
}
}
public function writeheader() {
// Build ICS properties - add header
$header = array(
'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:-//hacksw/handcal//NONSGML v1.0//EN',
'CALSCALE:GREGORIAN',
'X-WR-TIMEZONE:Europe/Paris'
);
return $this->exportformat($header);
}
public function writefooter() {
// Build ICS properties - add footer
$footer[] = 'END:VCALENDAR';
return $this->exportformat($footer);
}
public function writeevent() {
$event[]='BEGIN:VEVENT';
// Build ICS properties - add header
$props = array();
foreach($this->properties as $k => $v) {
if($k === 'url')
$props[strtoupper($k . ';VALUE=URI')] = $v;
elseif(($k=='dtstart'||$k=='dtend')&&$this->properties['allday'])
$props[strtoupper($k . ';VALUE=DATE')] = $v;
else
$props[strtoupper($k)] = $v;
}
// Set some default values
$props['DTSTAMP'] = $this->format_timestamp('now');
if(!isset($props['UID'])) $props['UID'] = uniqid();
// Append properties
foreach ($props as $k => $v) {
$event[] = "$k:$v";
}
// Build ICS properties - add footer
$event[] = 'END:VEVENT';
return $this->exportformat($event);
}
private function sanitize_val($val, $key = false, $allday) {
switch($key) {
case 'dtstamp':
$val = $this->format_timestamp($val);
break;
case 'dtend':
case 'dtstart':
if($allday)
$val = $this->format_daystamp($val);
else
$val = $this->format_timestamp($val);
break;
default:
$val = $this->escape_string($val);
}
return $val;
}
private function format_daystamp($timestamp) {
$dt = new \DateTime($timestamp, new \DateTimeZone('Europe/Paris'));
return $dt->format(self::DT_FORMATDAY);
}
private function format_timestamp($timestamp) {
$dt = new \DateTime($timestamp, new \DateTimeZone('Europe/Paris'));
return $dt->format(self::DT_FORMAT);
}
private function escape_string($str) {
return preg_replace('/([\,;])/','\\\$1', $str);
}
private function exportformat($string) {
return implode(($this->fgdebug?"<br>":"\r\n"), $string).($this->fgdebug?"<br>":"\r\n");
}
}