Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / classes / IndexColumn.php
blob0751337ef58c5a9fc2cb0ae5ca8fc52391929bf4
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin;
7 /**
8 * Index column wrapper
9 */
10 class IndexColumn
12 /** @var string The column name */
13 private $name = '';
15 /** @var int The column sequence number in the index, starting with 1. */
16 private $seqInIndex = 1;
18 /**
19 * @var string How the column is sorted in the index. "A" (Ascending) or
20 * NULL (Not sorted)
22 private $collation = null;
24 /**
25 * The number of indexed characters if the column is only partly indexed,
26 * NULL if the entire column is indexed.
28 * @var int
30 private $subPart = null;
32 /**
33 * Contains YES if the column may contain NULL.
34 * If not, the column contains NO.
36 * @var string
38 private $null = '';
40 /**
41 * An estimate of the number of unique values in the index. This is updated
42 * by running ANALYZE TABLE or myisamchk -a. Cardinality is counted based on
43 * statistics stored as integers, so the value is not necessarily exact even
44 * for small tables. The higher the cardinality, the greater the chance that
45 * MySQL uses the index when doing joins.
47 * @var int
49 private $cardinality = null;
51 /**
52 * @param array $params an array containing the parameters of the index column
54 public function __construct(array $params = [])
56 $this->set($params);
59 /**
60 * Sets parameters of the index column
62 * @param array $params an array containing the parameters of the index column
64 * @return void
66 public function set(array $params)
68 if (isset($params['Column_name'])) {
69 $this->name = $params['Column_name'];
71 if (isset($params['Seq_in_index'])) {
72 $this->seqInIndex = $params['Seq_in_index'];
74 if (isset($params['Collation'])) {
75 $this->collation = $params['Collation'];
77 if (isset($params['Cardinality'])) {
78 $this->cardinality = $params['Cardinality'];
80 if (isset($params['Sub_part'])) {
81 $this->subPart = $params['Sub_part'];
83 if (! isset($params['Null'])) {
84 return;
87 $this->null = $params['Null'];
90 /**
91 * Returns the column name
93 * @return string column name
95 public function getName()
97 return $this->name;
101 * Return the column collation
103 * @return string column collation
105 public function getCollation()
107 return $this->collation;
111 * Returns the cardinality of the column
113 * @return int cardinality of the column
115 public function getCardinality()
117 return $this->cardinality;
121 * Returns whether the column is nullable
123 * @param bool $as_text whether to returned the string representation
125 * @return string nullability of the column. True/false or Yes/No depending
126 * on the value of the $as_text parameter
128 public function getNull($as_text = false): string
130 if ($as_text) {
131 if (! $this->null || $this->null === 'NO') {
132 return __('No');
135 return __('Yes');
138 return $this->null;
142 * Returns the sequence number of the column in the index
144 * @return int sequence number of the column in the index
146 public function getSeqInIndex()
148 return $this->seqInIndex;
152 * Returns the number of indexed characters if the column is only
153 * partly indexed
155 * @return int the number of indexed characters
157 public function getSubPart()
159 return $this->subPart;
163 * Gets the properties in an array for comparison purposes
165 * @return array an array containing the properties of the index column
167 public function getCompareData()
169 return [
170 'Column_name' => $this->name,
171 'Seq_in_index' => $this->seqInIndex,
172 'Collation' => $this->collation,
173 'Sub_part' => $this->subPart,
174 'Null' => $this->null,