function _printResults() { if (empty($this->_congregations)) { return; } $GLOBALS['system']->includeDBClass('attendance_record_set'); $stats = Attendance_Record_Set::getCongregationalAttendanceStats($this->_start_date, $this->_end_date, $this->_congregations); $GLOBALS['system']->includeDBClass('person'); $dummy_person = new Person(); $status_map = $dummy_person->getStatusOptions(); ?> <table class="table table-bordered table-auto-width"> <?php foreach ($status_map as $k => $v) { if (isset($stats[$k])) { ?> <tr> <th><?php echo ents($v); ?> </th> <td style="width: 5ex"><?php echo $stats[$k]; ?> %</td> </tr> <?php } } ?> </table> <?php }
private function printFormSequential() { $cancelURL = build_url(array('*' => NULL, 'view' => 'attendance__record', 'cohortids' => $this->_cohortids, 'attendance_date' => $this->_attendance_date, 'release' => 1)); $totalPrinted = 0; foreach ($this->_record_sets as $i => $set) { if ((int) $set->congregationid) { $congregation = $GLOBALS['system']->getDBObject('congregation', (int) $set->congregationid); } else { if ($set->groupid) { $group =& $GLOBALS['system']->getDBObject('person_group', $set->groupid); } else { return; } } $title = $set->getCohortName(); $stats = $abs = array(); if ($set->statuses) { $options = Attendance_Record_Set::getStatusOptions(); foreach ($set->statuses as $s) { $stats[] = $options[$s]; } } if ($set->age_brackets) { $GLOBALS['system']->includeDBClass('person'); $p = new Person(); foreach ($set->age_brackets as $ab) { $p->setValue('age_bracket', $ab); $abs[] = $p->getFormattedValue('age_bracket'); } } $title = implode(', ', $stats) . ' ' . implode(',', $abs) . ' in ' . $title; ?> <h3><?php echo ents($title); ?> </h3> <div class="width-really-auto form-inline"> <?php $setPrinted = $set->printForm($i); if ($setPrinted > 0) { $totalPrinted += $setPrinted; ?> <div class="container row-fluid control-group"> <p class="span6"> <?php echo _('Total headcount:'); ?> <?php $set->printHeadcountField(); ?> </p> <p class="span6 align-right nowrap"> <input type="submit" class="btn" value="Save All Attendances" /> <a href="<?php echo $cancelURL; ?> " class="btn">Cancel</a> </p> </div> <?php } else { ?> <i><?php echo _('(No persons in this listing)'); ?> </i> <?php } ?> </div> <?php } return $totalPrinted; }
function _printResultSet($congid, $groupid) { echo '<h3>'; if ($congid) { $cong = $GLOBALS['system']->getDBObject('congregation', $congid); $cong->printFieldValue('name'); echo ' Congregation'; } else { $group = $GLOBALS['system']->getDBObject('person_group', $groupid); $group->printFieldValue('name'); echo ' Group'; } echo '</h3>'; list($dates, $attendances, $totals) = Attendance_Record_Set::getAttendances((array) $congid, $groupid, $this->age_bracket, $this->start_date, $this->end_date); if (empty($attendances)) { ?> <p><i>No attendance records found. Try adjusting your criteria.</i></p> <?php return; } $headcounts = Headcount::fetchRange($congid ? 'congregation' : 'person_group', $congid ? $congid : $groupid, $this->start_date, $this->end_date); $letters = array(0 => 'A', 1 => 'P', '' => '?'); $classes = array(0 => 'absent', 1 => 'present', '' => 'unknown'); $dummy = new Person(); ?> <form method="post" action="" class="bulk-person-action"> <table class="table table-hover table-auto-width nowrap table-bordered table-condensed"> <thead> <tr> <th>Last Name</th> <th>First Name</th> <th><?php echo $this->groupid ? 'Membership Status' : 'Status'; ?> </th> <?php foreach ($dates as $date) { ?> <th><?php echo date('j M', strtotime($date)); ?> </th> <?php } ?> <th>Actions</th> <th class="narrow selector form-inline"><input type="checkbox" class="select-all" title="Select all" /></th> </tr> </thead> <tbody> <?php foreach ($attendances as $personid => $record) { ?> <tr <?php if ($record['status'] == 'archived') { echo 'class="archived"'; } ?> > <td><?php echo ents($record['last_name']); ?> </td> <td><?php echo ents($record['first_name']); ?> </td> <td> <?php if ($this->groupid) { echo ents($record['membership_status']); } else { $dummy->printFieldValue('status', $record['status']); } ?> </td> <?php foreach ($dates as $date) { $letter = $letters[array_get($record, $date, '')]; $class = $classes[array_get($record, $date, '')]; echo '<td class="' . $class . '">' . $letter . '</td>'; } ?> <td class="narrow action-cell"> <a class="med-popup" href="?view=persons&personid=<?php echo $personid; ?> "><i class="icon-user"></i>View</a> <?php if ($GLOBALS['user_system']->havePerm(PERM_EDITPERSON)) { ?> <a class="med-popup" href="?view=_edit_person&personid=<?php echo $personid; ?> "><i class="icon-wrench"></i>Edit</a> <?php } if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) { ?> <a class="med-popup" href="?view=_add_note_to_person&personid=<?php echo $personid; ?> "><i class="icon-pencil"></i>Add Note</a> <?php } ?> </td> <td class="selector"><input name="personid[]" type="checkbox" value="<?php echo $personid; ?> " /></td> </tr> <?php } ?> </tbody> <tfoot class="attendance-stats"> <tr class="headcount"> <th colspan="3">Total Headcount</th> <?php foreach ($dates as $date) { ?> <td> <?php echo array_get($headcounts, $date); ?> </td> <?php } ?> <td colspan="2"> </td> </tr> <tr class="present"> <th colspan="3">Total Present</th> <?php foreach ($dates as $date) { ?> <td> <?php echo array_get($totals[$date], 1, 0); ?> </td> <?php } ?> <td colspan="2"> </td> </tr> <tr class="absent"> <th colspan="3">Total Absent</th> <?php foreach ($dates as $date) { ?> <td> <?php echo array_get($totals[$date], 0, 0); ?> </td> <?php } ?> <td colspan="2"> </td> </tr> <tr class="extras"> <th colspan="3">Extras</th> <?php foreach ($dates as $date) { ?> <td> <?php if (isset($headcounts[$date])) { echo $headcounts[$date] - array_get($totals[$date], 1, 0); } ?> </td> <?php } ?> <td colspan="2"> </td> </tr> </tfoot> </table> <?php include 'templates/bulk_actions.template.php'; ?> </form> <?php }
private function printSet($cohortid, $cohortname) { $stats = Attendance_Record_Set::getStatsForPeriod($this->_start_date, $this->_end_date, $cohortid); if (empty($stats) || $stats[NULL]['rate'] == 0) { return FALSE; } ?> <div class="span4"> <table class="table table-bordered attendance-stats"> <thead> <tr> <th colspan="4"><?php echo ents($cohortname); ?> </th> </tr> <tr> <th><?php echo _('Segment'); ?> </th> <th title=<?php echo _('"Percentage of dates marked present rather than absent"'); ?> ><?php echo _('Rate'); ?> </th> <th class="present" title=<?php echo _('"Average number marked present per date"'); ?> ><?php echo _('Avg P'); ?> </th> <th class="absent" title="<?php echo _('Average number marked absent per date"'); ?> ><?php echo _('Avg A'); ?> </th> </thead> <tbody> <?php $map['age_bracket'] = explode(',', AGE_BRACKET_OPTIONS); if ($cohortid[0] == 'g') { list($map['status'], $default) = Person_Group::getMembershipStatusOptionsAndDefault(); } else { $map['status'] = $this->status_map; } foreach (array('status', 'age_bracket') as $grouping) { foreach ($map[$grouping] as $k => $v) { if (!isset($stats[$grouping][$k])) { continue; } ?> <tr <?php if ($k == 0 && $grouping == 'age_bracket') { echo 'class="thick-top-border"'; } ?> > <th><?php echo ents($v); ?> </th> <?php if (isset($stats[$grouping][$k])) { ?> <td><?php echo $stats[$grouping][$k]['rate']; ?> %</td> <td><?php echo number_format($stats[$grouping][$k]['avg_present'], 1); ?> </td> <td><?php echo number_format($stats[$grouping][$k]['avg_absent'], 1); ?> </td> <?php } else { ?> <td>-</td> <td>-</td> <td>-</td> <?php } ?> </tr> <?php } } ?> <tr class="thick-top-border"> <th><?php echo _('Overall'); ?> </th> <td><?php echo $stats[NULL]['rate']; ?> %</td> <td><?php echo number_format($stats[NULL]['avg_present'], 1); ?> </td> <td><?php echo number_format($stats[NULL]['avg_absent'], 1); ?> </td> </tr> <tr class="headcount"> <th colspan="2"> <?php echo _('Avg Headcount'); ?> </th> <td class="right"> <?php $bits = explode('-', $cohortid); $hc = Headcount::fetchAverage($bits[0], $bits[1], $this->_start_date, $this->_end_date); if ($hc) { echo number_format($hc, 1); } else { echo 'N/A'; } ?> </td> <td colspan="2"></td> </tr> </tbody> </table> </div> <?php return TRUE; }
private function _printResultsTabular() { $GLOBALS['system']->includeDBClass('attendance_record_set'); $GLOBALS['system']->includeDBClass('person'); $dummy = new Person(); $all_persons = Attendance_Record_Set::getPersonIDsForCohorts($this->cohortids); $all_dates = $all_attendances = $all_totals = $all_headcounts = array(); if (!empty($this->cohortids)) { foreach ($this->cohortids as $cohortid) { $congid = $groupid = NULL; list($type, $id) = explode('-', $cohortid); if ($type == 'c') { $congid = $id; } if ($type == 'g') { $groupid = $id; } list($cdates, $cattendances, $ctotals) = Attendance_Record_Set::getAttendances((array) $congid, $groupid, $this->age_bracket, $this->start_date, $this->end_date); $hc = Headcount::fetchRange($congid ? 'congregation' : 'person_group', $congid ? $congid : $groupid, $this->start_date, $this->end_date); foreach ($hc as $date => $c) { $all_headcounts[$date][$cohortid] = $c; } $all_dates = array_merge($all_dates, $cdates); foreach ($ctotals as $date => $t) { $all_totals[$date][$cohortid] = $t; } foreach ($cattendances as $personid => $cat) { $all_persons[$personid]['cohortids'][] = $cohortid; foreach ($cat as $k => $v) { if (!in_array($k, array('first_name', 'last_name', 'membership_status', 'status'))) { $all_attendances[$personid][$cohortid][$k] = $v; } } } } } $all_dates = array_unique($all_dates); ?> <table class="table table-hover table-condensed table-auto-width valign-middle table-bordered parallel-attendance-report"> <thead> <tr> <th <?php if ($this->format != 'totals') { echo 'rowspan="2"'; } ?> >Name</th> <?php if (SizeDetector::isWide()) { ?> <th <?php if ($this->format != 'totals') { echo 'rowspan="2"'; } ?> >Status</th> <?php } if ($this->format == 'totals') { $colspan = 1; } else { $colspan = count($this->cohortids); } foreach ($all_dates as $date) { $classes = 'center nowrap'; if ($this->format != 'totals') { $classes .= ' new-cohort'; } ?> <th class="<?php echo $classes; ?> " colspan="<?php echo $colspan; ?> "><?php echo format_date($date); ?> </th> <?php } ?> <th <?php if ($this->format != 'totals') { echo 'rowspan="2"'; } ?> ></th> <th class="narrow selector form-inline" rowspan="2"><input type="checkbox" class="select-all" title="Select all" /></th> </tr> <?php if ($this->format != 'totals') { ?> <tr> <?php foreach ($all_dates as $date) { $first = TRUE; foreach ($this->cohortids as $cohortid) { $name = ''; list($type, $id) = explode('-', $cohortid); if ($type == 'c') { $congregation = $GLOBALS['system']->getDBObject('congregation', $id); $name = $congregation->getValue('name'); } else { if ($type == 'g') { $group =& $GLOBALS['system']->getDBObject('person_group', $id); $name = $group->getValue('name'); } } $short = reset(explode(' ', $name)); if (strlen($short) > 5 && !preg_match('/[0-9]/', $short)) { $short = substr($short, 0, 3) . '…'; } $class = $first ? 'new-cohort' : ''; ?> <th class="nowrap <?php echo $class; ?> " title="<?php echo ents($name); ?> "><?php echo ents($short); ?> </th> <?php $first = FALSE; } } ?> </tr> <?php } ?> </thead> <tbody> <?php foreach ($all_persons as $personid => $details) { if (!isset($all_attendances[$personid])) { continue; } ?> <tr <?php if ($details['status'] == 'archived') { echo 'class="archived"'; } ?> > <td class="nowrap"> <?php echo ents($details['first_name'] . ' ' . $details['last_name']); ?> </td> <?php if (SizeDetector::isWide()) { ?> <td><?php $dummy->printFieldValue('status', $details['status']); ?> </th> <?php } foreach ($all_dates as $date) { $first = TRUE; if ($this->format == 'totals') { $score = ''; foreach ($this->cohortids as $cohortid) { $catt = array_get($all_attendances[$personid], $cohortid, array()); $x = array_get($catt, $date, ''); if (strlen($x)) { $score = (int) $score + $x; } } $class = $this->classes[$score > 0 ? 1 : $score]; if ($score === '') { $score = '?'; } echo '<td class="center ' . $class . '">' . $score . '</td>'; } else { foreach ($this->cohortids as $cohortid) { if (!in_array($cohortid, array_get($all_persons[$personid], 'cohortids', array()))) { $class = 'disabled'; $letter = ''; } else { $catt = array_get($all_attendances[$personid], $cohortid, array()); $v = array_get($catt, $date, ''); $letter = $this->letters[$v]; $class = $this->classes[$v]; } if ($first) { $class .= ' new-cohort'; } echo '<td class="' . $class . '">' . $letter . '</td>'; $first = FALSE; } } } $this->_printActionsAndSelector($personid); ?> </tr> <?php } ?> </tbody> <?php if ($this->format != 'totals') { // headcounts don't make sense when we collapse groups down into totals $colspan = SizeDetector::isWide() ? 'colspan="2"' : ''; ?> <tfoot class="attendance-stats"> <tr class="headcount"> <th <?php echo $colspan; ?> >Total Headcount</th> <?php foreach ($all_dates as $date) { $hc = array_get($all_headcounts, $date, array()); foreach ($this->cohortids as $cohortid) { ?> <td> <?php echo array_get($hc, $cohortid, ''); ?> </td> <?php } } ?> <td colspan="2"> </td> </tr> <tr class="present"> <th <?php echo $colspan; ?> >Total Present</th> <?php foreach ($all_dates as $date) { $tots = array_get($all_totals, $date, array()); foreach ($this->cohortids as $cohortid) { ?> <td> <?php echo array_get(array_get($tots, $cohortid, array()), 1, 0); ?> </td> <?php } } ?> <td colspan="2"> </td> </tr> <tr class="absent"> <th <?php echo $colspan; ?> >Total Absent</th> <?php foreach ($all_dates as $date) { $tots = array_get($all_totals, $date, array()); foreach ($this->cohortids as $cohortid) { ?> <td> <?php echo array_get(array_get($tots, $cohortid, array()), 0, 0); ?> </td> <?php } } ?> <td colspan="2"> </td> </tr> <tr class="extras"> <th <?php echo $colspan; ?> >Extras</th> <?php foreach ($all_dates as $date) { $tots = array_get($all_totals, $date, array()); $hc = array_get($all_headcounts, $date, array()); foreach ($this->cohortids as $cohortid) { $present = array_get(array_get($tots, $cohortid, array()), 1, 0); $absent = array_get(array_get($tots, $cohortid, array()), 0, 0); $headcount = array_get($hc, $cohortid, NULL); ?> <td> <?php if ($headcount) { echo $headcount - $present - $absent; } ?> </td> <?php } } ?> <td colspan="2"> </td> </tr> </tfoot> <?php } ?> </table> <?php include 'templates/bulk_actions.template.php'; }
/** * Execute this plan. * * If executed against a person, add notes to the person and put the person * in the specified groups. If executed against a family, add notes to the * family and add the family members to the specified groups. */ function execute($subject_type, $subject_id, $reference_date) { //bam("Executing ".$this->getValue('name').' against '.$subject_type.' #'.$subject_id.' with ref date '.$reference_date); if ($subject_type == 'family') { $family = $GLOBALS['system']->getDBObject('family', (int) $subject_id); $personids = array_keys($family->getMemberData()); if (count($personids) == 1) { // Not allowed to add family notes to single-member families, so pretend we're runninng against the person $subject_type = 'person'; $subject_id = reset($personids); } } else { if ($subject_type == 'person') { $personids = array($subject_id); } else { trigger_error("Cannot execute plan against a {$subject_type}"); return; } } $actions = $this->getValue('actions'); foreach (array_get($actions, 'groups', array()) as $groupid) { $group = $GLOBALS['system']->getDBObject('person_group', $groupid); foreach ($personids as $personid) { $group->addMember($personid); } } foreach (array_get($actions, 'groups_remove', array()) as $groupid) { $group = $GLOBALS['system']->getDBObject('person_group', $groupid); $group->removeMembers($personids); } $note_type = $subject_type . '_note'; $GLOBALS['system']->includeDBClass($note_type); foreach (array_get($actions, 'notes', array()) as $notedata) { $note = new $note_type(); $notedata = Action_Plan_Note::getAbstractNoteData($notedata, $reference_date); $footnote = '[Added automatically by action plan "' . $this->getValue('name') . '" (#' . $this->id . ')]'; if (strlen($notedata['details'])) { $notedata['details'] .= "\n{$footnote}"; } else { $notedata['details'] = $footnote; } $note->populate(0, $notedata); $note->setValue($subject_type . 'id', $subject_id); $note->create(); } if ($fields = array_get($actions, 'fields')) { foreach ($personids as $personid) { $person = $GLOBALS['system']->getDBObject('person', $personid); foreach ($fields as $k => $v) { if (0 === strpos($k, 'custom_')) { if (0 === strpos($v['value'], '-1===')) { $v['value'] = $reference_date . ' ' . substr($v['value'], 5); } $fieldID = substr($k, 7); $person->setCustomValue($fieldID, $v['value'], $v['add']); } else { $person->setValue($k, $v['value']); } } $person->save(); } } if (array_get($actions, 'attendance')) { foreach ($personids as $personid) { $person = $GLOBALS['system']->getDBObject('person', $personid); $congID = $person->getValue('congregationid'); if ($congID) { $date = Attendance_Record_Set::getMostRecentDate('c-' . $congID); $person->saveAttendance(array($date => 1), NULL); } } } }
private function printSet($cohortid, $cohortname) { $stats = Attendance_Record_Set::getStatsForPeriod($this->_start_date, $this->_end_date, $cohortid); if (empty($stats)) { return FALSE; } ?> <div class="span4"> <table class="table table-bordered attendance-stats"> <thead> <tr> <th colspan="4"><?php echo ents($cohortname); ?> </th> </tr> <tr> <th>Status</th> <th title="Percentage of dates marked present rather than absent">Rate</th> <th class="present" title="Average number marked present per date">Avg P</th> <th class="absent" title="Average number marked absent per date">Avg A</th> </thead> <tbody> <?php if ($cohortid[0] == 'g') { list($map, $default) = Person_Group::getMembershipStatusOptionsAndDefault(); } else { $map = $this->status_map; } foreach ($map as $k => $v) { if (isset($stats[$k])) { ?> <tr> <th><?php echo ents($v); ?> </th> <td style="width: 6ex; text-align: right"><?php echo $stats[$k]['rate']; ?> %</td> <td style="width: 6ex; text-align: right"><?php echo number_format($stats[$k]['avg_present'], 1); ?> </td> <td style="width: 6ex; text-align: right"><?php echo number_format($stats[$k]['avg_absent'], 1); ?> </td> </tr> <?php } } ?> <tr class="thick-top-border"> <th>Overall</th> <td style="width: 6ex; text-align: right"><?php echo $stats[NULL]['rate']; ?> %</td> <td style="width: 6ex; text-align: right"><?php echo number_format($stats[NULL]['avg_present'], 1); ?> </td> <td style="width: 6ex; text-align: right"><?php echo number_format($stats[NULL]['avg_absent'], 1); ?> </td> </tr> <tr class="headcount"> <th colspan="2"> Avg Headcount </th> <td class="right"> <?php $bits = explode('-', $cohortid); $hc = Headcount::fetchAverage($bits[0], $bits[1], $this->_start_date, $this->_end_date); if ($hc) { echo number_format($hc, 1); } else { echo 'N/A'; } ?> </td> <td colspan="2"></td> </tr> </tbody> </table> </div> <?php return TRUE; }
private function printFormParallel() { $totalPersons = Attendance_Record_Set::getPersonIDsForCohorts($this->_cohortids); $totalPrinted = 0; $cancelURL = build_url(array('*' => NULL, 'view' => 'attendance__record', 'cohortids' => $this->_cohortids, 'attendance_date' => $this->_attendance_date, 'release' => 1)); $dummy = new Person(); ?> <table class="table table-condensed table-auto-width valign-middle"> <thead> <tr> <?php if (SizeDetector::isWide()) { ?> <th>ID</th> <?php } if ($this->_show_photos) { ?> <th> </th> </td> <?php } ?> <th>Name</th> <?php if (SizeDetector::isWide()) { ?> <th>Status</th> <?php } foreach ($this->_record_sets as $prefix => $set) { ?> <th class="center"><?php echo $set->getCohortName(); ?> </th> <?php } if (SizeDetector::isWide()) { ?> <th>Actions</th> <?php } ?> </tr> </thead> <tbody> <?php foreach ($totalPersons as $personid => $detail) { ?> <tr> <?php if (SizeDetector::isWide()) { ?> <td><?php echo $personid; ?> </td> <?php } if ($this->_show_photos) { ?> <td> <a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php echo $personid; ?> "> <img style="width: 50px; max-width: 50px" src="?call=person_photo&personid=<?php echo (int) $personid; ?> " /> </a> </td> <?php } ?> <td><?php echo ents($detail['first_name'] . ' ' . $detail['last_name']); ?> </td> <?php if (SizeDetector::isWide()) { ?> <td class=""><?php $dummy->printFieldValue('status', $detail['status']); ?> </td> <?php } foreach ($this->_record_sets as $prefix => $set) { ?> <td class="parallel-attendance"> <?php $totalPrinted += $set->printWidget($prefix, $personid); ?> </td> <?php } if (SizeDetector::isWide()) { ?> <td class="action-cell narrow"> <a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php echo $personid; ?> "><i class="icon-user"></i>View</a> <a class="med-popup" tabindex="-1" href="?view=_edit_person&personid=<?php echo $personid; ?> "><i class="icon-wrench"></i>Edit</a> <a class="med-popup" tabindex="-1" href="?view=_add_note_to_person&personid=<?php echo $personid; ?> "><i class="icon-pencil"></i>Add Note</a> </td> <?php } ?> </tr> <?php } ?> <tr class="headcount"> <th class="right" colspan="<?php echo 1 + 2 * (int) SizeDetector::isWide() + (int) $this->_show_photos; ?> ">Total Headcount: </th> <?php foreach ($this->_record_sets as $prefix => $set) { ?> <td class="center parallel-attendance"><?php $set->printHeadcountField(); ?> </td> <?php } ?> <td> </td> </tr> </tbody> </table> <input type="submit" class="btn" value="Save All Attendances" /> <a href="<?php echo $cancelURL; ?> " class="btn">Cancel</a> <?php return $totalPrinted; }