-
Notifications
You must be signed in to change notification settings - Fork 2
/
renderer.php
1270 lines (981 loc) · 33.8 KB
/
renderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Moodec Renderer
*
* @package local_moodec
* @copyright 2015 Thomas Threadgold <tj.threadgold@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Moodec Renderer
*
* @copyright 2015 Thomas Threadgold <tj.threadgold@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_moodec_renderer extends plugin_renderer_base {
function catalogue($products) {
$html = '';
if (is_array($products) && 0 < count($products)) {
// OPEN PRODUCT LIST
$html .= sprintf('<div class="product-list">');
foreach ($products as $product) {
$html .= $this->catalogue_item($product);
}
// CLOSE PRODUCT LIST
$html .= sprintf('</div>');
} else {
$html .= sprintf(
'<div class="catalogue-empty">%s</div>',
get_string(
'catalogue_empty',
'local_moodec'
)
);
}
return $html;
}
function catalogue_item($product) {
global $CFG;
// Require Moodec lib
require_once $CFG->dirroot . '/local/moodec/lib.php';
// OPEN PRODUCT ITEM
$html = sprintf('<div class="product-item">');
// OPEN PRODUCT DETAILS
$html .= sprintf('<div class="product-details">');
// output product image
if (!!get_config('local_moodec', 'page_catalogue_show_image')) {
$html .= $this->product_image($product);
}
// OPEN PRODUCT DETAILS WRAPPER
$html .= sprintf('<div class="product-details__wrapper">');
// output page title
$html .= $this->product_title($product);
//output course summary
if (!!get_config('local_moodec', 'page_catalogue_show_description')) {
$html .= sprintf(
'<div class="product-summary">%s</div>',
$product->get_summary()
);
}
// output product description
if (!!get_config('local_moodec', 'page_catalogue_show_additional_description')) {
$html .= sprintf(
'<div class="product-summary additional">%s</div>',
$product->get_description()
);
}
// output product duration
if(!!get_config('local_moodec', 'page_catalogue_show_duration')) {
$html .= $this->product_duration($product);
}
// output product category
if (!!get_config('local_moodec', 'page_catalogue_show_category')) {
$html .= $this->product_category($product);
}
// CLOSE PRODUCT DETAILS WRAPPER
$html .= sprintf('</div>');
// CLOSE PRODUCT DETAILS
$html .= sprintf('</div>');
// OPEN PRODUCT ACTIONS
$html .= sprintf('<div class="product-actions">');
//output price
if (!!get_config('local_moodec', 'page_catalogue_show_price')) {
if($product->get_type() === PRODUCT_TYPE_SIMPLE) {
$html .= sprintf(
'<h4 class="product-price">%s</h4>',
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')) . $product->get_price()
);
} else {
$attr = '';
foreach ($product->get_variations() as $v) {
$attr .= sprintf('data-tier-%d="%.2f" ', $v->get_id(), $v->get_price());
}
list($firstVariation) = array_values($product->get_variations());
$html .= sprintf('<h4 class="product-price" %s>%s<span class="amount">%.2f</span></h4>',
$attr,
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$firstVariation->get_price()
);
}
}
// output button
if (!!get_config('local_moodec', 'page_catalogue_show_button')) {
$html .= $this->product_button($product);
}
// CLOSE PRODUCT ACTIONS
$html .= sprintf('</div>');
// CLOSE PRODUCT ITEM
$html .= sprintf('</div>');
return $html;
}
/**
* Outputs the information for the single product page
* @param product $product object containing all the product information
* @return string the html output
*/
function single_product($product) {
global $CFG, $DB;
// Require Moodec lib
require_once $CFG->dirroot . '/local/moodec/lib.php';
$cart = new MoodecCart();
// Product single wrapper
$html = '<div class="product-single">';
// Product title
$html .= sprintf(
'<h1 class="product__title">%s</h1>',
get_string('product_title', 'local_moodec', array('coursename' => $product->get_fullname()) )
);
// Product/course image
if (!!get_config('local_moodec', 'page_product_show_image')) {
$html .= $this->product_image($product);
}
// Product details wrapper
$html .= '<div class="product-details">';
// Product description
if (!!get_config('local_moodec', 'page_product_show_description')) {
$description = $product->get_summary();
if( 0 < strlen($description) ) {
$html .= sprintf(
'<div class="product-description">%s</div>',
$description
);
}
}
// Product additional description
if (!!get_config('local_moodec', 'page_product_show_additional_description')) {
if( $product->has_description() ) {
$html .= sprintf(
'<div class="additional-info">%s</div>',
$product->get_description()
);
}
}
// Additional product details wrapper
$html .= '<div class="product-details__additional">';
// Product duration
$html .= '<div class="product-duration__wrapper">';
$html .= sprintf(
'<span class="product-duration__label">%s</span>',
get_string('enrolment_duration_label', 'local_moodec')
);
if( $product->get_type() === PRODUCT_TYPE_SIMPLE) {
$html .= sprintf(
'<span class="product-duration">%s</span>',
$product->get_duration()
);
} else {
$attr = '';
foreach ($product->get_variations() as $v) {
$attr .= sprintf('data-tier-%d="%s" ',
$v->get_id(),
$v->get_duration()
);
}
list($firstVariation) = array_values($product->get_variations());
$html .= sprintf(
'<span class="product-duration" %s>%s</span>',
$attr,
$firstVariation->get_duration()
);
}
$html .= '</div>';
// Product category
if (!!get_config('local_moodec', 'page_product_show_category')) {
// Get the category the product belongs to
$category = $DB->get_record(
'course_categories',
array(
'id' => $product->get_category_id()
)
);
// Get the url to link to the category page with the filter active
$categoryURL = new moodle_url(
$CFG->wwwroot . '/local/moodec/pages/catalogue.php',
array(
'category' => $product->get_category_id()
)
);
// Category wrapper
$html .= '<div class="product-category__wrapper">';
// Category label
$html .= sprintf(
'<span class="product-category__label">%s</span> ',
get_string('course_list_category_label', 'local_moodec')
);
// Category link
$html .= sprintf(
'<a class="product-category__link" href="%s">%s</a>',
$categoryURL,
$category->name
);
$html .= '</div>';
}
// Product Price
if($product->get_type() === PRODUCT_TYPE_SIMPLE) {
$html .= '<div class="product-price">';
// Price label
$html .= sprintf(
'<span class="product-price__label">%s</span>',
get_string('price_label', 'local_moodec')
);
// Price
$html .= sprintf(
'<span class="product-price__value">%s<span class="amount">%.2f</span></span>',
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$product->get_price()
);
$html .= '</div>';
} else {
$attr = '';
foreach ($product->get_variations() as $v) {
$attr .= sprintf('data-tier-%d="%.2f" ', $v->get_id(), $v->get_price() );
}
list($firstVariation) = array_values($product->get_variations());
$html .= sprintf(
'<div class="product-price" %s><span class="product-price__label">%s</span> <span class="product-price__value">%s<span class="amount">%.2f</span></span></div>',
$attr,
get_string('price_label', 'local_moodec'),
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$firstVariation->get_price()
);
}
// Add to cart button states
if (isloggedin() && is_enrolled(context_course::instance($product->get_course_id(), MUST_EXIST))) {
// Display 'enrolled' button
$html .= sprintf(
'<div class="product-single__form">
<button class="product-form__add button--enrolled" disabled="disabled">%s</button>
</div>',
get_string('button_enrolled_label', 'local_moodec')
);
} else if ( $cart->check($product->get_id()) ) {
// Display 'in cart' button
$html .= sprintf(
'<div class="product-single__form">
<a href="%s" class="product-form__add btn button--cart">%s</a>
</div>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'),
get_string('button_in_cart_label', 'local_moodec')
);
} else {
// Check whether this is a simple or variable product
if($product->get_type() === PRODUCT_TYPE_SIMPLE) {
// Display simple product 'add to cart' form
$html .= sprintf(
'<form action="%s" method="POST" class="product-single__form">
<input type="hidden" name="action" value="addToCart">
<input type="hidden" name="id" value="%d">
<input type="submit" class="product-form__add" value="%s">
</form>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'),
$product->get_id(),
get_string('button_add_label', 'local_moodec')
);
} else {
// Variable product selection 'add to cart' form
$html .= sprintf(
'<form action="%s" method="POST" class="product-single__form">
<input type="hidden" name="action" value="addVariationToCart">
<select class="product-tier" name="variation">',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')
);
// output variations
foreach($product->get_variations() as $variation) {
$html .= sprintf(
'<option value="%d">%s</option>',
$variation->get_id(),
$variation->get_name()
);
}
// output rest of the form
$html .= sprintf(
' </select>
<input type="hidden" name="id" value="%d">
<input type="submit" class="product-form__add" value="%s">
</form>',
$product->get_id(),
get_string('button_add_label', 'local_moodec')
);
}
}
// close additional product details wrapper
$html .= '</div>';
// close product details wrapper
$html .= '</div>';
// close product single wrapper
$html .= '</div>';
return $html;
}
/**
* Outputs the HTML to display related products given a product
* @param product $product the product for which to find the related ones
* @return string the HTML output
*/
function related_products($product) {
global $CFG;
// Require Moodec lib
require_once $CFG->dirroot . '/local/moodec/lib.php';
$html = '';
$iterator = 0;
// Get products related to the product passed to us
$products = $product->get_related();
// We only output anything if there ARE related products
if (is_array($products) && 0 < count($products)) {
// Output section wrapper
$html .= '<div class="related-products">';
// Show the section title
$html .= sprintf(
'<h2 class="related-products__title">%s</h2>',
get_string('product_related_label', 'local_moodec')
);
// Output container to hold product items
$html .= '<ul class="grid-container">';
foreach ($products as $p) {
$html .= '<li class="grid-item">';
// Product image
$html .= $this->product_image($p);
// Product title
$html .= sprintf(
'<h5>%s</h5>',
$p->get_fullname()
);
// Product link
$html .= sprintf(
'<a href="%s" class="product-view btn">%s</a>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/product.php', array('id' => $p->get_id()) ),
get_string('product_related_button_label', 'local_moodec')
);
$html .= '</li>';
// Iterator limits only 3 products to be shown
$iterator++;
if ($iterator > 2) {
break;
}
}
// Close item container
$html .= '</ul>';
// Close section wrapper
$html .= '</div>';
}
return $html;
}
/**
* Returns the HTML for the product image
* @param product $product the product for the image to be retrieved
* @return string the HTML output
*/
function product_image($product) {
global $CFG;
// Require Moodec lib
require_once $CFG->dirroot . '/local/moodec/lib.php';
$html = '';
$imageURL = $product->get_image_url();
if ( !!$imageURL ) {
$html = sprintf(
'<img src="%s" alt="%s" class="product-image">',
$imageURL,
$product->get_fullname()
);
}
return $html;
}
function product_title($product) {
global $CFG;
$html = sprintf('<h3 class="product-title">');
if (!!get_config('local_moodec', 'page_product_enable')) {
$html .= sprintf(
'<a href="%s">%s</a>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/product.php', array('id' => $product->get_id())),
$product->get_fullname()
);
} else {
$html .= $product->get_fullname();
}
$html .= sprintf('</h3>');
return $html;
}
function product_duration($product) {
// Product duration
$html = '<div class="product-duration__wrapper">';
// Product duration label
$html .= sprintf(
'<span class="product-duration__label">%s</span> ',
get_string('catalogue_enrolment_duration_label', 'local_moodec')
);
if( $product->get_type() === PRODUCT_TYPE_SIMPLE) {
$html .= sprintf(
'<span class="product-duration">%s</span>',
$product->get_duration()
);
} else {
$attr = '';
foreach ($product->get_variations() as $v) {
$attr .= sprintf(
'data-tier-%d="%s" ',
$v->get_id(),
$v->get_duration()
);
}
list($firstVariation) = array_values($product->get_variations());
$html .= sprintf(
'<span class="product-duration" %s>%s</span>',
$attr,
$firstVariation->get_duration()
);
}
// Product duration wrapper close
$html .= sprintf('</div>');
return $html;
}
function product_category($product) {
global $CFG, $DB;
// Get the category the product belongs to
$category = $DB->get_record(
'course_categories',
array(
'id' => $product->get_category_id()
)
);
// Get the url to link to the category page with the filter active
$categoryURL = new moodle_url(
$CFG->wwwroot . '/local/moodec/pages/catalogue.php',
array(
'category' => $product->get_category_id()
)
);
// Category wrapper
$html = '<div class="product-category__wrapper">';
// Category label
$html .= sprintf(
'<span class="product-category__label">%s</span> ',
get_string('course_list_category_label', 'local_moodec')
);
// Category link
$html .= sprintf(
'<a class="product-category__link" href="%s">%s</a>',
$categoryURL,
$category->name
);
$html .= '</div>';
return $html;
}
function product_button($product) {
global $CFG;
$cart = new MoodecCart();
if (isloggedin() && is_enrolled(context_course::instance($product->get_course_id(), MUST_EXIST))) {
$html = sprintf(
'<div class="product-form"><button class="product-form__add button--enrolled" disabled="disabled">%s</button></div>',
get_string('button_enrolled_label', 'local_moodec')
);
} else if( $cart->check($product->get_id()) ){
// Display 'in cart' button
$html = sprintf(
'<div class="product-single__form">
<a href="%s" class="product-form__add btn button--cart">%s</a>
</div>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'),
get_string('button_in_cart_label', 'local_moodec')
);
} else {
// Check whether this is a simple or variable product
if($product->get_type() === PRODUCT_TYPE_SIMPLE) {
// Display simple product 'add to cart' form
$html = sprintf(
'<form action="%s" method="POST" class="product-form">
<input type="hidden" name="action" value="addToCart">
<input type="hidden" name="id" value="%d">
<input type="submit" class="product-form__add" value="%s">
</form>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php'),
$product->get_id(),
get_string('button_add_label', 'local_moodec')
);
} else {
// Variable product selection 'add to cart' form
$html = sprintf(
'<form action="%s" method="POST" class="product-form">
<input type="hidden" name="action" value="addVariationToCart">
<select class="product-tier" name="variation">',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/cart.php')
);
// output variations
foreach($product->get_variations() as $variation) {
$html .= sprintf(
'<option value="%d">%s</option>',
$variation->get_id(),
$variation->get_name()
);
}
// output rest of the form
$html .= sprintf(
' </select>
<input type="hidden" name="id" value="%d">
<input type="submit" class="product-form__add" value="%s">
</form>',
$product->get_id(),
get_string('button_add_label', 'local_moodec')
);
}
}
return $html;
}
/**
* Outputs the HTML for the pagination
* @param array $products An array of the products to be paginated
* @param integer $currentPage The index of the current page
* @param int $category the category ID
* @param string $sort the string sorting parameter
* @return string the HTML output
*/
function pagination($products, $currentPage = 0, $category = null, $sort = null) {
global $CFG;
$html = '';
// Calculate total page count
$pageCount = ceil(count($products) / get_config('local_moodec', 'pagination'));
// Only output pagination when there is more than one page
if (1 < $pageCount && $currentPage <= $pageCount ) {
$html .= sprintf('<div class="pagination-bar"><ul class="pagination">');
$params = array();
if ($sort !== null) {
$params['sort'] = $sort;
}
if ($category !== null && !!$category ) {
$params['category'] = $category;
}
for ($paginator = 1; $paginator <= $pageCount; $paginator++) {
$params['page'] = $paginator;
$html .= sprintf('<li class="page-item"><a href="%s" %s>%d</a></li>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/catalogue.php', $params),
$paginator === $currentPage ? 'class="active"' : '',
$paginator
);
}
$html .= sprintf('</ul></div>');
}
return $html;
}
/**
* Returns the HTML for the Moodec cart
* @param array cart
* @param bool is it the checkout page
* @return string the HTML output
*/
function moodec_cart($cart) {
global $CFG, $USER;
// Require Moodec lib
require_once $CFG->dirroot . '/local/moodec/lib.php';
// Initialise vars
$html = '';
$html .= '<div class="cart-overview">';
if ( $cart->is_empty() === false ) {
$html .= '<ul class="products">';
// Go through each product in the cart
foreach ($cart->get() as $pID => $vID) {
$product = local_moodec_get_product($pID);
$html .= '<li class="product-item">';
// Product title and variation
$html .= sprintf(
'<h4 class="product-title"><a href="%s">%s</a></h4>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/product.php', array( 'id' => $product->get_id() )),
$product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_fullname() : $product->get_fullname() . ' - ' . $product->get_variation($vID)->get_name()
);
// Product price
$html .= sprintf(
'<div class="product-price">%s%.02f</div>',
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_price() : $product->get_variation($vID)->get_price()
);
// 'Remove' from cart button
$html .= sprintf(
'<form class="product__form" action="" method="POST">
<input type="hidden" name="id" value="%d">
<input type="hidden" name="action" value="removeFromCart">
<input class="form__submit" type="submit" value="%s">
</form>',
$product->get_id(),
get_string('button_remove_label', 'local_moodec')
);
$html .= '</li>';
}
$html .= '</ul>';
// Output cart summary section
$html .= '<div class="cart-summary">';
// Cart total price
$html .= sprintf(
'<h3 class="cart-total__label">%s</h3><h3 class="cart-total">%s%01.2f</h3>',
get_string('cart_total', 'local_moodec'),
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$cart->get_total(false)
);
$html .= '</div>';
// Get the cart action HTML
$html .= $this->cart_actions();
} else {
// Empty cart message
$html .= sprintf(
'<p class="cart-mesage--empty">%s</p>',
get_string('cart_empty_message', 'local_moodec')
);
// Return to store button
$html .= $this->return_to_store_action();
}
$html .= '</div>';
return $html;
}
/**
* Returns the HTML for the Moodec cart review on the checkout page
* @param array cart
* @param bool is it the checkout page
* @return string the HTML output
*/
function cart_review($cart, $removedProducts = array()) {
global $CFG, $USER;
// Require Moodec lib
require_once $CFG->dirroot . '/local/moodec/lib.php';
// OPEN cart-overview
$html = '<div class="cart-overview">';
// Output cart review message
$html .= sprintf(
'<p class="cart-review__message">%s</p>',
get_string('checkout_message', 'local_moodec')
);
if (!!$removedProducts && is_array($removedProducts)) {
$html .= '<div class="cart-review__wrapper">';
$html .= sprintf(
'<p class="cart-review__message--removed">%s</p>',
get_string('checkout_removed_courses_label', 'local_moodec')
);
$html .= '<ul>';
foreach ($removedProducts as $p) {
$thisProduct = local_moodec_get_product($p);
$html .= sprintf(
'<li class="cart-review__item--removed">%s</li>',
$thisProduct->get_fullname()
);
}
$html .= '</ul></div>';
}
if ( $cart->is_empty() === false ) {
$html .= '<ul class="products">';
// Go through each product in the cart
foreach ($cart->get() as $pID => $vID) {
$product = local_moodec_get_product($pID);
$html .= '<li class="product-item">';
// Product title and variation
$html .= sprintf(
'<h4 class="product-title"><a href="%s">%s</a></h4>',
new moodle_url($CFG->wwwroot . '/local/moodec/pages/product.php', array( 'id' => $product->get_id() )),
$product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_fullname() : $product->get_fullname() . ' - ' . $product->get_variation($vID)->get_name()
);
// Product price
$html .= sprintf(
'<div class="product-price">%s%.02f</div>',
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$product->get_type() === PRODUCT_TYPE_SIMPLE ? $product->get_price() : $product->get_variation($vID)->get_price()
);
$html .= '</li>';
}
$html .= '</ul>';
// Output cart summary section
$html .= '<div class="cart-summary">';
// Cart total price
$html .= sprintf(
'<h3 class="cart-total__label">%s</h3><h3 class="cart-total">%s%01.2f</h3>',
get_string('cart_total', 'local_moodec'),
local_moodec_get_currency_symbol(get_config('local_moodec', 'currency')),
$cart->get_total(false)
);
$html .= '</div>';
// Return to store button
$html .= $this->return_to_store_action();
// Render all active Gateway options
if( !!get_config('local_moodec', 'payment_dps_enable') ){
$gatewayDPS = new MoodecGatewayDPS($cart->get_transaction_id());
$html .= $gatewayDPS->render();
}
if( !!get_config('local_moodec', 'payment_paypal_enable') ){
$gatewayPaypal = new MoodecGatewayPaypal($cart->get_transaction_id());
$html .= $gatewayPaypal->render();
}
} else {
// Empty cart message
$html .= sprintf(
'<p class="cart-mesage--empty">%s</p>',
get_string('cart_empty_message', 'local_moodec')
);
// Return to store button
$html .= $this->return_to_store_action();
}
// CLOSE cart-overview
$html .= '</div>';
return $html;
}
/**
* Returns the HTML output for the catalogue page filter bar
* @param int $c The catalogue ID
* @param string $s The sorting string
* @return string HTML
*/
function filter_bar($c = null, $s= null) {
$filters = array(
'default-asc',
'fullname-asc',
'fullname-desc',
'price-asc',
'price-desc',
'duration-asc',
'duration-desc',
);
// open form wrapper
$html = '<form action="" method="GET" class="filter-bar">';
// Render category filter
$html .= sprintf(
'<div class="filter__category">
<span>%s</span>
<select name="category" id="category">
%s
</select>
</div>',
get_string('filter_category_label', 'local_moodec'),
local_moodec_get_category_list($c)
);
// Render sorting filter
$html .= sprintf(
'<div class="filter__sort">
<span>%s</span>
<select name="sort" id="sort">',
get_string('filter_sort_label', 'local_moodec')
);
// Output all options for filters
foreach ($filters as $f) {
// Category option
$html .= sprintf(
'<option value="%s" %s>%s</option>',
$f,
$s === $f ? 'selected="selected"' : '',
get_string('filter_sort_' . str_replace('-', '_', $f), 'local_moodec')
);