summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2011-06-14 16:40:32 +0000
committerfisharebest <fisharebest@gmail.com>2011-06-14 16:40:32 +0000
commit956cfbac0fd2ba13e91cce560bd9fe6a6c85d212 (patch)
treeec1e40b7644e87bdcb0e5279315024841f5ddd04 /library
parent68c6b52401a69d263e6761aaefaa1a2835cf2834 (diff)
downloadwebtrees-956cfbac0fd2ba13e91cce560bd9fe6a6c85d212.tar.gz
webtrees-956cfbac0fd2ba13e91cce560bd9fe6a6c85d212.tar.bz2
webtrees-956cfbac0fd2ba13e91cce560bd9fe6a6c85d212.zip
Tidy up constructor for WT_Event objects. We (almost) always need to know the parent, so pass it as a parameter.
Diffstat (limited to 'library')
-rw-r--r--library/WT/Controller/Media.php14
-rw-r--r--library/WT/Event.php33
-rw-r--r--library/WT/Family.php3
-rw-r--r--library/WT/GedcomRecord.php3
-rw-r--r--library/WT/Person.php83
5 files changed, 57 insertions, 79 deletions
diff --git a/library/WT/Controller/Media.php b/library/WT/Controller/Media.php
index 014c488d9e..60d28384ff 100644
--- a/library/WT/Controller/Media.php
+++ b/library/WT/Controller/Media.php
@@ -292,18 +292,18 @@ class WT_Controller_Media extends WT_Controller_Base {
function getFacts($includeFileName=true) {
$facts = $this->mediaobject->getFacts(array());
sort_facts($facts);
- //if ($includeFileName) $facts[] = new WT_Event("1 FILE ".$this->mediaobject->getFilename());
+ //if ($includeFileName) $facts[] = new WT_Event("1 FILE ".$this->mediaobject->getFilename(), $this->mediaobject, 0);
$mediaType = $this->mediaobject->getMediatype();
- $facts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType));
+ $facts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType), $this->mediaobject, 0);
if (($newrec=find_updated_record($this->pid, WT_GED_ID))!==null) {
$newmedia = new WT_Media($newrec);
$newfacts = $newmedia->getFacts(array());
$newimgsize = $newmedia->getImageAttributes();
- if ($includeFileName) $newfacts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType));
- $newfacts[] = new WT_Event("1 FORM ".$newimgsize['ext']);
+ if ($includeFileName) $newfacts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType), $this->mediaobject, 0);
+ $newfacts[] = new WT_Event("1 FORM ".$newimgsize['ext'], $this->mediaobject, 0);
$mediaType = $newmedia->getMediatype();
- $newfacts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType));
+ $newfacts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType), $this->mediaobject, 0);
//-- loop through new facts and add them to the list if they are any changes
//-- compare new and old facts of the Personal Fact and Details tab 1
for ($i=0; $i<count($facts); $i++) {
@@ -337,10 +337,10 @@ class WT_Controller_Media extends WT_Controller_Base {
// get height and width of image, when available
$imgsize = $this->mediaobject->getImageAttributes();
if (!empty($imgsize['WxH'])) {
- $facts[] = new WT_Event('1 __IMAGE_SIZE__ '.$imgsize['WxH']);
+ $facts[] = new WT_Event('1 __IMAGE_SIZE__ '.$imgsize['WxH'], $this->mediaobject, 0);
}
//Prints the file size
- $facts[] = new WT_Event('1 __FILE_SIZE__ '.$this->mediaobject->getFilesize());
+ $facts[] = new WT_Event('1 __FILE_SIZE__ '.$this->mediaobject->getFilesize(), $this->mediaobject, 0);
}
sort_facts($facts);
diff --git a/library/WT/Event.php b/library/WT/Event.php
index 6372ff64a5..f1269e90fd 100644
--- a/library/WT/Event.php
+++ b/library/WT/Event.php
@@ -79,21 +79,21 @@ class WT_Event {
return null;
}
- /**
- * Parses supplied subrecord to fill in the properties of the class.
- * Assumes the level of the subrecord is 1, and that all its associated sub records are provided.
- *
- * @param string $subrecord
- * @param int $lineNumber
- * @return WT_Event
- */
- function __construct($subrecord, $lineNumber=-1) {
- if (preg_match('/^1 ('.WT_REGEX_TAG.') *(.*)/', $subrecord, $match)) {
- $this->tag=$match[1];
+ // Create an event objects from a gedcom fragment.
+ // We also need to know the parent (to check privacy, etc.) and
+ // the line number (from the original, privacy-filtered) gedcom
+ // record, to allow editing
+ function __construct($subrecord, $parent, $lineNumber) {
+ if (preg_match('/^1 ('.WT_REGEX_TAG.') ?(.*)/', $subrecord, $match)) {
+ $this->tag =$match[1];
$this->detail=$match[2];
- $this->lineNumber=$lineNumber;
- $this->gedcomRecord=$subrecord;
+ } else {
+ // We are not ready for this yet.
+ // throw new Exception('Invalid GEDCOM data passed to WT_Event::_construct('.$subrecord.')');
}
+ $this->gedcomRecord=$subrecord;
+ $this->parentObject=$parent;
+ $this->lineNumber =$lineNumber;
}
function setState($s) {
@@ -224,13 +224,6 @@ class WT_Event {
/**
*
*/
- function setParentObject($parent) {
- $this->parentObject = $parent;
- }
-
- /**
- *
- */
function getDetail() {
return $this->detail;
}
diff --git a/library/WT/Family.php b/library/WT/Family.php
index afab263dfd..d58f3c4dd6 100644
--- a/library/WT/Family.php
+++ b/library/WT/Family.php
@@ -250,8 +250,7 @@ class WT_Family extends WT_GedcomRecord {
* parse marriage record
*/
function _parseMarriageRecord() {
- $this->marriage = new WT_Event(trim(get_sub_record(1, '1 MARR', $this->getGedcomRecord())), -1);
- $this->marriage->setParentObject($this);
+ $this->marriage = new WT_Event(get_sub_record(1, '1 MARR', $this->getGedcomRecord()), $this, 0);
}
/**
diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php
index b9b7cb02a0..89467fa265 100644
--- a/library/WT/GedcomRecord.php
+++ b/library/WT/GedcomRecord.php
@@ -828,10 +828,9 @@ class WT_GedcomRecord {
}
if ($i==$lct||$line{0}==1) {
if ($i>1) {
- $event = new WT_Event($factrec, $linenum);
+ $event = new WT_Event($factrec, $this, $linenum);
$fact = $event->getTag();
if ($nfacts==NULL || !in_array($fact, $nfacts)) {
- $event->setParentObject($this);
$this->facts[] = $event;
}
}
diff --git a/library/WT/Person.php b/library/WT/Person.php
index 5fa9f74673..5be48d0d31 100644
--- a/library/WT/Person.php
+++ b/library/WT/Person.php
@@ -1033,7 +1033,7 @@ class WT_Person extends WT_GedcomRecord {
}
//-- add a new sex fact if one was not found
if (!$sexfound) {
- $this->globalfacts[] = new WT_Event('1 SEX U', 'new');
+ $this->globalfacts[] = new WT_Event('1 SEX U', $this, 'new');
}
}
/**
@@ -1122,46 +1122,40 @@ class WT_Person extends WT_GedcomRecord {
$dDate=$this->getEstimatedDeathDate();
foreach ($person->getChildFamilies() as $famid=>$family) {
- foreach (array($family->getWife(), $family->getHusband()) as $parent) {
- if ($parent) {
- if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT'.($sosa==1 ? '_PARE' : '_GPAR'))) {
- foreach ($parent->getAllFactsByType(explode('|', WT_EVENTS_DEAT)) as $sEvent) {
- $srec = $sEvent->getGedcomRecord();
- if (WT_Date::Compare($bDate, $sEvent->getDate())<0 && WT_Date::Compare($sEvent->getDate(), $dDate)<=0) {
- switch ($sosa) {
- case 1:
- $factrec='1 _'.$sEvent->getTag().'_PARE';
- break;
- case 2:
- $factrec='1 _'.$sEvent->getTag().'_GPA1';
- break;
- case 3:
- $factrec='1 _'.$sEvent->getTag().'_GPA2';
- break;
- }
- $factrec.="\n".get_sub_record(2, '2 DATE', $srec)."\n".get_sub_record(2, '2 PLAC', $srec);
- if (!$sEvent->canShow()) {
- $factrec .= "\n2 RESN privacy";
- }
- if ($parent->getSex()=='F') {
- $factrec.="\n2 ASSO @".$parent->getXref()."@\n3 RELA ".$rela."mot";
- } else {
- $factrec.="\n2 ASSO @".$parent->getXref()."@\n3 RELA ".$rela."fat";
- }
- $event=new WT_Event($factrec, 0);
- $event->setParentObject($this);
- $this->indifacts[] = $event;
+ foreach ($family->getSpouses() as $parent) {
+ if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT'.($sosa==1 ? '_PARE' : '_GPAR'))) {
+ foreach ($parent->getAllFactsByType(explode('|', WT_EVENTS_DEAT)) as $sEvent) {
+ $srec = $sEvent->getGedcomRecord();
+ if (WT_Date::Compare($bDate, $sEvent->getDate())<0 && WT_Date::Compare($sEvent->getDate(), $dDate)<=0) {
+ switch ($sosa) {
+ case 1:
+ $factrec='1 _'.$sEvent->getTag().'_PARE';
+ break;
+ case 2:
+ $factrec='1 _'.$sEvent->getTag().'_GPA1';
+ break;
+ case 3:
+ $factrec='1 _'.$sEvent->getTag().'_GPA2';
+ break;
}
+ $factrec.="\n".get_sub_record(2, '2 DATE', $srec)."\n".get_sub_record(2, '2 PLAC', $srec);
+ if (!$sEvent->canShow()) {
+ $factrec .= "\n2 RESN privacy";
+ }
+ if ($parent->getSex()=='F') {
+ $factrec.="\n2 ASSO @".$parent->getXref()."@\n3 RELA ".$rela."mot";
+ } else {
+ $factrec.="\n2 ASSO @".$parent->getXref()."@\n3 RELA ".$rela."fat";
+ }
+ $event=new WT_Event($factrec, $parent, 0);
+ $this->indifacts[] = $event;
}
}
}
}
if ($sosa==1) {
// add father/mother marriages
- foreach (array($family->getHusband(), $family->getWife()) as $parent) {
- if (is_null($parent)) {
- continue;
- }
+ foreach ($family->getSpouses() as $parent) {
foreach ($parent->getSpouseFamilies() as $sfamily) {
if ($sfamily->equals($family)) {
if ($parent->getSex()=='F') {
@@ -1195,8 +1189,7 @@ class WT_Person extends WT_GedcomRecord {
if (!$sEvent->canShow()) {
$factrec .= "\n2 RESN privacy";
}
- $event = new WT_Event($factrec, 0);
- $event->setParentObject($this);
+ $event = new WT_Event($factrec, $sfamily, 0);
$this->indifacts[] = $event;
}
}
@@ -1276,8 +1269,7 @@ class WT_Person extends WT_GedcomRecord {
$factrec.='\n2 RESN privacy';
}
$factrec.="\n2 ASSO @".$child->getXref()."@\n3 RELA ".$rela;
- $event = new WT_Event($factrec, 0);
- $event->setParentObject($this);
+ $event = new WT_Event($factrec, $child, 0);
if (!in_array($event, $this->indifacts)) {
$this->indifacts[]=$event;
}
@@ -1303,8 +1295,7 @@ class WT_Person extends WT_GedcomRecord {
$factrec.='\n2 RESN privacy';
}
$factrec.="\n2 ASSO @".$child->getXref()."@\n3 RELA ".$rela;
- $event = new WT_Event($factrec, 0);
- $event->setParentObject($this);
+ $event = new WT_Event($factrec, $child, 0);
if (!in_array($event, $this->indifacts)) {
$this->indifacts[]=$event;
}
@@ -1337,8 +1328,7 @@ class WT_Person extends WT_GedcomRecord {
}
$factrec.="\n2 ASSO @".$child->getXref()."@\n3 RELA ".$rela;
$factrec.="\n2 ASSO @".$sfamily->getSpouseId($child->getXref())."@\n3 RELA ".$rela2;
- $event = new WT_Event($factrec, 0);
- $event->setParentObject($this);
+ $event = new WT_Event($factrec, $sfamily, 0);
if (!in_array($event, $this->indifacts)) {
$this->indifacts[]=$event;
}
@@ -1381,8 +1371,7 @@ class WT_Person extends WT_GedcomRecord {
case 'F': $srec.="\n2 ASSO @".$spouse->getXref()."@\n3 RELA wif"; break;
case 'U': $srec.="\n2 ASSO @".$spouse->getXref()."@\n3 RELA spo"; break;
}
- $event = new WT_Event($srec, 0);
- $event->setParentObject($this);
+ $event = new WT_Event($srec, $spouse, 0);
$this->indifacts[] = $event;
}
}
@@ -1417,8 +1406,7 @@ class WT_Person extends WT_GedcomRecord {
foreach ($histo as $indexval=>$hrec) {
$sdate=new WT_Date(get_gedcom_value('DATE', 2, $hrec, '', false));
if ($sdate->isOK() && WT_Date::Compare($this->getEstimatedBirthDate(), $sdate)<=0 && WT_Date::Compare($sdate, $this->getEstimatedDeathDate())<=0) {
- $event = new WT_Event($hrec);
- $event->setParentObject($this);
+ $event = new WT_Event($hrec, null, -1);
$this->indifacts[] = $event;
}
}
@@ -1496,8 +1484,7 @@ class WT_Person extends WT_GedcomRecord {
}
}
if (!$found) {
- $event = new WT_Event($factrec);
- $event->setParentObject($this);
+ $event = new WT_Event($factrec, $associate, 0);
$this->indifacts[] = $event;
}
}