key = $key; $this->title = $title; $this->width = $width; $this->alignment = $alignment; $this->isSumColumn = $isSumColumn; $this->id = $id; $this->sequence = $sequence; $this->sorting = $sorting; $this->formatType = $formatType; $this->formatStatement = $formatStatement; } /** * @param $data * * @return ReportColumn|null */ public static function fromDbState($data) { if (!isset($data['key_name'])) { return null; } if (!isset($data['title'])) { return null; } $key = (string)$data['key_name']; $title = (string)$data['title']; $width = ''; if (isset($data['width'])) { $width = $data['width']; } $alignment = ''; if (isset($data['alignment'])) { $alignment = $data['alignment']; } $sorting = 'numeric'; if (isset($data['sorting'])) { $sorting = $data['sorting']; } $sequence = 0; if (isset($data['sequence'])) { $sequence = $data['sequence']; } $format = null; if (array_key_exists('format_type', $data)) { $format = $data['format_type']; } $formatStatement = null; if (array_key_exists('format_statement', $data)) { $formatStatement = $data['format_statement']; } $sum = false; if (isset($data['sum']) && $data['sum'] === 1) { $sum = true; } $id = 0; if (isset($data['id'])) { $id = $data['id']; } return new self( $key, $title, $width, $alignment, $sum, $id, $sequence, $sorting, $format, $formatStatement ); } /** * @return array */ public function toArray(): array { return [ 'key_name' => $this->getKey(), 'title' => $this->getTitle(), 'width' => $this->getWidth(), 'alignment' => $this->getAlignment(), 'sorting' => $this->getSorting(), 'sum' => $this->isSumColumn(), 'id' => $this->getId(), 'sequence' => $this->getSequence(), 'format_type' => $this->getFormatType(), 'format_statement' => $this->getFormatStatement(), ]; } /** * Specify data which should be serialized to JSON * * @return mixed data which can be serialized by json_encode, */ public function jsonSerialize() { $data = $this->toArray(); unset($data['id'], $data['sequence']); return $data; } /** * @return string */ public function getKey() { return $this->key; } /** * @return string */ public function getTitle() { return $this->title; } /** * @return string */ public function getWidth() { return $this->width; } /** * @return string */ public function getAlignment() { return $this->alignment; } /** * @return bool */ public function isSumColumn() { return $this->isSumColumn; } /** * @return int */ public function getId() { return $this->id; } /** * @return int */ public function getSequence() { return $this->sequence; } /** * @return string */ public function getSorting() { return $this->sorting; } /** * Changes sequence number and returns old sequence number. * * @param int $sequence * * @return int previous sequence number */ public function changeSequence($sequence) { $oldSequence = $this->getSequence(); $this->sequence = $sequence; return $oldSequence; } /** * @return string|null */ public function getFormatType(): ?string { return $this->formatType; } /** * @return string|null */ public function getFormatStatement(): ?string { return $this->formatStatement; } }