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 Nov 25, 2016
2 parents 9885d67 + 012763b commit 5fd1da6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
6 changes: 5 additions & 1 deletion calls/call_csv.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ function run()
case 'person':
default:
$merge_data = $GLOBALS['system']->getDBObjectData('person', Array('id' => (array)$_POST['personid']));
foreach (Person::getCustomMergeData($_POST['personid']) as $personid => $data) {
$merge_data[$personid] += $data;
}
$dummy = new Person();
$dummy_family = new Family();
break;
Expand All @@ -31,7 +34,8 @@ function run()
}
fputcsv($fp, $headerrow);

foreach ($merge_data as $id => $row) {
foreach ($_REQUEST['personid'] as $id) {
$row = array_get($merge_data, $id, Array());
@$dummy->populate($id, $row);
$outputrow = Array($id);
foreach ($row as $k => $v) {
Expand Down
4 changes: 4 additions & 0 deletions calls/call_odf_merge.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ protected function getMergeData()
case 'person':
default:
$temp_merge_data = $GLOBALS['system']->getDBObjectData('person', Array('id' => $_POST['personid']));
foreach (Person::getCustomMergeData($_POST['personid']) as $personid => $data) {
$temp_merge_data[$personid] += $data;
}

$merge_data = Array();
foreach ($_REQUEST['personid'] as $id) {
$merge_data[$id] = $temp_merge_data[$id];
Expand Down
51 changes: 42 additions & 9 deletions db_objects/person.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected function _printSummaryRows() {
$showDivider = TRUE; // always show before first field
$showHeading = '';
$dummyField = new Custom_Field();
foreach ($this->getCustomFields() as $fieldid => $fieldDetails) {
foreach (self::getCustomFields() as $fieldid => $fieldDetails) {
$dummyField->populate($fieldid, $fieldDetails);
if ($fieldDetails['divider_before']) {
$showDivider = TRUE;
Expand Down Expand Up @@ -534,7 +534,7 @@ function _saveCustomValues() {
$SQL = 'INSERT INTO custom_field_value
(personid, fieldid, value_text, value_date, value_optionid)
VALUES ';
$customFields = $this->getCustomFields();
$customFields = self::getCustomFields();
$sets = Array();
foreach ($this->_custom_values as $fieldid => $values) {
if (!is_array($values)) $values = empty($values) ? Array() : Array($values);
Expand Down Expand Up @@ -567,7 +567,7 @@ protected function _getChanges()
{
$res = parent::_getChanges();
if (!empty($this->_old_custom_values)) {
$customFields = $this->getCustomFields();
$customFields = self::getCustomFields();
$dummyField = new Custom_Field();
foreach ($this->_old_custom_values as $fieldid => $oldVal) {
$dummyField->populate($fieldid, $customFields[$fieldid]);
Expand Down Expand Up @@ -647,6 +647,38 @@ static function getStatusStats()
}
return $out;
}

/**
* Get formatted custom field data indexed by personid and fieldname
* @param type $personids
* @return array
*/
static function getCustomMergeData($personids)
{
$db = $GLOBALS['db'];
$SQL = 'SELECT '.Custom_Field::getRawValueSQLExpr('v').' AS value, f.name, v.personid, v.fieldid
FROM custom_field_value v
JOIN custom_field f ON v.fieldid = f.id
WHERE v.personid IN ('.implode(',', array_map(Array($db, 'quote'), $personids)).')';
$qres = $db->queryAll($SQL);
$res = Array();

$customFields = self::getCustomFields();
foreach ($customFields as $fieldid => $fieldDetails) {
$customFields[$fieldid] = new Custom_Field();
$customFields[$fieldid]->populate($fieldid, $fieldDetails);
}
foreach ($qres as $row) {
$fname = strtoupper(str_replace(' ', '_', $row['name']));
$fVal = $customFields[$row['fieldid']]->formatValue($row['value']);
if (isset($res[$row['personid']][$fname])) {
$res[$row['personid']][$fname] .= ', '.$fVal;
} else {
$res[$row['personid']][$fname] = $fVal;
}
}
return $res;
}

function getInstancesQueryComps($params, $logic, $order)
{
Expand Down Expand Up @@ -684,7 +716,7 @@ function printForm($prefix='', $fields=NULL)

if (empty($fields) || in_array('custom', $fields)) {

$customFields = $this->getCustomFields();
$customFields = self::getCustomFields();
$dummyField = new Custom_Field();
if ($customFields) {
?>
Expand Down Expand Up @@ -785,17 +817,18 @@ public function setFeedUUID()
return $uuid;
}

private function &getCustomFields()
public static function &getCustomFields()
{
if (!isset($this->_tmp['custom_fields'])) {
$this->_tmp['custom_fields'] = $GLOBALS['system']->getDBObjectData('custom_field', Array(), 'OR', 'rank');
static $customFields = NULL;
if ($customFields === NULL) {
$customFields = $GLOBALS['system']->getDBObjectData('custom_field', Array(), 'OR', 'rank');
}
return $this->_tmp['custom_fields'];
return $customFields;
}

public function setCustomValue($fieldid, $newVal, $addToExisting=FALSE)
{
$fields = $this->getCustomFields();
$fields = self::getCustomFields();
$oldVal = array_get($this->_custom_values, $fieldid, '');
if ((!empty($oldVal) || !empty($newVal)) && ($addToExisting || ($oldVal != $newVal))) {
$this->_old_custom_values[$fieldid] = $oldVal;
Expand Down
4 changes: 3 additions & 1 deletion scripts/date_reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
)';
}
$SQL .= '
WHERE cfv.value_date = CURDATE() + INTERVAL '.(int)$ini['REMINDER_OFFSET'].' DAY';
WHERE cfv.value_date = CURDATE() + INTERVAL '.(int)$ini['REMINDER_OFFSET'].' DAY
AND p.status <> "archived"';
$res = $GLOBALS['db']->queryAll($SQL);
check_db_result($res);
foreach ($res as $row) {
if (empty($row['first_name'])) continue; // no matches = empty row
send_reminder($row);
}

Expand Down
2 changes: 1 addition & 1 deletion views/view_2_families__4_contact_list.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class View_Families__Contact_List extends View

static function getMenuPermissionLevel()
{
return PERM_SYSADMIN;
return PERM_RUNREPORT;
}

function processView()
Expand Down

0 comments on commit 5fd1da6

Please sign in to comment.