@@ -303,9 +303,9 @@ public static function showForZone(CommonDBTM $item)
303303 *
304304 * @param string $source_name
305305 * @param string $zone_name
306- * @return string
306+ * @return bool
307307 */
308- public function getFromDbBySourceAndZone (string $ source_name , string $ zone_name ): ? string
308+ public function getFromDbBySourceAndZone (string $ source_name , string $ zone_name ): bool
309309 {
310310 /** @var DBmysql $DB */
311311 global $ DB ;
@@ -314,7 +314,7 @@ public function getFromDbBySourceAndZone(string $source_name, string $zone_name)
314314 $ source_table = Source::getTable ();
315315 $ source_zone_table = self ::getTable ();
316316 $ request = [
317- 'SELECT ' => Source_Zone::getTableField ( ' code ' ) ,
317+ 'SELECT ' => Source_Zone::getTable () . ' .id ' ,
318318 'FROM ' => $ source_zone_table ,
319319 'INNER JOIN ' => [
320320 $ source_table => [
@@ -337,9 +337,11 @@ public function getFromDbBySourceAndZone(string $source_name, string $zone_name)
337337 'LIMIT ' => '1 '
338338 ];
339339 $ iterator = $ DB ->request ($ request );
340- $ zone_code = $ iterator ->current ()['code ' ] ?? null ;
341-
342- return $ zone_code ;
340+ if ($ iterator ->count () !== 1 ) {
341+ return false ;
342+ }
343+ $ id = $ iterator ->current ()['id ' ];
344+ return $ this ->getFromDB ($ id );
343345 }
344346
345347 /**
@@ -499,4 +501,46 @@ public function getOrCreate(array $params, array $where): ?self
499501 $ this ->update (array_merge ($ where , $ params , ['id ' => $ this ->getID ()]));
500502 return $ this ;
501503 }
504+
505+ /**
506+ * Show gaps in carbon intensities stored for the source and zone of the current instance
507+ *
508+ * @return void
509+ */
510+ public function showGaps ()
511+ {
512+ $ canedit = false ;
513+ $ oldest_asset_date = (new Toolbox ())->getOldestAssetDate ();
514+ $ carbon_intensity = new CarbonIntensity ();
515+ $ entries = $ carbon_intensity ->findGaps (
516+ $ this ->fields ['plugin_carbon_sources_id ' ],
517+ $ this ->fields ['plugin_carbon_zones_id ' ],
518+ $ oldest_asset_date
519+ );
520+ $ total = $ entries ->count ();
521+
522+ $ renderer = TemplateRenderer::getInstance ();
523+ $ renderer ->display ('components/datatable.html.twig ' , [
524+ 'is_tab ' => true ,
525+ 'nopager ' => true ,
526+ 'nofilter ' => true ,
527+ 'nosort ' => true ,
528+ 'columns ' => [
529+ 'start ' => __ ('Start ' ),
530+ 'end ' => __ ('End ' , 'carbon ' ),
531+ ],
532+ 'footers ' => [
533+ ['' , '' , '' , __ ('Total ' ), $ total , '' ]
534+ ],
535+ 'footer_class ' => 'fw-bold ' ,
536+ 'entries ' => $ entries ,
537+ 'total_number ' => count ($ entries ),
538+ 'filtered_number ' => count ($ entries ),
539+ 'showmassiveactions ' => $ canedit ,
540+ 'massiveactionparams ' => [
541+ 'num_displayed ' => count ($ entries ),
542+ 'container ' => 'mass ' . static ::class . mt_rand (),
543+ ]
544+ ]);
545+ }
502546}
0 commit comments