Completed
Push — master ( 9d5b94...91923c )
by Seth
02:07
created

Toolbox   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getGenerator() 0 12 1
A loadConfiguration() 0 9 1
A setCustomPrefs() 0 4 1
A getCustomPrefs() 0 4 1
A customPrefs_query() 0 4 1
1
<?php
2
3
namespace smtech\CanvasHack;
4
5
use mysqli;
6
use Battis\ConfigXML;
7
use smtech\LTI\Configuration\Option;
8
9
class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox
10
{
11
    /**
12
     * Custom Preferences database
13
     * @var mysqli
14
     */
15
    protected $customPrefs;
16
17
    /**
18
     * Configure account navigation placement
19
     *
20
     * @return Generator
21
     */
22
    public function getGenerator()
23
    {
24
        parent::getGenerator();
25
26
        $this->generator->setOptionProperty(
27
            Option::ACCOUNT_NAVIGATION(),
28
            'visibility',
29
            'admins'
30
        );
31
32
        return $this->generator;
33
    }
34
35
    /**
36
     * Update a Toolbox instance from a configuration file
37
     *
38
     * @see Toolbox::fromConfiguration() Use `Toolbox::fromConfiguration()`
39
     *
40
     * @param  string $configFilePath
41
     * @param  boolean $forceRecache
42
     * @return void
43
     */
44
    protected function loadConfiguration($configFilePath, $forceRecache = false)
45
    {
46
        parent::loadConfiguration($configFilePath, $forceRecache);
47
48
        $config = new ConfigXML($configFilePath);
49
50
        /* configure database connections */
51
        $this->setCustomPrefs($config->newInstanceOf(mysqli::class, '/config/customprefs'));
52
    }
53
54
    /**
55
     * Set MySQL connection object
56
     *
57
     * @param mysqli $mysql
58
     */
59
    public function setCustomPrefs(mysqli $mysql)
60
    {
61
        $this->customPrefs = $mysql;
62
    }
63
64
    /**
65
     * Get MySQL connection object
66
     *
67
     * @return mysqli
68
     */
69
    public function getCustomPrefs()
70
    {
71
        return $this->customPrefs;
72
    }
73
74
    /**
75
     * Make a MySQL query
76
     *
77
     * @link http://php.net/manual/en/mysqli.query.php Pass-through to `mysqli::query()`
78
     * @param string $query
79
     * @param int $resultMode (Optional, defaults to `MYSQLI_STORE_RESULT`)
80
     * @return mixed
81
     */
82
    public function customPrefs_query($query, $resultMode = MYSQLI_STORE_RESULT)
83
    {
84
        return $this->getCustomPrefs()->query($query, $resultMode);
85
    }
86
}
87