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
14 changes: 14 additions & 0 deletions CorsiInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Interfaccia per la gestione dei corsi
* @author Enrico Zimuel (enrico.zimuel@its-ictpiemonte.it)
*/
declare(strict_types=1);

interface CorsiInterface
{
public function getMediaCorsi(): float;
public function addCorso(string $corso): bool;
public function getCorsi(): array;
public function addVoto(string $corso, int $voto): bool;
}
4 changes: 4 additions & 0 deletions Esercizio.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Esercizio

Creare uno script PHP che selezioni a caso dei gruppi di studenti (minimo di 2 e massimo di 3 persone) da un elenco prestabilito.
Lo script deve stampare il nome dei partecipanti di ogni gruppo separandoli con una virgola. Ogni gruppo deve essere stampato su una riga differente.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Corso PHP Programming ITS - ICT Piemonte

Esempio di file PHP utilizzati durante il corso di PHP Programming
presso l'ITS ICT Piemonte.
Esercizi sul PHP utilizzati durante il corso di *PHP Programming*
presso l'[ITS ICT Piemonte](http://www.its-ictpiemonte.it/).

### Object Oriented Programming

- [Studente.php](https://github.com/ezimuel/Corso_PHP_ITS/blob/master/Studente.php)
- [ShoppingCart.php](https://github.com/ezimuel/Corso_PHP_ITS/blob/master/ShoppingCart.php)
26 changes: 26 additions & 0 deletions ShoppingCart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Classe per la gestione di un carrello elettronico
*
* @author Enrico Zimuel (enrico.zimuel@its-ictpiemonte.it)
*/
declare(strict_types=1);

class ShoppingCart
{
public function addProduct(string $product, int $quantity): bool
{
}

public function removeProduct(string $product): bool
{
}

public function changeQuantity(string $product, int $quantity): bool
{
}

public function removeAllProducts(): bool
{
}
}
18 changes: 3 additions & 15 deletions Studente.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?
<?php
/**
* Classe di esempio
* @author Enrico Zimuel (enrico.zimuel@its-ictpiemonte.it)
*/
declare(strict_types=1);

class Studente {
public $nome;
public $cognome;
Expand Down Expand Up @@ -32,17 +34,3 @@ public function getMediaEsami(): ?float
return array_sum($this->corsi) / count($this->corsi);
}
}

$studente = new Studente();
$studente->nome = 'Mario';
$studente->cognome = 'Rossi';
$studente->email = 'mario.rossi@itspiemonte.it';
$studente->dataDiNascita = '1/1/1995';

$studente->addCorso('Cloud Services');
$studente->addCorso('PHP Programming');

$studente->addVotoEsame('Cloud Services', 24);
$studente->addVotoEsame('PHP Programming', 26);

printf("Media voto esami: %.2f\n", $studente->getMediaEsami());
18 changes: 18 additions & 0 deletions StudenteInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Interfaccia per la gestione degli studenti
* @author Enrico Zimuel (enrico.zimuel@its-ictpiemonte.it)
*/
declare(strict_types=1);

interface StudenteInterface
{
public function setNome(string $nome): bool;
public function getNome(): string;
public function setCognome(string $cognome): bool;
public function getCognome(): string;
public function setEmail(string $email): bool;
public function getEmail(): string;
public function setDataDiNascita(int $giorno, int $mese, int $anno): bool;
public function getDataDiNascita(): string; // nel formato "gg/mm/AAAA"
}
31 changes: 31 additions & 0 deletions drawer-groups/Classes/Drawer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

<?php

class Drawer
{
protected $listToDraw = [];


public function __construct (array $listToDraw)
{
$this->listToDraw = $listToDraw;
shuffle($this->listToDraw);
}


public function makeGroups ($numberOfGroupMembers) : array
{
if(count($this->listToDraw) % $numberOfGroupMembers == 0)
return array_chunk($this->listToDraw, $numberOfGroupMembers);

else
{
$list = array_chunk($this->listToDraw, $numberOfGroupMembers);

for($i = 0; $i < count(end($list)); $i++)
array_push($list[$i], end($list)[$i]);

return $list;
}
}
}
15 changes: 15 additions & 0 deletions drawer-groups/Classes/info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<?php


define('STUDENTS', ['Bert Lorenzo', 'Buscema Antonio', 'Carbonati Davide',
'Cella Marco', "D'Augelli Mario", 'Dumitru Adrian',
'Faoro Claudio', 'Ferrero-Merlino Leonardo', 'Fornaro Roberto',
'Gomes Anielle', 'Gregoricchio Matteo', 'Iacobelli Sara',
'Laurenti Diana', 'Linari Matteo', 'Pietrapertosa Fabio',
'Presutti Edoardo', 'Reale Andrea', 'Revelli Ruben',
'Sacchet Gabriele', 'Sartori Alessandro', 'Sinatra Gianpaolo',
'Soncin Erika', 'Vellano Marco', 'Velocci Giuseppe',
'Schutt Daniele', 'Lo Presti Ilaria', 'Morales Yusdel',
'Mason Alessandro'
]);
46 changes: 46 additions & 0 deletions drawer-groups/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

<?php

require_once 'Classes/Drawer.php';
require_once 'Classes/info.php';


$drawer = new Drawer(STUDENTS);
?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 align="center">Groups</h1>
<div style="display: flex; justify-content: center; margin-top: 5%;">
<form method="post">
<input type="text" name="groupsMembers" placeholder="number of groups' members" required>
<input type="submit" name="groupsButton" value="Make groups!">
</form>
</div>
<div style="display: flex; justify-content: center; margin-top: 2%;">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$groups = $drawer->makeGroups($_POST['groupsMembers']);

foreach($groups as $key => $group)
{
echo '<br><br><br><br>Group ' . $key ;

foreach($group as $key => $member)
echo '<br>- ' . $member;
}
}
?>
</div>
</body>
</html>