H5pEvent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 8
c 1
b 1
f 0
dl 0
loc 38
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 9 1
A saveStats() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
/*
4
 *
5
 * @Project        Expression project.displayName is undefined on line 5, column 35 in Templates/Licenses/license-default.txt.
6
 * @Copyright      Djoudi
7
 * @Created        2018-02-21
8
 * @Filename       H5PEvent.php
9
 * @Description
10
 *
11
 */
12
13
namespace Djoudi\LaravelH5p\Events;
14
15
use Djoudi\LaravelH5p\Eloquents\H5pEventLog;
16
use H5PEventBase;
17
use Illuminate\Support\Facades\Auth;
18
19
//use Illuminate\Contracts\Events;
20
21
class H5pEvent extends H5PEventBase
22
{
23
    private $user;
24
25
    /**
26
     * Adds event type, h5p library and timestamp to event before saving it.
27
     *
28
     * @param string $type
29
     *                        Name of event to log
30
     * @param string $library
31
     *                        Name of H5P library affacted
32
     */
33
    public function __construct($type, $sub_type = null, $content_id = null, $content_title = null, $library_name = null, $library_version = null)
34
    {
35
        $this->user = Auth::id();
36
        parent::__construct($type, $sub_type, $content_id, $content_title, $library_name, $library_version);
37
    }
38
39
    /**
40
     * Store the event.
41
     */
42
    protected function save()
43
    {
44
45
                // Get data in array format without NULL values
46
        $data = $this->getDataArray();
47
        $data['user_id'] = Auth::id();
48
49
        // Insert into DB
50
        return H5pEventLog::create($data);
51
    }
52
53
    /**
54
     * Count number of events.
55
     */
56
    protected function saveStats()
57
    {
58
        return true;
59
60
//        $type = $this->type . ' ' . $this->sub_type;
61
                //        $current_num = $wpdb->get_var($wpdb->prepare(
62
                //                        "SELECT num
63
                //           FROM h5p_counters
64
                //          WHERE type = '%s'
65
                //            AND library_name = '%s'
66
                //            AND library_version = '%s'
67
                //        ", $type, $this->library_name, $this->library_version));
68
                //
69
                //
70
                //        if ($current_num === NULL) {
71
                //            // Insert
72
                //            $wpdb->insert("h5p_counters", array(
73
                //                'type' => $type,
74
                //                'library_name' => $this->library_name,
75
                //                'library_version' => $this->library_version,
76
                //                'num' => 1
77
                //                    ), array('%s', '%s', '%s', '%d'));
78
                //        } else {
79
                //            // Update num+1
80
                //            $wpdb->query($wpdb->prepare(
81
                //                            "UPDATE h5p_counters
82
                //              SET num = num + 1
83
                //            WHERE type = '%s'
84
                //              AND library_name = '%s'
85
                //              AND library_version = '%s'
86
                //                      ", $type, $this->library_name, $this->library_version));
87
                //        }
88
                //
89
    }
90
}
91