* @license PHP License * @package WB * @subpackage db */ /** * Reference lists * * List of URL references * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_URLReference extends WBStdClass { /** * table object * @var WBDatasource_Table */ protected $table; /** * dictionary * @var WBDictionary_URL */ protected $dict; const TABLE_REF = 'reference'; const TABLE_URL = 'url'; /** * Constructor * * Instantiate table and URL dictionary */ public function __construct() { $this->table = WBClass::create('WBDatasource_Table'); $this->dict = WBClass::create('WBDictionary_URL'); } /** * Get list of references for URL * * Resolve URL using dictionary (receive URLid). Retrieve list of * references for URL. Optionally, references can be limited to tags * and namespaces. * * Types. * If $types is emtpy (or not an array), return all types of references * Otherwise, types is a list of tags with optional namespaces. * * 1) short form: * $types = array( * 'url', * 'vfsfile', * ); * * 2) long form * $types = array( * array( * 'namespace' => 'wb', * 'tag' => 'url' * ), * array( * 'namespace' => 'wb', * 'tag' => 'vfsfile' * ) * ); * * @param string $url * @param array $types * @return array */ public function get($url, $types = array()) { if (!$this->dict->lookupWord($url)) { return array(); } $urlId = $this->dict->getId(); $clause = array(); $clause[] = array( 'value' => $this->dict->getId(), 'field' => $this->table->getIdentifier(self::TABLE_URL) ); if (!is_array($types)) { $types = array(); } if (!empty($types)) { $sub = array(); foreach ($types as $t) { if (!is_array($t)) { $t = array( 'namespace' => 'wb', 'tag' => $t ); } $sub[] = array( 'type' => 'complex', 'bond' => 'and', 'clause' => array( array( 'field' => 'xnamespace', 'value' => $t['namespace'] ), array( 'field' => 'xtag', 'value' => $t['tag'] ) ) ); } if (!empty($sub)) { $clause[] = array( 'type' => 'complex', 'clause' => $sub, 'bond' => 'or' ); } } return $this->table->get(self::TABLE_REF, null, null, $clause); } } ?>