Commit e6bd509e authored by Alexandr Sitchenko's avatar Alexandr Sitchenko

First version for presentation

parent a0c1bb30
div {
}
table { table {
table-layout: fixed; table-layout: fixed;
width: 300px; width: 300px;
...@@ -10,7 +8,4 @@ table { ...@@ -10,7 +8,4 @@ table {
} }
td { td {
border: 1px solid grey; border: 1px solid grey;
/*color: red;
background-color: white;
text-align: center;*/
} }
\ No newline at end of file
...@@ -19,7 +19,18 @@ require_once './data/sample.php'; ...@@ -19,7 +19,18 @@ require_once './data/sample.php';
if (empty($data->err) == 0) {echo $data->err;} if (empty($data->err) == 0) {echo $data->err;}
else else
{ {
echo "<p>This is the input array:</p>";
foreach ($tbl->data as $key => $value)
{
echo "[$key] = $value<br>";
foreach ($value as $a => $b)
{
echo "{$a} => $b<br>";
}
}
echo "<br>"; echo "<br>";
$tbl->html_table();
echo "<p>This is the output array:</p>";
foreach ($tbl->data as $key => $value) foreach ($tbl->data as $key => $value)
{ {
echo "[$key] = $value<br>"; echo "[$key] = $value<br>";
...@@ -28,11 +39,16 @@ require_once './data/sample.php'; ...@@ -28,11 +39,16 @@ require_once './data/sample.php';
echo "{$a} => $b<br>"; echo "{$a} => $b<br>";
} }
} }
$tbl->html_matrix() echo "<p>This is the matrix:</p>";
?> foreach ($tbl->matrix as $key => $value)
</table> {
</div> echo "[$key] = $value<br>";
foreach ($value as $a => $b)
{
echo "{$a} => $b<br>";
}
} ?>
</div> </div>
</body> </body>
</html> </html>
<?php } ?> <?php } ?>
<?php <?php
class Check class Check
{ {
public $data; public $data; // input array
public $sim; public $sim;
public $matrix; public $matrix; // array of data keys for output
public $alibaba; public $err; // data validation errors
public $err; public $cnt; // number of rectangles
public $cnt; public $max; // the size of square
public $max; //public $temp; // temp data
public $temp;
public $stoplist;
public $k;
public function __construct($data) // output $cnt - значений квадратов в таблице, $max - сторона квадрат, $sim['keys'] $err -проверка на ошибки public function __construct($data)
{ {
// assign var $data value $input // assign var $data value $input
$this->data = $data; $this->data = $data;
...@@ -47,30 +44,30 @@ public function __construct($data) // output $cnt - значений квадр ...@@ -47,30 +44,30 @@ public function __construct($data) // output $cnt - значений квадр
$this->err = "Variable names in the array are not valid."; $this->err = "Variable names in the array are not valid.";
break; break;
} }
// убираем лишние пробелы
str_replace(" ", "", $this->data{$k}['cells']); str_replace(" ", "", $this->data{$k}['cells']);
// извлекаем цифры в массив
$this->temp['temp_keys'] = explode(",", $this->data{$k}['cells']); $this->temp['temp_keys'] = explode(",", $this->data{$k}['cells']);
$this->sim['keys'][$k] = $this->temp['temp_keys']; //html table`s key $this->sim['keys'][$k] = $this->temp['temp_keys'];
$this->temp['cnt'] = array_merge($this->temp['cnt'], $this->temp['temp_keys']); // складываем массивы, получаем все значение целлс входные $this->temp['cnt'] = array_merge($this->temp['cnt'], $this->temp['temp_keys']);
} }
ksort ($this->sim['keys']); //сортирует массив по ключам ksort ($this->sim['keys']);
unset($k); $this->temp['count']['1'] = count($this->temp['cnt']);
$this->temp['count']['1'] = count($this->temp['cnt']); //считаем
$this->temp['cnt'] = array_flip($this->temp['cnt']); $this->temp['cnt'] = array_flip($this->temp['cnt']);
$this->temp['count']['2'] = count(array_flip($this->temp['cnt'])); $this->temp['count']['2'] = count(array_flip($this->temp['cnt']));
if ($this->temp['count']['1'] !== $this->temp['count']['2']) {$this->err = "The numbers of the squares coincide in 'cells'. Please enter correct data";} if ($this->temp['count']['1'] !== $this->temp['count']['2'])
{
$this->err = "The numbers of the squares coincide in 'cells'. Please enter correct data";
}
else else
{ {
sort($this->temp['cnt']); sort($this->temp['cnt']);
$this->max = end($this->temp['cnt']); $this->max = end($this->temp['cnt']);
$this->max = ceil(sqrt($this->max)); $this->max = ceil(sqrt($this->max));
} }
unset($temp); unset($temp, $k);
} }
} }
public function html_matrix()
public function html_table()
{ {
$this->street = 1; $this->street = 1;
$this->sim['k'] = []; $this->sim['k'] = [];
...@@ -79,14 +76,13 @@ public function __construct($data) // output $cnt - значений квадр ...@@ -79,14 +76,13 @@ public function __construct($data) // output $cnt - значений квадр
for ($mm = 0; $mm < $this->cnt; ++$mm) for ($mm = 0; $mm < $this->cnt; ++$mm)
{ {
$sch = count($this->sim['keys'][$mm]); $sch = count($this->sim['keys'][$mm]);
//print_r ($this->sim['keys'][$mm]);
for ($p = 0; $p < $sch; ++$p) for ($p = 0; $p < $sch; ++$p)
{ {
$this->sim['k'] = array($this->sim['keys'][$mm][$p] => $mm); $this->sim['k'] = array($this->sim['keys'][$mm][$p] => $mm);
$this->sim['street'] = $this->sim['street'] + $this->sim['k']; // складываем массивы, получаем все значение целлс входные $this->sim['street'] = $this->sim['street'] + $this->sim['k'];
} }
} }
// создаём матрицу // create a matrix
for ($str = 1; $str <= $max; ++$str) for ($str = 1; $str <= $max; ++$str)
{ {
for ($col=1; $col <= $max; ++$col) for ($col=1; $col <= $max; ++$col)
...@@ -110,7 +106,8 @@ public function __construct($data) // output $cnt - значений квадр ...@@ -110,7 +106,8 @@ public function __construct($data) // output $cnt - значений квадр
foreach ($this->data as $key => $value) foreach ($this->data as $key => $value)
{ {
$this->data[$key] = $this->data[$key] + ['colspan' => 0, $this->data[$key] = $this->data[$key] + [
'colspan' => 0,
'rowspan' => 0, 'rowspan' => 0,
'colspan_flag' => 0, 'colspan_flag' => 0,
'rowspan_flag' => 0, 'rowspan_flag' => 0,
...@@ -150,7 +147,7 @@ public function __construct($data) // output $cnt - значений квадр ...@@ -150,7 +147,7 @@ public function __construct($data) // output $cnt - значений квадр
} }
} }
} }
// displaying the table on the screen
$this->t = "#"; $this->t = "#";
echo "<table>"; echo "<table>";
for ($str = 1; $str <= $max; ++$str) for ($str = 1; $str <= $max; ++$str)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment