Passed
Pull Request — master (#752)
by
unknown
02:07
created

BookmarkBusinessLayer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 1
1
<?php
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Gavin E <[email protected]>
10
 * @copyright Gavin E 2020
11
 */
12
13
namespace OCA\Music\BusinessLayer;
14
15
use \OCA\Music\AppFramework\BusinessLayer\BusinessLayer;
16
use \OCA\Music\AppFramework\Core\Logger;
17
18
use \OCA\Music\Db\BookmarkMapper;
19
use \OCA\Music\Db\Bookmark;
20
21
use \OCA\Music\Utility\Util;
22
23
class BookmarkBusinessLayer extends BusinessLayer {
24
	private $logger;
25
26
	public function __construct(
27
			BookmarkMapper $bookmarkMapper,
28
			Logger $logger) {
29
		parent::__construct($bookmarkMapper);
30
		$this->logger = $logger;
31
	}
32
33
  public function findAll($userId) {
34
    $bookmarks = $this->mapper->findAll($userId);
35
36
    foreach ($bookmarks as $key => $bookmark) {
37
      if ($bookmark->getTrackId() < 0) {
38
        unset($bookmarks[$key]);
39
        break;
40
      }
41
    }
42
43
    return $bookmarks;
44
  }
45
46
  public function createPlayQueueBookmark($userId, $trackId, $position) {
47
    // first remove any existing playqueue bookmarks
48
    $this->mapper->removePlayQueueBookmarks($userId);
49
50
    // create bookmark and store update time in comment field
51
    return $this->create($userId, -$trackId, $position, gmdate('Y-m-d\TH:i:s\Z', time()));
52
  }
53
54
  public function findPlayQueueBookmark($userId) {
55
    return $this->mapper->findPlayQueueBookmark($userId);
56
  }
57
58
	public function create($userId, $trackId, $position, $comment) {
59
    // ensure no existing record exists
60
    $this->mapper->remove($userId, $trackId);
61
62
    $bookmark = new Bookmark();
63
    $bookmark->setUserId($userId);
64
    $bookmark->setTrackId($trackId);
65
    $bookmark->setPosition($position);
66
    $bookmark->setComment(Util::truncate($comment, 256));
67
68
		return $this->mapper->insert($bookmark);
69
	}
70
71
	public function remove($userId, $trackId) {
72
    return $this->mapper->remove($userId, $trackId);
73
	}
74
}
75