コード例 #1
0
    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> &nbsp;
					<?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> &nbsp;
						<?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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</td>
				</tr>
			</tfoot>
		</table>
		<?php 
        include 'templates/bulk_actions.template.php';
        ?>
		</form>
		<?php 
    }
コード例 #2
0
    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">&nbsp;</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">&nbsp;</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">&nbsp;</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">&nbsp;</td>
				</tr>
			</tfoot>
			<?php 
        }
        ?>
		</table>
		<?php 
        include 'templates/bulk_actions.template.php';
    }