size_s =12; $this->size_m =6; $this->size_l =4; $this->size_xl =3; $this->ordered = 0; $this->rows = new ArrayCollection(); $this->publicKey = $this->generateToken(64); $this->parentRow = $row; $this->cache = []; } public function gridSize(string $mode){ switch ($mode){ case 's': return 's'.$this->getSizeS(); break; case 'm': return 's'.$this->getSizeM(); break; case 'l': return 's'.$this->getSizeL(); break; case 'xl': return 's'.$this->getSizeXl(); break; default: return null; break; } } public function renderingClassSize(){ return 's'.$this->getSizeS().' m'.$this->getSizeM().' l'.$this->getSizeL().' xl'.$this->getSizeXl(); } /** * @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 Collection */ public function getRows(): Collection { return $this->rows; } /** * @param Collection $rows * @return AGridCol */ public function setRows(Collection $rows): AGridCol { $this->rows = $rows; return $this; } public function addRow(AGridRow $row): self { if (!$this->rows->contains($row)) { $this->rows[] = $row; } return $this; } public function removeRow(AGridRow $row): self { if ($this->rows->contains($row)) { $this->rows->removeElement($row); } return $this; } public function getSizeS(): ?int { return $this->size_s; } public function setSizeS(int $size_s): self { $this->size_s = $size_s; return $this; } public function getSizeM(): ?int { return $this->size_m; } public function setSizeM(int $size_m): self { $this->size_m = $size_m; return $this; } public function getSizeL(): ?int { return $this->size_l; } public function setSizeL(int $size_l): self { $this->size_l = $size_l; return $this; } public function getSizeXl(): ?int { return $this->size_xl; } public function setSizeXl(int $size_xl): self { $this->size_xl = $size_xl; return $this; } public function getOrdered(): ?int { return $this->ordered; } public function setOrdered(int $ordered): self { $this->ordered = $ordered; return $this; } 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; } public function getPublicKey(): ?string { return $this->publicKey; } public function setPublicKey(string $publicKey): self { $this->publicKey = $publicKey; return $this; } /** * @return AGridRow */ public function getParentRow(): AGridRow { return $this->parentRow; } public function setParentRow(?AGridRow $parentRow): self { $this->parentRow = $parentRow; return $this; } public function setCache(?array $cache): self { $this->cache = $cache; return $this; } }