1<?php 2 3 4namespace ComboStrap; 5 6 7class LowQualityCalculatedIndicator extends MetadataBoolean 8{ 9 10 public const LOW_QUALITY_INDICATOR_CALCULATED = "low_quality_indicator_calculated"; 11 12 public static function createFromPage(Page $page) 13 { 14 return (new LowQualityCalculatedIndicator()) 15 ->setResource($page); 16 } 17 18 public function getTab(): ?string 19 { 20 // not in a form 21 return null; 22 } 23 24 public function getDescription(): string 25 { 26 return "The indicator calculated by the analytics process that tells if a page is of a low quality"; 27 } 28 29 public function getValue(): ?bool 30 { 31 $value = parent::getValue(); 32 if ($value !== null) { 33 return $value; 34 } 35 36 /** 37 * Migration code 38 * The indicator {@link LowQualityCalculatedIndicator::LOW_QUALITY_INDICATOR_CALCULATED} is new 39 * but if the analytics was done, we can get it 40 */ 41 $resource = $this->getResource(); 42 if (!($resource instanceof Page)) { 43 return null; 44 } 45 $analyticsDocument = $resource->getAnalyticsDocument(); 46 if (!FileSystems::exists($analyticsDocument->getCachePath())) { 47 return null; 48 } 49 try { 50 return $analyticsDocument->getJson()->toArray()[AnalyticsDocument::QUALITY][AnalyticsDocument::LOW]; 51 } catch (ExceptionCombo $e) { 52 LogUtility::msg("Error while reading the json analytics. {$e->getMessage()}"); 53 return null; 54 } 55 56 } 57 58 59 public function getLabel(): string 60 { 61 return "Low Quality Indicator"; 62 } 63 64 static public function getName(): string 65 { 66 return self::LOW_QUALITY_INDICATOR_CALCULATED; 67 } 68 69 public function getPersistenceType(): string 70 { 71 return Metadata::DERIVED_METADATA; 72 } 73 74 public function getMutable(): bool 75 { 76 return false; 77 } 78 79 /** 80 * By default, if a file has not been through 81 * a {@link \renderer_plugin_combo_analytics} 82 * analysis, this is a low page if protection is set 83 */ 84 public function getDefaultValue(): bool 85 { 86 87 if (!Site::isLowQualityProtectionEnable()) { 88 return false; 89 } 90 return true; 91 } 92} 93