2020-11-18 13:22:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Drupal\materio_flag\Controller;
|
|
|
|
|
|
|
|
use Drupal\Core\Controller\ControllerBase;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
2020-11-19 17:09:48 +01:00
|
|
|
use Drupal\Core\Session\AccountProxy;
|
|
|
|
use Drupal\Core\Session\AccountProxyInterface;
|
2020-11-18 13:22:30 +01:00
|
|
|
use Drupal\flag_lists\FlagListsService;
|
2020-11-19 17:09:48 +01:00
|
|
|
use Drupal\flag_lists\Entity\FlaggingCollection;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2020-11-18 13:22:30 +01:00
|
|
|
/**
|
|
|
|
* Class AjaxHomeController.
|
|
|
|
*/
|
|
|
|
class MaterioFlagController extends ControllerBase {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Drupal\flag_lists\FlagListsService
|
|
|
|
*/
|
|
|
|
protected $flaglists;
|
|
|
|
|
|
|
|
/**
|
2020-11-19 17:09:48 +01:00
|
|
|
* @var \Drupal\user\User
|
2020-11-18 13:22:30 +01:00
|
|
|
*/
|
2020-11-19 17:09:48 +01:00
|
|
|
protected $user;
|
2020-11-18 13:22:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function create(ContainerInterface $container) {
|
|
|
|
return new static(
|
|
|
|
$container->get('flaglists'),
|
2020-11-19 17:09:48 +01:00
|
|
|
$container->get('current_user')
|
2020-11-18 13:22:30 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:48 +01:00
|
|
|
/**
|
|
|
|
* Constructs a new MaterioFlagController object.
|
|
|
|
*/
|
|
|
|
public function __construct(FlagListsService $flag_lists_service, AccountProxyInterface $account) {
|
|
|
|
$this->flaglists = $flag_lists_service;
|
|
|
|
$this->user = $account;
|
|
|
|
}
|
|
|
|
|
2020-11-18 13:22:30 +01:00
|
|
|
/**
|
|
|
|
* Hello.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* Return Hello string.
|
|
|
|
*/
|
|
|
|
public function getUsersFlaggingCollections() {
|
|
|
|
|
|
|
|
$colls = $this->flaglists->getUsersFlaggingCollections();
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
foreach ($colls as $id => $collection) {
|
|
|
|
$data[] = array(
|
|
|
|
"id" => $id,
|
|
|
|
"name" => $collection->getName()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new JsonResponse($data);
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:09:48 +01:00
|
|
|
public function createUserFlaggingCollection(Request $request) {
|
|
|
|
// dpm($request);
|
|
|
|
$post_data = json_decode( $request->getContent(),TRUE);
|
|
|
|
$name = $post_data['name'];
|
|
|
|
|
|
|
|
$newFlagColl = FlaggingCollection::Create([
|
|
|
|
'type' => 'flagging_collection_type',
|
|
|
|
'name' => $name,
|
|
|
|
'user_id' => $this->user->id(),
|
|
|
|
'templateflag' => 'dossier'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$newFlagColl->save();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'status' => $newFlagColl->get('status')->value,
|
|
|
|
'id' => $newFlagColl->id(),
|
|
|
|
'name' => $newFlagColl->getName(),
|
|
|
|
'newflagcoll_toarray' => $newFlagColl->toArray()
|
|
|
|
];
|
|
|
|
return new JsonResponse($data);
|
|
|
|
}
|
|
|
|
|
2020-11-19 19:02:04 +01:00
|
|
|
public function deleteUserFlaggingCollection(Request $request) {
|
|
|
|
// dpm($request);
|
|
|
|
$post_data = json_decode( $request->getContent(),TRUE);
|
|
|
|
$flagid = $post_data['flagid'];
|
|
|
|
|
|
|
|
$flagcoll = $this->flaglists->getFlaggingCollectionById($flagid);
|
|
|
|
$result = $flagcoll->delete();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'result' => $result,
|
|
|
|
'id' => $flagid
|
|
|
|
];
|
|
|
|
return new JsonResponse($data);
|
|
|
|
}
|
2020-11-19 17:09:48 +01:00
|
|
|
|
2020-11-18 13:22:30 +01:00
|
|
|
}
|