Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
251e3bc
Added LayoutController - moved from themes
anothersoftware-lv Aug 9, 2023
6c360c8
Added FlashHelper - moved from themes
anothersoftware-lv Aug 9, 2023
bf8f1a5
Added FieldAppendButtonHelper - moved from themes
anothersoftware-lv Aug 9, 2023
dd7deaf
Out of Blankontheme - Controllers extended from LayoutController
anothersoftware-lv Aug 10, 2023
b3b6c41
Out of Blankontheme - added D3SystemWidget component
anothersoftware-lv Aug 10, 2023
e5e29c2
Out of Blankontheme - included D3SystemWidget component
anothersoftware-lv Aug 10, 2023
8303d7e
Out of Blankontheme - isLayoutMinimal fix
anothersoftware-lv Aug 10, 2023
331864d
LayoutController - isLayoutMinimal fix
anothersoftware-lv Aug 10, 2023
2c2475d
Out of Blankontheme - D3SystemView button widget from D3SystemWidget
anothersoftware-lv Aug 10, 2023
bbe6078
Out of Blankontheme - UrlManager moved from theme
anothersoftware-lv Aug 10, 2023
30dd51f
Export buttons - default color primary
anothersoftware-lv Aug 10, 2023
83e38ac
Added Error Controller and views (resolved theme dependency problem)
anothersoftware-lv Aug 27, 2023
fb37061
Added backButtons to D3SystemView
uldisn Sep 5, 2023
210a1db
translation for crud improved
uldisn Sep 18, 2023
6f55ad3
D3SystemView - added page navigation functions
anothersoftware-lv Oct 13, 2023
073c2f5
Fixed FlashHelper bug for adding multi flashes
uldisn Nov 12, 2023
7224f8a
D3SystemView - added header (title) buttons
anothersoftware-lv Nov 12, 2023
e194189
Merge remote-tracking branch 'origin/argon' into argon
anothersoftware-lv Nov 12, 2023
cf44f40
D3SystemView added property pageTitleEncoded
uldisn Jan 25, 2024
a8688d3
i18n - Improved crud translations
anothersoftware-lv Feb 24, 2024
8943c5a
i18n - translation messages
anothersoftware-lv Feb 26, 2024
5a0febb
Improved D3EditableAction.php
uldisn Mar 27, 2024
3264f62
D3SystemView added property buttonDropdownClass
uldisn Apr 8, 2024
c16278c
ThBadge widget fix - removed bootstrap widget dependency
anothersoftware-lv Apr 16, 2024
9b38038
ThBadge - extended from D3Widget
anothersoftware-lv Apr 16, 2024
242030c
i18n - translation fixes
anothersoftware-lv Apr 17, 2024
281acc6
Merge remote-tracking branch 'origin/master' into argon
anothersoftware-lv Aug 9, 2024
ef47702
fixed comments
uldisn Aug 10, 2024
1784683
translation
uldisn Aug 13, 2024
e2ec42a
Merge remote-tracking branch 'origin/master' into argon
anothersoftware-lv Sep 23, 2024
e371c3a
Merge branch 'refs/heads/master' into argon
anothersoftware-lv Oct 9, 2024
2114171
Added ThKartikEditableColumnAction
uldisn Nov 13, 2024
e5216f7
To D3SystemView added themeName
uldisn Dec 4, 2024
bd4b816
Add ModelHelper class for normalizing float attributes
uldisn Feb 19, 2025
43c6d00
Add method to normalize integer data attributes
uldisn Feb 24, 2025
615af04
Refactor data normalization methods to handle null attributes
uldisn Feb 27, 2025
be9dedb
Add D3TrimValidator for conditional value trimming
uldisn May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actions/D3SettingAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace d3system\actions;

use eaBlankonThema\components\FlashHelper;
use d3system\helpers\FlashHelper;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Model;
Expand Down
80 changes: 80 additions & 0 deletions actions/ThKartikEditableColumnAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace d3system\actions;

use Exception;
use kartik\grid\EditableColumnAction;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;


