PHP code example of openclassrooms / front-desk

1. Go to this page and download the library: Download openclassrooms/front-desk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

openclassrooms / front-desk example snippets



OpenClassrooms\FrontDesk\Services\PackService;
use OpenClassrooms\FrontDesk\Services\PersonService;

//do things

use OpenClassrooms\FrontDesk\Client\Impl\ClientFactoryImpl; 

$factory = new ClientFactoryImpl();
        
$client = $factory->createCoreApi('your_front_desk_server_name', 'your_token');
\\
$client = $factory->createReportingApi('your_front_desk_server_name', 'your_token');

use OpenClassrooms\FrontDesk\Repository\PackRepository;

$enrollmentGateway = new EnrollmentRepository();
        
$enrollmentGateway->setReportingApiClient($client);
  

use OpenClassrooms\FrontDesk\Services\Impl\EnrollmentServiceImpl;

$service = new EnrollmentServiceImpl();
$service->setEnrollmentGateway($enrollmentGateway);
   
...
$service->query($field, $filter, $limit); 

use OpenClassrooms\FrontDesk\Repository\PackRepository;

$packGateway = new PackRepository();
        
$packGateway->setCoreApiClient($client);
   

use OpenClassrooms\FrontDesk\Models\PersonBuilder;

$pack = $packBuilder
            ->create()
            ->withCount(5)
            ->withEndDate(new \DateTime())
            ->withPersonIds([21987])
            ->withStartDate(new \DateTime())
            ->build();

use OpenClassrooms\FrontDesk\Services\Impl\PackServiceImpl;

$service = new PackServiceImpl();
$service->setPackGateway($packGateway);
   
...
$service->create($pack, $packProductId); 
   
...
$service->deletePack($packId); 

use OpenClassrooms\FrontDesk\Repository\PersonRepository;

$personGateway = new PersonRepository();
        
$personGateway->setCoreApiClient($client);

$personGateway->setPersonBuilder(new PersonBuilderImpl());            

use OpenClassrooms\FrontDesk\Models\PersonBuilder;

$person = $personBuilder->create()
                        ->withAddress('address')
                        ->withEmail('email')
                        ->withFirstName('first_name')
                        ->withJoinedAt(new \DateTime())
                        ->withLastName('last_name')
                        ...
                        ->build();

use OpenClassrooms\FrontDesk\Services\Impl\PersonServiceImpl;

$service = new PersonServiceImpl();
$service->setPersonGateway($personGateway);

$service->create($person);

$service->update($person);

$service->find($personId);

$service->findAll($page);

$service->search($query);

$planGateway = new PlanRepository();
        
$planGateway->setCoreApiClient($client);
 
$planGateway->setPlanBuilder(new PlanBuilderImpl());        

$service = new PlanServiceImpl();
$service->setPlanGateway($planGateway);

$service->getPlans($personId);

use OpenClassrooms\FrontDesk\Repository\VisitRepository;

$visitGateway = new VisitRepository();
        
$visitGateway->setCoreApiClient($client);
 
$visitGateway->setVisitBuilder(new VisitBuilderImpl());

$service = new VisitServiceImpl();
$service->setVisitGateway($visitGateway);

$service->getVisits($personId, $from, $to);

$service->deleteVisit($visitId);