summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2013-06-23 21:05:50 +0000
committerfisharebest <fisharebest@gmail.com>2013-06-23 21:05:50 +0000
commit535f5d3688d1c1fafbe4e48efa9ce8d526cd256b (patch)
tree6a4c4135959fe3b1ca74f000fb9a402ef4cb78aa /library
parenta30e3d5b12f5c5aa1d1e55ba0aa7f4db74e68498 (diff)
downloadwebtrees-535f5d3688d1c1fafbe4e48efa9ce8d526cd256b.tar.gz
webtrees-535f5d3688d1c1fafbe4e48efa9ce8d526cd256b.tar.bz2
webtrees-535f5d3688d1c1fafbe4e48efa9ce8d526cd256b.zip
Use PHP5.3 language features in gedcom-record classes
Diffstat (limited to 'library')
-rw-r--r--library/WT/Controller/GedcomRecord.php3
-rw-r--r--library/WT/Controller/Lifespan.php2
-rw-r--r--library/WT/Family.php14
-rw-r--r--library/WT/GedcomRecord.php37
-rw-r--r--library/WT/Media.php12
-rw-r--r--library/WT/Note.php16
-rw-r--r--library/WT/Person.php12
-rw-r--r--library/WT/Report/Base.php19
-rw-r--r--library/WT/Repository.php19
-rw-r--r--library/WT/Source.php16
10 files changed, 47 insertions, 103 deletions
diff --git a/library/WT/Controller/GedcomRecord.php b/library/WT/Controller/GedcomRecord.php
index e024736626..18c64bd9fa 100644
--- a/library/WT/Controller/GedcomRecord.php
+++ b/library/WT/Controller/GedcomRecord.php
@@ -42,7 +42,8 @@ class WT_Controller_GedcomRecord extends WT_Controller_Page {
$this->setPageTitle($this->record->getFullName());
} else {
// e.g. "Individual" or "Source"
- $this->setPageTitle(WT_Gedcom_Tag::getLabel($this->record->getType()));
+ $record = $this->record;
+ $this->setPageTitle(WT_Gedcom_Tag::getLabel($record::RECORD_TYPE));
}
} else {
// No such record
diff --git a/library/WT/Controller/Lifespan.php b/library/WT/Controller/Lifespan.php
index a124e4948b..60c6664289 100644
--- a/library/WT/Controller/Lifespan.php
+++ b/library/WT/Controller/Lifespan.php
@@ -140,7 +140,7 @@ class WT_Controller_Lifespan extends WT_Controller_Page {
$this->pids[$key] = $value;
$person = WT_Person::getInstance($value);
// list of linked records includes families as well as individuals.
- if ($person && $person->getType()=='INDI') {
+ if ($person) {
$bdate = $person->getEstimatedBirthDate();
$ddate = $person->getEstimatedDeathDate();
//--Checks to see if the details of that person can be viewed
diff --git a/library/WT/Family.php b/library/WT/Family.php
index 9dc61b7abd..cc7876451c 100644
--- a/library/WT/Family.php
+++ b/library/WT/Family.php
@@ -2,7 +2,7 @@
// Class file for a Family
//
// webtrees: Web based Family History software
-// Copyright (C) 2011 webtrees development team.
+// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Family extends WT_GedcomRecord {
+ const RECORD_TYPE = 'FAM';
+ const URL_PREFIX = 'family.php?famid=';
+
private $husb = null;
private $wife = null;
private $marriage = null;
@@ -330,15 +333,6 @@ class WT_Family extends WT_GedcomRecord {
return array();
}
- // Generate a URL to this record, suitable for use in HTML
- public function getHtmlUrl() {
- return parent::_getLinkUrl('family.php?famid=', '&amp;');
- }
- // Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
- public function getRawUrl() {
- return parent::_getLinkUrl('family.php?famid=', '&');
- }
-
// Get an array of structures containing all the names in the record
public function getAllNames() {
if (is_null($this->_getAllNames)) {
diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php
index 5b2bb76d6c..5e75369e62 100644
--- a/library/WT/GedcomRecord.php
+++ b/library/WT/GedcomRecord.php
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_GedcomRecord {
+ const RECORD_TYPE = 'UNKNOWN';
+ const URL_PREFIX = 'gedrecord.php?pid=';
+
protected $xref =null; // The record identifier
protected $type =null; // INDI, FAM, etc.
public $ged_id =null; // The gedcom file, only set if this record comes from the database
@@ -223,13 +226,7 @@ class WT_GedcomRecord {
public function getGedId() {
return $this->ged_id;
}
- /**
- * get the object type
- * @return string returns the type of this object 'INDI','FAM', etc.
- */
- public function getType() {
- return $this->type;
- }
+
/**
* get gedcom record
*/
@@ -270,14 +267,14 @@ class WT_GedcomRecord {
// Generate a URL to this record, suitable for use in HTML
public function getHtmlUrl() {
- return self::_getLinkUrl('gedrecord.php?pid=', '&amp;');
+ return self::_getLinkUrl(static::URL_PREFIX, '&amp;');
}
// Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
public function getRawUrl() {
- return self::_getLinkUrl('gedrecord.php?pid=', '&');
+ return self::_getLinkUrl(static::URL_PREFIX, '&');
}
- protected function _getLinkUrl($link, $separator) {
+ private function _getLinkUrl($link, $separator) {
if ($this->ged_id) {
// If the record was created from the database, we know the gedcom
return $link.$this->getXref().$separator.'ged='.rawurlencode(get_gedcom_from_id($this->ged_id));
@@ -356,9 +353,9 @@ class WT_GedcomRecord {
protected function _canDisplayDetailsByType($access_level) {
global $global_facts;
- if (isset($global_facts[$this->getType()])) {
+ if (isset($global_facts[static::RECORD_TYPE])) {
// Restriction found
- return $global_facts[$this->getType()]>=$access_level;
+ return $global_facts[static::RECORD_TYPE]>=$access_level;
} else {
// No restriction found - must be public:
return true;
@@ -486,10 +483,10 @@ class WT_GedcomRecord {
}
}
} else {
- $this->_addName($this->getType(), $this->getFallBackName(), null);
+ $this->_addName(static::RECORD_TYPE, $this->getFallBackName(), null);
}
} else {
- $this->_addName($this->getType(), WT_I18N::translate('Private'), null);
+ $this->_addName(static::RECORD_TYPE, WT_I18N::translate('Private'), null);
}
}
return $this->_getAllNames;
@@ -694,22 +691,22 @@ class WT_GedcomRecord {
// Fetch the records that link to this one
public function fetchLinkedIndividuals() {
- return fetch_linked_indi($this->getXref(), $this->getType(), $this->ged_id);
+ return fetch_linked_indi($this->getXref(), static::RECORD_TYPE, $this->ged_id);
}
public function fetchLinkedFamilies() {
- return fetch_linked_fam($this->getXref(), $this->getType(), $this->ged_id);
+ return fetch_linked_fam($this->getXref(), static::RECORD_TYPE, $this->ged_id);
}
public function fetchLinkedNotes() {
- return fetch_linked_note($this->getXref(), $this->getType(), $this->ged_id);
+ return fetch_linked_note($this->getXref(), static::RECORD_TYPE, $this->ged_id);
}
public function fetchLinkedSources() {
- return fetch_linked_sour($this->getXref(), $this->getType(), $this->ged_id);
+ return fetch_linked_sour($this->getXref(), static::RECORD_TYPE, $this->ged_id);
}
public function fetchLinkedRepositories() {
- return fetch_linked_repo($this->getXref(), $this->getType(), $this->ged_id);
+ return fetch_linked_repo($this->getXref(), static::RECORD_TYPE, $this->ged_id);
}
public function fetchLinkedMedia() {
- return fetch_linked_obje($this->getXref(), $this->getType(), $this->ged_id);
+ return fetch_linked_obje($this->getXref(), static::RECORD_TYPE, $this->ged_id);
}
// Get all attributes (e.g. DATE or PLAC) from an event (e.g. BIRT or MARR).
diff --git a/library/WT/Media.php b/library/WT/Media.php
index ee744979ea..e370da631b 100644
--- a/library/WT/Media.php
+++ b/library/WT/Media.php
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Media extends WT_GedcomRecord {
+ const RECORD_TYPE = 'OBJE';
+ const URL_PREFIX = 'mediaviewer.php?mid=';
+
public $title = null; // TODO: these should be private, with getTitle() and getFilename() functions
public $file = null;
@@ -330,15 +333,6 @@ class WT_Media extends WT_GedcomRecord {
return $this->$var;
}
- // Generate a URL to this record, suitable for use in HTML
- public function getHtmlUrl() {
- return parent::_getLinkUrl('mediaviewer.php?mid=', '&amp;');
- }
- // Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
- public function getRawUrl() {
- return parent::_getLinkUrl('mediaviewer.php?mid=', '&');
- }
-
// Generate a URL directly to the media file
public function getHtmlUrlDirect($which='main', $download=false) {
// “cb” is “cache buster”, so clients will make new request if anything significant about the user or the file changes
diff --git a/library/WT/Note.php b/library/WT/Note.php
index 7cf671322f..a97f87e542 100644
--- a/library/WT/Note.php
+++ b/library/WT/Note.php
@@ -2,7 +2,7 @@
// Class file for a Shared Note (NOTE) object
//
// webtrees: Web based Family History software
-// Copyright (C) 2011 webtrees development team.
+// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2009 PGV Development Team. All rights reserved.
@@ -21,7 +21,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// @version $Id$
+// $Id$
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Note extends WT_GedcomRecord {
+ const RECORD_TYPE = 'NOTE';
+ const URL_PREFIX = 'note.php?nid=';
+
// Implement note-specific privacy logic
protected function _canDisplayDetailsByType($access_level) {
// Hide notes if they are attached to private records
@@ -64,15 +67,6 @@ class WT_Note extends WT_GedcomRecord {
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
}
- // Generate a URL to this record, suitable for use in HTML
- public function getHtmlUrl() {
- return parent::_getLinkUrl('note.php?nid=', '&amp;');
- }
- // Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
- public function getRawUrl() {
- return parent::_getLinkUrl('note.php?nid=', '&');
- }
-
// The 'name' of a note record is the first line. This can be
// somewhat unwieldy if lots of CONC records are used. Limit to 100 chars
protected function _addName($type, $value, $gedrec) {
diff --git a/library/WT/Person.php b/library/WT/Person.php
index 5b82ed467e..a2ab1229af 100644
--- a/library/WT/Person.php
+++ b/library/WT/Person.php
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Person extends WT_GedcomRecord {
+ const RECORD_TYPE = 'INDI';
+ const URL_PREFIX = 'individual.php?pid=';
+
var $indifacts = array();
var $otherfacts = array();
var $globalfacts = array();
@@ -1647,15 +1650,6 @@ class WT_Person extends WT_GedcomRecord {
return $txt;
}
- // Generate a URL to this record, suitable for use in HTML
- public function getHtmlUrl() {
- return parent::_getLinkUrl('individual.php?pid=', '&amp;');
- }
- // Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
- public function getRawUrl() {
- return parent::_getLinkUrl('individual.php?pid=', '&');
- }
-
// If this object has no name, what do we call it?
function getFallBackName() {
return '@P.N. /@N.N./';
diff --git a/library/WT/Report/Base.php b/library/WT/Report/Base.php
index b0d1dc874e..30e3cd9828 100644
--- a/library/WT/Report/Base.php
+++ b/library/WT/Report/Base.php
@@ -4,7 +4,7 @@
// used by the SAX parser to generate reports from the XML report file.
//
// webtrees: Web based Family History software
-// Copyright (C) 2012 webtrees development team.
+// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
@@ -2350,23 +2350,6 @@ function FactsSHandler($attrs) {
}
} else {
$record = new WT_GedcomRecord($gedrec);
- switch ($record->getType()) {
- case "INDI":
- $record=new WT_Person($gedrec);
- break;
- case "FAM":
- $record=new WT_Family($gedrec);
- break;
- case "SOUR":
- $record=new WT_Source($gedrec);
- break;
- case "REPO":
- $record=new WT_Repository($gedrec);
- break;
- case "NOTE":
- $record=new WT_Note($gedrec);
- break;
- }
$oldrecord = WT_GedcomRecord::getInstance($record->getXref());
$oldrecord->diffMerge($record);
$facts = $oldrecord->getFacts();
diff --git a/library/WT/Repository.php b/library/WT/Repository.php
index d50d8f9036..3959c1a840 100644
--- a/library/WT/Repository.php
+++ b/library/WT/Repository.php
@@ -2,7 +2,7 @@
// Class file for a Repository (REPO) object
//
// webtrees: Web based Family History software
-// Copyright (C) 2011 webtrees development team.
+// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
@@ -21,7 +21,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// @version $Id$
+// $Id$
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Repository extends WT_GedcomRecord {
+ const RECORD_TYPE = 'REPO';
+ const URL_PREFIX = 'repo.php?rid=';
+
// Fetch the record from the database
protected static function fetchGedcomRecord($xref, $ged_id) {
static $statement=null;
@@ -36,22 +39,12 @@ class WT_Repository extends WT_GedcomRecord {
if ($statement===null) {
$statement=WT_DB::prepare(
"SELECT o_type AS type, o_id AS xref, o_file AS ged_id, o_gedcom AS gedrec ".
- "FROM `##other` WHERE o_id=? AND o_file=? AND o_type='REPO'"
+ "FROM `##other` WHERE o_id=? AND o_file=?"
);
}
return $statement->execute(array($xref, $ged_id))->fetchOneRow(PDO::FETCH_ASSOC);
}
- // Generate a URL to this record, suitable for use in HTML
- public function getHtmlUrl() {
- return parent::_getLinkUrl('repo.php?rid=', '&amp;');
- }
-
- // Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
- public function getRawUrl() {
- return parent::_getLinkUrl('repo.php?rid=', '&');
- }
-
// Generate a private version of this record
protected function createPrivateGedcomRecord($access_level) {
return "0 @".$this->xref."@ REPO\n1 NAME ".WT_I18N::translate('Private');
diff --git a/library/WT/Source.php b/library/WT/Source.php
index daf24f4f09..3e1c2db595 100644
--- a/library/WT/Source.php
+++ b/library/WT/Source.php
@@ -2,7 +2,7 @@
// Class file for a Source (SOUR) object
//
// webtrees: Web based Family History software
-// Copyright (C) 2011 webtrees development team.
+// Copyright (C) 2013 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
@@ -21,7 +21,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// @version $Id$
+// $Id$
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
@@ -29,6 +29,9 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Source extends WT_GedcomRecord {
+ const RECORD_TYPE = 'SOUR';
+ const URL_PREFIX = 'source.php?sid=';
+
// Implement source-specific privacy logic
protected function _canDisplayDetailsByType($access_level) {
// Hide sources if they are attached to private repositories ...
@@ -66,15 +69,6 @@ class WT_Source extends WT_GedcomRecord {
return get_gedcom_value('AUTH', 1, $this->getGedcomRecord());
}
- // Generate a URL to this record, suitable for use in HTML
- public function getHtmlUrl() {
- return parent::_getLinkUrl('source.php?sid=', '&amp;');
- }
- // Generate a URL to this record, suitable for use in javascript, HTTP headers, etc.
- public function getRawUrl() {
- return parent::_getLinkUrl('source.php?sid=', '&');
- }
-
// Get an array of structures containing all the names in the record
public function getAllNames() {
return parent::_getAllNames('TITL', 1);