/**
* use d3system\actions\D3EditableAction;
*
* class SiteController extends Controller
* {
* public function actions()
* {
* return [
* 'column-editable' => [
* 'class' => ThEditableColumnAction::class, // action class name
* 'modelClass' => PkPersonPlaygroundLimit::class,
* 'findModelControllerMethod' => 'findModelForEditable',
* 'canUpdateAttributes' => ['recomended']
* ],
* ];
* }
* }
*
* // column
* $columns = [
* [
* 'class' => EditableColumn::class,
* 'attribute' => 'recomended',
* 'editableOptions' => [
* 'inputType' => kartik\editable\Editable::INPUT_TEXT,
* 'formOptions' => [
* 'action' => Url::to([
* 'pk-person-playground-limit/column-recommended-update',
* ])
* ],
* ]
* ];
*
*/
class ThKartikEditableColumnAction extends EditableColumnAction
{
/**
* @var string|null controller method for find model record
*/
public ?string $findModelControllerMethod = null;

/**
* @var array attributes, which can be updated
*/
public array $canUpdateAttributes = [];

/**
* @throws InvalidConfigException
* @throws Exception
*/
public function init()
{
if ($this->findModelControllerMethod) {
$controller = $this->controller;
$method = $this->findModelControllerMethod;
$this->findModel = static function ($id) use ($controller, $method) {
return $controller->$method($id);
};
}
if ($this->canUpdateAttributes) {
$post = Yii::$app->request->post();
$attributeName = ArrayHelper::getValue($post, 'editableAttribute');
if (!in_array($attributeName, $this->canUpdateAttributes, true)) {
throw new \yii\base\Exception('Illegal request');
}
}
parent::init();
}
}
35 changes: 35 additions & 0 deletions controllers/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace d3system\controllers;

use Yii;
use yii\helpers\VarDumper;
use yii\web\Controller;

class ErrorController extends Controller
{
public function actionIndex()
{

$message = null;
if ($exception = Yii::$app->errorHandler->exception) {
$message = $exception->getMessage();
// echo VarDumper::dumpAsString($exception->getMessage());
// echo VarDumper::dumpAsString($exception->getTraceAsString());
}

switch (Yii::$app->response->statusCode) {
case 403:
return $this->render('error-403', ['message' => $message]);

case 404:
return $this->render('error-404');

case 500:
return $this->render('error-500');

default:
return $this->render('error-other');
}
}
}
2 changes: 1 addition & 1 deletion exceptions/D3ActiveRecordException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace d3system\exceptions;

use eaBlankonThema\components\FlashHelper;
use d3system\helpers\FlashHelper;
use Yii;
use yii\base\Exception;
use yii\console\Application;
Expand Down
121 changes: 121 additions & 0 deletions helpers/FieldAppendButtonHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

namespace d3system\helpers;

use cornernote\returnurl\ReturnUrl;
use Exception;
use Yii;
use yii\web\Request;

class FieldAppendButtonHelper
{

/**
* @param string|null $modelPrimaryKeyValue
* @param Request $request
* @param array $addModels
* @return bool|string
*/
public static function createReturnUrl($modelPrimaryKeyValue, Request $request, array $addModels = [])
{
try {
/**
* if create open by "INPUT +", redirect back with fixed relAtributes
*/

$returnFormUpdateField = $request->get('rfuf');
$returnUrl = ReturnUrl::getUrl();
$returnForm = $request->get('rf');

if (!$returnForm) {
return false;
}

$returnFormData = $request->get($returnForm, []);

if ($returnFormUpdateField && isset($returnFormData[$returnFormUpdateField])) {
self::removeQsVar($returnUrl, $returnForm . '[' . $returnFormUpdateField . ']');
}
if ($modelPrimaryKeyValue) {
$returnFormData[$returnFormUpdateField] = $modelPrimaryKeyValue;
}
$returnFormData = [$returnForm => $returnFormData];

/**
* load add models
*/

if ($addForms = $request->get('addModels')) {
$addForms = explode(',', $addForms);
foreach ($addForms as $addFormName) {
if ($addFormData = $request->get($addFormName)) {
if ($returnFormUpdateField && isset($addFormData[$returnFormUpdateField])) {
self::removeQsVar($returnUrl, $addFormName . '[' . $returnFormUpdateField . ']');
$addFormData[$returnFormUpdateField] = $modelPrimaryKeyValue;
}
$returnFormData[$addFormName] = $addFormData;
}
}
}

/**
* Assign fields from another models if aliases specified
*/
if (!empty($addModels) && $aliases = $request->get('rfa')) {
$data = unserialize(base64_decode($aliases));
if (is_array($data)) {
foreach ($data as $formName => $fields) {
foreach ($fields as $field => $alias) {
$aliasData = explode('|', $alias);
if (!isset($addModels[$aliasData[0]])) {
continue;
}
if (!isset($addModels[$aliasData[0]]->{$aliasData[1]})) {
continue;
}
$returnFormData[$formName][$field] = $addModels[$aliasData[0]]->{$aliasData[1]};
}
}
}
}

$returnParams = http_build_query($returnFormData);
return $returnUrl . '&' . $returnParams;
} catch (Exception $err) {
Yii::error($err->getMessage());
}
}

/**
* @param string $fieldName
* @param Request $request
* @return bool|mixed
*/
public static function getReturnFormField(string $fieldName, Request $request)
{
if (!($returnFormName = $request->get('rf'))) {
return false;
}
if (!($returnForm = $request->get($returnFormName))) {
return false;
}
return $returnForm[$fieldName];
}

/**
* @param $url
* @param $varname
* @return string
*/
public static function removeQsVar($url, $varname): string
{
[$urlpart, $qspart] = array_pad(explode('?', $url), 2, '');
parse_str($qspart, $qsvars);
if (!isset($qsvars[$varname])) {
return $url;
}
unset($qsvars[$varname]);
$newqs = http_build_query($qsvars);
return $urlpart . '?' . $newqs;
}
}
131 changes: 131 additions & 0 deletions helpers/FlashHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace d3system\helpers;

