Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
muhtasimhafiz committed Aug 14, 2024
1 parent a4e0b11 commit a2fd8f8
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 40 deletions.
59 changes: 49 additions & 10 deletions app/Domain/Goalcanvas/Controllers/DelCanvas.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
<?php

/**
* Controller / Delete Canvas
* delCanvas class - Generic canvas controller / Delete Canvas
*/


namespace Leantime\Domain\Goalcanvas\Controllers {

// use AWS\CRT\HTTP\Response;
use Symfony\Component\HttpFoundation\Response;

use Leantime\Core\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Illuminate\Support\Str;
use Leantime\Core\Frontcontroller;

/**
*
*/
class DelCanvas extends \Leantime\Domain\Canvas\Controllers\DelCanvas
class DelCanvas extends Controller
{
/**
* Constant that must be redefined
*/
protected const CANVAS_NAME = 'goal';

public function get($params):Response
private mixed $canvasRepo;

/**
* init - initialize private variables
*/
public function init()
{
$canvasName = Str::studly(static::CANVAS_NAME) . 'canvas';
$repoName = app()->getNamespace() . "Domain\\$canvasName\\Repositories\\$canvasName";
$this->canvasRepo = app()->make($repoName);
}

/**
* run - display template and edit data
*
* @access public
*/
public function run()
{
$id = filter_var($params['id'] ?? '', FILTER_SANITIZE_NUMBER_INT);
$this->tpl->assign('id', $id);

return $this->tpl->displayPartial('goalcanvas.delCanvas');
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager, Roles::$editor]);

if (isset($_POST['del']) && isset($_GET['id'])) {
$id = (int)($_GET['id']);
$this->canvasRepo->deleteCanvas($id);

$allCanvas = $this->canvasRepo->getAllCanvas(session("currentProject"));
session(["current' . strtoupper(static::CANVAS_NAME) . 'Canvas" => $allCanvas[0]['id'] ?? -1]);

$this->tpl->setNotification($this->language->__('notification.board_deleted'), 'success', strtoupper(static::CANVAS_NAME) . 'canvas_deleted');

$allCanvas = $this->canvasRepo->getAllCanvas(session("currentProject"));

//Create default canvas.
if (!$allCanvas || count($allCanvas) == 0) {
return Frontcontroller::redirect(BASE_URL . '/strategy/showBoards');
} else {
return Frontcontroller::redirect(BASE_URL . '/' . static::CANVAS_NAME . 'canvas/showCanvas');
}
}

return $this->tpl->displayPartial(static::CANVAS_NAME . 'canvas.delCanvas');
}
}
}
48 changes: 39 additions & 9 deletions app/Domain/Goalcanvas/Controllers/DelCanvasItem.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
<?php

/**
* Controller / Delete Canvas Item
* delCanvasItem class - Generic canvas controller / Delete Canvas Item
*/

namespace Leantime\Domain\Goalcanvas\Controllers {
use Symfony\Component\HttpFoundation\Response;

use Leantime\Core\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Illuminate\Support\Str;
use Leantime\Core\Frontcontroller;

/**
*
*/
class DelCanvasItem extends \Leantime\Domain\Canvas\Controllers\DelCanvasItem
class DelCanvasItem extends Controller
{
/**
* Constant that must be redefined
*/
protected const CANVAS_NAME = 'goal';
public function get($params):Response
{
$id = filter_var($params['id'] ?? '', FILTER_SANITIZE_NUMBER_INT);
$this->tpl->assign('id', $id);

return $this->tpl->displayPartial('goalcanvas.delCanvasItem');
private mixed $canvasRepo;

/**
* init - initialize private variables
*/
public function init()
{
$canvasName ='goalcanvas';
$repoName = app()->getNamespace() . "Domain\\goalcanvas\\Repositories\\goalcanvas";
$this->canvasRepo = app()->make($repoName);
}

}
/**
* run - display template and edit data
*
* @access public
*/
public function run()
{
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager, Roles::$editor]);

if (isset($_POST['del']) && isset($_GET['id'])) {
$id = (int)($_GET['id']);
$this->canvasRepo->delCanvasItem($id);

$this->tpl->setNotification($this->language->__('notification.element_deleted'), 'success', strtoupper(static::CANVAS_NAME) . 'canvasitem_deleted');
return Frontcontroller::redirect(BASE_URL . '/' . static::CANVAS_NAME . 'canvas/showCanvas');
}

return $this->tpl->displayPartial(static::CANVAS_NAME . 'canvas.delCanvasItem');
}
}
}
Loading

0 comments on commit a2fd8f8

Please sign in to comment.