}
}
- public function existsForContact(int $cid, int $uid): bool
+ /**
+ * Checks, if the suggested contact already exists for the user
+ *
+ * @param int $sid
+ * @param int $uid
+ *
+ * @return bool
+ */
+ public function suggestionExistsForUser(int $sid, int $uid): bool
{
try {
- return $this->exists(['uid' => $uid, 'suggest-cid' => $cid]);
+ return $this->exists(['uid' => $uid, 'suggest-cid' => $sid]);
} catch (\Exception $e) {
- throw new IntroductionPersistenceException(sprintf('Cannot check Introductions for contact %d and user %d', $cid, $uid), $e);
+ throw new IntroductionPersistenceException(sprintf('Cannot check suggested Introduction for contact %d and user %d', $sid, $uid), $e);
}
}
/**
* @property-read int $uid
- * @property-read int $sid
- * @property-read int|null $cid
+ * @property-read int $cid
+ * @property-read int|null $sid
* @property-read bool $knowyou
* @property-read bool $duplex
* @property-read string $note
/** @var int */
protected $uid;
/** @var int */
- protected $sid;
- /** @var int|null */
protected $cid;
+ /** @var int|null */
+ protected $sid;
/** @var bool */
protected $knowyou;
/** @var bool */
/**
* @param int $uid
- * @param int $sid
- * @param int|null $cid
+ * @param int $cid
+ * @param int|null $sid
* @param bool $knowyou
* @param bool $duplex
* @param string $note
* @param bool $ignore
* @param int|null $id
*/
- public function __construct(int $uid, int $sid, ?int $cid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
+ public function __construct(int $uid, int $cid, ?int $sid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
{
$this->uid = $uid;
- $this->sid = $sid;
$this->cid = $cid;
+ $this->sid = $sid;
$this->knowyou = $knowyou;
$this->duplex = $duplex;
$this->note = $note;
{
return new Entity\Introduction(
$row['uid'] ?? 0,
- $row['suggest-cid'] ?? 0,
- $row['contact-id'] ?? null,
+ $row['contact-id'] ?? 0,
+ $row['suggest-cid'] ?? null,
!empty($row['knowyou']),
!empty($row['duplex']),
$row['note'] ?? '',
public function createNew(
int $uid,
- int $sid,
+ int $cid,
string $note,
- int $cid = null,
+ int $sid = null,
bool $knowyou = false,
bool $duplex = false
): Entity\Introduction {
}
// Quit if we already have an introduction for this person
- if (DI::intro()->existsForContact($cid, $uid)) {
+ if (DI::intro()->suggestionExistsForUser($cid, $uid)) {
return false;
}
],
'assertion' => [
'uid' => 0,
- 'suggest-cid' => 0,
- 'contact-id' => null,
+ 'contact-id' => 0,
+ 'suggest-cid' => null,
'knowyou' => false,
'duplex' => false,
'note' => '',
{
self::assertEquals($intro->id, $assertion['id'] ?? null);
self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
- self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? 0);
- self::assertEquals($intro->cid, $assertion['contact-id'] ?? null);
+ self::assertEquals($intro->cid, $assertion['contact-id'] ?? 0);
+ self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? null);
self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
self::assertEquals($intro->duplex, $assertion['duplex'] ?? false);
self::assertEquals($intro->note, $assertion['note'] ?? '');
{
$factory = new Introduction(new NullLogger());
- $intro = $factory->createNew($input['uid'] ?? 0, $input['sid'] ?? 0, $input['note'] ?? '');
+ $intro = $factory->createNew($input['uid'] ?? 0, $input['cid'] ?? 0, $input['note'] ?? '');
$this->assertIntro($intro, [
- 'uid' => $input['uid'] ?? 0,
- 'sid' => $input['sid'] ?? 0,
- 'note' => $input['note'] ?? '',
+ 'uid' => $input['uid'] ?? 0,
+ 'contact-id' => $input['cid'] ?? 0,
+ 'note' => $input['note'] ?? '',
]);
}