Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions assets/vendor/atk4/ui/2.0.4/atkjs-ui.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
}
],
"require": {
"atk4/ui": "2.0.4"
"atk4/ui": "2.0.4",
"atk4/data": "2.0.4",
"atk4/core": "2.0.2",
"atk4/dsql": "2.0.2"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
Expand Down
13 changes: 13 additions & 0 deletions src/AtkWp.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class AtkWp
*/
private $ajaxMode = false;

/**
* Manage the models involved in the plugin.
*
* @var AtkWpModelManager
*/
private $atkWpModelManager;

/**
* AtkWp constructor.
*
Expand All @@ -116,6 +123,7 @@ class AtkWp
*/
public function __construct($pluginName, PathInterface $pathFinder, ComponentCtrlInterface $ctrl)
{
$this->atkWpModelManager = new AtkWpModelManager($this);
$this->pluginName = $pluginName;
$this->pathFinder = $pathFinder;
$this->componentCtrl = $ctrl;
Expand Down Expand Up @@ -490,4 +498,9 @@ public function wpShortcodeExecute($shortcode, $args)
$this->caughtException($e);
}
}

public function getModelManager(): AtkWpModelManager
{
return $this->atkWpModelManager;
}
}
41 changes: 41 additions & 0 deletions src/AtkWpApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,45 @@ public function loadTemplate($name)

return $template->load($this->plugin->getTemplateLocation($name));
}

public function terminate($output = null)
{
if ($output !== null) {
if ($this->isJsonRequest()) {
if (is_string($output)) {
$decode = json_decode($output, true);
if (json_last_error() === JSON_ERROR_NONE) {
$decode['modals'] = $this->getRenderedModals();
$output = $decode;
}
} elseif (is_array($output)) {
$output['modals'] = $this->getRenderedModals();
}
$this->outputResponseJSON($output);
} elseif (isset($_GET['__atk_tab'])) {
// ugly hack for TABS
// because fomantic ui tab only deal with html and not JSON
// we need to hack output to include app modal.
$keys = null;
$remove_function = '';
foreach ($this->getRenderedModals() as $key => $modal) {
// add modal rendering to output
$keys[] = '#'.$key;
$output['atkjs'] = $output['atkjs'].';'.$modal['js'];
$output['html'] = $output['html'].$modal['html'];
}
if ($keys) {
$ids = implode(',', $keys);
$remove_function = "$('.ui.dimmer.modals.page').find('${ids}').remove();";
}
$output = '<script>var $=jQuery.noConflict();(function() {'.$remove_function.$output['atkjs'].'})($);</script>'.$output['html'];
$this->outputResponseHtml($output);
} else {
$this->outputResponseHTML($output);
}
}

$this->run_called = true; // prevent shutdown function from triggering.
$this->callExit();
}
}
75 changes: 75 additions & 0 deletions src/AtkWpModelManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace atkwp;

use atkwp\helpers\WpUtil;
use atkwp\models\Model;

class AtkWpModelManager
{
/**
* @var Model[]
*/
private $models = [];
/**
* @var AtkWp
*/
private $atkwp;

public function __construct(AtkWp $atkwp)
{
$this->atkwp = $atkwp;
}

public function addModel(string $fqcn_model)
{
$name = strtolower((new \ReflectionClass($fqcn_model))->getShortName());
$this->models[$fqcn_model] = new $fqcn_model(
$this->atkwp->getDbConnection(),
$this->getTableName($name)
);
}

private function getTableName(string $name)
{
return strtolower(
sprintf(
'%s_%s_%s',
WpUtil::getDbPrefix(),
$this->atkwp->getPluginName(),
$name,
)
);
}

public function upgradeDb()
{
// process models statement for dbDelta
foreach ($this->models as $model) {
// check if the model allow upgrade
if ($model->isEnabledDbDelta()) {
$stmt = $statement = sprintf(
'CREATE TABLE `%s` (%s%s%s)%sCOLLATE {%s}',
$model->table,
PHP_EOL,
$model->getSQLSchema(),
PHP_EOL,
PHP_EOL,
WpUtil::getDbCharsetCollate()
);

dbDelta($stmt);
}
}
}

/**
* @param string $fqcn Model FQCN
*
* @return Model|null
*/
public function getModel(string $fqcn): ?Model
{
return clone $this->models[$fqcn] ?? null;
}
}
7 changes: 4 additions & 3 deletions src/helpers/Pathfinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace atkwp\helpers;

use atk4\ui\Exception;
use atkwp\interfaces\PathInterface;

class Pathfinder implements PathInterface
Expand Down Expand Up @@ -88,7 +89,7 @@ public function getAssetsPath()
*
* @param string $fileName The name of the template file.
*
* @throws \atk4\ui\Exception
* @throws Exception
*
* @return mixed|string
*/
Expand Down Expand Up @@ -121,7 +122,7 @@ private function setFilesLocation($path, $skin)
* @param string $type
* @param string $fileName
*
* @throws \atk4\ui\Exception
* @throws Exception
*
* @return string
*/
Expand All @@ -134,7 +135,7 @@ private function getFileLocation($type, $fileName)
}
}

throw new \atk4\ui\Exception([
throw new Exception([
'Unable to get path location for file: '.$fileName,
]);
}
Expand Down
33 changes: 30 additions & 3 deletions src/models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,43 @@

use atkwp\helpers\WpUtil;

class Model extends \atk4\data\Model
abstract class Model extends \atk4\data\Model
{
public $wp_table;

public function init()
protected $dbdelta_enabled = true;

public function init(): void
{
if (!empty($this->wp_table)) {
$this->table = WpUtil::getDbPrefix().$this->wp_table;
}

return parent::init();
parent::init();
}

/**
* Used during installation of plugin, if Model schema need to be processed via dbDelta.
*
* @return bool
*/
public function isEnabledDbDelta(): bool
{
return $this->dbdelta_enabled;
}

/**
* Return internal declaration of SQL Schema.
*
* Ex : return "
* `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
* `type` VARCHAR(255) NOT NULL DEFAULT '',
* `imported` int(11) NOT NULL DEFAULT 0,
* `date` DATE NOT NULL,
* PRIMARY KEY (`id`)
* "
*
* @return string
*/
abstract public function getSQLSchema(): string;
}
3 changes: 2 additions & 1 deletion src/services/DashboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public function registerDashboard($key, $dashboard)
};
}

wp_add_dashboard_widget($key,
wp_add_dashboard_widget(
$key,
$dashboard['title'],
$this->executable,
$configureCallback
Expand Down
2 changes: 1 addition & 1 deletion src/services/EnqueueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EnqueueService
*/
private $ctrl;

protected $atkUiVersion = '1.6';
protected $atkUiVersion = '2.0.4';
protected $fomanticUiVersion = '2.6.4';

/**
Expand Down
2 changes: 1 addition & 1 deletion templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{$HEAD}
<div id="{$_id}" class="ui container {$class} {$_class}">{$Content}</div>
<div id="{$_id}" style="{$style}" class="ui container {$class} {$_class}">{$Content}</div>