Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tbar0970/jethro-pmm
Browse files Browse the repository at this point in the history
  • Loading branch information
tbar0970 committed Jan 31, 2022
2 parents 4fd1706 + 269b7b4 commit a425db2
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion db_objects/attendance_record_set.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public static function getStatsForPeriod($start_date, $end_date, $cohortid)
$sql = '
SELECT '.$groupingField.', '.$rank.' AVG(percent_present) as avg_attendance FROM
(
SELECT ar.personid, '.$selectCol.' AS '.$groupingField.', '.$rank.' CONCAT(ROUND(SUM(ar.present) * 100 / COUNT(ar.date)), '.$db->quote('%').') as percent_present
SELECT ar.personid, '.$selectCol.' AS '.$groupingField.', '.$rank.' ROUND(SUM(ar.present) * 100 / COUNT(ar.date)) as percent_present
FROM
person p
JOIN attendance_record ar ON p.id = ar.personid
Expand Down
2 changes: 1 addition & 1 deletion db_objects/congregation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getInstancesQueryComps($params, $logic, $order)
{
$res = parent::getInstancesQueryComps($params, $logic, $order);
$res['select'][] = 'COUNT(p.id) AS member_count';
$res['from'] .= ' LEFT JOIN person p ON p.status <> "archived" AND p.congregationid = congregation.id ';
$res['from'] .= ' LEFT JOIN person p ON p.congregationid = congregation.id ';
$res['group_by'] = 'congregation.id';
$restrictions = Array();
if (!empty($GLOBALS['user_system'])) {
Expand Down
8 changes: 4 additions & 4 deletions db_objects/family.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected static function _getFields()
'width' => 40,
'maxlength' => 128,
'allow_empty' => FALSE,
'initial_cap' => TRUE,
'initial_cap_singleword' => TRUE,
'class' => 'family-name autofocus',
'trim' => TRUE,
),
Expand Down Expand Up @@ -343,12 +343,12 @@ function printCustomSummary($showMembersCallback)
unset($this->fields['members']);
}

function getMemberData()
function getMemberData($refreshCache=FALSE)
{
//$objectType = $GLOBALS['user_system']->getCurrentUser() ? 'person' : 'member';
$restriction = $GLOBALS['user_system']->getCurrentUser() ? Array() : Array('!status' => 'archived');
if (!isset($this->_tmp['members'])) {
$this->_tmp['members'] = $GLOBALS['system']->getDBObjectData('person', Array('familyid' => $this->id)+$restriction, 'AND', 'ab.`rank`, gender DESC');
if ($refreshCache || !isset($this->_tmp['members'])) {
$this->_tmp['members'] = $GLOBALS['system']->getDBObjectData('person', Array('familyid' => $this->id)+$restriction, 'AND', 'ab.`rank`, gender DESC', $refreshCache);
}
return $this->_tmp['members'];
}
Expand Down
6 changes: 3 additions & 3 deletions db_objects/person.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ protected static function _getFields()
'width' => 30,
'maxlength' => 128,
'allow_empty' => false,
'initial_cap' => true,
'initial_cap_singleword' => true,
'trim' => TRUE,
),
'last_name' => Array(
'type' => 'text',
'width' => 30,
'maxlength' => 128,
'allow_empty' => false,
'initial_cap' => true,
'initial_cap_singleword' => true,
'trim' => TRUE,
),
'gender' => Array(
Expand Down Expand Up @@ -540,7 +540,7 @@ public function save($update_family=TRUE)

if (!empty($this->_old_values['status']) || !empty($this->_old_values['last_name'])) {
$family = $GLOBALS['system']->getDBObject('family', $this->getValue('familyid'));
$members = $family->getMemberData();
$members = $family->getMemberData(TRUE);

if (!empty($this->_old_values['status']) && ($this->getValue('status') == 'archived')) {
// status has just been changed to 'archived' so archive family if no live members
Expand Down
5 changes: 4 additions & 1 deletion db_objects/person_query.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ function getSQL($custom_select_fields=NULL)
$values = (array)$values;
switch (count($values)) {
case 0:
$query['where'][] = $field.' = 0';
$query['where'][] = '(('.$field.' = 0) OR ('.$field.' IS NULL))';
break;
case 1:
$query['where'][] = $field.' = '.$db->quote(reset($values));
break;
Expand Down Expand Up @@ -1448,6 +1449,8 @@ function printResults($format='html')
$params = $this->_convertParams($this->getValue('params'));

$sql = $this->getSQL();
bam($params);
bam($sql);
if (is_null($sql)) return;

if ($format == 'html' && in_array('checkbox', $params['show_fields'])) {
Expand Down
9 changes: 9 additions & 0 deletions db_objects/staff_member.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,14 @@ public function checkUniqueUsername()
}
return TRUE;
}

public static function getUsernamesByCongregationRestriction($congregationid)
{
$SQL = 'SELECT distinct sm.username
FROM account_congregation_restriction acr
JOIN staff_member sm ON sm.id = acr.personid
WHERE congregationid = '.(int)$congregationid;
return $GLOBALS['db']->queryCol($SQL);
}
}
?>
6 changes: 5 additions & 1 deletion include/db_object.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ public function setValue($name, $value)
if (array_get($this->fields[$name], 'initial_cap')) {
$value = ucfirst($value);
}
// Force initial cap only if value is a single world
if (array_get($this->fields[$name], 'initial_cap_singleword') && (false === strpos($value, ' '))) {
$value = ucfirst($value);
}
if (array_get($this->fields[$name], 'trim')) {
$value = hard_trim($value);
}
Expand Down Expand Up @@ -900,7 +904,7 @@ public function canAcquireLock($type='')

public function acquireLock($type='')
{
if (!$this->id) return TRUE;
if (!intval($this->id)) return TRUE;
if ($this->haveLock($type)) return TRUE;
if (!$this->canAcquireLock($type)) return FALSE;
$bits = explode(' ', self::getLockLength());
Expand Down
4 changes: 2 additions & 2 deletions views/view_0_export_checkins.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function processView() {
$to = process_widget('to', Array('type' => 'date')).' 23:59:59';
$params['-timestamp'] = Array($from, $to);
$params['venueid'] = $_REQUEST['venueid'];
$this->data = $GLOBALS['system']->getDBObjectData('checkin', $params);
$this->data = $GLOBALS['system']->getDBObjectData('checkin', $params, 'AND');
if ($this->data) {
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=checkins.csv");
Expand Down Expand Up @@ -45,7 +45,7 @@ public function printView()
Please select the date range to export:
<form method="post" class="form-horizontal well">
From <?php print_widget('from', Array('type' => 'date'), date('Y-m-d', strtotime('-1 month'))); ?>
to <?php print_widget('from', Array('type' => 'date'), date('Y-m-d')); ?>
to <?php print_widget('to', Array('type' => 'date'), date('Y-m-d')); ?>
<?php
?>
<input type="submit" class="btn" />
Expand Down
3 changes: 3 additions & 0 deletions views/view_10_admin__1_congregations.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ function processView()
$cong = $GLOBALS['system']->getDBObject('congregation', (int)$_REQUEST['congregationid']);
if ($cong) {
$members = $GLOBALS['system']->getDBObjectData('person', Array('congregationid' => $cong->id));
$usernames = Staff_Member::getUsernamesByCongregationRestriction($cong->id);
if (count($members)) {
add_message(_("Cannot delete congregation because it is not empty"), "error");
} else if (count($usernames)) {
add_message(_("Cannot delete congregation because there are user accounts restricted to it: ").implode(',', $usernames), 'error');
} else {
$cong->delete();
add_message(_("Congregation deleted"));
Expand Down
6 changes: 3 additions & 3 deletions views/view_6_attendance__3_statistics.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ private function printSet($cohortid, $cohortname)
</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&nbsp;P');?></th>
<th class="absent" title="<?php echo _('Average number marked absent per date"');?>><?php echo _('Avg&nbsp;A');?></th>
<th title=<?php echo _('"Ratio of present to absent per person, averaged across all persons in segment"');?>><?php echo _('Rate');?></th>
<th class="present" title=<?php echo _('"Total number marked present, averaged across all dates in the range');?>><?php echo _('Avg&nbsp;P');?></th>
<th class="absent" title="<?php echo _('Total number marked absent, averaged across all dates in the range"');?>><?php echo _('Avg&nbsp;A');?></th>
</thead>
<tbody>
<?php
Expand Down
3 changes: 2 additions & 1 deletion views/view_8_services.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ private function printComponentSelector()
$runsheetTitle = $this->service->replaceKeywords($runsheetTitle);
}
$comp['personnel'] = $this->service->replaceKeywords($comp['personnel']);
$lastUse = $lastUseSort = '';
$lastUse = '';
$lastUseSort = 0;
if ($comp['lastused']) {
$lastTS = strtotime($comp['lastused']);
$lastUseSort = (int)$lastTS;
Expand Down

0 comments on commit a425db2

Please sign in to comment.