Skip to content

Commit 33cca0f

Browse files
committed
Merge pull request #666 from LearningLocker/develop
v1.5.2
2 parents 4cbfb20 + 7647bff commit 33cca0f

File tree

215 files changed

+73458
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+73458
-76
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ Thumbs.db
77
/app/config/ht2
88
/app/config/production
99
/app/config/staging
10-
11-
/public/assets/js/bower_components

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ services:
77
- mongodb
88

99
install:
10-
- npm install -g bower
11-
- composer install --no-interaction --dev
10+
- php -r "readfile('https://getcomposer.org/installer');" | php
11+
- php composer.phar install --no-interaction --dev
1212

1313
before_script:
1414
- phpenv config-add travisconfig.ini

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.1
1+
1.5.2

app/locker/repository/Statement/EloquentRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ public function store(array $statements, array $attachments, array $opts) {
3939
public function index(array $opts) {
4040
$opts = new IndexOptions($opts);
4141
$builder = $this->indexer->index($opts);
42+
$count = $this->indexer->count($builder, $opts);
4243
return [
4344
$this->indexer->format($builder, $opts),
44-
$this->indexer->count($builder, $opts),
45+
$count,
4546
$opts->options
4647
];
4748
}

app/models/Report.php

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,47 @@ class Report extends Eloquent {
1313
public static $rules = [];
1414
protected $fillable = ['name', 'description', 'query', 'lrs', 'since', 'until'];
1515
protected $actorQuery = [ 'statement.actor.account', 'statement.actor.mbox', 'statement.actor.openid', 'statement.actor.mbox_sha1sum' ];
16-
17-
public function getFilterAttribute() {
18-
$reportArr = $this->toArray();
19-
$filter = [];
20-
21-
if (isset($reportArr['query'])) $filter['filter'] = json_encode($reportArr['query']);
22-
if (isset($reportArr['since'])) {
23-
$filter['since'] = (new \Carbon\Carbon($reportArr['since']))->toIso8601String();
24-
}
25-
if (isset($reportArr['until'])) {
26-
$filter['until'] = (new \Carbon\Carbon($reportArr['until']))->toIso8601String();
16+
protected $instructorQuery = [
17+
'statement.context.instructor.account',
18+
'statement.context.instructor.mbox',
19+
'statement.context.instructor.openid',
20+
'statement.context.instructor.mbox_sha1sum'
21+
];
22+
23+
private function constructOr($key, $value) {
24+
$query = [];
25+
foreach ($value as $actor_id) {
26+
if (is_object($actor_id)) {
27+
$object_vars = get_object_vars($actor_id);
28+
$filter = [];
29+
foreach ($object_vars as $var_key => $var_val) {
30+
$filter[$key.'.'.$var_key] = $var_val;
31+
}
32+
return $filter;
33+
} else {
34+
return [$key => $actor_id];
35+
}
2736
}
37+
return $query;
38+
}
2839

29-
return $filter;
40+
private function constructDate($date) {
41+
return (new \Carbon\Carbon($date))->toIso8601String();
3042
}
3143

3244
public function getMatchAttribute() {
3345
$reportArr = $this->toArray();
3446
$match = [];
47+
$actorMatch = [];
48+
$instructorMatch = [];
3549
$query = isset($reportArr['query']) ? (array) $reportArr['query'] : null;
3650

3751
if (is_array($query) && count($query) > 0 && !isset($query[0])) {
3852
foreach ($query as $key => $value) {
3953
if (in_array($key, $this->actorQuery)) {
40-
foreach ($value as $actor_id) {
41-
if (is_object($actor_id)) {
42-
$object_vars = get_object_vars($actor_id);
43-
$filter = [];
44-
foreach ($object_vars as $var_key => $var_val) {
45-
$filter[$key.'.'.$var_key] = $var_val;
46-
}
47-
$match['$or'][] = $filter;
48-
} else {
49-
$match['$or'][][$key] = $actor_id;
50-
}
51-
}
54+
$actorMatch['$or'][] = $this->constructOr($key, $value);
55+
} else if (in_array($key, $this->instructorQuery)) {
56+
$instructorMatch['$or'][] = $this->constructOr($key, $value);
5257
} else {
5358
if (is_array($value)) {
5459
$match[$key] = ['$in' => $value];
@@ -59,8 +64,8 @@ public function getMatchAttribute() {
5964
}
6065
}
6166

62-
$since = isset($reportArr['since']) ? (new \Carbon\Carbon($reportArr['since']))->toIso8601String() : null;
63-
$until = isset($reportArr['until']) ? (new \Carbon\Carbon($reportArr['until']))->toIso8601String() : null;
67+
$since = isset($reportArr['since']) ? $this->constructDate($reportArr['since']) : null;
68+
$until = isset($reportArr['until']) ? $this->constructDate($reportArr['until']) : null;
6469

6570
if ($since || $until) {
6671
$match['statement.timestamp'] = [];
@@ -71,20 +76,28 @@ public function getMatchAttribute() {
7176
if ($until) {
7277
$match['statement.timestamp']['$lte'] = $until;
7378
}
79+
$andMatch = ['$and' => []];
80+
if (!empty($actorMatch)) $andMatch['$and'][] = $actorMatch;
81+
if (!empty($instructorMatch)) $andMatch['$and'][] = $instructorMatch;
82+
if (!empty($match)) $andMatch['$and'][] = $match;
83+
//echo(json_encode($andMatch));die;
7484

75-
return $match;
85+
return $andMatch;
7686
}
7787

7888
public function getWhereAttribute() {
7989
$reportArr = $this->toArray();
8090
$wheres = [];
8191
$query = isset($reportArr['query']) ? (array) $reportArr['query'] : null;
8292
$actorArray = [];
93+
$instructorArray = [];
8394

8495
if (is_array($query) && count($query) > 0 && !isset($query[0])) {
8596
foreach (array_keys($query) as $key) {
8697
if (in_array($key, $this->actorQuery)) {
8798
array_push($actorArray, [$key, $query[$key]]);
99+
} else if (in_array($key, $this->instructorQuery)) {
100+
array_push($instructorArray, [$key, $query[$key]]);
88101
} else {
89102
if (is_array($query[$key])) {
90103
array_push($wheres, [$key, 'in', $query[$key]]);
@@ -94,10 +107,11 @@ public function getWhereAttribute() {
94107
}
95108
}
96109
array_push($wheres, ['orArray', 'or', $actorArray]);
110+
array_push($wheres, ['orArray', 'or', $instructorArray]);
97111
}
98112

99-
$since = isset($reportArr['since']) ? (new \Carbon\Carbon($reportArr['since']))->toIso8601String() : null;
100-
$until = isset($reportArr['until']) ? (new \Carbon\Carbon($reportArr['until']))->toIso8601String() : null;
113+
$since = isset($reportArr['since']) ? $this->constructDate($reportArr['since']) : null;
114+
$until = isset($reportArr['until']) ? $this->constructDate($reportArr['until']) : null;
101115

102116
if ($since && $until) {
103117
$wheres[] = ['statement.timestamp', 'between', $since, $until];

composer.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,26 @@
6666
},
6767
"scripts": {
6868
"post-install-cmd": [
69-
"php artisan optimize",
70-
"php artisan js-localization:refresh",
71-
"cd public/assets/js && bower --allow-root update && cd ../../.."
69+
"php composer.phar refresh"
7270
],
7371
"post-update-cmd": [
7472
"php artisan clear-compiled",
75-
"php artisan optimize",
76-
"php artisan js-localization:refresh",
77-
"cd public/assets/js && bower --allow-root update && cd ../../.."
73+
"php composer.phar refresh"
7874
],
7975
"post-create-project-cmd": [
8076
"php artisan key:generate"
77+
],
78+
"refresh": [
79+
"php artisan optimize",
80+
"php artisan js-localization:refresh",
81+
"php composer.phar clean-bower"
82+
],
83+
"clean-bower": [
84+
"find public/assets/js/bower_components/ -type f -name '*.md' | xargs rm -f",
85+
"find public/assets/js/bower_components/ -type d -name 'docs' | xargs rm -rf",
86+
"find public/assets/js/bower_components/ -type d -name 'spec' | xargs rm -rf",
87+
"find public/assets/js/bower_components/ -type d -name 'test' | xargs rm -rf",
88+
"find public/assets/js/bower_components/ -type f -not \\( -name '*.css' -o -name '*.js' \\) | xargs rm -rf"
8189
]
8290
},
8391
"minimum-stability": "stable"

0 commit comments

Comments
 (0)