Ejemplo n.º 1
0
 /**
  * Extends the Media constructor.
  * Create a certificate from the file path
  * @param string $data
  * @param Tree $tree Reference tree
  * @param CertificateProviderInterface $provider
  */
 public function __construct($data, Tree $tree, CertificateProviderInterface $provider)
 {
     $this->provider = $provider;
     // Data is only the file name
     $data = str_replace("\\", '/', $data);
     $xref = Functions::encryptToSafeBase64($data);
     $gedcom = sprintf('0 @%1$s@ OBJE' . PHP_EOL . '1 FILE %2$s', $xref, $data);
     parent::__construct($xref, $gedcom, '', $tree);
     $this->title = basename($this->getFilename(), '.' . $this->extension());
     $match = null;
     $ct = preg_match("/(?<year>\\d{1,4})(\\.(?<month>\\d{1,2}))?(\\.(?<day>\\d{1,2}))?( (?<type>[A-Z]{1,2}) )?(?<details>.*)/", $this->title, $match);
     if ($ct > 0) {
         $monthId = (int) $match['month'];
         $calendarShortMonths = Functions::getCalendarShortMonths();
         $monthShortName = array_key_exists($monthId, $calendarShortMonths) ? $calendarShortMonths[$monthId] : $monthId;
         $this->certDate = new Date($match['day'] . ' ' . strtoupper($monthShortName) . ' ' . $match['year']);
         $this->certType = $match['type'];
         $this->certDetails = $match['details'];
     } else {
         $this->certDetails = $this->title;
     }
 }