more good code

This commit is contained in:
Ste Vaidis 2024-04-18 10:11:15 +03:00
parent 31d1c745b8
commit b718cd36e3
2 changed files with 23 additions and 10 deletions

View File

@ -187,6 +187,15 @@ class NodesController extends ControllerBase implements ContainerInjectionInterf
} }
} }
/* pager: ?offset=0&limit=3 */
$offset = $request->get('offset');
$limit = $request->get('limit');
if (isset($offset) && isset($limit)) {
$offset = intval($offset);
$limit = intval($limit);
$query->range($offset, $limit);
}
/* execute query to get node ids */ /* execute query to get node ids */
$nodeIds = $query $nodeIds = $query
->condition('type', self::NODE_TYPE) ->condition('type', self::NODE_TYPE)
@ -198,14 +207,18 @@ class NodesController extends ControllerBase implements ContainerInjectionInterf
->getStorage('node') ->getStorage('node')
->loadMultiple($nodeIds); ->loadMultiple($nodeIds);
/* Response List */ /* build the response list of nodes */
$nodeList=[]; $nodeList=[];
foreach ($nodes as $node) { foreach ($nodes as $node) {
$tid = $node->id(); if ($node instanceof NodeInterface && $node->access('view')) {
$nodeList[$tid] = $node->hasTranslation($lang) ? $node->getTranslation($lang) : $node; $tid = $node->id();
$node->currentTranslation = $lang; $translatedNode = $node->hasTranslation($lang) ? $node->getTranslation($lang) : $node;
} $translatedNode->currentTranslation = $lang;
return $nodeList; $nodeList[$tid] = $translatedNode;
}
}
return $nodeList;
} }
// \Drupal::logger('Bundle AAAAA')->notice(''.$some_var); // \Drupal::logger('Bundle AAAAA')->notice(''.$some_var);
} }

View File

@ -2,7 +2,7 @@
DIR_PATH=${1} DIR_PATH=${1}
DIR=$(/usr/bin/basename ${DIR_PATH}) DIR=$(/usr/bin/basename ${DIR_PATH})
LOG="${DIR}.log" LOG="${DIR}.backup.log"
TIMESTAMP=$(/usr/bin/date +%Y/%m/%d' '%H:%M:%S) TIMESTAMP=$(/usr/bin/date +%Y/%m/%d' '%H:%M:%S)
# #