Skip to content

Commit 3ff506b

Browse files
Expand Short links entity interface (#3737)
1 parent e8be806 commit 3ff506b

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

module/VuFind/src/VuFind/Db/Entity/ShortlinksEntityInterface.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
namespace VuFind\Db\Entity;
3131

32+
use DateTime;
33+
3234
/**
3335
* Entity model interface for shortlinks table
3436
*
@@ -40,4 +42,59 @@
4042
*/
4143
interface ShortlinksEntityInterface extends EntityInterface
4244
{
45+
/**
46+
* Get identifier (returns null for an uninitialized or non-persisted object).
47+
*
48+
* @return ?int
49+
*/
50+
public function getId(): ?int;
51+
52+
/**
53+
* Get the path of the URL.
54+
*
55+
* @return string
56+
*/
57+
public function getPath(): string;
58+
59+
/**
60+
* Set the path (e.g. /Search/Results?lookfor=foo) of the URL being shortened;
61+
* shortened URLs are always assumed to be within the hostname where VuFind is running.
62+
*
63+
* @param string $path Path
64+
*
65+
* @return ShortlinksEntityInterface
66+
*/
67+
public function setPath(string $path): ShortlinksEntityInterface;
68+
69+
/**
70+
* Get shortlinks hash.
71+
*
72+
* @return ?string
73+
*/
74+
public function getHash(): ?string;
75+
76+
/**
77+
* Set shortlinks hash.
78+
*
79+
* @param ?string $hash Shortlinks hash
80+
*
81+
* @return ShortlinksEntityInterface
82+
*/
83+
public function setHash(?string $hash): ShortlinksEntityInterface;
84+
85+
/**
86+
* Get creation timestamp.
87+
*
88+
* @return DateTime
89+
*/
90+
public function getCreated(): DateTime;
91+
92+
/**
93+
* Set creation timestamp.
94+
*
95+
* @param DateTime $dateTime Creation timestamp
96+
*
97+
* @return ShortlinksEntityInterface
98+
*/
99+
public function setCreated(DateTime $dateTime): ShortlinksEntityInterface;
43100
}

module/VuFind/src/VuFind/Db/Row/Shortlinks.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
namespace VuFind\Db\Row;
3131

32+
use DateTime;
33+
use VuFind\Db\Entity\ShortlinksEntityInterface;
34+
3235
/**
3336
* Row Definition for shortlinks
3437
*
@@ -37,6 +40,11 @@
3740
* @author Demian Katz <[email protected]>
3841
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
3942
* @link https://vufind.org Main Site
43+
*
44+
* @property int $id
45+
* @property string $path
46+
* @property string $hash
47+
* @property string $created
4048
*/
4149
class Shortlinks extends RowGateway implements \VuFind\Db\Entity\ShortlinksEntityInterface
4250
{
@@ -49,4 +57,84 @@ public function __construct($adapter)
4957
{
5058
parent::__construct('id', 'shortlinks', $adapter);
5159
}
60+
61+
/**
62+
* Get identifier (returns null for an uninitialized or non-persisted object).
63+
*
64+
* @return ?int
65+
*/
66+
public function getId(): ?int
67+
{
68+
return $this->id ?? null;
69+
}
70+
71+
/**
72+
* Get the path of the URL.
73+
*
74+
* @return string
75+
*/
76+
public function getPath(): string
77+
{
78+
return $this->path ?? '';
79+
}
80+
81+
/**
82+
* Set the path (e.g. /Search/Results?lookfor=foo) of the URL being shortened;
83+
* shortened URLs are always assumed to be within the hostname where VuFind is running.
84+
*
85+
* @param string $path Path
86+
*
87+
* @return ShortlinksEntityInterface
88+
*/
89+
public function setPath(string $path): ShortlinksEntityInterface
90+
{
91+
$this->path = $path;
92+
return $this;
93+
}
94+
95+
/**
96+
* Get shortlinks hash.
97+
*
98+
* @return ?string
99+
*/
100+
public function getHash(): ?string
101+
{
102+
return $this->hash ?? null;
103+
}
104+
105+
/**
106+
* Set shortlinks hash.
107+
*
108+
* @param ?string $hash Shortlinks hash
109+
*
110+
* @return ShortlinksEntityInterface
111+
*/
112+
public function setHash(?string $hash): ShortlinksEntityInterface
113+
{
114+
$this->hash = $hash;
115+
return $this;
116+
}
117+
118+
/**
119+
* Get creation timestamp.
120+
*
121+
* @return DateTime
122+
*/
123+
public function getCreated(): DateTime
124+
{
125+
return DateTime::createFromFormat('Y-m-d H:i:s', $this->created);
126+
}
127+
128+
/**
129+
* Set creation timestamp.
130+
*
131+
* @param DateTime $dateTime Creation timestamp
132+
*
133+
* @return ShortlinksEntityInterface
134+
*/
135+
public function setCreated(DateTime $dateTime): ShortlinksEntityInterface
136+
{
137+
$this->created = $dateTime->format('Y-m-d H:i:s');
138+
return $this;
139+
}
52140
}

0 commit comments

Comments
 (0)