@@ -65,7 +65,7 @@ public function __construct($AppName, IRequest $request, IUserSession $userSessi
6565 */
6666 public function workIntervals () {
6767 $ i = 0 ;
68- $ tryIntervals =[7 , 14 , 31 ,365 ,365 *5 ];
68+ $ tryIntervals =[90 , 180 ,365 ,365 *5 ];
6969 do {
7070 $ l = $ this ->workIntervalMapper ->findLatestDays ($ this ->userId ,$ tryIntervals [$ i ],0 );
7171 $ i ++;
@@ -279,6 +279,87 @@ public function updateWorkInterval($id) {
279279 }
280280
281281
282+ /**
283+ *
284+ * @NoAdminRequired
285+ */
286+
287+ public function addWorkInterval () {
288+
289+ $ wi = new WorkInterval ();
290+ $ wi ->setUserUid ($ this ->userId );
291+ $ wi ->setRunning (0 );
292+
293+ if (isset ($ this ->request ->name )) {
294+ $ wi ->setName ($ this ->request ->name );
295+ }
296+ if (isset ($ this ->request ->projectId )) {
297+ $ wi ->setProjectId ($ this ->request ->projectId );
298+ if ($ wi ->projectId != null ){
299+ $ project = $ this ->projectMapper ->find ($ wi ->projectId );
300+ $ locked = $ project ->locked ;
301+ if ($ locked ){
302+ $ allowedTags = $ this ->tagMapper ->findAllAlowedForProject ($ project ->id );
303+ $ allowedTagsIds = array_map (function ($ tag ) { return $ tag ->id ;}, $ allowedTags );
304+ $ currentTags = $ this ->workIntervalToTagMapper ->findAllForWorkInterval ($ id );
305+ $ currentTagsIds = array_map (function ($ witag ) { return $ witag ->tagId ;}, $ currentTags );
306+ $ newTags = array_intersect ($ allowedTagsIds ,$ currentTagsIds );
307+
308+ $ this ->workIntervalToTagMapper ->deleteAllForWorkInterval ($ id );
309+ foreach ($ newTags as $ tag ){
310+ if (empty ($ tag ))
311+ continue ;
312+ $ newWiToTag = new WorkIntervalToTag ();
313+ $ newWiToTag ->setWorkIntervalId ($ id );
314+ $ newWiToTag ->setTagId ($ tag );
315+ $ newWiToTag ->setCreatedAt (time ());
316+ $ this ->workIntervalToTagMapper ->insert ($ newWiToTag );
317+
318+ }
319+
320+ }
321+
322+ }
323+ }
324+ if (isset ($ this ->request ->tagId )) {
325+ $ tags = \explode (", " , $ this ->request ->tagId );
326+ $ this ->workIntervalToTagMapper ->deleteAllForWorkInterval ($ id );
327+ $ project = null ;
328+ $ locked = 0 ;
329+
330+
331+ foreach ($ tags as $ tag ){
332+ if (empty ($ tag ))
333+ continue ;
334+ $ newWiToTag = new WorkIntervalToTag ();
335+ $ newWiToTag ->setWorkIntervalId ($ id );
336+ $ newWiToTag ->setTagId ($ tag );
337+ $ newWiToTag ->setCreatedAt (time ());
338+ //var_dump($newWiToTag);
339+ $ this ->workIntervalToTagMapper ->insert ($ newWiToTag );
340+
341+ }
342+ }
343+ if (isset ($ this ->request ->start )) {
344+ $ tzoffset = 0 ;
345+ if (isset ($ this ->request ->tzoffset )) {
346+ $ tzoffset = $ this ->request ->tzoffset ;
347+ }
348+
349+ date_default_timezone_set ('UTC ' );
350+ $ dt = \DateTime::createFromFormat ( "d/m/y H:i " ,$ this ->request ->start );
351+ $ dt ->setTimeZone (new \DateTimeZone ('UTC ' ));
352+ $ wi ->setStart ($ dt ->getTimestamp ()+$ tzoffset *60 );
353+ $ de = \DateTime::createFromFormat ( "d/m/y H:i " ,$ this ->request ->end );
354+ $ de ->setTimeZone (new \DateTimeZone ('UTC ' ));
355+ $ wi ->setDuration ($ de ->getTimestamp () - $ dt ->getTimestamp ());
356+ }
357+
358+ $ this ->workIntervalMapper ->insert ($ wi );
359+
360+ return new JSONResponse (["WorkIntervals " => json_decode (json_encode ($ running ), true )]);
361+ }
362+
282363
283364 /**
284365 *
0 commit comments