2017-07-16 00:35:08 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* IntroController.php
|
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
|
|
*
|
2017-10-21 01:40:00 -05:00
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 07:41:58 -06:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2017-07-16 00:35:08 -05:00
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\Json;
|
|
|
|
|
2018-08-09 10:50:30 -05:00
|
|
|
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
|
2018-07-08 05:28:42 -05:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2017-07-22 03:50:30 -05:00
|
|
|
use Log;
|
2017-07-16 00:35:08 -05:00
|
|
|
|
|
|
|
/**
|
2017-11-15 05:25:49 -06:00
|
|
|
* Class IntroController.
|
2017-07-16 00:35:08 -05:00
|
|
|
*/
|
|
|
|
class IntroController
|
|
|
|
{
|
2018-08-09 10:50:30 -05:00
|
|
|
use GetConfigurationData;
|
|
|
|
|
2017-07-16 00:35:08 -05:00
|
|
|
/**
|
2018-07-21 01:06:24 -05:00
|
|
|
* Returns the introduction wizard for a page.
|
|
|
|
*
|
2018-07-08 05:08:53 -05:00
|
|
|
* @param string $route
|
|
|
|
* @param string|null $specificPage
|
2017-07-16 00:35:08 -05:00
|
|
|
*
|
2018-07-08 05:28:42 -05:00
|
|
|
* @return JsonResponse
|
2017-07-16 00:35:08 -05:00
|
|
|
*/
|
2018-07-08 05:28:42 -05:00
|
|
|
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse
|
2017-07-16 00:35:08 -05:00
|
|
|
{
|
2017-12-23 10:42:07 -06:00
|
|
|
Log::debug(sprintf('getIntroSteps for route "%s" and page "%s"', $route, $specificPage));
|
2018-07-08 05:08:53 -05:00
|
|
|
$specificPage = $specificPage ?? '';
|
2017-07-20 23:00:10 -05:00
|
|
|
$steps = $this->getBasicSteps($route);
|
|
|
|
$specificSteps = $this->getSpecificSteps($route, $specificPage);
|
2019-05-30 05:31:19 -05:00
|
|
|
if (0 === count($specificSteps)) {
|
2017-12-23 10:42:07 -06:00
|
|
|
Log::debug(sprintf('No specific steps for route "%s" and page "%s"', $route, $specificPage));
|
2017-12-29 02:05:35 -06:00
|
|
|
|
2018-03-10 13:30:09 -06:00
|
|
|
return response()->json($steps);
|
2017-07-20 23:00:10 -05:00
|
|
|
}
|
|
|
|
if ($this->hasOutroStep($route)) {
|
2017-12-23 10:42:07 -06:00
|
|
|
// @codeCoverageIgnoreStart
|
2017-07-20 23:00:10 -05:00
|
|
|
// save last step:
|
2019-05-30 05:31:19 -05:00
|
|
|
$lastStep = $steps[count($steps) - 1];
|
2017-07-20 23:00:10 -05:00
|
|
|
// remove last step:
|
|
|
|
array_pop($steps);
|
|
|
|
// merge arrays and add last step again
|
|
|
|
$steps = array_merge($steps, $specificSteps);
|
|
|
|
$steps[] = $lastStep;
|
2017-12-23 10:42:07 -06:00
|
|
|
// @codeCoverageIgnoreEnd
|
2017-07-20 23:00:10 -05:00
|
|
|
}
|
|
|
|
if (!$this->hasOutroStep($route)) {
|
|
|
|
$steps = array_merge($steps, $specificSteps);
|
|
|
|
}
|
|
|
|
|
2018-03-10 13:30:09 -06:00
|
|
|
return response()->json($steps);
|
2017-07-20 23:00:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-21 01:06:24 -05:00
|
|
|
* Returns true if there is a general outro step.
|
|
|
|
*
|
2017-07-20 23:00:10 -05:00
|
|
|
* @param string $route
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasOutroStep(string $route): bool
|
|
|
|
{
|
|
|
|
$routeKey = str_replace('.', '_', $route);
|
2017-12-23 10:42:07 -06:00
|
|
|
Log::debug(sprintf('Has outro step for route %s', $routeKey));
|
2017-07-20 23:00:10 -05:00
|
|
|
$elements = config(sprintf('intro.%s', $routeKey));
|
2019-06-22 06:09:25 -05:00
|
|
|
if (!is_array($elements)) {
|
2017-07-22 03:50:30 -05:00
|
|
|
return false;
|
|
|
|
}
|
2018-04-02 08:10:40 -05:00
|
|
|
|
|
|
|
$hasStep = array_key_exists('outro', $elements);
|
|
|
|
|
2017-12-23 10:42:07 -06:00
|
|
|
Log::debug('Elements is array', $elements);
|
|
|
|
Log::debug('Keys is', array_keys($elements));
|
2018-04-02 08:10:40 -05:00
|
|
|
Log::debug(sprintf('Keys has "outro": %s', var_export($hasStep, true)));
|
2017-07-20 23:00:10 -05:00
|
|
|
|
2018-04-02 08:10:40 -05:00
|
|
|
return $hasStep;
|
2017-07-20 23:00:10 -05:00
|
|
|
}
|
2017-07-23 00:35:30 -05:00
|
|
|
|
2017-07-23 00:30:05 -05:00
|
|
|
/**
|
2018-07-21 01:06:24 -05:00
|
|
|
* Enable the boxes for a specific page again.
|
|
|
|
*
|
2018-07-08 05:08:53 -05:00
|
|
|
* @param string $route
|
|
|
|
* @param string|null $specialPage
|
2017-07-23 00:30:05 -05:00
|
|
|
*
|
2018-07-08 05:28:42 -05:00
|
|
|
* @return JsonResponse
|
2017-07-23 00:30:05 -05:00
|
|
|
*/
|
2018-07-08 05:28:42 -05:00
|
|
|
public function postEnable(string $route, string $specialPage = null): JsonResponse
|
2017-07-23 00:30:05 -05:00
|
|
|
{
|
2018-07-08 05:08:53 -05:00
|
|
|
$specialPage = $specialPage ?? '';
|
|
|
|
$route = str_replace('.', '_', $route);
|
|
|
|
$key = 'shown_demo_' . $route;
|
2017-11-15 05:25:49 -06:00
|
|
|
if ('' !== $specialPage) {
|
2017-07-23 00:30:05 -05:00
|
|
|
$key .= '_' . $specialPage;
|
|
|
|
}
|
|
|
|
Log::debug(sprintf('Going to mark the following route as NOT done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
2018-07-14 09:08:34 -05:00
|
|
|
app('preferences')->set($key, false);
|
2017-07-23 00:30:05 -05:00
|
|
|
|
2018-07-15 02:38:49 -05:00
|
|
|
return response()->json(['message' => (string)trans('firefly.intro_boxes_after_refresh')]);
|
2017-07-23 00:30:05 -05:00
|
|
|
}
|
2017-07-20 23:00:10 -05:00
|
|
|
|
|
|
|
/**
|
2018-07-21 01:06:24 -05:00
|
|
|
* Set that you saw them.
|
|
|
|
*
|
2018-07-08 05:08:53 -05:00
|
|
|
* @param string $route
|
|
|
|
* @param string|null $specialPage
|
2017-07-20 23:00:10 -05:00
|
|
|
*
|
2018-07-08 05:28:42 -05:00
|
|
|
* @return JsonResponse
|
2017-07-20 23:00:10 -05:00
|
|
|
*/
|
2018-07-08 05:28:42 -05:00
|
|
|
public function postFinished(string $route, string $specialPage = null): JsonResponse
|
2017-07-20 23:00:10 -05:00
|
|
|
{
|
2018-07-08 05:08:53 -05:00
|
|
|
$specialPage = $specialPage ?? '';
|
|
|
|
$key = 'shown_demo_' . $route;
|
2017-11-15 05:25:49 -06:00
|
|
|
if ('' !== $specialPage) {
|
2017-07-22 03:50:30 -05:00
|
|
|
$key .= '_' . $specialPage;
|
|
|
|
}
|
2017-07-23 00:30:05 -05:00
|
|
|
Log::debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
2018-07-14 09:08:34 -05:00
|
|
|
app('preferences')->set($key, true);
|
2017-07-20 23:00:10 -05:00
|
|
|
|
2019-06-21 22:51:32 -05:00
|
|
|
return response()->json(['result' => sprintf('Reported demo watched for route "%s" (%s): %s.', $route, $specialPage, $key)]);
|
2017-07-20 23:00:10 -05:00
|
|
|
}
|
|
|
|
|
2017-08-12 00:48:39 -05:00
|
|
|
}
|