Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrzk committed Aug 31, 2022
0 parents commit f9d2721
Show file tree
Hide file tree
Showing 50 changed files with 2,610 additions and 0 deletions.
104 changes: 104 additions & 0 deletions Api/Data/QuestionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Api\Data;

/**
* Interface QuestionInterface
*
* @api
* @since 1.0.0
*/
interface QuestionInterface
{
public const ID = 'id';
public const QUESTION = 'question';
public const ANSWER = 'answer';
public const POSITION = 'position';
public const ACTIVE = 'active';
public const STORE_IDS = 'store_ids';
public const CREATED_AT = 'created_at';
public const UPDATED_AT = 'updated_at';

/**
* @return mixed
*/
public function getId();

/**
* @return string
*/
public function getQuestion(): string;

/**
* @param string $question
*
* @return QuestionInterface
*/
public function setQuestion(string $question): QuestionInterface;

/**
* @return string|null
*/
public function getAnswer(): ?string;

/**
* @param string|null $answer
*
* @return QuestionInterface
*/
public function setAnswer(?string $answer): QuestionInterface;

/**
* @return int
*/
public function getPosition(): int;

/**
* @param int|null $position
*
* @return QuestionInterface
*/
public function setPosition(?int $position): QuestionInterface;

/**
* @return bool
*/
public function isActive(): bool;

/**
* @param bool $active
*
* @return QuestionInterface
*/
public function setActive(bool $active): QuestionInterface;

/**
* @param string $createdAt
*
* @return QuestionInterface
*/
public function setCreatedAt(string $createdAt): QuestionInterface;

/**
* @return string
*/
public function getCreatedAt(): string;

/**
* @param string $updatedAt
*
* @return QuestionInterface
*/
public function setUpdatedAt(string $updatedAt): QuestionInterface;

/**
* @return string
*/
public function getUpdatedAt(): string;
}
33 changes: 33 additions & 0 deletions Api/Data/QuestionSearchResultInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

/**
* Interface QuestionSearchResultInterface
*/
interface QuestionSearchResultInterface extends SearchResultsInterface
{
/**
* Get customers list.
*
* @return QuestionInterface[]
*/
public function getItems(): array;

/**
* Set customers list.
*
* @param QuestionInterface[] $items
*
* @return QuestionSearchResultInterface
*/
public function setItems(array $items): self;
}
70 changes: 70 additions & 0 deletions Api/QuestionRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Api;

use Mtrzk\FaqPage\Api\Data\QuestionInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Interface QuestionRepositoryInterface
*
* @api
* @since 1.0.0
*/
interface QuestionRepositoryInterface
{
/**
* @param QuestionInterface $question
*
* @return QuestionInterface
*
* @throws CouldNotSaveException
*/
public function save(QuestionInterface $question): QuestionInterface;

/**
* @param int $id
*
* @return QuestionInterface
*
* @throws NoSuchEntityException
*/
public function getById(int $id): QuestionInterface;

/**
* @param SearchCriteriaInterface $searchCriteria
*
* @return SearchResultsInterface
*/
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface;

/**
* @param mixed $id
*
* @return bool
*
* @throws CouldNotDeleteException
* @throws NoSuchEntityException
*/
public function delete($id): bool;

/**
* @param int $id
*
* @return bool
*
* @throws CouldNotDeleteException
* @throws NoSuchEntityException
*/
public function deleteById(int $id): bool;
}
33 changes: 33 additions & 0 deletions Block/Adminhtml/Form/Question/Back.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Block\Adminhtml\Form\Question;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Back to grid button.
*/
class Back extends GenericButton implements ButtonProviderInterface
{
/**
* Retrieve Back To Grid button settings.
*
* @return array
*/
public function getButtonData(): array
{
return $this->wrapButtonSettings(
'Back To Grid',
'back',
sprintf("location.href = '%s';", $this->getUrl('*/*/')),
[],
10
);
}
}
35 changes: 35 additions & 0 deletions Block/Adminhtml/Form/Question/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Block\Adminhtml\Form\Question;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Delete entity button.
*/
class Delete extends GenericButton implements ButtonProviderInterface
{
/**
* Retrieve Delete button settings.
*
* @return array
*/
public function getButtonData(): array
{
return $this->wrapButtonSettings(
'Delete',
'delete',
'deleteConfirm(\''
. __('Are you sure you want to delete this line configuration?')->render()
. '\', \'' . $this->getUrl('*/*/remove', ['id' => $this->getId()]) . '\')',
[],
20
);
}
}
79 changes: 79 additions & 0 deletions Block/Adminhtml/Form/Question/GenericButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Block\Adminhtml\Form\Question;

use Magento\Backend\Block\Widget\Context;
use Magento\Framework\UrlInterface;

/**
* Generic (form) button for FaqPage Question entity.
*/
class GenericButton
{
/** @var Context */
private Context $context;

/** @var UrlInterface */
private UrlInterface $urlBuilder;

/**
* @param Context $context
*/
public function __construct(Context $context)
{
$this->context = $context;
$this->urlBuilder = $context->getUrlBuilder();
}

/**
* @return int
*/
public function getId(): int
{
return (int) $this->context->getRequest()->getParam('id');
}

/**
* @param string $label
* @param string $class
* @param string $onclick
* @param array $dataAttribute
* @param int $sortOrder
*
* @return array
*/
protected function wrapButtonSettings(
string $label,
string $class,
string $onclick = '',
array $dataAttribute = [],
int $sortOrder = 0
): array {
return [
'label' => $label,
'on_click' => $onclick,
'data_attribute' => $dataAttribute,
'class' => $class,
'sort_order' => $sortOrder,
];
}

/**
* Get url.
*
* @param string $route
* @param array $params
*
* @return string
*/
protected function getUrl(string $route, array $params = []): string
{
return $this->urlBuilder->getUrl($route, $params);
}
}
36 changes: 36 additions & 0 deletions Block/Adminhtml/Form/Question/Save.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Marcin Materzok - MTRZK Sp. z o .o. All rights reserved.
* See LICENSE_MTRZK for license details.
*/

declare(strict_types=1);

namespace Mtrzk\FaqPage\Block\Adminhtml\Form\Question;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Save entity button.
*/
class Save extends GenericButton implements ButtonProviderInterface
{
/**
* Retrieve Save button settings.
*
* @return array
*/
public function getButtonData(): array
{
return $this->wrapButtonSettings(
'Save',
'save primary',
'',
[
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
10
);
}
}
Loading

0 comments on commit f9d2721

Please sign in to comment.