/
ca_sets.php
2936 lines (2635 loc) · 127 KB
/
ca_sets.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
/** ---------------------------------------------------------------------
* app/models/ca_sets.php : table access class for table ca_sets
* ----------------------------------------------------------------------
* CollectiveAccess
* Open-source collections management software
* ----------------------------------------------------------------------
*
* Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
* Copyright 2009-2021 Whirl-i-Gig
*
* For more information visit http://www.CollectiveAccess.org
*
* This program is free software; you may redistribute it and/or modify it under
* the terms of the provided license as published by Whirl-i-Gig
*
* CollectiveAccess is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* This source code is free and modifiable under the terms of
* GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
* the "license.txt" file for details, or visit the CollectiveAccess web site at
* http://www.CollectiveAccess.org
*
* @package CollectiveAccess
* @subpackage models
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License version 3
*
* ----------------------------------------------------------------------
*/
/**
*
*/
require_once(__CA_LIB_DIR__."/IBundleProvider.php");
require_once(__CA_LIB_DIR__."/BundlableLabelableBaseModelWithAttributes.php");
require_once(__CA_LIB_DIR__.'/SetUniqueIdnoTrait.php');
require_once(__CA_APP_DIR__.'/models/ca_set_items.php');
require_once(__CA_APP_DIR__.'/models/ca_set_item_labels.php');
require_once(__CA_APP_DIR__.'/models/ca_users.php');
require_once(__CA_APP_DIR__.'/helpers/htmlFormHelpers.php');
define('__CA_SET_NO_ACCESS__', 0);
define('__CA_SET_READ_ACCESS__', 1);
define('__CA_SET_EDIT_ACCESS__', 2);
BaseModel::$s_ca_models_definitions['ca_sets'] = array(
'NAME_SINGULAR' => _t('set'),
'NAME_PLURAL' => _t('sets'),
'FIELDS' => array(
'set_id' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_HIDDEN,
'IDENTITY' => true, 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => '',
'LABEL' => _t('CollectiveAccess id'), 'DESCRIPTION' => _t('Unique numeric identifier used by CollectiveAccess internally to identify this set')
),
'parent_id' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => true,
'DEFAULT' => '',
'LABEL' => 'Parent id', 'DESCRIPTION' => 'Identifier of parent set; is null if set is root of hierarchy.'
),
'hier_set_id' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => '',
'LABEL' => 'Set hierarchy', 'DESCRIPTION' => 'Identifier of set that is root of the set hierarchy.'
),
'user_id' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => true,
'DISPLAY_FIELD' => array('ca_users.lname', 'ca_users.fname'),
'DEFAULT' => '',
'LABEL' => _t('User'), 'DESCRIPTION' => _t('The user who created the set.')
),
'table_num' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
'DONT_USE_AS_BUNDLE' => true,
'IS_NULL' => false,
'DEFAULT' => '',
'BOUNDS_VALUE' => array(1,255),
'LABEL' => _t('Set content'), 'DESCRIPTION' => _t('Determines what kind of items (objects, entities, places, etc.) are stored by the set.'),
'BOUNDS_CHOICE_LIST' => array(
_t('Objects') => 57,
_t('Object lots') => 51,
_t('Entities') => 20,
_t('Places') => 72,
_t('Occurrences') => 67,
_t('Collections') => 13,
_t('Storage locations') => 89,
_t('Object representations') => 56,
_t('Loans') => 133,
_t('Movements') => 137,
_t('List items') => 33,
_t('Tours') => 153,
_t('Tour stops') => 155
)
),
'type_id' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => '',
'LIST_CODE' => 'set_types',
'LABEL' => _t('Type'), 'DESCRIPTION' => _t('The type of the set determines what sorts of information the set and each item in the set can have associated with them.')
),
'set_code' => array(
'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_FIELD,
'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => true,
'DEFAULT' => '',
'LABEL' => _t('Set code'), 'DESCRIPTION' => _t('A unique alphanumeric code for this set. You will need to specify this if you are using this set in a special context (on a web front-end, for example) in which the set must be unambiguously identified.'),
'BOUNDS_LENGTH' => array(0, 100),
'UNIQUE_WITHIN' => array()
),
'access' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => 0,
'BOUNDS_CHOICE_LIST' => array(
_t('Not accessible to public') => 0,
_t('Accessible to public') => 1
),
'LIST' => 'access_statuses',
'LABEL' => _t('Access'), 'DESCRIPTION' => _t('Indicates if object is accessible to the public or not. ')
),
'status' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => 0,
'BOUNDS_CHOICE_LIST' => array(
_t('Newly created') => 0,
_t('Editing in progress') => 1,
_t('Editing complete - pending review') => 2,
_t('Review in progress') => 3,
_t('Completed') => 4
),
'LIST' => 'workflow_statuses',
'LABEL' => _t('Status'), 'DESCRIPTION' => _t('Indicates the current state of the object record.')
),
'hier_left' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => '',
'LABEL' => 'Hierarchical index - left bound', 'DESCRIPTION' => 'Left-side boundary for nested set-style hierarchical indexing; used to accelerate search and retrieval of hierarchical record sets.'
),
'hier_right' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_OMIT,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => '',
'LABEL' => 'Hierarchical index - right bound', 'DESCRIPTION' => 'Right-side boundary for nested set-style hierarchical indexing; used to accelerate search and retrieval of hierarchical record sets.'
),
'deleted' => array(
'FIELD_TYPE' => FT_BIT, 'DISPLAY_TYPE' => DT_OMIT,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => 0,
'LABEL' => _t('Is deleted?'), 'DESCRIPTION' => _t('Indicates if the set is deleted or not.'),
'BOUNDS_VALUE' => array(0,1)
),
'rank' => array(
'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_FIELD,
'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
'IS_NULL' => false,
'DEFAULT' => '',
'LABEL' => _t('Sort order'), 'DESCRIPTION' => _t('Sort order'),
)
)
);
class ca_sets extends BundlableLabelableBaseModelWithAttributes implements IBundleProvider {
use SetUniqueIdnoTrait;
# ---------------------------------
# --- Object attribute properties
# ---------------------------------
# Describe structure of content object's properties - eg. database fields and their
# associated types, what modes are supported, et al.
#
# ------------------------------------------------------
# --- Basic object parameters
# ------------------------------------------------------
# what table does this class represent?
protected $TABLE = 'ca_sets';
# what is the primary key of the table?
protected $PRIMARY_KEY = 'set_id';
# ------------------------------------------------------
# --- Properties used by standard editing scripts
#
# These class properties allow generic scripts to properly display
# records from the table represented by this class
#
# ------------------------------------------------------
# Array of fields to display in a listing of records from this table
protected $LIST_FIELDS = array('user_id');
# When the list of "list fields" above contains more than one field,
# the LIST_DELIMITER text is displayed between fields as a delimiter.
# This is typically a comma or space, but can be any string you like
protected $LIST_DELIMITER = ' ';
# What you'd call a single record from this table (eg. a "person")
protected $NAME_SINGULAR;
# What you'd call more than one record from this table (eg. "people")
protected $NAME_PLURAL;
# List of fields to sort listing of records by; you can use
# SQL 'ASC' and 'DESC' here if you like.
protected $ORDER_BY = array('user_id');
# Maximum number of record to display per page in a listing
protected $MAX_RECORDS_PER_PAGE = 20;
# How do you want to page through records in a listing: by number pages ordered
# according to your setting above? Or alphabetically by the letters of the first
# LIST_FIELD?
protected $PAGE_SCHEME = 'alpha'; # alpha [alphabetical] or num [numbered pages; default]
# If you want to order records arbitrarily, add a numeric field to the table and place
# its name here. The generic list scripts can then use it to order table records.
protected $RANK = 'rank';
# ------------------------------------------------------
# Hierarchical table properties
# ------------------------------------------------------
protected $HIERARCHY_TYPE = __CA_HIER_TYPE_ADHOC_MONO__;
protected $HIERARCHY_LEFT_INDEX_FLD = 'hier_left';
protected $HIERARCHY_RIGHT_INDEX_FLD = 'hier_right';
protected $HIERARCHY_PARENT_ID_FLD = 'parent_id';
protected $HIERARCHY_DEFINITION_TABLE = 'ca_sets';
protected $HIERARCHY_ID_FLD = 'hier_set_id';
protected $HIERARCHY_POLY_TABLE = null;
# ------------------------------------------------------
# Change logging
# ------------------------------------------------------
protected $UNIT_ID_FIELD = null;
protected $LOG_CHANGES_TO_SELF = true;
protected $LOG_CHANGES_USING_AS_SUBJECT = array(
"FOREIGN_KEYS" => array(
),
"RELATED_TABLES" => array(
)
);
# ------------------------------------------------------
# Group-based access control
# ------------------------------------------------------
protected $USERS_RELATIONSHIP_TABLE = 'ca_sets_x_users';
protected $USER_GROUPS_RELATIONSHIP_TABLE = 'ca_sets_x_user_groups';
# ------------------------------------------------------
# Labels
# ------------------------------------------------------
protected $LABEL_TABLE_NAME = 'ca_set_labels';
# ------------------------------------------------------
# Attributes
# ------------------------------------------------------
protected $ATTRIBUTE_TYPE_ID_FLD = 'type_id'; // name of type field for this table - attributes system uses this to determine via ca_metadata_type_restrictions which attributes are applicable to rows of the given type
protected $ATTRIBUTE_TYPE_LIST_CODE = 'set_types'; // list code (ca_lists.list_code) of list defining types for this table
# ------------------------------------------------------
# ID numbering
# ------------------------------------------------------
protected $ID_NUMBERING_ID_FIELD = 'set_code'; // name of field containing user-defined identifier
protected $ID_NUMBERING_SORT_FIELD = null; // name of field containing version of identifier for sorting (is normalized with padding to sort numbers properly)
protected $ID_NUMBERING_CONTEXT_FIELD = null; // name of field to use value of for "context" when checking for duplicate identifier values; if not set identifer is assumed to be global in scope; if set identifer is checked for uniqueness (if required) within the value of this field
# ------------------------------------------------------
# Search
# ------------------------------------------------------
protected $SEARCH_CLASSNAME = 'SetSearch';
protected $SEARCH_RESULT_CLASSNAME = 'SetSearchResult';
# ------------------------------------------------------
# $FIELDS contains information about each field in the table. The order in which the fields
# are listed here is the order in which they will be returned using getFields()
protected $FIELDS;
# cache for haveAccessToSet()
static $s_have_access_to_set_cache = array();
# ------------------------------------------------------
# --- Constructor
#
# This is a function called when a new instance of this object is created. This
# standard constructor supports three calling modes:
#
# 1. If called without parameters, simply creates a new, empty objects object
# 2. If called with a single, valid primary key value, creates a new objects object and loads
# the record identified by the primary key value
#
# ------------------------------------------------------
public function __construct($pn_id=null) {
// Filter list of tables set can be used for to those enabled in current config
BaseModel::$s_ca_models_definitions['ca_sets']['FIELDS']['table_num']['BOUNDS_CHOICE_LIST'] = caFilterTableList(BaseModel::$s_ca_models_definitions['ca_sets']['FIELDS']['table_num']['BOUNDS_CHOICE_LIST']);
parent::__construct($pn_id); # call superclass constructor
}
# ------------------------------------------------------
/**
*
*/
protected function initLabelDefinitions($pa_options=null) {
parent::initLabelDefinitions($pa_options);
unset($this->BUNDLES['nonpreferred_labels']); // sets have no nonpreferred labels
$this->BUNDLES['ca_users'] = array('type' => 'special', 'repeating' => true, 'label' => _t('User access'));
$this->BUNDLES['ca_user_groups'] = array('type' => 'special', 'repeating' => true, 'label' => _t('Group access'));
$this->BUNDLES['ca_set_items'] = array('type' => 'special', 'repeating' => true, 'label' => _t('Set items'));
}
# ------------------------------------------------------
/**
* Overrides default implementation with code to ensure consistency of set contents
*/
public function update($pa_options=null) {
$this->_setUniqueIdno(['noUpdate' => true]);
if ($vn_rc = parent::update($pa_options)) {
// make sure all items have the same type as the set
$this->getDb()->query("
UPDATE ca_set_items
SET type_id = ?
WHERE
set_id = ?
", (int)$this->get('type_id'), (int)$this->getPrimaryKey());
}
return $vn_rc;
}
# ------------------------------------------------------
/**
* Override set() to reject changes to user_id for existing rows
*/
public function set($pa_fields, $pm_value="", $pa_options=null) {
if ($this->getPrimaryKey()) {
if (is_array($pa_fields)) {
if (isset($pa_fields['user_id'])) { unset($pa_fields['user_id']); }
if (isset($pa_fields['table_num'])) { unset($pa_fields['table_num']); }
} else {
if ($pa_fields === 'user_id') { return false; }
if ($pa_fields === 'table_num') { return false; }
}
}
return parent::set($pa_fields, $pm_value, $pa_options);
}
# ------------------------------------------------------
/**
* Override delete() to scramble the set_code before we soft-delete. This is useful
* because the database field has a unique key that really enforces uniqueneness
* and we might wanna reuse a code of a set we previously deleted.
*/
public function delete($pb_delete_related=false, $pa_options=null, $pa_fields=null, $pa_table_list=null) {
if(!is_array($pa_options)) { $pa_options = array(); }
$vb_web_set_change_log_unit_id = BaseModel::setChangeLogUnitID();
if($pb_delete_related) {
// quickly delete all labels for all set items in this set
$this->getDb()->query('DELETE FROM ca_set_item_labels WHERE item_id IN (SELECT item_id FROM ca_set_items WHERE set_id=?)', $this->getPrimaryKey());
// quickly delete attribute values
$this->getDb()->query('
DELETE FROM ca_attribute_values WHERE attribute_id IN
(SELECT attribute_id FROM ca_attributes WHERE table_num=? and row_id IN (SELECT item_id FROM ca_set_items WHERE set_id = ?))
', array($this->tableNum(), $this->getPrimaryKey()));
// quickly delete attributes
$this->getDb()->query('
DELETE FROM ca_attributes WHERE table_num=? and row_id IN (SELECT item_id FROM ca_set_items WHERE set_id = ?)
', array($this->tableNum(), $this->getPrimaryKey()));
// get list of set item ids
$qr_items = $this->getDb()->query('SELECT item_id FROM ca_set_items WHERE set_id = ?', array($this->getPrimaryKey()));
$va_item_ids = $qr_items->getAllFieldValues('item_id');
// nuke set items
$this->getDb()->query('DELETE FROM ca_set_items WHERE set_id = ?', array($this->getPrimaryKey()));
// remove search indexing for deleted set items
foreach($va_item_ids as $vn_item_id) {
$this->getSearchIndexer()->commitRowUnIndexing($this->tableNum(), $vn_item_id, array('queueIndexing' => true));
}
}
if($vn_rc = parent::delete($pb_delete_related, array_merge(array('queueIndexing' => true), $pa_options), $pa_fields, $pa_table_list)) {
if(!caGetOption('hard', $pa_options, false)) { // only applies if we don't hard-delete
$vb_we_set_transaction = false;
if (!$this->inTransaction()) {
$this->setTransaction($o_t = new Transaction($this->getDb()));
$vb_we_set_transaction = true;
}
$this->set('set_code', $this->get('set_code') . '_' . time());
$this->update(array('force' => true));
if ($vb_we_set_transaction) { $this->removeTransaction(true); }
}
}
if ($vb_web_set_change_log_unit_id) { BaseModel::unsetChangeLogUnitID(); }
return $vn_rc;
}
# ------------------------------------------------------
/**
* @param array $pa_options
* duplicate_subitems
*/
public function duplicate($pa_options=null) {
$vb_we_set_transaction = false;
if (!$this->inTransaction()) {
$this->setTransaction($o_trans = new Transaction($this->getDb()));
$vb_we_set_transaction = true;
} else {
$o_trans = $this->getTransaction();
}
if ($t_dupe = parent::duplicate($pa_options)) {
$vb_duplicate_subitems = caGetOption('duplicate_subitems', $pa_options, false);
if ($vb_duplicate_subitems) {
// Try to dupe related ca_set_items rows
$o_db = $this->getDb();
$qr_res = $o_db->query("
SELECT *
FROM ca_set_items
WHERE set_id = ?
", (int)$this->getPrimaryKey());
$va_items = array();
while($qr_res->nextRow()) {
$va_items[$qr_res->get('item_id')] = $qr_res->getRow();
}
foreach($va_items as $vn_item_id => $va_item) {
$t_item = new ca_set_items();
$t_item->setTransaction($o_trans);
$t_item->setMode(ACCESS_WRITE);
$va_item['set_id'] = $t_dupe->getPrimaryKey();
$t_item->set($va_item);
$t_item->insert();
if ($t_item->numErrors()) {
$this->errors = $t_item->errors;
if ($vb_we_set_transaction) { $this->removeTransaction(false);}
return false;
}
}
}
}
if ($vb_we_set_transaction) { $this->removeTransaction(true);}
return $t_dupe;
}
# ------------------------------------------------------
/**
* Convert provided row_ids in currently loaded set to their corresponding set item_ids
*
* @param array $pa_row_ids Array of "row_ids" (eg. object_id's for object sets)
* @param array $pa_options Options include:
* returnAsInfoArray = Return an array for each item_id containing keys for set_id and item_id [Default is false]
*
* @return array A list of item_ids, or arrays if returnAsInfoArray option is set
*/
public function rowIDsToItemIDs($pa_row_ids, $pa_options=null) {
if (!($vn_set_id = $this->getPrimaryKey())) { return null; }
if (!is_array($pa_row_ids) || !sizeof($pa_row_ids)) { return null; }
$pa_row_ids = array_filter($pa_row_ids, function($a) { return (bool)$a; });
if (!sizeof($pa_row_ids)) { return null; }
$o_db = $this->getDb();
$qr_items = $o_db->query("
SELECT item_id, row_id
FROM ca_set_items
WHERE
row_id IN (?) AND set_id = ?
", array($pa_row_ids, $vn_set_id));
if (caGetOption('returnAsInfoArray', $pa_options, false)) {
$va_acc = array();
while ($qr_items->nextRow()) {
$va_acc[$qr_items->get('row_id')][] = array(
'item_id' => $qr_items->get('item_id'),
'set_id' => $vn_set_id
);
}
return $va_acc;
}
return $qr_items->getAllFieldValues('item_id');
}
# ------------------------------------------------------
# Set lists
# ------------------------------------------------------
/**
* Returns list of sets subject to options
*
* @param array $pa_options Array of options. Supported options are:
* table - if set, list is restricted to sets that can contain the specified item. You can pass a table name or number. If omitted sets containing any content will be returned.
* setType - Restricts returned sets to those of the specified type. You can pass a type_id or list item code for the set type. If omitted sets are returned regardless of type.
* user_id - Restricts returned sets to those accessible by the current user. If omitted then all sets, regardless of access are returned.
* access - Restricts returned sets to those with at least the specified access level for the specified user. If user_id is omitted then this option has no effect. If user_id is set and this option is omitted, then sets where the user has at least read access will be returned.
* checkAccess - Restricts returned sets to those with an public access level with the specified values. If omitted sets are returned regardless of public access (ca_sets.access) value. Can be a single value or array if you wish to filter on multiple public access values.
* row_id = if set to an integer only sets containing the specified row are returned
* setIDsOnly = if set to true only set_id values are returned, in a simple array
* omitCounts =
* all =
* allUsers =
* publicUsers =
* name =
* byUser = return sets grouped by user with access. The array will be key'ed by sortable user name. Each entry includes a 'user' array with information about the user and a 'sets' array with the list of sets that user has access to. [Default is false]
* codes =
* includeItems =
* item_id = Get set that contains specified item_id
*
* @return array A list of sets keyed by set_id and then locale_id. Keys for the per-locale value array include: set_id, set_code, status, public access, owner user_id, content table_num, set type_id, set name, number of items in the set (item_count), set type name for display and set content type name for display. If setIDsOnly option is set then a simple array of set_id values is returned instead.
*/
public function getSets($pa_options=null) {
if (!is_array($pa_options)) { $pa_options = array(); }
$pm_table_name_or_num = isset($pa_options['table']) ? $pa_options['table'] : null;
$pm_type = isset($pa_options['setType']) ? $pa_options['setType'] : null;
$pn_user_id = isset($pa_options['user_id']) ? (int)$pa_options['user_id'] : null;
$pn_access = isset($pa_options['access']) ? $pa_options['access'] : null;
$pb_set_ids_only = isset($pa_options['setIDsOnly']) ? (bool)$pa_options['setIDsOnly'] : false;
$pb_omit_counts = isset($pa_options['omitCounts']) ? (bool)$pa_options['omitCounts'] : false;
$ps_set_name = isset($pa_options['name']) ? $pa_options['name'] : null;
$pn_item_id = isset($pa_options['item_id']) ? (int)$pa_options['item_id'] : null;
$codes = caGetOption('codes', $pa_options, null);
if ($codes && !is_array($codes)) { $codes = [$codes]; }
$include_items = caGetOption('includeItems', $pa_options, false);
$pb_by_user = caGetOption('byUser', $pa_options, null);
$pn_row_id = (isset($pa_options['row_id']) && ((int)$pa_options['row_id'])) ? (int)$pa_options['row_id'] : null;
$ps_sort = caGetOption('sort', $pa_options, null);
$ps_sort_direction = caGetOption('sortDirection', $pa_options, null);
$pa_public_access = isset($pa_options['checkAccess']) ? $pa_options['checkAccess'] : null;
if ($pa_public_access && is_numeric($pa_public_access) && !is_array($pa_public_access)) {
$pa_public_access = array($pa_public_access);
}
if (!is_array($pa_public_access)) { $pa_public_access = []; }
for($vn_i=0; $vn_i < sizeof($pa_public_access); $vn_i++) { $pa_public_access[$vn_i] = intval($pa_public_access[$vn_i]); }
if ($pm_table_name_or_num && !($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) { return null; }
$va_extra_joins = array();
$o_db = $this->getDb();
$va_sql_wheres = array("(cs.deleted = 0)");
$va_sql_params = array();
if ($vn_table_num) {
$va_sql_wheres[] = "(cs.table_num = ?)";
$va_sql_params[] = (int)$vn_table_num;
}
if(is_array($codes) && sizeof($codes)) {
$va_sql_wheres[] = "(cs.set_code IN (?))";
$va_sql_params[] = $codes;
}
if ($pb_set_ids_only) {
$va_sql_selects = array('cs.set_id');
} else {
$va_sql_selects = array(
'cs.set_id', 'cs.set_code', 'cs.status', 'cs.access', 'cs.user_id', 'cs.table_num', 'cs.type_id',
'csl.label_id', 'csl.name', 'csl.locale_id', 'l.language', 'l.country', 'u.fname', 'u.lname', 'u.email'
);
}
if (isset($pa_options['all']) && $pa_options['all']) {
$va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass != 255))";
} elseif (isset($pa_options['allUsers']) && $pa_options['allUsers']) {
$va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass = 0))";
} elseif (isset($pa_options['publicUsers']) && $pa_options['publicUsers']) {
$va_sql_wheres[] = "(cs.user_id IN (SELECT user_id FROM ca_users WHERE userclass = 1))";
} else {
if ($pn_user_id && !$this->getAppConfig()->get('dont_enforce_access_control_for_ca_sets')) {
$t_user = Datamodel::getInstanceByTableName('ca_users', true);
$t_user->load($pn_user_id);
if ($t_user->getPrimaryKey()) {
$vs_access_sql = ($pn_access > 0) ? " AND (access >= ".intval($pn_access).")" : "";
if (is_array($va_groups = $t_user->getUserGroups()) && sizeof($va_groups)) {
$vs_sql = "(
(cs.user_id = ".intval($pn_user_id).") OR
(cs.set_id IN (
SELECT set_id
FROM ca_sets_x_user_groups
WHERE
group_id IN (".join(',', array_keys($va_groups)).") {$vs_access_sql}
AND
(
(sdatetime IS NULL AND edatetime IS NULL)
OR
(
sdatetime <= ".time()." AND edatetime >= ".time()."
)
)
)
)
)";
} else {
$vs_sql = "(cs.user_id = {$pn_user_id})";
}
$vs_sql .= " OR (cs.set_id IN (
SELECT set_id
FROM ca_sets_x_users
WHERE
user_id = {$pn_user_id} {$vs_access_sql}
AND
(
(sdatetime IS NULL AND edatetime IS NULL)
OR
(
sdatetime <= ".time()." AND edatetime >= ".time()."
)
)
)
)";
$va_sql_wheres[] = "({$vs_sql})";
}
}
}
if (!is_null($pa_public_access) && is_array($pa_public_access) && sizeof($pa_public_access)) {
$va_sql_wheres[] = "(cs.access IN (?))";
$va_sql_params[] = $pa_public_access;
}
if (isset($pn_item_id) && ($pn_item_id > 0)) {
$va_extra_joins[] = "INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id";
$va_sql_wheres[] = "(csi.item_id IN (?))";
$va_sql_params[] = is_array($pn_item_id) ? $pn_item_id : [$pn_item_id];
}
if (isset($pm_type) && $pm_type) {
if(is_numeric($pm_type)){
$va_sql_wheres[] = "(cs.type_id = ?)";
$va_sql_params[] = (int)$pm_type;
}else{
# --- look up code of set type
$t_list = new ca_lists();
$vn_type_id = $t_list->getItemIDFromList("set_types", $pm_type);
if($vn_type_id){
$va_sql_wheres[] = "(cs.type_id = ?)";
$va_sql_params[] = (int)$vn_type_id;
}
}
}
if($va_restrict_to_types = caGetOption(['restrict_to_types', 'restrictToTypes'], $pa_options, false)) {
if(!is_array($va_restrict_to_types)) { $va_restrict_to_types = [$va_restrict_to_types]; }
$va_restrict_to_type_ids = array();
foreach($va_restrict_to_types as $vm_type) {
if(is_numeric($vm_type)){
$va_restrict_to_type_ids[] = (int)$vm_type;
} else {
# --- look up code of set type
$vn_type_id = caGetListItemID('set_types', $pm_type);
if($vn_type_id){
$va_restrict_to_type_ids[] = (int) $vn_type_id;
}
}
}
if(sizeof($va_restrict_to_type_ids)) {
$va_sql_wheres[] = "(cs.type_id IN (?))";
$va_sql_params[] = $va_restrict_to_type_ids;
}
}
if ($pn_row_id > 0) {
$va_sql_wheres[] = "((csi.row_id = ?) AND (csi.table_num = ?))";
$va_extra_joins[] = "INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id";
$va_sql_selects[] = 'csi.item_id';
$va_sql_params[] = (int)$pn_row_id;
$va_sql_params[] = (int)$vn_table_num;
}
if ($ps_set_name) {
$va_sql_wheres[] = "(csl.name = ?)";
$va_sql_params[] = (string)$ps_set_name;
}
if (!$pb_set_ids_only && !$pb_omit_counts) {
// get set item counts
$qr_table_nums = $o_db->query("
SELECT DISTINCT cs.table_num
FROM ca_sets cs
INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id
".(sizeof($va_sql_wheres) ? 'WHERE ' : '')."
".join(' AND ', $va_sql_wheres)."
", $va_sql_params);
$va_item_counts = array();
while($qr_table_nums->nextRow()) {
$t_instance = Datamodel::getInstanceByTableNum($vn_table_num = (int)$qr_table_nums->get('table_num'), true);
if (!$t_instance) { continue; }
$va_item_sql_params = $va_sql_params;
$va_item_wheres = $va_sql_wheres;
$va_item_wheres[] = "(cs.table_num = {$vn_table_num})";
if ($t_instance->hasField('deleted')) {
$va_item_wheres[] = "(t.deleted = 0)";
}
if (!is_null($pa_public_access) && is_array($pa_public_access) && sizeof($pa_public_access)) {
$va_item_wheres[] = "(t.access IN (?))";
$va_item_sql_params[] = $pa_public_access;
}
$qr_res = $o_db->query("
SELECT cs.set_id, count(distinct row_id) item_count
FROM ca_sets cs
INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id
INNER JOIN ".$t_instance->tableName()." AS t ON t.".$t_instance->primaryKey()." = csi.row_id
".(sizeof($va_item_wheres) ? 'WHERE ' : '')."
".join(' AND ', $va_item_wheres)."
GROUP BY cs.set_id
", $va_item_sql_params);
while($qr_res->nextRow()) {
$va_item_counts[(int)$qr_res->get('set_id')] = (int)$qr_res->get('item_count');
}
}
// get sets
$qr_res = $o_db->query("
SELECT ".join(', ', $va_sql_selects)."
FROM ca_sets cs
LEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id
LEFT JOIN ca_locales AS l ON csl.locale_id = l.locale_id
INNER JOIN ca_users AS u ON cs.user_id = u.user_id
".join("\n", $va_extra_joins)."
".(sizeof($va_sql_wheres) ? 'WHERE ' : '')."
".join(' AND ', $va_sql_wheres)."
ORDER BY csl.name
", $va_sql_params);
$va_sets = array();
$va_type_name_cache = array();
$t_list = new ca_lists();
while($qr_res->nextRow()) {
$set_id = $qr_res->get('set_id');
$vn_table_num = $qr_res->get('table_num');
if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
$vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
}
$vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
$extras = ['item_count' => intval($va_item_counts[$qr_res->get('set_id')]), 'set_content_type' => $vs_set_type, 'set_type' => $vs_type];
if ($include_items) {
$extras['items'] = caExtractValuesByUserLocale(ca_sets::getItemsForSet($set_id, $pa_options));
}
$va_sets[$qr_res->get('set_id')][$qr_res->get('locale_id')] = array_merge($qr_res->getRow(), $extras);
}
if ($pb_by_user) {
$va_sets_by_user = [];
$va_sets = caExtractValuesByUserLocale($va_sets);
foreach($va_sets as $va_set) {
$va_users = $this->getUsers(['row_id' => $va_set['set_id']]);
$vs_user_key = strtolower(str_pad(substr($va_set['lname'], 0, 20), 20, ' ', STR_PAD_RIGHT).str_pad(substr($va_set['fname'], 0, 20), 20, ' ', STR_PAD_RIGHT).str_pad($va_set['user_id'], 10, '0', STR_PAD_LEFT));
if (!isset($va_sets_by_user[$vs_user_key]['user'])) {
$va_sets_by_user[$vs_user_key]['user'] = [
'user_id' => $va_set['user_id'], 'user_name' => $va_set['user_name'],
'fname' => $va_set['fname'], 'lname' => $va_set['lname'],
'email' => $va_set['email']
];
}
$va_sets_by_user[$vs_user_key]['sets'][] = $va_set;
foreach($va_users as $va_user) {
$vs_user_key = strtolower(str_pad(substr($va_user['lname'], 0, 20), 20, ' ', STR_PAD_RIGHT).str_pad(substr($va_user['fname'], 0, 20), 20, ' ', STR_PAD_RIGHT).str_pad($va_user['user_id'], 10, '0', STR_PAD_LEFT));
$va_sets_by_user[$vs_user_key]['user'] = $va_user;
$va_sets_by_user[$vs_user_key]['sets'][] = $va_set;
}
}
ksort($va_sets_by_user);
return $va_sets_by_user;
}
return $va_sets;
} elseif ($pb_set_ids_only) {
// get sets
$qr_res = $o_db->query("
SELECT ".join(', ', $va_sql_selects)."
FROM ca_sets cs
INNER JOIN ca_users AS u ON cs.user_id = u.user_id
LEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id
".join("\n", $va_extra_joins)."
".(sizeof($va_sql_wheres) ? 'WHERE ' : '')."
".join(' AND ', $va_sql_wheres)."
ORDER BY csl.name
", $va_sql_params);
return $qr_res->getAllFieldValues("set_id");
} else {
$qr_res = $o_db->query("
SELECT ".join(', ', $va_sql_selects)."
FROM ca_sets cs
INNER JOIN ca_users AS u ON cs.user_id = u.user_id
LEFT JOIN ca_set_labels AS csl ON cs.set_id = csl.set_id
LEFT JOIN ca_locales AS l ON csl.locale_id = l.locale_id
".join("\n", $va_extra_joins)."
".(sizeof($va_sql_wheres) ? 'WHERE ' : '')."
".join(' AND ', $va_sql_wheres)."
ORDER BY csl.name
", $va_sql_params);
$t_list = new ca_lists();
$va_sets = array();
while($qr_res->nextRow()) {
$vn_table_num = $qr_res->get('table_num');
if (!isset($va_type_name_cache[$vn_table_num]) || !($vs_set_type = $va_type_name_cache[$vn_table_num])) {
$vs_set_type = $va_type_name_cache[$vn_table_num] = $this->getSetContentTypeName($vn_table_num, array('number' => 'plural'));
}
$vs_type = $t_list->getItemFromListForDisplayByItemID('set_types', $qr_res->get('type_id'));
$va_sets[$qr_res->get('set_id')][$qr_res->get('locale_id')] = array_merge($qr_res->getRow(), array('item_count' => intval($va_item_counts[$qr_res->get('set_id')]), 'set_content_type' => $vs_set_type, 'set_type' => $vs_type));
}
return $va_sets;
}
}
# ------------------------------------------------------
/**
* Returns list of sets to which the item (as specified by $pm_table_name_or_num and $pn_row_id) can be associated and is not already part of.
*
* @param mixed $pm_table_name_or_num Name or number of table
* @param int $pn_row_id ID of row in table specified by $pm_table_name_or_num to check for
* @param array $pa_options Optional list of options. Supported options are the same as those for ca_sets::getSets() and ca_sets::getSetsForItem()
* @return array A list of sets keyed by set_id and then locale_id. Keys for the per-locale value array include: set_id, set_code, status, public access, owner user_id, content table_num, set type_id, set name, number of items in the set (item_count), set type name for display and set content type name for display. This is the same format as returned by ca_sets::getSets().
*/
public function getAvailableSetsForItem($pm_table_name_or_num, $pn_row_id, $pa_options=null) {
if (!is_array($pa_options)) { $pa_options = array(); }
if (!($va_full_set_list = $this->getSets(array_merge(array('table' => $pm_table_name_or_num), $pa_options)))) { return null; }
if (!($va_current_set_list = $this->getSetsForItem($pm_table_name_or_num, $pn_row_id, $pa_options))) { $va_current_set_list = []; }
$va_available_sets = array();
foreach($va_full_set_list as $vn_set_id => $va_set_info_by_locale) {
if (isset($va_current_set_list[$vn_set_id]) && $va_current_set_list[$vn_set_id]) { continue;}
$va_available_sets[$vn_set_id] = $va_set_info_by_locale;
}
return $va_available_sets;
}
# ------------------------------------------------------
/**
* Returns list of sets in which the specified item is a member
*
* @param mixed $pm_table_name_or_num Name or number of table
* @param int $pn_row_id ID of row in table specified by $pm_table_name_or_num to check for
* @param array $pa_options Optional list of options. Supported options are the same as those for ca_sets::getSets() and ca_sets::getSetsForItem()
* @return array A list of sets keyed by set_id and then locale_id. Keys for the per-locale value array include: set_id, set_code, status, public access, owner user_id, content table_num, set type_id, set name, number of items in the set (item_count), set type name for display and set content type name for display. This is the same format as returned by ca_sets::getSets().
*/
public function getSetsForItem($pm_table_name_or_num, $pn_row_id, $pa_options=null) {
if (!is_array($pa_options)) { $pa_options = array(); }
if (!$pn_row_id) { return array(); }
return $this->getSets(array_merge($pa_options, array('table' => $pm_table_name_or_num, 'row_id' => $pn_row_id)));
}
# ------------------------------------------------------
/**
* Returns list of set_ids of sets in which the specified item is a member
*
* @param mixed $pm_table_name_or_num Name or number of table
* @param int $pn_row_id ID of row in table specified by $pm_table_name_or_num to check for
* @param array $pa_options Optional list of options. Supported options are the same as those for ca_sets::getSets() and ca_sets::getSetsForItem()
* @return array A list of set_ids, or null if parameters are invalid
*/
public function getSetIDsForItem($pm_table_name_or_num, $pn_row_id, $pa_options=null) {
if (is_array($va_sets = $this->getSetsForItem($pm_table_name_or_num, $pn_row_id, $pa_options))) {
return array_keys($va_sets);
}
return null;
}
# ------------------------------------------------------
/**
* Checks if a row of a table is in a set.
*
* @param mixed $pm_table_name_or_num Name or number of table
* @param int $pn_row_id ID of row in table specified by $pm_table_name_or_num to check for
* @param mixed $pm_set_code_or_id Set code or set_id of set to check for item
* @return bool True if row is in set, false if now. If the table or set are invalid null will be returned.
*/
public function isInSet($pm_table_name_or_num, $pn_row_id, $pm_set_code_or_id) {
if (!($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) { return null; }
if (!($vn_set_id = $this->_getSetID($pm_set_code_or_id))) { return null; }
$o_db = $this->getDb();
$qr_res = $o_db->query("
SELECT cs.set_id
FROM ca_sets cs
INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id
WHERE
(cs.deleted = 0) AND (cs.set_id = ?) AND (csi.row_id = ?) AND (cs.table_num = ?)
", (int)$vn_set_id, (int)$pn_row_id, (int)$vn_table_num);
if ($qr_res->numRows() > 0) {
return true;
}
return false;
}
# ------------------------------------------------------
/**
* Checks if array of row ids of a table are in a set.
*
* @param mixed $pm_table_name_or_num Name or number of table
* @param int $ps_row_ids array of row ids in table specified by $pm_table_name_or_num to check for
* @param mixed $pm_set_code_or_id Set code or set_id of set to check for item
* @return array of row_ids found in set. If the table or set are invalid null will be returned.
*/
public function areInSet($pm_table_name_or_num, $pa_row_ids, $pm_set_code_or_id) {
if (!($vn_table_num = $this->_getTableNum($pm_table_name_or_num))) { return null; }
if (!($vn_set_id = $this->_getSetID($pm_set_code_or_id))) { return null; }
if (!is_array($pa_row_ids) || !sizeof($pa_row_ids)) { return null; }
$o_db = $this->getDb();
$qr_res = $o_db->query("
SELECT csi.row_id
FROM ca_sets cs
INNER JOIN ca_set_items AS csi ON cs.set_id = csi.set_id
WHERE
(cs.deleted = 0) AND (cs.set_id = ?) AND (csi.row_id IN (".join(", ", $pa_row_ids).")) AND (cs.table_num = ?)
", (int)$vn_set_id, (int)$vn_table_num);
$va_found_row_ids = array();
if ($qr_res->numRows() > 0) {
while($qr_res->nextRow()){
$va_found_row_ids[] = $qr_res->get("row_id");
}
}
return $va_found_row_ids;
}
# ------------------------------------------------------
/**
* Returns a random set_id from a group defined by specified options. These options are the same as those for ca_sets::getSets()
*
* @param array $pa_options Array of options. Supported options are:
* table - if set, list is restricted to sets that can contain the specified item. You can pass a table name or number. If omitted sets containing any content will be returned.
* setType - Restricts returned sets to those of the specified type. You can pass a type_id or list item code for the set type. If omitted sets are returned regardless of type.
* user_id - Restricts returned sets to those accessible by the current user. If omitted then all sets, regardless of access are returned.
* access - Restricts returned sets to those with at least the specified access level for the specified user. If user_id is omitted then this option has no effect. If user_id is set and this option is omitted, then sets where the user has at least read access will be returned.
* checkAccess - Restricts returned sets to those with an public access level with the specified values. If omitted sets are returned regardless of public access (ca_sets.access) value. Can be a single value or array if you wish to filter on multiple public access values.
* row_id = if set to an integer only sets containing the specified row are returned
* @return int A randomly selected set_id value
*/
public function getRandomSetID($pa_options=null) {
$va_set_ids = $this->getSets(array_merge($pa_options, array('setIDsOnly' => true)));
return $va_set_ids[rand(0, sizeof($va_set_ids) - 1)];
}
# ------------------------------------------------------
/**
* Determines if user has access to a set at a specified access level.
*
* @param int $pn_user_id user_id of user to check set access for
* @param int $pn_access type of access required. Use __CA_SET_READ_ACCESS__ for read-only access or __CA_SET_EDIT_ACCESS__ for editing (full) access
* @param int $pn_set_id The id of the set to check. If omitted then currently loaded set will be checked.
* @param array $pa_options No options yet
* @return bool True if user has access, false if not
*/
public function haveAccessToSet($pn_user_id, $pn_access, $pn_set_id=null, $pa_options=null) {
if ($this->getAppConfig()->get('dont_enforce_access_control_for_ca_sets')) { return true; }
if ($pn_set_id) {
$vn_set_id = $pn_set_id;
$t_set = new ca_sets($vn_set_id);
$vn_set_user_id = $t_set->get('user_id');