-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbim-information-levels.php
1337 lines (1275 loc) · 53.1 KB
/
bim-information-levels.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
/*
Plugin Name: BIM Information Levels
Plugin URI:
Description:
Version: 1.0
Author: Bastiaan Grutters
Author URI: http://www.bastiaangrutters.nl
*/
/*
* Usage: Place shortcodes in pages:
* [showBIMInformationLevels]
* [showBIMInformationLevelsProperties]
* [showBIMInformationLevelsByLevel]
* [showBIMInformationLevelsLevels]
* [showBIMInformationLevelsReport]
*/
class BIMInformationLevels {
private $options;
public function __construct() {
register_activation_hook( __FILE__, Array( 'BIMInformationLevels', 'install' ) );
register_deactivation_hook( __FILE__, Array( 'BIMInformationLevels', 'uninstall' ) );
add_action( 'admin_menu', Array( 'BIMInformationLevels', 'optionsMenu' ) );
$this->options = get_option( 'bim_information_levels_options', Array() );
if( isset( $this->options[ 'bim_property_post_type' ] ) && isset( $this->options[ 'bim_object_post_type' ] ) ) {
add_action( 'admin_init', Array( 'BIMInformationLevels', 'editorInit' ) );
}
add_action( 'admin_enqueue_scripts', Array( 'BIMInformationLevels', 'adminEnqueueScripts' ) );
add_action( 'wp_enqueue_scripts', Array( 'BIMInformationLevels', 'wpEnqueueScripts' ) );
add_action( 'delete_post', Array( 'BIMInformationLevels', 'deletePost' ) );
// Add post types etc at the WordPress init action
add_action( 'init', Array( 'BIMInformationLevels', 'wordPressInit' ) );
// --- Add shortcodes ---
add_shortcode( 'showBIMInformationLevels', Array( 'BIMInformationLevels', 'showBIMInformationLevels' ) );
add_shortcode( 'showBIMInformationLevelsProperties', Array( 'BIMInformationLevels', 'showBIMInformationLevelsProperties' ) );
add_shortcode( 'showBIMInformationLevelsByLevel', Array( 'BIMInformationLevels', 'showBIMInformationLevelsByLevel' ) );
add_shortcode( 'showBIMInformationLevelsLevels', Array( 'BIMInformationLevels', 'showBIMInformationLevelsLevels' ) );
add_shortcode( 'showBIMInformationLevelsReport', Array( 'BIMInformationLevels', 'showBIMInformationLevelsReport' ) );
// Add filters for search
add_filter( 'the_title', Array( 'BIMInformationLevels', 'theTitleSearch' ), 10, 2 );
add_filter( 'the_permalink', Array( 'BIMInformationLevels', 'thePermalinkSearch' ) );
add_filter( 'the_excerpt', Array( 'BIMInformationLevels', 'theExcerptSearch' ) );
add_filter( 'comments_open', Array( 'BIMInformationLevels', 'commentsOpen' ), 999, 2 );
}
public static function optionsMenu() {
$pfile = basename( dirname( __FILE__ ) ) . '/bim-information-levels-options.php';
add_options_page( __( 'BIM Information Levels Options', 'bim-information-levels' ), __( 'BIM Information Levels Options', 'bim-information-levels' ), 'activate_plugins', $pfile );
}
public static function adminEnqueueScripts() {
wp_enqueue_script( 'jquery' );
//wp_enqueue_script( 'bim-information-levels-admin', plugins_url( 'bim-information-levels-admin.js', __FILE__ ), Array( 'jquery' ), "1.0", true );
}
public static function wpEnqueueScripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-cookie', plugins_url( 'jquery.cookie.js', __FILE__ ), Array( 'jquery' ), "1.0", true );
wp_enqueue_script( 'bim-information-levels', plugins_url( 'bim-information-levels.js', __FILE__ ), Array( 'jquery', 'jquery-cookie' ), "1.0", true );
wp_enqueue_style( 'bim-information-levels', plugins_url( 'bim-information-levels.css', __FILE__ ) );
}
public static function editorInit() {
$options = BIMInformationLevels::getOptions();
add_meta_box( 'bim-information-levels-meta', __( 'Information Level Options', 'bim-information-levels' ), Array( 'BIMInformationLevels', 'editorWidget' ), $options[ 'bim_object_post_type' ], 'normal', 'high' );
add_meta_box( 'bim-information-levels-meta', __( 'Information Level Options', 'bim-information-levels' ), Array( 'BIMInformationLevels', 'editorWidget' ), $options[ 'bim_property_post_type' ], 'normal', 'high' );
add_action( 'save_post', Array( 'BIMInformationLevels', 'saveEditorWidget' ) );
}
public static function getOptions( $forceReload = false ) {
global $bimInformationLevels;
if( $forceReload ) {
$bimInformationLevels->options = get_option( 'bim_information_levels_options', Array() );
}
return $bimInformationLevels->options;
}
public static function wordPressInit() {
$options = BIMInformationLevels::getOptions();
// Change rewrite rules
if( isset( $options[ 'information_levels_uri' ] ) && $options[ 'information_levels_uri' ] != '' ) {
if( substr( $options[ 'information_levels_uri' ], 0, 1 ) == '/' ) {
$uri = substr( $options[ 'information_levels_uri' ], 1 );
} else {
$uri = $options[ 'information_levels_uri' ];
}
add_rewrite_tag( '%bim_object%', '([^&]+)' );
add_rewrite_tag( '%bim_category_id%', '([^&]+)' );
add_rewrite_rule( '^' . $uri . '([^/]*)/([^/]*)/?', 'index.php?page_id=' . $options[ 'information_levels_page' ] . '&bim_object=$matches[1]&bim_category_id=$matches[2]', 'top' );
//var_dump( '^' . $uri . '([^/]*)/([^/]*)/?', 'index.php?page_id=' . $options[ 'information_levels_page' ] . '&object=$matches[1]&id=$matches[2]' );
}
$postTypeArguments = Array(
'labels' => Array(
'name' => _x( 'BIM objects', 'post type general name' ),
'singular_name' => _x( 'BIM object', 'post type singular name'),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New BIM object' ),
'edit_item' => __( 'Edit BIM object' ),
'new_item' => __( 'New BIM object' ),
'all_items' => __( 'All BIM objects' ),
'view_item' => __( 'View BIM object' ),
'search_items' => __( 'Search BIM objects' ),
'not_found' => __( 'No BIM objects found' ),
'not_found_in_trash' => __( 'No BIM objects found in Trash' ),
'parent_item_colon' => '',
'menu_name' => 'BIM objects' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => Array( 'title', 'editor', 'thumbnail', 'custom-fields', 'comments' )
);
register_post_type( 'bim_object', $postTypeArguments );
$postTypeArguments = Array(
'labels' => Array(
'name' => _x( 'BIM property', 'post type general name' ),
'singular_name' => _x( 'BIM property', 'post type singular name'),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New BIM property' ),
'edit_item' => __( 'Edit BIM property' ),
'new_item' => __( 'New BIM property' ),
'all_items' => __( 'All BIM properties' ),
'view_item' => __( 'View BIM property' ),
'search_items' => __( 'Search BIM properties' ),
'not_found' => __( 'No BIM property found' ),
'not_found_in_trash' => __( 'No BIM properties found in Trash' ),
'parent_item_colon' => '',
'menu_name' => 'BIM properties' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => false,
'rewrite' => false,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => Array( 'title', 'editor', 'thumbnail', 'custom-fields' )
);
register_post_type( 'bim_property', $postTypeArguments );
$postTypeArguments = Array(
'labels' => Array(
'name' => _x( 'Information Level', 'post type general name' ),
'singular_name' => _x( 'Information Level', 'post type singular name'),
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add New Information Level' ),
'edit_item' => __( 'Edit Information Level' ),
'new_item' => __( 'New Information Level' ),
'all_items' => __( 'All Information Levels' ),
'view_item' => __( 'View Information Level' ),
'search_items' => __( 'Search Information Levels' ),
'not_found' => __( 'No Information Levels found' ),
'not_found_in_trash' => __( 'No Information Levels found in Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Information Levels' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => Array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions' )
);
register_post_type( 'information_level', $postTypeArguments );
$arguments = Array(
'hierarchical' => true,
'labels' => Array(
'name' => _x( 'BIM object categories', 'taxonomy general name' ),
'singular_name' => _x( 'BIM object category', 'taxonomy singular name' ),
'search_items' => __( 'Search BIM object categories' ),
'all_items' => __( 'All BIM object categories' ),
'parent_item' => __( 'Parent BIM object category' ),
'parent_item_colon' => __( 'Parent BIM object category:' ),
'edit_item' => __( 'Edit BIM object category' ),
'update_item' => __( 'Update BIM object category' ),
'add_new_item' => __( 'Add New BIM object category' ),
'new_item_name' => __( 'New BIM object category Name' ),
'menu_name' => __( 'BIM object category' ),
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'bim-object-category' )
);
register_taxonomy( 'bim_object_category', Array( 'bim_object', 'bim_property' ), $arguments );
}
public static function install() {
global $wpdb;
$tableName = $wpdb->prefix . 'property_information_level';
$sql = "CREATE TABLE $tableName (
property_information_level_id int(14) NOT NULL AUTO_INCREMENT,
object_id int(14) NOT NULL,
property_id int(14) NOT NULL,
information_level_id int(14) NOT NULL,
UNIQUE KEY property_information_level_id (property_information_level_id),
INDEX `object_id` ( `object_id` ),
INDEX `property_id` ( `property_id` ),
INDEX `information_level_id` ( `information_level_id` )
)";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
public static function uninstall() {
// do we want to delete all information here... maybe not, could be dangerous
// For now we leave it as it is, there is a button in the plugin options to delete all data
}
public static function deletePost( $postId ) {
global $wpdb;
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}property_information_level WHERE property_id = %d", $postId ) );
}
public static function hasLevels( $objectId, $levels, $propertyId = -1 ) {
global $wpdb;
return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( property_information_level_id )
FROM {$wpdb->prefix}property_information_level
WHERE object_id = %d AND property_id = %d AND information_level_id IN ( " . implode( ', ', $levels ) . " )", $objectId, $propertyId ) ) > 0;
}
public static function getItemInformationLevels( $objectId, $propertyId = -1 ) {
global $wpdb;
return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}property_information_level
WHERE object_id = %d AND property_id = %d", $objectId, $propertyId ) );
}
public static function editorWidget() {
global $post, $wpdb;
$informationLevels = BimInformationLevels::getInformationLevels();
$options = BIMInformationLevels::getOptions();
/*
* Display added property editor options
*/
if( $post->post_type == $options[ 'bim_property_post_type' ] ) {
$objects = get_posts( Array(
'post_type' => $options[ 'bim_object_post_type' ],
'orderby' => 'title',
'order' => 'ASC',
'numberposts' => -1
) );
$objectIds = get_post_meta( $post->ID, '_object_id' );
?>
<div id="bim-object-container">
<?php
$count = 0;
foreach( $objectIds as $objectId ) {
$itemInformationLevels = BimInformationLevels::getItemInformationLevels( $objectId, $post->ID );
?>
<label for="linked-object-id-<?php print( $count ); ?>"><?php _e( 'Property of object', 'bim-information-levels' ); ?></label> <select name="_object_id[]" id="linked-object-id-<?php print( $count ); ?>">
<option value=""><?php _e( 'None', 'bim-information-levels' ); ?></option>
<?php
foreach( $objects as $object ) {
?>
<option value="<?php print( $object->ID ); ?>"<?php print( $objectId == $object->ID ? ' selected' : '' ); ?>><?php print( $object->post_title ); ?></option>
<?php
}
?>
</select><br />
<div id="bim-information-levels-container">
<h4><?php _e( 'Information Levels', 'bim-information-levels' ); ?></h4>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $itemInformationLevels as $itemInformationLevel ) {
if( $itemInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<input type="checkbox" <?php print( $checked ? 'checked ' : '' ); ?>value="true" name="information_level_<?php print( $objectId ); ?>_<?php print( $informationLevel->information_level ); ?>" id="information-level-<?php print( $objectId ); ?>-<?php print( $informationLevel->information_level ); ?>" /> <label for="information-level-<?php print( $objectId ); ?>-<?php print( $informationLevel->information_level ); ?>"><?php print( $informationLevel->information_level ); ?> - <?php print( $informationLevel->post_title ); ?></label><br />
<?php
$count ++;
}
?>
</div><br />
<?php
}
?>
<h4><?php _e( 'Add to object', 'bim-information-levels' ); ?></h4>
<label for="add-property-to-object"><?php _e( 'Add this property to another object', 'bim-information-levels' ); ?></label> <select name="_object_id[]" id="add-property-to-object">
<option value=""><?php _e( 'No', 'bim-information-levels' ); ?></option>
<?php
foreach( $objects as $object ) {
?>
<option value="<?php print( $object->ID ); ?>"><?php print( $object->post_title ); ?></option>
<?php
}
?>
</select>
<br />
</div>
<?php
/*
* Display added object editor options
*/
} else {
$properties = $wpdb->get_results( $wpdb->prepare( "SELECT post_id
FROM $wpdb->postmeta
WHERE meta_key = '_object_id' AND meta_value = %d", $post->ID ) );
$itemInformationLevels = BimInformationLevels::getItemInformationLevels( $post->ID );
?>
<div id="bim-information-levels-container">
<h4><?php _e( 'Information Levels', 'bim-information-levels' ); ?></h4>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $itemInformationLevels as $itemInformationLevel ) {
if( $itemInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<input type="checkbox" <?php print( $checked ? 'checked ' : '' ); ?>value="true" name="information_level_<?php print( $informationLevel->information_level ); ?>" id="information-level-<?php print( $informationLevel->information_level ); ?>" /> <label for="information-level-<?php print( $informationLevel->information_level ); ?>"><?php print( $informationLevel->information_level ); ?> - <?php print( $informationLevel->post_title ); ?></label><br />
<?php
}
?>
</div>
<div id="bim-object-properties">
<h4><?php _e( 'Properties', 'bim-information-levels' ); ?></h4>
<?php
foreach( $properties as $propertyId ) {
$property = get_post( $propertyId->post_id );
?>
<div class="property" id="bim-property-<?php print( $propertyId->post_id ); ?>"><a href="<?php print( get_edit_post_link( $property->ID ) ); ?>"><?php print( $property->post_title ); ?></a></div>
<?php
}
?>
</div>
<?php
}
?>
<input type="hidden" name="bim_information_levels_noncename" value="<?php print( wp_create_nonce(__FILE__) ); ?>" />
<?php
}
public static function saveEditorWidget( $postId ) {
global $wpdb;
if( !isset( $_POST[ 'bim_information_levels_noncename' ] ) || !wp_verify_nonce( $_POST[ 'bim_information_levels_noncename' ], __FILE__ ) ) {
return $postId;
}
if ( !current_user_can( 'edit_post', $postId ) ) {
return $postId;
}
$post = get_post( $postId );
$options = BIMInformationLevels::getOptions();
if( $post->post_type == $options[ 'bim_property_post_type' ] || $post->post_type == $options[ 'bim_object_post_type' ] ) {
if( $post->post_type == $options[ 'bim_property_post_type' ] ) {
$propertyId = $post->ID;
$objectIds = Array();
if( isset( $_POST[ '_object_id' ] ) && is_array( $_POST[ '_object_id' ] ) ) {
delete_post_meta( $postId, '_object_id' );
foreach( $_POST[ '_object_id' ] as $objectId ) {
if( ctype_digit( $objectId ) ) {
add_post_meta( $postId, '_object_id', $objectId );
$objectIds[] = $objectId;
}
}
}
} else {
$objectIds = Array( $postId );
$propertyId = -1;
}
$informationLevels = BimInformationLevels::getInformationLevels();
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}property_information_level WHERE object_id = %d AND property_id = %d", $objectId, $propertyId ) );
$sql = "INSERT INTO {$wpdb->prefix}property_information_level\n
( `object_id`, `property_id`, `information_level_id` )\n
VALUES ";
$count = 0;
foreach( $objectIds as $objectId ) {
$ids = Array();
foreach( $informationLevels as $informationLevel ) {
if( ( isset( $_POST[ 'information_level_' . $informationLevel->information_level ] ) && $_POST[ 'information_level_' . $informationLevel->information_level ] == 'true' ) ||
( isset( $_POST[ 'information_level_' . $objectId . '_' . $informationLevel->information_level ] ) && $_POST[ 'information_level_' . $objectId . '_' . $informationLevel->information_level ] == 'true' ) ) {
$ids[] = $informationLevel->ID;
}
}
foreach( $ids as $id ) {
if( $count > 0 ) {
$sql .= ', ';
}
$sql .= "( $objectId, $propertyId, $id )";
$count ++;
}
}
if( $count > 0 ) {
$wpdb->query( $sql );
}
}
return $postId;
}
public static function getInformationLevels() {
$options = BimInformationLevels::getOptions();
$informationLevels = get_posts( Array(
'post_type' => $options[ 'information_level_post_type' ],
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => 'information_level',
'numberposts' => -1
) );
foreach( $informationLevels as $key => $informationLevel ) {
$informationLevels[$key]->information_level = get_post_meta( $informationLevel->ID, 'information_level', true );
}
return $informationLevels;
}
public static function showBIMInformationLevels() {
global $wp_query, $wp_rewrite;
$options = BIMInformationLevels::getOptions();
$informationLevels = BIMInformationLevels::getInformationLevels();
$parent = ( isset( $_GET[ 'id'] ) && ctype_digit( $_GET[ 'id' ] ) ) ? $_GET[ 'id' ] : 0;
$objectId = ( isset( $_GET[ 'object'] ) && ctype_digit( $_GET[ 'object' ] ) ) ? $_GET[ 'object' ] : 0;
$propertyId = ( isset( $_GET[ 'property'] ) && ctype_digit( $_GET[ 'property' ] ) ) ? $_GET[ 'property' ] : 0;
if( isset( $_COOKIE[ 'filter_levels' ] ) ) {
$selectedLevels = explode( ',', $_COOKIE[ 'filter_levels' ] );
array_walk( $selectedLevels, 'intval' );
} else {
$selectedLevels = Array();
foreach( $informationLevels as $informationLevel ) {
$selectedLevels[] = $informationLevel->ID;
}
}
if( $objectId == 0 && $propertyId == 0 ) {
$topics = get_terms( $options[ 'bim_object_category_taxonomy' ], Array( 'hide_empty' => false, 'parent' => 0 ) );
foreach( $topics as $key => $topic ) {
$topics[$key]->children = get_terms( $options[ 'bim_object_category_taxonomy' ], Array( 'hide_empty' => false, 'parent' => $topic->term_id ) );
}
$settings = Array(
'ajaxUrl' => plugins_url( 'ajax-callback.php', __FILE__ ),
'mainTopics' => $topics,
'text' => Array(
'all' => __( 'all', 'bim-information-levels' ),
'topicLabel' => __( 'Topic', 'bim-information-levels' ),
'subTopicLabel' => __( 'Sub topic', 'bim-information-levels' ),
'trash' => __( 'Remove', 'bim-information-levels' )
),
'type' => 'list'
);
$bimCategories = get_terms( $options[ 'bim_object_category_taxonomy' ], Array( 'hide_empty' => false, 'parent' => $parent ) );
if( $parent != 0 ) {
$parentTerm = get_term( $parent, $options[ 'bim_object_category_taxonomy' ] );
?>
<a href="?"><?php _e( 'To overview', 'bim-information-levels' );?></a><br />
<br />
<h3 id="parent-term-<?php print( $parent ); ?>" class="parent-term"><?php print( $parentTerm->name ); ?></h3>
<?php
}
?>
<h3><?php _e( 'Show objects by information level(s)', 'bim-information-levels' ); ?> <a id="toggle-information-level-container" class="toggle-link" href="javascript:void( null );" onclick="BIMInformationLevels.toggleBox( this );">+</a></h3>
<div id="information-level-container">
<?php
foreach( $informationLevels as $informationLevel ) {
?>
<input type="checkbox" class="filter-checkbox"<?php print( in_array( $informationLevel->ID, $selectedLevels ) ? ' checked' : '' ); ?> value="<?php print( $informationLevel->ID ); ?>" id="information-level-<?php print( $informationLevel->ID ); ?>" /> <label for="information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $informationLevel->post_title ); ?></label><br />
<?php
}
?>
</div>
<h3><?php _e( 'Show object with topics', 'bim-information-levels' ); ?> <a id="toggle-report-control-panel" class="toggle-link" href="javascript:void( null );" onclick="BIMInformationLevels.toggleBox( this );">+</a></h3>
<div id="report-control-panel">
<div class="content"></div>
<a href="javascript:void( null );" onclick="BIMInformationLevels.addReportOptionRow();"><?php _e( 'add specific topic', 'bim-information-levels' ); ?></a><br />
</div>
<br />
<script type="text/javascript">
var informationLevelsControlSettings = <?php print( json_encode( $settings ) ); ?>;
</script>
<?php
foreach( $bimCategories as $bimCategory ) {
$objects = get_posts( Array(
'post_type' => $options[ 'bim_object_post_type' ],
'post_status' => 'publish',
'tax_query' => Array(
Array(
'taxonomy' => $options[ 'bim_object_category_taxonomy' ],
'field' => 'id',
'terms' => $bimCategory->term_id
)
),
'meta_key' => 'code',
'numberposts' => -1,
'orderby' => 'meta_value title',
'order' => 'ASC'
) );
?>
<div class="bim-object-category<?php print( $parent != 0 ? ( ' parent-topic-' . $parent ) : '' ); ?>" id="topic-<?php print( $bimCategory->term_id ); ?>">
<h4><a href="?id=<?php print( $bimCategory->term_id ); ?>"><?php print( $bimCategory->name ); ?></a></h4>
<?php
if( count( $objects ) > 0 ) {
$count = 0;
?>
<table class="bim-information-level-table">
<tr class="odd">
<th class="numeric"><?php _e( 'NlSfb Code', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Object', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Unit', 'bim-information-levels' ); ?></th>
<th><?php _e( 'ifcEquivalent', 'bim-information-levels' ); ?></th>
<th><?php _e( 'BSDD GUID', 'bim-information-levels' ); ?></th>
<th><?php _e( 'CBNL ID', 'bim-information-levels' ); ?></th>
<?php
foreach( $informationLevels as $informationLevel ) {
?>
<th><?php print( '<span class="information-level">' . $informationLevel->information_level . '</span>' ); ?></th>
<?php
}
?>
</tr>
<?php
foreach( $objects as $object ) {
$objectInformationLevels = BIMInformationLevels::getItemInformationLevels( $object->ID );
$terms = wp_get_object_terms( $object->ID, $options[ 'bim_object_category_taxonomy' ], Array( 'fields' => 'ids' ) );
$specificTerm = 'none';
$termParentId = -1;
foreach( $terms as $term ) {
if( $term != $bimCategory->term_id ) {
$specificTerm = $term;
break 1;
}
}
?>
<tr class="item-row <?php print( $count % 2 == 0 ? 'even' : 'odd' ); ?> <?php print( 'row-sub-topic-' . $specificTerm ); ?>">
<td class="numeric"><?php print( get_post_meta( $object->ID, 'code', true ) ); ?></td>
<td><a href="?object=<?php print( $object->ID ); ?>&id=<?php print( $parent ); ?>"><?php print( $object->post_title ); ?></a></td>
<td><?php print( get_post_meta( $object->ID, 'unit', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'ifc_equivalent', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'bsdd_guid', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'cbnl_id', true ) ); ?></td>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $objectInformationLevels as $objectInformationLevel ) {
if( $objectInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<td class="<?php print( $checked ? 'checked' : 'unchecked' ); ?> information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $checked ? 'x' : '' ); ?></td>
<?php
}
?>
</tr>
<?php
$count ++;
}
?>
</table>
<?php
}
?>
</div>
<?php
}
} elseif( $propertyId != 0 ) {
?>
<a href="?"><?php _e( 'To overview', 'bim-information-levels' );?></a><br />
<br />
<?php
$property = get_post( $propertyId );
if( isset( $property ) && $property->post_type == $options[ 'bim_property_post_type' ] ) {
?>
<h2><?php print( $property->post_title ); ?></h2>
Unit: <?php print( get_post_meta( $property->ID, 'unit', true ) ); ?><br />
IfcEquivalent: <?php print( get_post_meta( $property->ID, 'ifc_equivalent', true ) ); ?><br />
BSDD Guid: <?php print( get_post_meta( $property->ID, 'bsdd_guid', true ) ); ?><br />
<br />
<table class="bim-information-level-table">
<tr class="odd">
<th class="numeric"><?php _e( 'NlSfb Code', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Object', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Unit', 'bim-information-levels' ); ?></th>
<th><?php _e( 'ifcEquivalent', 'bim-information-levels' ); ?></th>
<th><?php _e( 'BSDD GUID', 'bim-information-levels' ); ?></th>
<th><?php _e( 'CBNL ID', 'bim-information-levels' ); ?></th>
<?php
foreach( $informationLevels as $informationLevel ) {
?>
<th><?php print( '<span class="information-level">' . $informationLevel->information_level . '</span>' ); ?></th>
<?php
}
?>
</tr>
<?php
$count = 0;
$objectIds = get_post_meta( $property->ID, '_object_id' );
foreach( $objectIds as $objectId ) {
$object = get_post( $objectId );
$objectInformationLevels = BIMInformationLevels::getItemInformationLevels( $object->ID, $property->ID );
?>
<tr class="item-row <?php print( $count % 2 == 0 ? 'even' : 'odd' ); ?>">
<td class="numeric"><?php print( get_post_meta( $object->ID, 'code', true ) ); ?></td>
<td><a href="?object=<?php print( $object->ID ); ?>"><?php print( $object->post_title ); ?></a></td>
<td><?php print( get_post_meta( $object->ID, 'unit', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'ifc_equivalent', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'bsdd_guid', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'cbnl_id', true ) ); ?></td>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $objectInformationLevels as $objectInformationLevel ) {
if( $objectInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<td class="<?php print( $checked ? 'checked' : 'unchecked' ); ?> information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $checked ? 'x' : '' ); ?></td>
<?php
}
?>
</tr>
<?php
$count ++;
}
?>
</table>
<?php
} else {
_e( 'Not a valid property', 'bim-information-levels' );
}
} else {
// Here we show a single object
$object = get_post( $objectId );
$parent = ( isset( $_GET[ 'id'] ) && ctype_digit( $_GET[ 'id' ] ) ) ? $_GET[ 'id' ] : 0;
if( $parent != 0 ) {
$parentTerm = get_term( $parent, $options[ 'bim_object_category_taxonomy' ] );
}
if( $parent == 0 || !isset( $parentTerm ) ) {
?>
<a href="?"><?php _e( 'To overview', 'bim-information-levels' );?></a><br />
<br />
<?php
} else {
?>
<a href="?id=<?php print( $parent ); ?>"><?php print( $parentTerm->name ); ?></a><br />
<br />
<?php
}
if( isset( $object->post_type ) && $object->post_type == $options[ 'bim_object_post_type' ] ) {
?>
<h3><?php _e( 'Show properties by information level(s)', 'bim-information-levels' ); ?></h3>
<?php
foreach( $informationLevels as $informationLevel ) {
?>
<input type="checkbox" class="filter-checkbox"<?php print( in_array( $informationLevel->ID, $selectedLevels ) ? ' checked' : '' ); ?> value="<?php print( $informationLevel->ID ); ?>" id="information-level-<?php print( $informationLevel->ID ); ?>" /> <label for="information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $informationLevel->post_title ); ?></label><br />
<?php
}
$properties = get_posts( Array(
'post_type' => $options[ 'bim_property_post_type' ],
'post_status' => 'publish',
'meta_query' => Array(
Array(
'key' => '_object_id',
'compare' => '=',
'value' => $object->ID
)
),
'meta_key' => 'code',
'numberposts' => -1,
'orderby' => 'meta_value title',
'order' => 'ASC'
) );
$count = 0;
$objectInformationLevels = BIMInformationLevels::getItemInformationLevels( $object->ID );
$thumbnail = get_the_post_thumbnail( $object->ID, 'medium_size' );
?>
<br />
<h2 class="title"><?php print( apply_filters( 'the_title', $object->post_title ) ); ?></h2>
<?php
if( $thumbnail != '' ) {
?>
<div class="image-container"><?php print( $thumbnail ); ?></div>
<?php
}
?>
<p><?php print( apply_filters( 'the_content', $object->post_content ) ); ?></p>
<table class="bim-information-level-table">
<tr class="odd">
<th class="numeric"><?php _e( 'NlSfb Code', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Object/property', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Unit', 'bim-information-levels' ); ?></th>
<th><?php _e( 'ifcEquivalent', 'bim-information-levels' ); ?></th>
<th><?php _e( 'BSDD GUID', 'bim-information-levels' ); ?></th>
<th><?php _e( 'CBNL ID', 'bim-information-levels' ); ?></th>
<?php
foreach( $informationLevels as $informationLevel ) {
?>
<th><?php print( '<span class="information-level">' . $informationLevel->information_level . '</span>' ); ?></th>
<?php
}
?>
</tr>
<tr class="item-row <?php print( $count % 2 == 0 ? 'even' : 'odd' ); ?>">
<td class="numeric"><?php print( get_post_meta( $object->ID, 'code', true ) ); ?></td>
<td><h3><?php print( $object->post_title ); ?></h3></td>
<td><?php print( get_post_meta( $object->ID, 'unit', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'ifc_equivalent', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'bsdd_guid', true ) ); ?></td>
<td><?php print( get_post_meta( $object->ID, 'cbnl_id', true ) ); ?></td>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $objectInformationLevels as $objectInformationLevel ) {
if( $objectInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<td class="<?php print( $checked ? 'checked' : 'unchecked' ); ?> information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $checked ? 'x' : '' ); ?></td>
<?php
}
?>
</tr>
<?php
$count ++;
foreach( $properties as $property ) {
$propertyInformationLevels = BIMInformationLevels::getItemInformationLevels( $object->ID, $property->ID );
?>
<tr class="item-row <?php print( $count % 2 == 0 ? 'even' : 'odd' ); ?>">
<td class="numeric"><?php print( get_post_meta( $property->ID, 'code', true ) ); ?></td>
<td><a href="?property=<?php print( $property->ID ); ?>"><?php print( $property->post_title ); ?></a></td>
<td><?php print( get_post_meta( $property->ID, 'unit', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'ifc_equivalent', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'bsdd_guid', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'cbnl_id', true ) ); ?></td>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $propertyInformationLevels as $propertyInformationLevel ) {
if( $propertyInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<td class="<?php print( $checked ? 'checked' : 'unchecked' ); ?> information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $checked ? 'x' : '' ); ?></td>
<?php
}
?>
</tr>
<?php
$count ++;
}
?>
</table>
<a name="comments"></a>
<?php
$comments = get_comments( Array(
'post_id' => $object->ID
) );
?>
<ol class="comment-list">
<?php
wp_list_comments( Array(), $comments );
?>
</ol>
<script type="text/javascript">
jQuery( document ).ready( function() {
jQuery( "#comments" ).remove();
jQuery( "#commentform .form-submit" ).append( "<input type=\"hidden\" name=\"redirect_to\" value=\"<?php print( get_bloginfo( 'wpurl' ) . $options[ 'information_levels_uri' ] . '?object=' . $object->ID . '&id=' . $parent ); ?>\" />" );
} );
</script>
<?php
comment_form( Array(), $object->ID );
} else {
_e( 'No valid object id', 'bim-information-levels' );
}
}
}
public static function showBIMInformationLevelsProperties() {
global $wp_query, $wp_rewrite, $wpdb;
$options = BIMInformationLevels::getOptions();
$perPage = 50;
$totalProperties = $wpdb->get_var( "SELECT COUNT(ID)
FROM {$wpdb->posts}
WHERE post_type = '{$options[ 'bim_property_post_type' ]}' AND post_status = 'publish'" );
$maxPages = ceil( $totalProperties / $perPage );
if( isset( $wp_query->query_vars[ 'page' ] ) && is_numeric( $wp_query->query_vars[ 'page' ] ) ) {
if( $wp_query->query_vars[ 'page' ] > 0 && $wp_query->query_vars[ 'page' ] <= $maxPages ) {
$page = $wp_query->query_vars[ 'page' ];
} else {
$page = 1;
}
} else {
$page = 1;
}
$count = 0;
$properties = get_posts( Array(
'post_type' => $options[ 'bim_property_post_type' ],
'posts_per_page' => $perPage,
'orderby' => 'title',
'order' => 'ASC',
'offset' => ( $page - 1 ) * $perPage,
'post_status' => 'publish'
) );
?>
<table class="bim-information-level-table">
<tr class="odd">
<th><?php _e( 'Property', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Unit', 'bim-information-levels' ); ?></th>
<th><?php _e( 'ifcEquivalent', 'bim-information-levels' ); ?></th>
<th><?php _e( 'BSDD GUID', 'bim-information-levels' ); ?></th>
<th><?php _e( 'CBNL ID', 'bim-information-levels' ); ?></th>
</tr>
<?php
foreach( $properties as $property ) {
//$propertyInformationLevels = BIMInformationLevels::getItemInformationLevels( $object->ID, $property->ID );
?>
<tr class="<?php print( $count % 2 == 0 ? 'even' : 'odd' ); ?>">
<td><a href="<?php bloginfo( 'wpurl' ); print( $options[ 'information_levels_uri' ] ); ?>?property=<?php print( $property->ID ); ?>"><?php print( $property->post_title ); ?></a></td>
<td><?php print( get_post_meta( $property->ID, 'unit', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'ifc_equivalent', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'bsdd_guid', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'cbnl_id', true ) ); ?></td>
</tr>
<?php
$count ++;
}
?>
</table>
<?php
if( $maxPages > 1 ) {
?>
<div class="property-pages">
<?php
if( false && $page > 1 ) {
?>
<a href="?page=<?php print( $page - 1 ); ?>"><?php _e( 'Previous', 'bim-information-levels' ); ?></a>
<?php
}
for( $i = 1; $i <= $maxPages; $i ++ ) {
if( $i == $page ) {
?>
<span class="selected"><?php print( $i ); ?></span>
<?php
} else {
?>
<a href="?page=<?php print( $i ); ?>"><?php print( $i ); ?></a>
<?php
}
}
if( false && $page < $maxPages ) {
?>
<a href="?page=<?php print( $page + 1 ); ?>"><?php _e( 'Next', 'bim-information-levels' ); ?></a>
<?php
}
?>
</div>
<?php
}
}
public static function showBIMInformationLevelsByLevel() {
global $wp_query, $wp_rewrite, $wpdb;
$options = BIMInformationLevels::getOptions();
$selectedLevels = ( isset( $_GET[ 'filter' ] ) && is_array( $_GET[ 'filter' ] ) ) ? $_GET[ 'filter' ] : Array();
array_walk( $selectedLevels, 'intval' );
if( count( $selectedLevels ) > 0 ) {
$filters = ' AND information_level_id IN( ' . implode( ', ', $selectedLevels ) . ' )';
} else {
$filters = ' AND 0 = 1';
}
$perPage = 50;
$totalProperties = count( $wpdb->get_results( "SELECT ID
FROM {$wpdb->posts}
LEFT JOIN {$wpdb->prefix}property_information_level ON property_id = ID
WHERE post_type = '{$options[ 'bim_property_post_type' ]}' AND post_status = 'publish'$filters
GROUP BY ID, object_id" ) );
$maxPages = ceil( $totalProperties / $perPage );
if( isset( $wp_query->query_vars[ 'page' ] ) && is_numeric( $wp_query->query_vars[ 'page' ] ) ) {
if( $wp_query->query_vars[ 'page' ] > 0 && $wp_query->query_vars[ 'page' ] <= $maxPages ) {
$page = $wp_query->query_vars[ 'page' ];
} else {
$page = 1;
}
} else {
$page = 1;
}
$count = 0;
?>
<h3><?php _e( 'Show properties and objects by information level(s)', 'bim-information-levels' ); ?></h3>
<form method="get" action="">
<?php
$informationLevels = BIMInformationLevels::getInformationLevels();
foreach( $informationLevels as $informationLevel ) {
?>
<input type="checkbox" name="filter[]"<?php print( in_array( $informationLevel->ID, $selectedLevels ) ? ' checked' : '' ); ?> value="<?php print( $informationLevel->ID ); ?>" id="information-level-<?php print( $informationLevel->ID ); ?>" /> <label for="information-level-<?php print( $informationLevel->ID ); ?>"><?php print( $informationLevel->post_title ); ?></label><br />
<?php
}
?>
<input type="submit" value="<?php _e( 'Filter', 'bim-information-levels' ); ?>" />
</form>
<br />
<?php print( $totalProperties ); ?> <?php _e( 'results', 'bim-information-levels' ); ?><br />
<br />
<?php
$properties = $wpdb->get_results( $wpdb->prepare( "SELECT *
FROM {$wpdb->posts}
LEFT JOIN {$wpdb->prefix}property_information_level ON property_id = ID
WHERE post_type = '{$options[ 'bim_property_post_type' ]}' AND post_status = 'publish'$filters
GROUP BY ID, object_id
ORDER BY post_title
LIMIT %d, %d", ( $page - 1 ) * $perPage, $perPage ) );
?>
<table class="bim-information-level-table">
<tr class="odd">
<th><?php _e( 'Object', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Property', 'bim-information-levels' ); ?></th>
<th><?php _e( 'Unit', 'bim-information-levels' ); ?></th>
<th><?php _e( 'ifcEquivalent', 'bim-information-levels' ); ?></th>
<th><?php _e( 'BSDD GUID', 'bim-information-levels' ); ?></th>
<?php
foreach( $informationLevels as $informationLevel ) {
?>
<th><?php print( '<span class="information-level">' . $informationLevel->information_level . '</span>' ); ?></th>
<?php
}
?>
</tr>
<?php
foreach( $properties as $property ) {
$object = get_post( $property->object_id );
/*$objects = $wpdb->get_results( $wpdb->prepare( "SELECT object_id, post_title
FROM {$wpdb->prefix}property_information_level
LEFT JOIN $wpdb->posts ON ID = object_id
WHERE property_id = %d $filters", $property->ID ) );
foreach( $objects as $object ) {*/
$propertyInformationLevels = BIMInformationLevels::getItemInformationLevels( $property->object_id, $property->ID );
?>
<tr class="<?php print( $count % 2 == 0 ? 'even' : 'odd' ); ?>">
<td><a href="<?php bloginfo( 'wpurl' ); print( $options[ 'information_levels_uri' ] ); ?>?object=<?php print( $property->object_id ); ?>"><?php print( $object->post_title ); ?></a></td>
<td><a href="<?php bloginfo( 'wpurl' ); print( $options[ 'information_levels_uri' ] ); ?>?property=<?php print( $property->ID ); ?>"><?php print( $property->post_title ); ?></a></td>
<td><?php print( get_post_meta( $property->ID, 'unit', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'ifc_equivalent', true ) ); ?></td>
<td><?php print( get_post_meta( $property->ID, 'bsdd_guid', true ) ); ?></td>
<?php
foreach( $informationLevels as $informationLevel ) {
$checked = false;
foreach( $propertyInformationLevels as $propertyInformationLevel ) {
if( $propertyInformationLevel->information_level_id == $informationLevel->ID ) {
$checked = true;
break;
}
}
?>
<td class="<?php print( $checked ? 'checked' : 'unchecked' ); ?>"><?php print( $checked ? 'x' : '' ); ?></td>
<?php
}
?>
</tr>
<?php
$count ++;
//}
}
?>
</table>
<?php
if( $maxPages > 1 ) {
$linkFilter = '&filter[]=' . implode( '&filter[]=', $selectedLevels );
?>