add Collection and Student and classes

This commit is contained in:
Aleksandr Zaitsev 2024-07-18 18:14:09 +03:00
commit 436554faf7
3 changed files with 238 additions and 0 deletions

51
Collection.php Normal file
View File

@ -0,0 +1,51 @@
<?php
class Collection implements Iterator {
private int $cursor = 0;
public function __construct(
private array $items = []
) {}
#[ReturnTypeWillChange]
public function current(): int
{
return $this->items[$this->cursor];
}
#[ReturnTypeWillChange]
public function key(): int
{
return $this->cursor;
}
#[ReturnTypeWillChange]
public function next(): void
{
++$this->cursor;
}
#[ReturnTypeWillChange]
public function prev(): int {
--$this->cursor;
}
public function rewind(): void {
$this->cursor = 0;
}
public function valid(): bool
{
return isset($this->items[$this->cursor]);
}
}
// Adding an array [1,2,3,4,5,6,7,8,9,10] to the collection
$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// Calculating the sum of the elements in the collection
$sum = 0;
foreach ($collection as $item) {
$sum += $item;
}
echo "The sum of the elements in the collection is: $sum\n";

177
README.md Normal file
View File

@ -0,0 +1,177 @@
**Test tasks**
** \
Сollections**
You need to write a collection class (which can be used in a foreach construct). The class inherits the iterator interface, that is, it necessarily implements methods:
* __construct(array $items),
* prev,
* next,
* current,
* rewind (method rewind returns a pointer to the first element of the collection).
Add an array [1,2,3,4,5,6,7,8,9,10] to the collection.
In the loop, run through the collection and calculate the sum of the elements.
**Students & classes**
There are tables:
<table>
<tr>
<td>id
</td>
<td>First name
</td>
<td>Last name
</td>
</tr>
<tr>
<td>1
</td>
<td>Bob
</td>
<td>Biden
</td>
</tr>
<tr>
<td>2
</td>
<td>Joey
</td>
<td>Johnsen
</td>
</tr>
<tr>
<td>3
</td>
<td>Mike
</td>
<td>Buffollo
</td>
</tr>
</table>
Classes:
<table>
<tr>
<td>id
</td>
<td>title
</td>
</tr>
<tr>
<td>1
</td>
<td>A
</td>
</tr>
<tr>
<td>2
</td>
<td>B
</td>
</tr>
</table>
Students_Classes
<table>
<tr>
<td>id
</td>
<td>class_id
</td>
<td>student_id
</td>
</tr>
<tr>
<td>1
</td>
<td>1
</td>
<td>1
</td>
</tr>
<tr>
<td>2
</td>
<td>1
</td>
<td>2
</td>
</tr>
<tr>
<td>3
</td>
<td>2
</td>
<td>3
</td>
</tr>
</table>
You need to write a SQL query that displays the id of the class, its name and the number of students in the class, that is:
<table>
<tr>
<td>id
</td>
<td>title
</td>
<td>student_count
</td>
</tr>
</table>
#### **API Development**
**Task:** Create a simple REST API endpoint in PHP that returns a JSON response with a list of users from the `users` table.
**Additional Test tasks**
**Basic Node.js Knowledge**
Create a Node.js application that serves a simple webpage. The webpage should display a list of users fetched from a JSON file.
**Basic Understanding of Server Software (Apache, Nginx)**
Write a basic configuration for an Nginx server with https redirect that serves a PHP application.
**Basic Understanding of Linux Servers**
This task will assess your fundamental knowledge of Linux server management, including basic command-line operations, file system navigation, user management, and basic network configuration. Give the list of bash commands for each subtask.
### **Task Instructions:**
1. **Connecting to a Linux Server:**
* Use SSH to connect to a remote Linux server. Assume the server's IP address is `192.168.1.10` and the SSH port is the default one.
2. **File System Navigation:**
* Once connected, navigate to the `/var/log` directory.
* List all files and directories within `/var/log` and save the output to a file named `log_list.txt` in your home directory.
3. **User Management:**
* Create a new user named `testuser` without a home directory.
4. **File Permissions:**
* Create a directory named `testdir` in your home directory.
* Change the permissions of `testdir` to allow read, write, and execute access only to the owner.
5. **Basic Network Configuration:**
* Display the current network configuration, including IP addresses and network interfaces.
6. **Package Management:**
* Update the package list on the server and install the `curl` package.

10
StudentAndClasses.sql Normal file
View File

@ -0,0 +1,10 @@
SELECT
c.id,
c.title,
COUNT(sc.student_id) AS student_count
FROM
Classes c
LEFT JOIN
Students_Classes sc ON c.id = sc.class_id
GROUP BY
c.id, c.title;