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 Jul 23, 2018
2 parents 4a7467b + 6622ab7 commit c5a0b30
Show file tree
Hide file tree
Showing 29 changed files with 478 additions and 151 deletions.
18 changes: 16 additions & 2 deletions db_objects/abstract_note.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function canEditOriginal() {
function delete()
{
if (!$this->canBeDeleted()) {
trigger_error("This note can not be deleted");
trigger_error("This note can not be deleted", E_USER_WARNING);
return FALSE;
}
if (!parent::delete()) return FALSE;
Expand Down Expand Up @@ -303,7 +303,7 @@ public static function getNotifications($minutes)
COUNT(DISTINCT nn.id) as new_notes,
GROUP_CONCAT(nn.id) as new_note_ids
FROM person p
JOIN abstract_note nn ON nn.assignee = p.id
JOIN abstract_note nn ON nn.assignee = p.id
AND nn.status = "pending"
AND nn.action_date <= DATE(NOW())
AND ((
Expand All @@ -320,4 +320,18 @@ public static function getNotifications($minutes)
GROUP BY p.id';
return $GLOBALS['db']->queryAll($SQL);
}

/**
* Clean up any orphaned records that are not references by a person or family note
* @return boolean
*/
public static function cleanupInstances()
{
$SQL = 'DELETE FROM abstract_note WHERE id NOT IN (
SELECT id FROM person_note
UNION
SELECT id from family_note
)';
return $GLOBALS['db']->exec($SQL);
}
}
26 changes: 26 additions & 0 deletions db_objects/attendance_record.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
include_once 'include/db_object.class.php';
class Attendance_Record extends db_object
{
// NB This class only exists for the following SQL
// See Attendance_Record_Set for CRUD functionality of this table

function getInitSQL($table_name=NULL)
{
return "
CREATE TABLE `attendance_record` (
`date` date NOT NULL,
`personid` int(11) NOT NULL,
`groupid` int(11) NOT NULL,
`present` tinyint(1) unsigned NOT NULL,
PRIMARY KEY (`date`,`personid`,`groupid`)
) ENGINE=InnoDB ;
";
}

public function getForeignKeys()
{
return Array('personid' => '`_person` (`id`) ON DELETE CASCADE');
}
}
?>
23 changes: 2 additions & 21 deletions db_objects/attendance_record_set.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,6 @@ function create()
{
}


function getInitSQL($table_name=NULL)
{
return "
CREATE TABLE `attendance_record` (
`date` date NOT NULL default '0000-00-00',
`personid` int(11) NOT NULL default '0',
`groupid` int(11) NOT NULL default '0',
`present` tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (`date`,`personid`,`groupid`)
) ENGINE=InnoDB ;
";
}

public function getForeignKeys()
{
return Array();
}

function load($date, $cohort, $age_brackets, $statuses)
{
$this->date = $date;
Expand Down Expand Up @@ -346,7 +327,7 @@ function printHeadcountField()
$headcountValue = Headcount::fetch('person_group', $this->date, $this->groupid);
}
?>
<input type="text" class="int-box" name="<?php echo $headcountFieldName; ?>" value="<?php echo $headcountValue; ?>" size="5" />
<input type="number" name="<?php echo $headcountFieldName; ?>" value="<?php echo $headcountValue; ?>" style="width: 60px" />
<input type="button" class="btn" onclick="var x = $(this).siblings('input').get(0); x.value = x.value == '' ? 1 : parseInt(x.value, 10)+1" value="+" />
<?php
}
Expand Down Expand Up @@ -512,7 +493,7 @@ public static function getStatsForPeriod($start_date, $end_date, $cohortid)
GROUP BY ar.personid, '.$selectCol.'
) indiv
GROUP BY '.$rank.' '.$groupingField.' WITH ROLLUP';
$res = $db->queryAll($sql);
$res = $db->queryAll($sql);

