src/Webtrees/Module/Certificates/Model/Certificate.php
public function fetchALinkedSource(){		
		$sid = null;
		
		// Try to find in individual, then families, then other types of records. We are interested in the first available value.
		$ged =
		Database::prepare(
				'SELECT i_gedcom AS gedrec FROM `##individuals`'.
				' WHERE i_file=:gedcom_id AND i_gedcom LIKE :gedcom')
		  ->execute(array(
		      'gedcom_id' => $this->tree->getTreeId(), 
		      'gedcom' => '%_ACT '.$this->getFilename().'%'		      
		  ))->fetchOne();
		if(!$ged){
			$ged = Database::prepare(
					'SELECT f_gedcom AS gedrec FROM `##families`'.
					' WHERE f_file=:gedcom_id AND f_gedcom LIKE :gedcom')
			     ->execute(array(
			         'gedcom_id' => $this->tree->getTreeId(), 
			         'gedcom' => '%_ACT '.$this->getFilename().'%'			         
			     ))->fetchOne();
			if(!$ged){
				$ged = Database::prepare(
				    'SELECT o_gedcom AS gedrec FROM `##other`'.
				    ' WHERE o_file=:gedcom_id AND o_gedcom LIKE :gedcom')
				    ->execute(array(
				        'gedcom_id' => $this->tree->getTreeId(),
				        'gedcom' => '%_ACT '.$this->getFilename().'%'				        
				    ))->fetchOne();
			}
		}
		//If a record has been found, parse it to find the source reference.
		if($ged){
			$gedlines = explode("\n", $ged);
			$level = 0;
			$levelsource = -1;
			$sid_tmp=null;
			$sourcefound = false;
			foreach($gedlines as $gedline){
				// Get the level
				$match = null;
				if (!$sourcefound && preg_match('~^('.WT_REGEX_INTEGER.') ~', $gedline, $match)) {
					$level = $match[1];
					//If we are not any more within the context of a source, reset
					if($level <= $levelsource){
						$levelsource = -1;
						$sid_tmp = null;
					}
					// If a source, get the level and the reference
					$match2 = null;
					if (preg_match('~^'.$level.' SOUR @('.WT_REGEX_XREF.')@$~', $gedline, $match2)) {
						$levelsource = $level;
						$sid_tmp=$match2[1];
					}
					// If the image has be found, get the source reference and exit.
					$match3 = null;
					if($levelsource>=0 && $sid_tmp && preg_match('~^'.$level.' _ACT '.preg_quote($this->getFilename()).'~', $gedline, $match3)){
						$sid = $sid_tmp;
						$sourcefound = true;
					}
				}
			}
		}
		
		if($sid) $this->source = Source::getInstance($sid, $this->tree);
		
		return $this->source;	
	}
public function fetchALinkedSource(){		
		$sid = null;
		
		// Try to find in individual, then families, then other types of records. We are interested in the first available value.
		$ged =
		Database::prepare(
				'SELECT i_gedcom AS gedrec FROM `##individuals`'.
				' WHERE i_file=:gedcom_id AND i_gedcom LIKE :gedcom')
		  ->execute(array(
		      'gedcom_id' => $this->tree->getTreeId(), 
		      'gedcom' => '%_ACT '.$this->getFilename().'%'		      
		  ))->fetchOne();
		if(!$ged){
			$ged = Database::prepare(
					'SELECT f_gedcom AS gedrec FROM `##families`'.
					' WHERE f_file=:gedcom_id AND f_gedcom LIKE :gedcom')
			     ->execute(array(
			         'gedcom_id' => $this->tree->getTreeId(), 
			         'gedcom' => '%_ACT '.$this->getFilename().'%'			         
			     ))->fetchOne();
			if(!$ged){
				$ged = Database::prepare(
				    'SELECT o_gedcom AS gedrec FROM `##other`'.
				    ' WHERE o_file=:gedcom_id AND o_gedcom LIKE :gedcom')
				    ->execute(array(
				        'gedcom_id' => $this->tree->getTreeId(),
				        'gedcom' => '%_ACT '.$this->getFilename().'%'				        
				    ))->fetchOne();
			}
		}
		//If a record has been found, parse it to find the source reference.
		if($ged){
			$gedlines = explode("\n", $ged);
			$level = 0;
			$levelsource = -1;
			$sid_tmp=null;
			$sourcefound = false;
			foreach($gedlines as $gedline){
				// Get the level
				$match = null;
				if (!$sourcefound && preg_match('~^('.WT_REGEX_INTEGER.') ~', $gedline, $match)) {
					$level = $match[1];
					//If we are not any more within the context of a source, reset
					if($level <= $levelsource){
						$levelsource = -1;
						$sid_tmp = null;
					}
					// If a source, get the level and the reference
					$match2 = null;
					if (preg_match('~^'.$level.' SOUR @('.WT_REGEX_XREF.')@$~', $gedline, $match2)) {
						$levelsource = $level;
						$sid_tmp=$match2[1];
					}
					// If the image has be found, get the source reference and exit.
					$match3 = null;
					if($levelsource>=0 && $sid_tmp && preg_match('~^'.$level.' _ACT '.preg_quote($this->getFilename()).'~', $gedline, $match3)){
						$sid = $sid_tmp;
						$sourcefound = true;
					}
				}
			}
		}
		
		if($sid) $this->source = Source::getInstance($sid, $this->tree);
		
		return $this->source;	
	}
