{
protected $role = 'link';
+ protected static $_all = [];
+
public function getURL()
{
- return static::_getURL($this->to);
+ $res = static::_getURL($this->to);
+ return $res;
}
public function getTarget()
{
$ref = str_replace('custom:', '', $ref);
$e = explode(':', $ref, 2);
- if (count($e) == 2 && $e[0] == $type) {
+ if (count($e) == 2) {
$ref = $e[1];
$type = $e[0];
}
$nospaceref = str_replace(' ', '', $ref);
- $res = DB::table('fluidbook_reference_url')->where('type', $type)->whereIn('ref', [$ref, $nospaceref])->get();
- if ($res->count() > 0) {
- $url = $res->get('url');
- if (!$url || $url === '-') {
- return $default;
- }
- return $url;
+ $all = self::getAllURLOf($type);
+ if (isset($all[$ref])) {
+ $res = $all[$ref];
+ } else if (isset($all[$nospaceref])) {
+ $res = $all[$nospaceref];
+ } else {
+ return $default;
}
- return $default;
+
+ if (!$res || $res === '-') {
+ return $default;
+ }
+ return $res;
}
public function ignore()
{
return parent::ignore() || !$this->getURL() || $this->getURL() === '-';
}
+
+ protected static function getAllURLOf($type)
+ {
+ if (!isset(self::$_all[$type])) {
+ self::$_all[$type] = [];
+ $res = DB::table('fluidbook_reference_url')->where('type', $type)->get(['url', 'ref']);
+ foreach ($res as $item) {
+ self::$_all[$type][$item->ref] = $item->url;
+ }
+ }
+ return self::$_all[$type];
+ }
}