<?php

class PhotoLinks extends Model
{

	function __construct($fromArray = array())
	{
		$this->_tableName_ = 'photoLinks';
		parent::__construct($fromArray);
	}

	static function model()
	{
		return new self();
	}

	static function addLink($photo, $url)
	{
		$parsedUrl = parse_url($url);
		$photoDetails = explode('_', $photo);
		$pointId = (int) $photoDetails[0];
		App::DB()->query('INSERT INTO photoLinks VALUES ("' . $photo . '", "' . $pointId . '","' . $url . '","' . $parsedUrl['host'] . '") ON DUPLICATE KEY UPDATE url=url;');
	}

	static function getCaption($photo)
	{
		$photolink = self::model()->getOne('photo', $photo);

		if (!$photolink) {
			return 'не определён';
		}

		return $photolink->host ? $photolink->host : $photolink->url;
	}

}