use Exception;
use Yii;
use yii\base\Model;

class FlashHelper
{
public const TYPE_SUCCESS = 'success';
public const TYPE_INFO = 'info';
public const TYPE_WARNING = 'warning';
public const TYPE_DANGER = 'danger';
public const TYPE_DEFAULT = 'default';
public const TYPE_LILAC = 'lilac';
public const TYPE_INVERSE = 'inverse';
public const TYPE_TEALS = 'teals';

/**
* @param Exception $e
* @param string $flashMessage message for displaying to user
* @param string $errorMessage message for error log
*/
public static function processException($e, string $flashMessage = '', string $errorMessage = ''): void
{
$messageList = [];

if ($errorMessage) {
$messageList[] = 'ErrorMessage: ' . $errorMessage;
}

if ($flashMessage) {
$messageList[] = 'FlashMessage: ' . $flashMessage;
}

$messageList[] = 'ExceptionMessage: ' . $e->getMessage();

$messageList[] = $e->getTraceAsString();

Yii::error(implode(PHP_EOL, $messageList));

self::addWarning($flashMessage ?: $e->getMessage());
}

public static function addWarning(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_WARNING, $message, ['showStrongText' => $short]);
}

public static function addDanger(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_DANGER, $message, ['showStrongText' => $short]);
}

public static function addInfo(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_INFO, $message, ['showStrongText' => $short]);
}

public static function addDefault(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_DEFAULT, $message, ['showStrongText' => $short]);
}

public static function addSuccess(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_SUCCESS, $message, ['showStrongText' => $short]);
}

public static function addLilac(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_LILAC, $message, ['showStrongText' => $short]);
}

public static function addTeals(string $message, bool $short = false): void
{
self::addFlash(self::TYPE_TEALS, $message, ['showStrongText' => $short]);
}

public static function addFlash($type, $message, $options = null): void
{
/** search free flash key for type $k */
$k = 0;
while (self::hasFlash(self::createKey($type, $k))) {
$k++;
}
$options['body'] = $message;
Yii::$app->session->addFlash(self::createKey($type, $k), $options);
}

/**
* check if exist flash with key
* @param string $key
* @return bool
*/
private static function hasFlash(string $key): bool
{
$session = Yii::$app->session;
$counters = $session->get($session->flashParam);
return isset($counters[$key]);
}

public static function createKey($type, $k): string
{
return $type . '::' . $k;
}

public static function getTypeFromKey(string $key)
{
$list = explode('::', $key, 2);
if (count($list) !== 2) {
return $key;
}

return $list[0];
}

/**
* @param $model Model
* @return void
*/
public static function modelErrorSummary($model): void
{
foreach ($model->getErrors() as $attribute => $errorList) {
foreach ($errorList as $error) {
self::addWarning($model->getAttributeLabel($attribute) . ': ' . $error);
}
}
}
}
Loading