Completed
Pull Request — master (#822)
by
unknown
19:08
created

OtoLayerMapper::passwordCheck()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 2
1
<?php
2
// db/otolayermapper.php
3
4
namespace OCA\Calendar\Db;
5
6
use OCP\IDBConnection;
7
use OCP\AppFramework\Db\Mapper;
8
use OCA\Calendar\Db\OtoLayer;
9
10
class OtoLayerMapper extends Mapper {
11
12
	protected $db;
13
	
14
    public function __construct(IDBConnection $db) {
15
        parent::__construct($db, 'calendar_oto_layers','\OCA\Calendar\Db\OtoLayer');
16
		
17
		$this->db = $db;
18
    }
19
20
21
    /**
22
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
23
     * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
24
     */
25
    public function find($otoLayerId) {
26
        $sql = 'SELECT * FROM `*PREFIX*calendar_oto_layers` WHERE `oto_layer_id` = ?';
27
        return $this->findEntity($sql, [$otoLayerId]);
28
    }
29
	
30
	public function createGetId($layer){
31
		$returnLayer = $this -> insert($layer);
32
		$returnLayer->setOtoLayerId($this->db->lastInsertId());
33
		return $returnLayer;
34
	}
35
	/**
36
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
37
    */
38
    public function findUserLayers($userId) {
39
        $sql = 'SELECT * FROM `*PREFIX*calendar_oto_layers` WHERE `user_id` = ?';
40
        return $this->findEntities($sql, [$userId]);
41
    }
42
	
43 View Code Duplication
	public function passwordCheck($otoLayerId, $password){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
		$sql = 'SELECT COUNT(*) AS `count` FROM `*PREFIX*calendar_oto_layers` ' .
45
            'WHERE `oto_layer_id` = ? AND `password` = ?';
46
        $stmt = $this->execute($sql, [$otoLayerId,$password]);
47
48
        $row = $stmt->fetch();
49
        $stmt->closeCursor();
50
        if( $row['count'] > 0 ){
51
			return true;
52
		}else{
53
			return false;
54
		}
55
	}
56
	//deletes all layers where otoLayerId = $otoLayerId
57 View Code Duplication
	public function deleteLayer($otoLayerId){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
		$sql = 'DELETE FROM `*PREFIX*calendar_oto_layers` WHERE `oto_layer_id` = ?';
59
		$stmt = $this->db->prepare($sql);
60
		$stmt->bindParam(1,$otoLayerId, \PDO::PARAM_INT);
61
		$stmt -> execute();
62
	}
63
	//checks if a calendar layer is being used for scheduling
64 View Code Duplication
	public function isOtoLayer($sourceId){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
		$sql = 'SELECT COUNT(*) AS `count` FROM `*PREFIX*calendar_oto_layers` ' .
66
            'WHERE `source_id` = ?';
67
        $stmt = $this->execute($sql, [$sourceId]);
68
69
        $row = $stmt->fetch();
70
        $stmt->closeCursor();
71
        if( $row['count'] > 0 ){
72
			return true;
73
		}else{
74
			return false;
75
		}
76
	}
77
	//deletes all layers with the given sourceId
78
	public function deleteBySourceId($sourceId,$userId){
79
		$sql = 'DELETE FROM `*PREFIX*calendar_oto_layers` WHERE `source_id` = ? AND `user_id` = ?';
80
		$stmt = $this->db->prepare($sql);
81
		$stmt->bindParam(1,$sourceId);
82
		$stmt->bindParam(2,$userId);
83
		$stmt -> execute();
84
	}
85
}