public function fetchALinkedSource ( ) { $ sid = null ; // Try to find in individual, then families, then other types of records. We are interested in the first available value. $ ged = Database :: prepare ( 'SELECT i_gedcom AS gedrec FROM `##individuals`' . ' WHERE i_file=:gedcom_id AND i_gedcom LIKE :gedcom' ) -> execute ( array ( 'gedcom_id' => $ this -> tree -> getTreeId ( ) , 'gedcom' => '%_ACT ' . $ this -> getFilename ( ) . '%' ) ) -> fetchOne ( ) ; if ( ! $ ged ) { $ ged = Database :: prepare ( 'SELECT f_gedcom AS gedrec FROM `##families`' . ' WHERE f_file=:gedcom_id AND f_gedcom LIKE :gedcom' ) -> execute ( array ( 'gedcom_id' => $ this -> tree -> getTreeId ( ) , 'gedcom' => '%_ACT ' . $ this -> getFilename ( ) . '%' ) ) -> fetchOne ( ) ; if ( ! $ ged ) { $ ged = Database :: prepare ( 'SELECT o_gedcom AS gedrec FROM `##other`' . ' WHERE o_file=:gedcom_id AND o_gedcom LIKE :gedcom' ) -> execute ( array ( 'gedcom_id' => $ this -> tree -> getTreeId ( ) , 'gedcom' => '%_ACT ' . $ this -> getFilename ( ) . '%' ) ) -> fetchOne ( ) ; } } //If a record has been found, parse it to find the source reference. if ( $ ged ) { $ gedlines = explode ( "\n" , $ ged ) ; $ level = 0 ; $ levelsource = - 1 ; $ sid_tmp = null ; $ sourcefound = false ; foreach ( $ gedlines as $ gedline ) { // Get the level $ match = null ; if ( ! $ sourcefound && preg_match ( '~^(' . WT_REGEX_INTEGER . ') ~' , $ gedline , $ match ) ) { $ level = $ match [ 1 ] ; //If we are not any more within the context of a source, reset if ( $ level <= $ levelsource ) { $ levelsource = - 1 ; $ sid_tmp = null ; } // If a source, get the level and the reference $ match2 = null ; if ( preg_match ( '~^' . $ level . ' SOUR @(' . WT_REGEX_XREF . ')@$~' , $ gedline , $ match2 ) ) { $ levelsource = $ level ; $ sid_tmp = $ match2 [ 1 ] ; } // If the image has be found, get the source reference and exit. $ match3 = null ; if ( $ levelsource >= 0 && $ sid_tmp && preg_match ( '~^' . $ level . ' _ACT ' . preg_quote ( $ this -> getFilename ( ) ) . '~' , $ gedline , $ match3 ) ) { $ sid = $ sid_tmp ; $ sourcefound = true ; } } } } if ( $ sid ) $ this -> source = Source :: getInstance ( $ sid , $ this -> tree ) ; return $ this -> source ; }
Returns a unique source linked to the certificate

@return Source|NULL Linked source
Returns a unique source linked to the certificate