PHP Classes

File: src/routes.php

Recommend this page to a friend!
  Classes of Chun-Sheng, Li   PHP Women's Menstruation   src/routes.php   Download  
File: src/routes.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Women's Menstruation
Application to calculate women's menstruation days
Author: By
Last change:
Date: 1 year ago
Size: 2,017 bytes
 

Contents

Class file image Download
<?php
// Routes

$app->get('/[{name}]', function ($request, $response, $args) {
   
// Sample log message
   
$this->logger->info("Slim-Result '/' route");

   
// Render index view
   
if(isset($args["name"])) {
        return
'Not Found';
    } else {
        return
$this->renderer->render($response, 'index.phtml', []);
    }
});

$app->post('/[{action}]', function ($request, $response, $args) {
   
$data = $request->getParsedBody();
   
$menstrData = [];
   
$menstrData['avg-menstr'] = filter_var($data['avg-menstr'], FILTER_SANITIZE_STRING);
   
$menstrData['start-menstr-date'] = filter_var($data['start-menstr-date'], FILTER_SANITIZE_STRING);
   
$date = $menstrData['start-menstr-date'];
   
$states = [
       
'danger' => [],
       
'menstr' => [],
       
'safe' => [],
    ];
   
$daySec = 86400;
   
$startTime = strtotime($menstrData['start-menstr-date']);
   
$date = date_parse($date);
    if (
checkdate($date['month'], $date['day'], $date['year'])) {
       
$times = 1;
        while (
$times <= 2) {
            for (
$index=1;$index<=5;$index++) {
               
$states['menstr'][] = date('m-d-Y', $startTime);
               
$startTime += $daySec;
            }
           
$theCount = $menstrData['avg-menstr'] - 24;
            if (
$theCount !== 0) {
                for (
$index=1;$index<=$theCount;$index++) {
                   
$states['safe'][] = date('m-d-Y', $startTime);
                   
$startTime += $daySec;
                }
            }
            for (
$index=1;$index<=10;$index++) {
               
$states['danger'][] = date('m-d-Y', $startTime);
               
$startTime += $daySec;
            }
            for (
$index=1;$index<=9;$index++) {
               
$states['safe'][] = date('m-d-Y', $startTime);
               
$startTime += $daySec;
            }
           
$times += 1;
        }

        return
$this->renderer->render($response, 'index.phtml', [
           
'eventList' => $states
       
]);
    } else {
        return
'Invalid date';
    }
});