Skip to content

Commit

Permalink
The last changes
Browse files Browse the repository at this point in the history
  • Loading branch information
phili67 committed Feb 18, 2018
1 parent 33a4d5b commit a518f8a
Showing 1 changed file with 48 additions and 45 deletions.
93 changes: 48 additions & 45 deletions src/EcclesiaCRM/Service/CalendarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,65 +45,68 @@ public function getEvents($start, $end)
}

$firstYear = $startDate->format('Y');


if ($_SESSION['bSeePrivacyData'] || $_SESSION['bAdmin']) {
$peopleWithBirthDays = PersonQuery::create()
->JoinWithFamily();

$peopleWithBirthDays = PersonQuery::create()
->JoinWithFamily();

// get the first and the last month
$firstMonth = $startDate->format('m');
$endMonth = $endDate->format('m');
// get the first and the last month
$firstMonth = $startDate->format('m');
$endMonth = $endDate->format('m');

$month = $firstMonth;
$month = $firstMonth;

$peopleWithBirthDays->filterByBirthMonth($firstMonth);// the event aren't more than a month
$peopleWithBirthDays->filterByBirthMonth($firstMonth);// the event aren't more than a month

while ($month != $endMonth) {// we loop to have all the months from the first in the start to the end
$month += 1;
if ($month == 13) {
while ($month != $endMonth) {// we loop to have all the months from the first in the start to the end
$month += 1;
if ($month == 13) {
$month = 1;
}
if ($month == 0) {
$month = 1;
}
$peopleWithBirthDays->_or()->filterByBirthMonth($month);// the event aren't more than a month
}
if ($month == 0) {
$month = 1;
}
$peopleWithBirthDays->_or()->filterByBirthMonth($month);// the event aren't more than a month
}

$peopleWithBirthDays->find();
$peopleWithBirthDays->find();

foreach ($peopleWithBirthDays as $person) {
$year = $firstYear;
if ($person->getBirthMonth() == 1 && $endsNextYear) {
$year = $firstYear + 1;
}
foreach ($peopleWithBirthDays as $person) {
$year = $firstYear;
if ($person->getBirthMonth() == 1 && $endsNextYear) {
$year = $firstYear + 1;
}

$start = date_create($year.'-'.$person->getBirthMonth().'-'.$person->getBirthDay());
$start = date_create($year.'-'.$person->getBirthMonth().'-'.$person->getBirthDay());

$event = $this->createCalendarItem('birthday',
$person->getFullName()." ".$person->getAge(), $start->format(DATE_ATOM), '', $person->getViewURI());
$event = $this->createCalendarItem('birthday',
$person->getFullName()." ".$person->getAge(), $start->format(DATE_ATOM), '', $person->getViewURI());

array_push($events, $event);
}
array_push($events, $event);
}

// we search the Anniversaries
$Anniversaries = FamilyQuery::create()
->filterByWeddingDate(['min' => '0001-00-00']) // a Wedding Date
->filterByDateDeactivated(null, Criteria::EQUAL) //Date Deactivated is null (active)
->find();
// we search the Anniversaries
$Anniversaries = FamilyQuery::create()
->filterByWeddingDate(['min' => '0001-00-00']) // a Wedding Date
->filterByDateDeactivated(null, Criteria::EQUAL) //Date Deactivated is null (active)
->find();

$curYear = date('Y');
$curMonth = date('m');
foreach ($Anniversaries as $anniversary) {
$year = $curYear;
if ($anniversary->getWeddingMonth() < $curMonth) {
$year = $year + 1;
}
$start = $year.'-'.$anniversary->getWeddingMonth().'-'.$anniversary->getWeddingDay();

$event = $this->createCalendarItem('anniversary', $anniversary->getName(), $start, '', $anniversary->getViewURI());

array_push($events, $event);
$curYear = date('Y');
$curMonth = date('m');
foreach ($Anniversaries as $anniversary) {
$year = $curYear;
if ($anniversary->getWeddingMonth() < $curMonth) {
$year = $year + 1;
}
$start = $year.'-'.$anniversary->getWeddingMonth().'-'.$anniversary->getWeddingDay();

$event = $this->createCalendarItem('anniversary', $anniversary->getName(), $start, '', $anniversary->getViewURI());

array_push($events, $event);
}
}

$activeEvents = EventQuery::create()
->filterByInActive('false')
->orderByStart()
Expand Down

0 comments on commit a518f8a

Please sign in to comment.