Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
test_sq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandr Sitchenko
test_sq
Commits
e6bd509e
Commit
e6bd509e
authored
Mar 05, 2018
by
Alexandr Sitchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First version for presentation
parent
a0c1bb30
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
39 deletions
+46
-39
style.css
css/style.css
+0
-6
index.php
index.php
+22
-6
class.php
lib/class.php
+24
-27
No files found.
css/style.css
View file @
e6bd509e
div
{
}
table
{
table-layout
:
fixed
;
width
:
300px
;
...
...
@@ -10,7 +8,4 @@ table {
}
td
{
border
:
1px
solid
grey
;
/*color: red;
background-color: white;
text-align: center;*/
}
\ No newline at end of file
index.php
View file @
e6bd509e
...
...
@@ -19,7 +19,7 @@ require_once './data/sample.php';
if
(
empty
(
$data
->
err
)
==
0
)
{
echo
$data
->
err
;}
else
{
echo
"<
br
>"
;
echo
"<
p>This is the input array:</p
>"
;
foreach
(
$tbl
->
data
as
$key
=>
$value
)
{
echo
"[
$key
] =
$value
<br>"
;
...
...
@@ -28,11 +28,27 @@ require_once './data/sample.php';
echo
"
{
$a
}
=>
$b
<br>"
;
}
}
$tbl
->
html_matrix
()
?>
</table>
</div>
echo
"<br>"
;
$tbl
->
html_table
();
echo
"<p>This is the output array:</p>"
;
foreach
(
$tbl
->
data
as
$key
=>
$value
)
{
echo
"[
$key
] =
$value
<br>"
;
foreach
(
$value
as
$a
=>
$b
)
{
echo
"
{
$a
}
=>
$b
<br>"
;
}
}
echo
"<p>This is the matrix:</p>"
;
foreach
(
$tbl
->
matrix
as
$key
=>
$value
)
{
echo
"[
$key
] =
$value
<br>"
;
foreach
(
$value
as
$a
=>
$b
)
{
echo
"
{
$a
}
=>
$b
<br>"
;
}
}
?>
</div>
</body>
</html>
<?php
}
?>
<?php
}
?>
lib/class.php
View file @
e6bd509e
<?php
class
Check
{
public
$data
;
public
$sim
;
public
$matrix
;
public
$alibaba
;
public
$err
;
public
$cnt
;
public
$max
;
public
$temp
;
public
$stoplist
;
public
$k
;
public
$data
;
// input array
public
$sim
;
public
$matrix
;
// array of data keys for output
public
$err
;
// data validation errors
public
$cnt
;
// number of rectangles
public
$max
;
// the size of square
//public $temp; // temp data
public
function
__construct
(
$data
)
// output $cnt - значений квадратов в таблице, $max - сторона квадрат, $sim['keys'] $err -проверка на ошибки
public
function
__construct
(
$data
)
{
// assign var $data value $input
$this
->
data
=
$data
;
...
...
@@ -47,30 +44,30 @@ public function __construct($data) // output $cnt - значений квадр
$this
->
err
=
"Variable names in the array are not valid."
;
break
;
}
// убираем лишние пробелы
str_replace
(
" "
,
""
,
$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
->
temp
[
'cnt'
]
=
array_merge
(
$this
->
temp
[
'cnt'
],
$this
->
temp
[
'temp_keys'
]);
// складываем массивы, получаем все значение целлс входные
$this
->
sim
[
'keys'
][
$k
]
=
$this
->
temp
[
'temp_keys'
];
$this
->
temp
[
'cnt'
]
=
array_merge
(
$this
->
temp
[
'cnt'
],
$this
->
temp
[
'temp_keys'
]);
}
ksort
(
$this
->
sim
[
'keys'
]);
//сортирует массив по ключам
unset
(
$k
);
$this
->
temp
[
'count'
][
'1'
]
=
count
(
$this
->
temp
[
'cnt'
]);
//считаем
ksort
(
$this
->
sim
[
'keys'
]);
$this
->
temp
[
'count'
][
'1'
]
=
count
(
$this
->
temp
[
'cnt'
]);
$this
->
temp
[
'cnt'
]
=
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
{
sort
(
$this
->
temp
[
'cnt'
]);
$this
->
max
=
end
(
$this
->
temp
[
'cnt'
]);
$this
->
max
=
ceil
(
sqrt
(
$this
->
max
));
}
unset
(
$temp
);
unset
(
$temp
,
$k
);
}
}
public
function
html_matrix
()
public
function
html_table
()
{
$this
->
street
=
1
;
$this
->
sim
[
'k'
]
=
[];
...
...
@@ -79,14 +76,13 @@ public function __construct($data) // output $cnt - значений квадр
for
(
$mm
=
0
;
$mm
<
$this
->
cnt
;
++
$mm
)
{
$sch
=
count
(
$this
->
sim
[
'keys'
][
$mm
]);
//print_r ($this->sim['keys'][$mm]);
for
(
$p
=
0
;
$p
<
$sch
;
++
$p
)
{
$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
(
$col
=
1
;
$col
<=
$max
;
++
$col
)
...
...
@@ -110,7 +106,8 @@ public function __construct($data) // output $cnt - значений квадр
foreach
(
$this
->
data
as
$key
=>
$value
)
{
$this
->
data
[
$key
]
=
$this
->
data
[
$key
]
+
[
'colspan'
=>
0
,
$this
->
data
[
$key
]
=
$this
->
data
[
$key
]
+
[
'colspan'
=>
0
,
'rowspan'
=>
0
,
'colspan_flag'
=>
0
,
'rowspan_flag'
=>
0
,
...
...
@@ -150,7 +147,7 @@ public function __construct($data) // output $cnt - значений квадр
}
}
}
// displaying the table on the screen
$this
->
t
=
"#"
;
echo
"<table>"
;
for
(
$str
=
1
;
$str
<=
$max
;
++
$str
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment