Skip to content

Commit

Permalink
phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMis committed Apr 28, 2021
1 parent 8242439 commit 19aab8b
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 78 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function renderTwigAjaxReturn(Request $request, Response $response)

// Render the view manually with Twig, parse it and pull out various bits
try {
$view = $this->getView()->render($response,$state->template . '.twig', $data);
$view = $this->getView()->render($response, $state->template . '.twig', $data);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
throw new GeneralException(__('Twig Error ') . $e->getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ public function download(Request $request, Response $response)
public function fontCss(Request $request, Response $response)
{
// Regenerate the CSS for fonts
$css = $this->getMediaService()->installFonts(RouteContext::fromRequest($request)->getRouteParser(),['invalidateCache' => false]);
$css = $this->getMediaService()->installFonts(RouteContext::fromRequest($request)->getRouteParser(), ['invalidateCache' => false]);

// Work out the etag
/** @var $httpCache HttpCacheProvider*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/MenuBoardProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function grid(Request $request, Response $response, $id): Response
'text' => __('Delete'),
'multi-select' => true,
'dataAttributes' => [
['name' => 'commit-url', 'value' => $this->urlFor($request,'menuBoard.product.delete', ['id' => $menuBoardProduct->menuProductId])],
['name' => 'commit-url', 'value' => $this->urlFor($request, 'menuBoard.product.delete', ['id' => $menuBoardProduct->menuProductId])],
['name' => 'commit-method', 'value' => 'delete'],
['name' => 'id', 'value' => 'menuBoardProduct_delete_button'],
['name' => 'text', 'value' => __('Delete')],
Expand Down
7 changes: 4 additions & 3 deletions lib/Controller/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -1056,11 +1056,11 @@ public function savedReportExport(Request $request, Response $response, $id, $na
$emailTemplate = $this->reportService->getReportEmailTemplate($name);

if (!empty($emailTemplate)) {

// Save PDF attachment
ob_start();
// Render the template
echo $this->getView()->fetch($emailTemplate,
echo $this->getView()->fetch(
$emailTemplate,
[
'header' => $report->description,
'logo' => $this->getConfig()->uri('img/xibologo.png', true),
Expand All @@ -1072,7 +1072,8 @@ public function savedReportExport(Request $request, Response $response, $id, $na
'src' => isset($src) ? $src : null,
'multipleCharts' => isset($multipleCharts) ? $multipleCharts : null,
'placeholder' => isset($placeholder) ? $placeholder : null
]);
]
);
$body = ob_get_contents();
ob_end_clean();

Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ public function permissionsMultiGrid(Request $request, Response $response, $enti
for ($i=0; $i < count($ids); $i++) {
$objectId = $ids[$i];

$objects[$i] = $this->parsePermissionsEntity($entity, $objectId);;
$objects[$i] = $this->parsePermissionsEntity($entity, $objectId);

// Does this user have permission to edit the permissions?!
if (!$this->getUser()->checkPermissionsModifyable($objects[$i])) {
Expand Down Expand Up @@ -1864,7 +1864,7 @@ public function permissions(Request $request, Response $response, $entity, $id)
/** @var $object Media */
if ($object->mediaType === 'font') {
// Drop permissions (we need to reassess).
$this->getMediaService($this->getUser())->installFonts(RouteContext::fromRequest($request)->getRouteParser(),['invalidateCache' => true]);
$this->getMediaService($this->getUser())->installFonts(RouteContext::fromRequest($request)->getRouteParser(), ['invalidateCache' => true]);
}
}

Expand Down
19 changes: 8 additions & 11 deletions lib/Entity/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public function save($validate = true)
} else {
$this->edit();
}


}

public function delete()
Expand Down Expand Up @@ -226,7 +224,6 @@ private function manageChildren($mode)
$children = array_filter(explode(',', $this->children));

if ($mode === 'delete') {

// remove this folder from children of the parent
foreach ($parentChildren as $index => $child) {
if ((int)$child === (int)$this->id) {
Expand Down Expand Up @@ -324,39 +321,39 @@ private function manageChildPermissions($permissionFolderId)

private function updateChildObjects($permissionFolderId, $folderId)
{
$this->getStore()->update('UPDATE `folder` SET permissionsFolderId = :permissionsFolderId WHERE parentId = :folderId',[
$this->getStore()->update('UPDATE `folder` SET permissionsFolderId = :permissionsFolderId WHERE parentId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);

$this->getStore()->update('UPDATE `media` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId',[
$this->getStore()->update('UPDATE `media` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);

$this->getStore()->update('UPDATE `campaign` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId',[
$this->getStore()->update('UPDATE `campaign` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);

$this->getStore()->update('UPDATE `displaygroup` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId',[
$this->getStore()->update('UPDATE `displaygroup` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);

$this->getStore()->update('UPDATE `dataset` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId',[
$this->getStore()->update('UPDATE `dataset` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);

$this->getStore()->update('UPDATE `playlist` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId',[
$this->getStore()->update('UPDATE `playlist` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);

$this->getStore()->update('UPDATE `menu_board` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId',[
$this->getStore()->update('UPDATE `menu_board` SET permissionsFolderId = :permissionsFolderId WHERE folderId = :folderId', [
'permissionsFolderId' => $permissionFolderId,
'folderId' => $folderId
]);
}
}
}
67 changes: 48 additions & 19 deletions lib/Factory/ModuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,22 @@ public function create($type)
{
$modules = $this->query(['enabled DESC'], array('type' => $type));

$this->getLog()->debug(sprintf('Creating %s out of possible %s', $type, json_encode(array_map(function($element) { return $element->class; }, $modules))));

if (count($modules) <= 0)
$this->getLog()->debug(sprintf(
'Creating %s out of possible %s',
$type,
json_encode(
array_map(
function ($element) {
return $element->class;
},
$modules
)
)
));

if (count($modules) <= 0) {
throw new NotFoundException(sprintf(__('Unknown type %s'), $type));
}

// Create a module
return $this->moduleService->get(
Expand Down Expand Up @@ -232,10 +244,22 @@ public function createByClass($class)
{
$modules = $this->query(['enabled DESC'], array('class' => $class));

$this->getLog()->debug(sprintf('Creating %s out of possible %s', $class, json_encode(array_map(function($element) { return $element->class; }, $modules))));

if (count($modules) <= 0)
$this->getLog()->debug(sprintf(
'Creating %s out of possible %s',
$class,
json_encode(
array_map(
function ($element) {
return $element->class;
},
$modules
)
)
));

if (count($modules) <= 0) {
throw new NotFoundException(sprintf(__('Unknown class %s'), $class));
}

// Create a module
return $this->moduleService->get(
Expand Down Expand Up @@ -324,8 +348,9 @@ public function createWithMedia($media)
{
$modules = $this->query(null, array('type' => $media->mediaType));

if (count($modules) <= 0)
if (count($modules) <= 0) {
throw new NotFoundException(sprintf(__('Unknown type %s'), $media->mediaType));
}

// Create a widget
$widget = $this->widgetFactory->createEmpty();
Expand Down Expand Up @@ -389,8 +414,7 @@ public function createForWidget($type, $widgetId = 0, $ownerId = 0, $playlistId
// Create a new widget to use
$widget = $this->widgetFactory->create($ownerId, $playlistId, $module->getModuleType(), null);
$module->setWidget($widget);
}
else {
} else {
// Load the widget
$module->setWidget($this->widgetFactory->loadByWidgetId($widgetId));
}
Expand Down Expand Up @@ -434,8 +458,7 @@ public function get($key = 'type')
$modules = $this->query();

if ($key != null && $key != '') {

$keyed = array();
$keyed = [];
foreach ($modules as $module) {
/* @var Module $module */
$keyed[$module->type] = $module;
Expand Down Expand Up @@ -465,8 +488,9 @@ public function getById($moduleId)
{
$modules = $this->query(null, array('moduleId' => $moduleId));

if (count($modules) <= 0)
if (count($modules) <= 0) {
throw new NotFoundException();
}

return $modules[0];
}
Expand All @@ -481,8 +505,9 @@ public function getByInstallName($installName)
{
$modules = $this->query(null, ['installName' => $installName]);

if (count($modules) <= 0)
if (count($modules) <= 0) {
throw new NotFoundException();
}

return $modules[0];
}
Expand All @@ -498,8 +523,9 @@ public function getByType($name)
{
$modules = $this->query(['enabled DESC'], ['name' => $name]);

if (count($modules) <= 0)
if (count($modules) <= 0) {
throw new NotFoundException(sprintf(__('Module type %s does not match any enabled Module'), $name));
}

return $modules[0];
}
Expand All @@ -523,8 +549,9 @@ public function getByExtension($extension)
{
$modules = $this->query(['enabled DESC'], array('extension' => $extension));

if (count($modules) <= 0)
if (count($modules) <= 0) {
throw new NotFoundException(sprintf(__('Extension %s does not match any enabled Module'), $extension));
}

return $modules[0];
}
Expand All @@ -539,7 +566,7 @@ public function getValidExtensions($filterBy = [])
$modules = $this->query(null, $filterBy);
$extensions = array();

foreach($modules as $module) {
foreach ($modules as $module) {
/* @var Module $module */
if ($module->validExtensions != '') {
foreach (explode(',', $module->validExtensions) as $extension) {
Expand Down Expand Up @@ -577,8 +604,9 @@ public function query($sortOrder = null, $filterBy = [])
{
$parsedBody = $this->getSanitizer($filterBy);

if ($sortOrder == null)
if ($sortOrder == null) {
$sortOrder = array('Module');
}

$entries = array();

Expand Down Expand Up @@ -665,8 +693,9 @@ public function query($sortOrder = null, $filterBy = [])

// Sorting?
$order = '';
if (is_array($sortOrder))
if (is_array($sortOrder)) {
$order .= 'ORDER BY ' . implode(',', $sortOrder);
}

$limit = '';
// Paging
Expand Down Expand Up @@ -718,4 +747,4 @@ public function query($sortOrder = null, $filterBy = [])

return $entries;
}
}
}
20 changes: 15 additions & 5 deletions lib/Middleware/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,26 @@ public function process(Request $request, RequestHandler $handler): Response

// Process Actions
if (!Environment::migrationPending() && $container->get('configService')->getSetting('DEFAULTS_IMPORTED') == 0) {

$folder = $container->get('configService')->uri('layouts', true);

foreach (array_diff(scandir($folder), array('..', '.')) as $file) {
if (stripos($file, '.zip')) {
try {
/** @var \Xibo\Entity\Layout $layout */
$layout = $container->get('layoutFactory')->createFromZip($folder . '/' . $file, null,
$container->get('userFactory')->getSystemUser()->getId(), false, false, true, false,
true, $container->get('dataSetFactory'), null, $routeContext->getRouteParser(), $container->get('mediaService'));
$layout = $container->get('layoutFactory')->createFromZip(
$folder . '/' . $file,
null,
$container->get('userFactory')->getSystemUser()->getId(),
false,
false,
true,
false,
true,
$container->get('dataSetFactory'),
null,
$routeContext->getRouteParser(),
$container->get('mediaService')
);
$layout->save([
'audit' => false,
'import' => true
Expand Down Expand Up @@ -179,4 +189,4 @@ private function isAjax(Request $request)
{
return strtolower($request->getHeaderLine('X-Requested-With')) === 'xmlhttprequest';
}
}
}
2 changes: 1 addition & 1 deletion lib/Middleware/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ public static function registerFactoriesWithDi()
public static function registerDispatcherWithDi()
{
return [
'dispatcher' => function(ContainerInterface $c) {
'dispatcher' => function (ContainerInterface $c) {
$dispatcher = new EventDispatcher();

// Media Delete Events
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/MenuBoardCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function tearDown()

public function testListEmpty()
{
$response = $this->sendRequest('GET','/menuboard/' . $this->menuBoard['menuId'] . '/categories');
$response = $this->sendRequest('GET', '/menuboard/' . $this->menuBoard['menuId'] . '/categories');

$this->assertSame(200, $response->getStatusCode());
$this->assertNotEmpty($response->getBody());
Expand All @@ -68,7 +68,7 @@ public function testAdd()
$media = (new XiboLibrary($this->getEntityProvider()))->create(Random::generateString(10, 'API Image'), PROJECT_ROOT . '/tests/resources/xts-night-001.jpg');
$name = Random::generateString(10, 'Category Add');

$response = $this->sendRequest('POST','/menuboard/' . $this->menuBoard['menuId'] . '/category', [
$response = $this->sendRequest('POST', '/menuboard/' . $this->menuBoard['menuId'] . '/category', [
'name' => $name,
'mediaId' => $media->mediaId
]);
Expand All @@ -86,16 +86,16 @@ public function testAdd()

public function testEdit()
{
$menuBoardCategory = $this->getEntityProvider()->post( '/menuboard/' . $this->menuBoard['menuId'] . '/category', [
$menuBoardCategory = $this->getEntityProvider()->post('/menuboard/' . $this->menuBoard['menuId'] . '/category', [
'name' => 'Test Menu Board Category Edit'
]);
$name = Random::generateString(10, 'Category Edit');

$response = $this->sendRequest('PUT','/menuboard/' . $menuBoardCategory['menuCategoryId'] . '/category', [
$response = $this->sendRequest('PUT', '/menuboard/' . $menuBoardCategory['menuCategoryId'] . '/category', [
'name' => $name,
]);

$this->assertSame(200, $response->getStatusCode(), "Not successful: " . $response->getBody());
$this->assertSame(200, $response->getStatusCode(), 'Not successful: ' . $response->getBody());

$object = json_decode($response->getBody());
$this->assertObjectHasAttribute('data', $object);
Expand All @@ -113,6 +113,6 @@ public function testDelete()

$object = json_decode($response->getBody());
$this->assertSame(204, $object->status);
$this->assertSame(200, $response->getStatusCode(), "Not successful: " . $response->getBody());
$this->assertSame(200, $response->getStatusCode(), 'Not successful: ' . $response->getBody());
}
}
Loading

0 comments on commit 19aab8b

Please sign in to comment.