Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

//при рендере появляются артефакты в виде строки "1"

//хотелось полностью автоматизировать процесс подключения файлов
//и поэтому усложнил код доп скриптом не относящимся к домашке
function dirToArray($path = '.') {

$result = array();

$cdir = scandir($path);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($path . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($path . DIRECTORY_SEPARATOR . $value);
}
else
{
$result[] = $value;
}
}
}

return $result;
}

function renderTemplates($entryPoint){
$templates = dirToArray($entryPoint);
$content = '';

foreach ($templates as $key => $value) {
$content = include("$entryPoint/$value");
}
return $content;

}

// function renderTemplatesRecursive($pageName, $content = ''){
// ob_start();
// $filename = 'templates/' . $pageName . '.php';
// if(file_exists($filename)){
// include($filename);
// }
// return ob_get_clean();
// }


renderTemplates('templates');
?>
12 changes: 12 additions & 0 deletions scripts/task1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
$a = rand(-50, 50);
$b = rand(-50, 50);

if ($a >= 0 && $b >= 0) {
$sub = $a - $b;
} elseif ($a < 0 || $b < 0) {
$mul = $a * $b;
} else {
$sum = $a + $b;
}
?>
41 changes: 41 additions & 0 deletions scripts/task2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
$n = rand(0, 15);

function renderNumbers($n){
echo $n . ' ';
if($n < 15) renderNumbers($n + 1);
}

// switch ($n) {
// case 1:
// echo 1;
// case 2:
// echo 2;
// case 3:
// echo 3;
// case 4:
// echo 4;
// case 5:
// echo 5;
// case 6:
// echo 6;
// case 7:
// echo 7;
// case 8:
// echo 8;
// case 9:
// echo 9;
// case 10:
// echo 10;
// case 11:
// echo 11;
// case 12:
// echo 12;
// case 13:
// echo 13;
// case 14:
// echo 14;
// default:
// echo 15;
// }
?>
47 changes: 47 additions & 0 deletions scripts/task3&4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
function sum($arg1, $arg2){
return $arg1 + $arg2;
}

function sub($arg1, $arg2){
return $arg1 - $arg2;
}

function mul($arg1, $arg2){
return $arg1 * $arg2;
}

function div($arg1, $arg2){
if($arg2 == 0) {
return 'Ошибка! На ноль делить нельзя.';
}
return round($arg1 / $arg2, 3);
}

function mathOperation($str){
$arr = explode(" ", $str);
switch ($arr[1]) {
case '+':
return sum($arr[0], $arr[2]);
case '-':
return sub($arr[0], $arr[2]);
case '*':
return mul($arr[0], $arr[2]);
case '/':
return div($arr[0], $arr[2]);
default:
return "Нет такой операции";
}
}

/* Вариант реализации по заданию, выше - собственный

function mathOperation($arg1, $arg2, $operation){
if(function_exists($operation)){
return $operation($arg1, $arg2);
}
}
echo mathOperation(4, 7, 'mul');

*/
?>
13 changes: 13 additions & 0 deletions scripts/task6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
function power($val, $pow){
if($pow !== 0) {
return $val * pow($val, $pow - 1);
}
return 1;
}


$val = 2;
$pow = 8;
$res = power($val, $pow);
?>
28 changes: 28 additions & 0 deletions scripts/task7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
function getHours(){
return date('H');
}

function getMinutes(){
return date('i');
}

function handleCases($str, $for_1, $for_2, $for_5){
$str = abs($str) % 100;
$str_x = $str % 10;

if ($str > 10 && $str < 20){ //11 - 19
return $for_5;
}
if ($str_x > 1 && $str_x < 5){ //2,3,4
return $for_2;
}
if ($str_x == 1){ //1
return $for_1;
}
return $for_5;
}

$h = handleCases(getHours(), 'час', 'часа', 'часов');
$m = handleCases(getMinutes(), 'минута', 'минуты', 'минут');
?>
65 changes: 65 additions & 0 deletions templates/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lesson2</title>
<style type="text/css">
* {
margin: 0 auto;
padding: 0;
}

body {
font-family: Times New Roman sans-serif;
border-collapse: collapse;
}

footer {
display: flex;
justify-content: center;
}

.container {
max-width: 700px;
display: flex;
flex-direction: column;
justify-content: space-between;
}

.block {
margin: 10px;
}

.block_flex-wrapper {
display: flex;
justify-content: space-between;
border: 1px solid black;
}

.block_exp {
padding: 5px;
display: flex;
justify-content: center;
align-items: center;
border-right: 1px solid black;
}

.block_exp-border-none {
border-right: none;
}

.header {
text-align: center;
}

.text {

}
</style>
</head>
<body>
<div class="container">

</div>
</body>
</html>
21 changes: 21 additions & 0 deletions templates/task1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?= include('scripts/task1.php'); ?>
<div class="block">
<h3 class="header">Задание 1</h3>
<div class="block_flex-wrapper">
<div class="block_exp">
<span>A: <?= $a ?></span>
</div>
<div class="block_exp">
<span>B: <?= $b ?></span>
</div>
<div class="block_exp">
<span>Сумма: <?= $sum ?></span>
</div>
<div class="block_exp">
<span>Разность: <?= $sub ?></span>
</div>
<div class="block_exp block_exp-border-none">
<span>Произведение: <?= $mul ?></span>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions templates/task2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?= include('scripts/task2.php'); ?>
<div class="block">
<h3 class="header">Задание 2</h3>
<h4 class="header">Значения чисел от $a до 15</h4>
<div class="block_flex-wrapper">
<div class="block_exp block_exp-border-none">
<span>A: <?= renderNumbers($n) ?> </span>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions templates/task3&4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?= include('scripts/task3&4.php'); ?>
<div class="block">
<h3 class="header">Задание 3,4</h3>
<div class="block_flex-wrapper">
<div class='block_exp'>Сумма: <?= mathOperation('24 + 17') ?></div>
<div class='block_exp'>Разность: <?= mathOperation('73 - 48') ?></div>
<div class='block_exp'>Произведение: <?= mathOperation('44 * 21') ?></div>
<div class='block_exp block_exp-border-none'>Частное: <?= mathOperation('75 / 14') ?></div>
</div>
</div>
9 changes: 9 additions & 0 deletions templates/task6.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?= include('scripts/task6.php'); ?>
<div class="block">
<h3 class="header">Задание 6</h3>
<div class="block_flex-wrapper">
<div class="block_exp">Число: <?= $val ?></div>
<div class="block_exp">Степень: <?= $pow ?></div>
<div class="block_exp block_exp-border-none">Значение: <?= $res ?></div>
</div>
</div>
8 changes: 8 additions & 0 deletions templates/task7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?= include('scripts/task7.php'); ?>

<div class="block">
<h4 class="header">Задание 7</h4>
<div class="block_flex-wrapper">
<div class="block_exp block_exp-border-none">Текущее время: <?= getHours() . ' ' . $h; ?> <?= getMinutes() . ' ' . $m ?></div>
</div>
</div>