<?php

/*
 * Created on 11.02.2012
 * Oliver Soop(osoop1@ut.ee)
 */

include_once ("XMLBaseTagger.php");
class DCTagger extends XMLBaseTagger {
	protected static $nameSpace = "http://purl.org/dc/elements/1.1/";
	protected static $prefix = "dc";
	protected static $creatorTag = "creator";
	protected static $contributorTag = "contributor";
	protected static $coverageTag = "coverage";
	protected static $dateTag = "date";
	protected static $descriptionTag = "description";
	protected static $formatTag = "format";
	protected static $identifierTag = "identifier";
	protected static $languageTag = "language";
	protected static $publisherTag = "publisher";
	protected static $relationTag = "relation";
	protected static $rightsTag = "rights";
	protected static $sourceTag = "source";
	protected static $subjectTag = "subject";
	protected static $titleTag = "title";
	protected static $typeTag = "type";

	public function __construct() {
		$this->name = "DC";
	}

	/**
	 * Funktsioon, millega etteantud Story objekti täiendatakse vastavalt algoritmile
	 */
	public function updateNewsStory($story, $domElement) {
		$list = $domElement->getElementsByTagNameNS(DCTagger::$nameSpace, "*");
		
		foreach($list as $element) {
			if(strcasecmp($element->prefix, DCTagger::$prefix) != 0) {
 				continue;
 			}
 			
 			switch ($element->localName) {
	 			case DCTagger::$creatorTag:
	 				$story->author($element->nodeValue);
	 				break;
	 			case DCTagger::$descriptionTag:
	 				$story->desc($element->nodeValue);
	 				break;
	 			case DCTagger::$dateTag:
	 				$story->pubDate($element->nodeValue);
	 				break;
	 			default:
	 				continue;
	 		}
		}
		return $story;

	}
	
	/**
 	 * Funktsioon, mis tagastab Dublin Core-i märgenditele vastava Story objekti väärtuse
 	 */
 	public static function getStoryEnum($tag) {
 		if(strcasecmp($tag->prefix, DCTagger::$prefix) != 0) {
 			return null;
 		}
 		switch ($tag->localName) {
 			case DCTagger::$dateTag:
 				return StoryEnum::PUBDATE;
 			case DCTagger::$titleTag:
 				return StoryEnum::TITLE;
 			case DCTagger::$descriptionTag:
 				return StoryEnum::DESCRIPTION;
 			case YahooMediaTagger::$mediaCreditTag:
 				if(strcasecmp($tag->getAttribute($this->mediaCreditTagRoleAttribute), "author")){
 					return StoryEnum::AUTHOR;
 				}
 				return null;
 			
 			default:
 				return null;
 		}
 		
 		
 	}
}
?>
