1. Go to this page and download the library: Download 5pm-hdh/churchtools-api 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/ */
5pm-hdh / churchtools-api example snippets
use \CTApi\CTConfig;
//set the url of your ChurchTools application api
//important! ApiUrl must end with Top-Level-Domain. No paths allowed!
CTConfig::setApiUrl("https://example.church.tools");
//authenticates the application and load the api-key into the config
CTConfig::authWithCredentials(
"[email protected]",
"myPassword1234"
);
// Multi-factor authentication:
CTConfig::authWithCredentials(
"[email protected]",
"myPassword1234",
"291521"
);
use CTApi\Models\Groups\Person\PersonRequest;
$myself = PersonRequest::whoami();
echo "Hello ".$myself->getLastName() . $myself->getFirstName();
// Retrieve all Persons
$allPersons = PersonRequest::all();
// Filter Data with Where-Clause
$teenager = PersonRequest::where('birthday_before', '2007-01-01')
->where('birthday_after', '2003-01-01')
->orderBy('birthday')
->get();
foreach($teenager as $teenPerson){
echo "Hello Teenager with E-Mail: ".$teenPerson->getEmail();
}
// Get specific Person
$personA = PersonRequest::find(21); // returns "null" if id is invalid
$personB = PersonRequest::findOrFail(22); // throws exception if id is invalid
use CTApi\Models\Events\Event\EventAgendaRequest;use CTApi\Models\Events\Event\EventRequest;
// Retrieve all events
$allEvents = EventRequest::all();
// Get specific Event
$event = EventRequest::find(21); // returns "null" if id is invalid
$event = EventRequest::findOrFail(22); // throws exception if id is invalid
// Filter events in period
$christmasServices = EventRequest::where('from', '2020-12-24')
->where('to', '2020-12-26')
->orderBy('id')
->get();
$christmasService = $christmasServices[0];
// get the Agenda with event id...
$eventId = $christmasServices->getId();
$agenda = EventAgendaRequest::fromEvent($eventId)->get();
// ...or direct on event-Model
$agenda = $event->requestAgenda();
// Use Songs-API
$songsOnChristmas = $agenda->getSongs();
foreach($songsOnChristmas as $song){
echo $song->getTitle() . " - (Key: " .$song->getKey() . ")";
}
use CTApi\Models\Wiki\WikiCategory\WikiCategoryRequest;
$wikiCategory = WikiCategoryRequest::find(21);
$rootNodeWiki = $wikiCategory->requestWikiPageTree();
echo "<h1>Table of content:</h1>";
echo "<ul class='first-level'>";
// First Level
foreach($rootNodeWiki->getChildNodes() as $node){
echo "<li>";
echo $node->getWikiPage()->getTitle();
echo "<ul class='second-level'>";
foreach($node->getChildNodes() as $nodeSecondLevel){
echo "<li>";
echo $nodeSecondLevel->getWikiPage()->getTitle();
echo "</li>";
}
echo "</ul>";
echo "</li>";
}
echo "</ul>";