From 436554faf7601f2b36f92c970b836a8144cd0c64 Mon Sep 17 00:00:00 2001 From: Aleksandr Zaitsev Date: Thu, 18 Jul 2024 18:14:09 +0300 Subject: [PATCH] add Collection and Student and classes --- Collection.php | 51 ++++++++++++ README.md | 177 ++++++++++++++++++++++++++++++++++++++++++ StudentAndClasses.sql | 10 +++ 3 files changed, 238 insertions(+) create mode 100644 Collection.php create mode 100644 README.md create mode 100644 StudentAndClasses.sql diff --git a/Collection.php b/Collection.php new file mode 100644 index 0000000..0fafc09 --- /dev/null +++ b/Collection.php @@ -0,0 +1,51 @@ +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"; \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f13c7d8 --- /dev/null +++ b/README.md @@ -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: + + + + + + + + + + + + + + + + + + + + + + + +
id + First name + Last name +
1 + Bob + Biden +
2 + Joey + Johnsen +
3 + Mike + Buffollo +
+ + +Classes: + + + + + + + + + + + + + + + +
id + title +
1 + A +
2 + B +
+ + +Students_Classes + + + + + + + + + + + + + + + + + + + + + + + +
id + class_id + student_id +
1 + 1 + 1 +
2 + 1 + 2 +
3 + 2 + 3 +
+ + +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: + + + + + + + + +
id + title + student_count +
+ + + +#### **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. diff --git a/StudentAndClasses.sql b/StudentAndClasses.sql new file mode 100644 index 0000000..ebbb42f --- /dev/null +++ b/StudentAndClasses.sql @@ -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; \ No newline at end of file