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

OtoConfirmationMapper::deleteBySourceId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
// db/otoconfirmationmapper.php
3
4
namespace OCA\Calendar\Db;
5
6
use OCP\IDBConnection;
7
use OCP\AppFramework\Db\Mapper;
8
9
class OtoConfirmationMapper extends Mapper {
10
11
    public function __construct(IDBConnection $db) {
12
        parent::__construct($db, 'calendar_oto_confirmations','\OCA\Calendar\Db\OtoConfirmation');
13
    }
14
15
16
    /**
17
     * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
18
     * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
19
     */
20
    public function find($otoConfirmationId) {
21
        $sql = 'SELECT * FROM `*PREFIX*calendar_oto_confirmations` WHERE `otoConfirmationId` = ?';
22
        return $this->findEntity($sql, [$otoConfirmationId]);
23
    }
24
	
25
	public function getConfirmationsByUser($userId){
26
		$sql = 'SELECT `t1`.`oto_confirmation_id`, `t1`.`oto_layer_id`, `t1`.`name`, `t1`.`event_id`, `t2`.`source_id`, `t2`.`dest_id` FROM `*PREFIX*calendar_oto_confirmations` AS `t1` ' .
27
		'INNER JOIN `*PREFIX*calendar_oto_layers` as `t2` ON `t1`.`oto_layer_id` = `t2`.`oto_layer_id` ' .
28
		'WHERE `t2`.`user_id` = ?';
29
        return $this->findEntities($sql, [$userId]);
30
	}
31
	
32 View Code Duplication
	public function canConfirm($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...
33
		$sql = 'SELECT COUNT(*) as `count` FROM `*PREFIX*calendar_oto_confirmations` AS `t1` ' .
34
		'INNER JOIN `*PREFIX*calendar_oto_layers` as `t2` ON `t1`.`oto_layer_id` = `t2`.`oto_layer_id` ' .
35
		'WHERE `t2`.`oto_layer_id` = ?';
36
		$stmt = $this->execute($sql, [$otoLayerId]);
37
38
        $row = $stmt->fetch();
39
        $stmt->closeCursor();
40
        if( $row['count'] > 0 ){
41
			return false;
42
		}else{
43
			return true;
44
		}
45
	}
46
	//deletes all confirmations where otoLayerId = $otoLayerId
47 View Code Duplication
	public function deleteConfirmationsByOtoLayer($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...
48
		$sql = 'DELETE FROM `*PREFIX*calendar_oto_confirmations` WHERE `oto_layer_id` = ?';
49
		$stmt = $this->db->prepare($sql);
50
		$stmt->bindParam(1,$otoLayerId, \PDO::PARAM_INT);
51
		$stmt -> execute();
52
	}
53
	//deletes all confirmations with the given sourceId
54
	public function deleteBySourceId($sourceId,$userId){
55
		$sql = 'DELETE `t1` FROM `*PREFIX*calendar_oto_confirmations` AS `t1` ' .
56
		'INNER JOIN `*PREFIX*calendar_oto_layers` AS `t2` ON `t1`.`oto_layer_id` = `t2`.`oto_layer_id` ' .
57
		'WHERE `source_id` = ? AND `t2`.`user_id` = ?';
58
		$stmt = $this->db->prepare($sql);
59
		$stmt->bindParam(1,$sourceId, \PDO::PARAM_INT);
60
		$stmt->bindParam(2,$userId, \PDO::PARAM_STR);
61
		$stmt -> execute();
62
	}
63
}