public function modify(eZContentObject $contentObject, &$docList)
 {
     $isEvent = $from = $to = false;
     $attributes = $contentObject->fetchAttributesByIdentifier(array('from_time', 'to_time'));
     if (empty($attributes)) {
         return false;
     }
     foreach ($attributes as $attribute) {
         if ($attribute instanceof eZContentObjectAttribute) {
             if ($attribute->attribute('contentclass_attribute_identifier') == 'from_time' && $attribute->hasContent()) {
                 $from = $attribute->toString();
             }
             if ($attribute->attribute('contentclass_attribute_identifier') == 'to_time' && $attribute->hasContent()) {
                 $to = $attribute->toString();
             }
         }
     }
     if ($from && $to) {
         $isEvent = true;
     }
     if ($isEvent) {
         $duration = $to - $from;
         $version = $contentObject->currentVersion();
         if ($version === false) {
             return;
         }
         $availableLanguages = $version->translationList(false, false);
         foreach ($availableLanguages as $languageCode) {
             if ($docList[$languageCode] instanceof eZSolrDoc) {
                 if ($docList[$languageCode]->Doc instanceof DOMDocument) {
                     $xpath = new DomXpath($docList[$languageCode]->Doc);
                     if ($xpath->evaluate('//field[@name="extra_event_duration_s"]')->length == 0) {
                         $docList[$languageCode]->addField('extra_event_duration_s', $duration);
                         $docList[$languageCode]->addField('extra_event_duration_si', intval($duration));
                     }
                 } elseif (is_array($docList[$languageCode]->Doc) && !isset($docList[$languageCode]->Doc['extra_event_duration_s'])) {
                     $docList[$languageCode]->addField('extra_event_duration_s', $duration);
                     $docList[$languageCode]->addField('extra_event_duration_si', intval($duration));
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function testOPS($path = null)
 {
     $this->_saveMeta();
     if ($path == null) {
         $path = $this->packagepath;
     }
     $mimetypepath = $path . '/' . $this->getMimetypeFilename();
     // filename of mimetype file
     $metapath = $path . '/META-INF';
     $result = array();
     $result[0] = 'fail';
     $result[1] = 'error message';
     if (is_dir($metapath)) {
         // dir exists
         if ($container = file_get_contents($metapath . '/container.xml')) {
             // found container file
             $contdoc = new DomDocument();
             if ($cd = $contdoc->loadXML($container)) {
                 // loaded container xml
                 $fp = $contdoc->getElementsByTagName('rootfiles')->item(0)->getElementsByTagName('rootfile')->item(0)->getAttribute('full-path');
                 if ($fullp = $this->_getRelPathWithOpf($fp)) {
                     // found full path to opf file
                     $p = strlen($fullp[0]) > 0 ? "{$path}/{$fullp['0']}" : "{$path}";
                     $op = "{$p}/{$fullp['1']}";
                     $this->logerr($op, 2);
                     if (file_exists($op)) {
                         // found opf file
                         $opf = new DomDocument('1.0', 'utf-8');
                         $opf->preserveWhiteSpace = FALSE;
                         $opf->loadXML(file_get_contents($op));
                         $package = $opf->getElementsByTagName('package')->item(0);
                         $meta = $package->getElementsByTagName('metadata')->item(0);
                         $mani = $package->getElementsByTagName('manifest')->item(0);
                         $spine = $package->getElementsByTagName('spine')->item(0);
                         if ($meta && $mani && $spine) {
                             $tocatt = $spine->getAttribute('toc');
                             $opfXP = new DomXpath($opf);
                             $opfXP->registerNamespace("opfns", $this->opfNS);
                             $opfXP->registerNamespace("dc", $this->dcNS);
                             $tocitem = $opfXP->evaluate('//*[@id="' . $tocatt . '"]');
                             if ($tocitem->length > 0) {
                                 if (file_exists($p . '/' . $tocitem->item(0)->getAttribute('href'))) {
                                     $result[0] = 'pass';
                                     $result[1] = array('opf' => $fp);
                                     //foreach($mani->getElementsByTagName('item') as $item) {
                                     //  $href = $item->getAttribute('href');
                                     //}
                                 } else {
                                     $result[1] = "ncx file not found:" . $p . '/' . $tocitem->item(0)->getAttribute('href') . "\n";
                                 }
                             } else {
                                 $result[1] = "no item with ncx id found\n";
                             }
                         } else {
                             $result[1] = "one of the three required opf nodes is missing\n";
                         }
                     } else {
                         $result[1] = "opf not found\n";
                     }
                 } else {
                     $result[1] = "full path to opf not found\n";
                 }
             } else {
                 $result[1] = "container file not loaded\n";
             }
         } else {
             $result[1] = "container file not found\n";
         }
     } else {
         $result[1] = "meta-inf dir no exist\n";
     }
     return $result;
 }