Location: PHPKode > projects > Tagging manager > version 1.02/includes/metadata.php
<?php
/*  ============================================================
*                              metadata.php
*                              -------------------
*     Date                 : 15 june 2006
*     E-mail               : hide@address.com
*
*     Version              : 1.0 (15/06/2006 - 09:50)
*
*     This a free software
*     licensed under GPL (General public license)
*
============================================================ */
/**
 * Metadata describes the Link-object that contains all information about a link
 *
 * @author hide@address.com
 * @version 1.0
 * @package TaggingManager
 */


/**
 * Contains all information about a link
 *
 * @version      1.0.0
 */
class Link {


	/**
 * Get all information from database for that $id
 *
 * @param integer $id this is actually for the metadata in database
 */
	function Link($id=0) {
		if ($id>0) {
			$it = new iter("SELECT * FROM `tm_metadata` WHERE `meta_id` = $id");
			$data = $it->fetch();
			if ($data) { foreach (get_object_vars($data) as $key=>$val)$this->$key = $val;

			$it2 = new iter("SELECT * FROM `tm_taxonomy` WHERE `taxonomy_id` = $this->taxonomy_id");
			$data2 = $it2->fetch();
			$this->taxonomy = $data2->taxonomy;}

		}
	}
	/**
 * Write all information for a link to the database
 *
 * @return integer The id of the newly created link
 */    
	function Write() {

		$q = new query("INSERT INTO `tm_metadata` ( `meta_id` , `user_id` , `active` , `url` , `title` , `description` , `snipset` , `taxonomy_id`, `datum`, `author`  , `datecreated` , `datemodified` , `ip_creator` , `ip_modified` )
VALUES ( '', '$this->user_id', '1', '$this->url', '$this->title', '$this->description', '$this->snipset', '$this->taxonomy_id', '$this->datum', '$this->author', NOW() , NOW() , '$this->ipcreator', '$this->ipcreator'); ");
		$id = $q->insertId;

		$q2 = new query("INSERT INTO `tm_archive` ( `archive_id` , `meta_id` , `url`, `htmlarchive`, `active` , `datecreated` , `datemodified` )
VALUES ( '', '$id', '$this->url', '$this->html', '1', NOW() , NOW() );");


		$arrayTagspost = explode(' ',$this->tags); // todo:: replace by separtor

		//check tags and map them to metadata
		foreach($arrayTagspost as $tag){
			$tag = trim($tag);

			$tagselect = "SELECT * FROM `tm_tags` WHERE `tag_name` = '$tag'";
			$newTag = "INSERT INTO `tm_tags` ( `tag_id` , `tag_name` )VALUES ('', '$tag');";

			$alltags = new iter($tagselect); // check tag in db
			$t = $alltags->numRows; // look how many rows are returned

			if ($t == 0) {
				$q3 = new query($newTag);
				$newTagid = $q3->insertId;
				//echo "A ".$id.">>>".$newTagid."<br>";
				$q = new query("INSERT INTO `tm_tags_metadata` ( `meta_id` , `tag_id` )VALUES ('$id', '$newTagid');");
			}
			else {
				$item = $alltags->fetch();
				$newTagid = $item->tag_id;
				//echo "E ".$id.">>>".$newTagid."<br>";
				$q = new query("INSERT INTO `tm_tags_metadata` ( `meta_id` , `tag_id` )VALUES ('$id', '$newTagid');");
			}
		}
		return $id;
	}
	/**
 * Update all information from database for that $id
 *
 * @param integer $id this is actually for the metadata in database
 * @return integer $id returns the id of the updated link
 */  
	function Update($id) {

		//update where meta_id = id
		$q = new query("UPDATE `tm_metadata` SET
`url` =  '$this->url',		
`title` =  '$this->title',
`description` =  '$this->description',
`snipset` =  '$this->snipset',
`datum` =  '$this->datum',
`author` =  '$this->author',
`taxonomy_id` =  '$this->taxonomy_id',
`datemodified` = NOW( ) ,
`ip_modified` = '$this->ipcreator' WHERE `meta_id` = '$id' LIMIT 1 ;");

		//remove old tags
		$q = new query("DELETE FROM `tm_tags_metadata` WHERE `meta_id` = '$id'");

		//insert new tags

		$arrayTagspost = explode(' ',$this->tags); // todo:: replace by separtor

		//check tags and map them to metadata
		foreach($arrayTagspost as $tag){
			$tag = trim($tag);

			$tagselect = "SELECT * FROM `tm_tags` WHERE `tag_name` = '$tag'";
			$newTag = "INSERT INTO `tm_tags` ( `tag_id` , `tag_name` )VALUES ('', '$tag');";

			$alltags = new iter($tagselect); // check tag in db
			$t = $alltags->numRows; // look how many rows are returned

			if ($t == 0) {
				$q3 = new query($newTag);
				$newTagid = $q3->insertId;
				//echo "A ".$id.">>>".$newTagid."<br>";
				$q = new query("INSERT INTO `tm_tags_metadata` ( `meta_id` , `tag_id` )VALUES ('$id', '$newTagid');");
			}
			else {
				$item = $alltags->fetch();
				$newTagid = $item->tag_id;
				//echo "E ".$id.">>>".$newTagid."<br>";
				$q = new query("INSERT INTO `tm_tags_metadata` ( `meta_id` , `tag_id` )VALUES ('$id', '$newTagid');");
			}
		}
		return $id;
	}
	/**
 * Delete all information from database for that $id
 *
 * @param integer $id this is actually for the metadata in database
 */    	
	function Delete($id) {
		$q1 = new query("DELETE FROM `tm_metadata` WHERE `meta_id` = '$id'");
		$q2 = new query("DELETE FROM `tm_archive` WHERE `meta_id` = '$id'");
		$q3 = new query("DELETE FROM `tm_tags_metadata` WHERE `meta_id` = '$id'");
	}
}

?>
Return current item: Tagging manager