foreach ($res as $row) {
if (NULL !== $row[$groupingField]) {
Expand Down
8 changes: 5 additions & 3 deletions db_objects/custom_field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public function printWidget($value, $extraParams=Array(), $prefix='')
if (($this->getValue('type') == 'select') && strlen($value) && !empty($this->values['params']['allow_other'])) {
if (!isset($widgetParams['options'][$value])) {
$otherValue = $value;
if (0 === strpos($otherValue, '0 ')) $otherValue = substr($otherValue, 2);
$value = 'other';
}
}
Expand Down Expand Up @@ -637,12 +638,13 @@ public function parseValue($val)

/**
* Get SQL expression to retrieve a value suitable for use by formatValue() above.
* @param string $tableAlias Alias of the custom_field_value table in the SQL statement
* @param string $valueTableAlias Alias of the custom_field_value table in the SQL statement
* @param string $fieldTableAlias Alias of the custom_field table in the SQL statement
* @return string SQL
*/
public static function getRawValueSQLExpr($tableAlias)
public static function getRawValueSQLExpr($valueTableAlias, $fieldTableAlias)
{
return 'TRIM(CONCAT(COALESCE('.$tableAlias.'.value_optionid, CONCAT('.$tableAlias.'.value_date, " "), ""), COALESCE('.$tableAlias.'.value_text, "")))';
return 'TRIM(CONCAT(COALESCE('.$valueTableAlias.'.value_optionid, CONCAT('.$valueTableAlias.'.value_date, " "), ""), COALESCE(CONCAT(IF('.$fieldTableAlias.'.type="select", "0 ", ""), '.$valueTableAlias.'.value_text, ""))))';
}

/**
Expand Down
38 changes: 32 additions & 6 deletions db_objects/family.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function getInitSQL($table_name=NULL)
"CREATE TABLE family_photo (
familyid INT NOT NULL,
photodata MEDIUMBLOB NOT NULL,
CONSTRAINT `famliyphotofamilyid` FOREIGN KEY (`familyid`) REFERENCES `family` (`id`),
CONSTRAINT `famliyphotofamilyid` FOREIGN KEY (`familyid`) REFERENCES `family` (`id`) ON DELETE CASCADE,
PRIMARY KEY (familyid)
) ENGINE=InnoDB;
"
Expand Down Expand Up @@ -158,7 +158,7 @@ function printForm($prefix='', $fields=NULL)
function processForm($prefix='', $fields=NULL)
{
$res = parent::processForm($prefix, $fields);
$this->_photo_data = Photo_Handler::getUploadedPhotoData('photo');
$this->_photo_data = Photo_Handler::getUploadedPhotoData('photo', Photo_Handler::CROP_NONE);
return $res;
}

Expand Down Expand Up @@ -482,6 +482,13 @@ private function savePhoto() {
}
}

private function clearPhoto()
{
$db =& $GLOBALS['db'];
$SQL = 'DELETE FROM family_photo WHERE familyid = '.(int)$this->id;
return $db->query($SQL);
}

/* Find a family that looks like a duplicate of this one - if it has the same family name and a member with the same name
*/
public function findSimilarFamilies()
Expand Down Expand Up @@ -527,7 +534,7 @@ public static function getFamilyDataByMemberIDs($member_ids)
) allmembers ON allmembers.familyid = f.id
LEFT JOIN (
select f.id as familyid, GROUP_CONCAT(p.first_name ORDER BY ab.rank ASC, p.gender DESC SEPARATOR ", ") as names
FROM person p
FROM person p
JOIN family f on p.familyid = f.id
JOIN age_bracket ab ON ab.id = p.age_bracketid
WHERE ab.is_adult and p.status <> "archived"
Expand Down Expand Up @@ -563,29 +570,48 @@ public static function printSingleFinder($name, $currentval=NULL)
<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $currentid; ?>" />
<?php
}

public function archiveAndClean()
{
if (!$this->acquireLock()) return FALSE;
foreach ($this->fields as $fieldname => $params) {
switch ($fieldname) {
case 'family_name':
$this->setValue($fieldname, '(Removed)');
$this->setValue($fieldname, '['._('Removed').']');
break;
case 'status_last_changed':
case 'creator':
case 'created':
case 'state':
// leave these intact
break;
case 'status':
$this->setValue($fieldname, 'archived');
break;
case 'history':
$this->setValue($fieldname, Array());
break;
default:
$this->setValue($fieldname, '');
}
}
if (!$this->save()) return FALSE;
$this->clearPhoto();
if (!$this->save(FALSE)) return FALSE;

$notes = $GLOBALS['system']->getDBObjectData('family_note', Array('familyid' => $this->id));
foreach ($notes as $noteid => $data) {
$n = new Family_Note($noteid);
$n->delete();
}

$this->releaseLock();
return TRUE;
}

public function delete()
{
parent::delete();
Abstract_Note::cleanupInstances();
return TRUE;
}
}
4 changes: 3 additions & 1 deletion db_objects/family_note.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ function getInitSQL($table_name=NULL)
CREATE TABLE `family_note` (
`familyid` int(11) NOT NULL default '0',
`id` int(11) NOT NULL default '0',
PRIMARY KEY (`familyid`,`id`)
PRIMARY KEY (`familyid`,`id`),
CONSTRAINT `fn_familyid` FOREIGN KEY (familyid) REFERENCES family(id) ON DELETE CASCADE,
CONSTRAINT fn_id FOREIGN KEY (id) REFERENCES abstract_note(id) ON DELETE CASCADE
) ENGINE=InnoDB;
";
}
Expand Down
Loading

0 comments on commit c5a0b30

Please sign in to comment.