parentContainer = $content; $this->typeId = $moduleType; $this->moduleTypeContent = $moduleTypeContent; $this->publicKey = $this->generateToken(64); $this->cache = []; $this->parameters = []; $this->contents = []; $this->agridNewsFeeds = new ArrayCollection(); } /** * @param int $length * @return bool|string */ private function generateToken($length = 64){ $hash = ""; while(strlen($hash) < $length){ try { $hash .= hash('sha512', random_bytes($length)); } catch (\Exception $e) { $hash .= hash('sha512', mt_rand(0,$length*10000)); } } return substr($hash, 0,$length); } public function getId(): ?int { return $this->id; } /** * @return AGridContent */ public function getParentContainer(): AGridContent { return $this->parentContainer; } /** * @param AGridContent $parentContainer * @return AGridModule */ public function setParentContainer(AGridContent $parentContainer): AGridModule { $this->parentContainer = $parentContainer; return $this; } /** * @return mixed */ public function getParameters() { return $this->parameters; } public function getParameter($key) { if(isset($this->parameters[$key])) return $this->parameters[$key]; return null; } public function addParameter($key, $value) { $this->parameters[$key] = $value; return $this; } public function removeParameter($key) { if(isset($this->parameters[$key])) unset($this->parameters[$key]); return $this; } public function setParameters(array $parameters): self { $this->parameters = $parameters; return $this; } public function getTypeId(): ?AGridModuleType { return $this->typeId; } public function setTypeId(?AGridModuleType $typeId): self { $this->typeId = $typeId; return $this; } public function getModuleTypeContent(): ?AGridModuleTypeContent { return $this->moduleTypeContent; } public function setModuleTypeContent(?AGridModuleTypeContent $moduleTypeContent): self { $this->moduleTypeContent = $moduleTypeContent; return $this; } public function getPublicKey(): ?string { return $this->publicKey; } public function setPublicKey(string $publicKey): self { $this->publicKey = $publicKey; return $this; } /** * @return array */ public function getCaches() { return $this->cache; } /** * @param string|null $lang * @param string|null $resolution * @return string */ public function getCache(string $lang = null, string $resolution = null) { if($lang == null) $lang = 'default'; if($resolution == null) $resolution = 'default'; //on a l'information pour la langue et la résolution concernée if(isset($this->cache[$lang][$resolution]) && $this->cache[$lang][$resolution] != null) return $this->cache[$lang][$resolution]; //on regarde si on à l'information pour la résolution par defaut if(isset($this->cache[$lang]['default']) && $this->cache[$lang]['default'] != null) return $this->cache[$lang]['default']; //on regarde si on a l'information pour la langue par defaut if(isset($this->cache['default'][$resolution]) && $this->cache['default'][$resolution] != null) return $this->cache['default'][$resolution]; //on regarde si on a l'information pour la langue et la résolution par defaut if(isset($this->cache['default']['default']) && $this->cache['default']['default'] != null) return $this->cache['default']['default']; return ''; } /** * @param string $lang * @param string $resolution * @param $value * @return $this */ public function addCache(string $lang, string $resolution, $value) { if($lang == null) $lang = 'default'; if($resolution == null) $resolution = 'default'; $this->cache[$lang][$resolution] = $value; return $this; } /** * @param array $langs * @param array $resolutions * @return $this */ public function initCaches(array $langs, array $resolutions){ if(!isset($this->cache['default'])){ $this->cache['default'] = []; $this->cache['default']['default'] = null; } foreach ($langs as $lang) { if (!isset($this->cache[$lang])) { $this->cache[$lang] = []; $this->cache[$lang]['default'] = null; } foreach ($resolutions as $resolution) { if (!isset($this->cache[$lang][$resolution])) { $this->cache[$lang][$resolution] = null; } } } return $this; } /** * @return array */ public function getContents() { return $this->contents; } /** * @param string|null $lang * @param string|null $resolution * @return string */ public function getContent(string $lang = null, string $resolution = null) { if($lang == null) $lang = 'default'; if($resolution == null) $resolution = 'default'; //on a l'information pour la langue et la résolution concernée if(isset($this->contents[$lang][$resolution]) && $this->contents[$lang][$resolution] != null) return $this->contents[$lang][$resolution]; //on regarde si on à l'information pour la résolution par defaut if(isset($this->contents[$lang]['default']) && $this->contents[$lang]['default'] != null) return $this->contents[$lang]['default']; //on regarde si on a l'information pour la langue par defaut if(isset($this->contents['default'][$resolution]) && $this->contents['default'][$resolution] != null) return $this->contents['default'][$resolution]; //on regarde si on a l'information pour la langue et la résolution par defaut if(isset($this->contents['default']['default']) && $this->contents['default']['default'] != null) return $this->contents['default']['default']; return ''; } /** * @param string $lang * @param string $resolution * @param $value * @return $this */ public function addContent(string $lang, string $resolution, $value) { if($lang == null) $lang = 'default'; if($resolution == null) $resolution = 'default'; $this->contents[$lang][$resolution] = $value; return $this; } /** * @param string $lang * @param string $resolution * @return $this */ public function removeContent(string $lang, string $resolution) { $this->contents[$lang][$resolution] = null; return $this; } /** * @param array $langs * @param array $resolutions * @return $this */ public function initContents(array $langs, array $resolutions){ if(!isset($this->contents['default'])){ $this->contents['default'] = []; $this->contents['default']['default'] = null; } foreach ($langs as $lang) { if (!isset($this->contents[$lang])) { $this->contents[$lang] = []; $this->contents[$lang]['default'] = null; } foreach ($resolutions as $resolution) { if (!isset($this->contents[$lang][$resolution])) { $this->contents[$lang][$resolution] = null; } } } return $this; } public function setContents(array $contents): self { $this->contents = $contents; return $this; } public function setCache(array $cache): self { $this->cache = $cache; return $this; } }