Exemplo n.º 1
0
 /**
  * Get an array of maps from an array of database's rows.
  * 
  * @param Array $rows An array of database rows.
  */
 public static function rowsToMaps($rows)
 {
     $res = array();
     // Validate parameters.
     if (!is_array($rows)) {
         $rows = array($rows);
     }
     // Iterate over each row.
     foreach ($rows as $entry) {
         $map = ApiUtils::rowToMap($entry);
         if ($map != null) {
             array_push($res, $map);
         }
     }
     return $res;
 }
Exemplo n.º 2
0
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotLogged');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
        ApiUtils::handleException($app, $e);
    }
});
// Service for get all persons from a group.
$app->get('/assistanceList/:groupId/:eventId/:date', function ($groupId, $eventId, $date) use($app) {
    try {
        // Verify that the user is logged.
        if (isset($_SESSION['user'])) {
            // Get list of persons in the group.
            $now = new DateTime();
            $rows = ApiUtils::rowsToMaps(Assistance::find_by_sql("select * from get_assistance(" . $_SESSION['user']['id'] . "," . $groupId . "," . $eventId . "," . "'" . ($date !== 'today' ? $date : $now->format('Y-m-d')) . "')"));
            // Get name of event and group.
            $event = ApiUtils::rowToMap(Event::find($eventId));
            $group = ApiUtils::rowToMap(Group::find($groupId));
            // Return result.
            echo json_encode(array("rows" => $rows, "date" => $date !== 'today' ? $date : $now->format('Y-m-d'), "event" => $event, "group" => $group, "error" => null));
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotLogged');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
        ApiUtils::handleException($app, $e);
    }
});