xowf::test_item::Question_manager method get_pool_replacement_candidates (protected)

 <instance of xowf::test_item::Question_manager[i]> get_pool_replacement_candidates \
    [ -allowed_forms allowed_forms ] [ -minutes minutes ] \
    [ -points points ] [ -fc_dict fc_dict ] [ -lang lang ] \
    pool_question_obj

Defined in packages/xowf/tcl/test-item-procs.tcl

When fc_dict contains no item_types, return empty and signal in the logfile.

Switches:
-allowed_forms
(defaults to "en:edit-interaction.wf") (optional)
-minutes
(optional)
-points
(optional)
-fc_dict
(optional)
-lang
(optional)
Parameters:
pool_question_obj

Partial Call Graph (max 5 caller/called nodes):
%3 ad_log ad_log (public) xowf::test_item::Question_manager instproc get_pool_replacement_candidates xowf::test_item::Question_manager instproc get_pool_replacement_candidates xowf::test_item::Question_manager instproc get_pool_replacement_candidates->ad_log

Testcases:
No testcase defined.
Source code:
set item_types [dict get $fc_dict item_types]
if {[llength $item_types] == 0} {
  ad_log warning "No item types for this pool question"
  return
}

#
# Obtain for the specs in the pool_question_obj potential
# replacement items.
#
set parent_id [$pool_question_obj parent_id]
set package_id [$pool_question_obj package_id]

#
# We want to select only instances of these edit workflows
# specified in allowed_forms.
#
set form_objs [::$package_id instantiate_forms  -parent_id $parent_id  -forms $allowed_forms]
set form_object_item_ids [lmap f $form_objs {$f item_id}]

set pattern [dict get $fc_dict pattern]
set folder [dict get $fc_dict folder]

set item_ref_info [::$package_id item_ref  -use_package_path 0  -default_lang en  -parent_id $parent_id  $folder]
set folder_id [:dict_value $item_ref_info item_id]

#
# In case, all item types are selected, no additional clauses
# are needed.
#
if {[::xowiki::formfield::pool_question all_item_types_selected $item_types]} {
  set w_clauses ""
} else {
  set w_clauses [list "item_type = [join $item_types |]"]
}

#
# Never include PoolQuestions as a replacement for a pool
# question.
#
set u_clauses [list "item_type = PoolQuestion"]

#
# Perform language selection based on the name and combine this
# with the provided pattern.
#
if {$pattern eq ""} {
  set pattern *
}
if {$lang ne ""} {
  lappend w_clauses "_name matches ${lang}:$pattern"
} elseif {$pattern ne "*"} {
  lappend w_clauses "_name matches $pattern"
} else {
  #
  # In case thjere is no pattern and no lang provided, there is
  # no filter necessary.
  #
}

# The matching of minutes and points are more complex due to
# mutual completion (see below).
#
#if {$minutes ne ""} {
#  lappend w_clauses "question matches *question.minutes $minutes*"
#}

set filters [::xowiki::FormPage compute_filter_clauses  {*}[expr {[llength $u_clauses] > 0 ? [list -unless [join $u_clauses &&]] : ""}]  {*}[expr {[llength $w_clauses] ? [list -where [join $w_clauses &&]] : ""}]  ]

#ns_log notice "get_pool_replacement_candidates filters $filters"
#ns_log notice "get_pool_replacement_candidates filters WC $w_clauses -->\n[dict get $filters wc]"
#ns_log notice "get_pool_replacement_candidates filters UC $u_clauses -->\n[dict get $filters uc]"

#
# In case the folder_id is a symbolic link to a different
# folder, resolve the link and reset the folder_id to the
# item_id of the link target.
#
# In case we have links to different packages, some more work
# might be required (e.g. instantiate the other package, etc.).
#
if {![nsf::is object ::$folder_id]} {
  ::xowiki::FormPage get_instance_from_db -item_id $folder_id
}
if {[::$folder_id is_link_page]} {
  set targetObj [::$folder_id get_target_from_link_page]
  set folder_id [$targetObj item_id]
}

#
# TODO: one has to check the performance of the generic
# get_form_entries on learn with larger question pools. It would
# be possible to provide a quicker query based on the
# xowiki*item_index joined with acs-objects instead of the
# generic view used in get_form_entries. ... but maybe the
# current approach with caching is already quick enough.
#
set items [::xowiki::FormPage get_form_entries  -base_item_ids ${form_object_item_ids}  -form_fields {}  -publish_status ready  -parent_id $folder_id  -package_id ${package_id}  -h_where [dict get $filters wc]  -h_unless [dict get $filters uc]  -initialize false  -from_package_ids ""]

ns_log notice "get_pool_replacement_candidates parent_id $folder_id -> [llength [$items children]]"

#
# Since we allow the user to specify either minutes or points,
# and use the specified values as defaults for the others, we
# have to replace the empty values with the defaults (mutual
# completion).
#
if {$minutes eq "" && $points ne ""} {
  set minutes $points
} elseif {$minutes ne "" && $points eq ""} {
  set points $minutes
}

set result ""
foreach item [$items children] {
  set qn [:qualified_question_names $item]
  set ia [$item set instance_attributes]
  set qa [dict get $ia question]

  #
  # Replace empty values for "minutes" and "points" with the
  # defaults before comparing.
  #
  set item_minutes [dict get $qa question.minutes]
  set item_points [dict get $qa question.points]
  if {$item_minutes eq "" && $item_points ne ""} {
    set item_minutes $item_points
  } elseif {$item_minutes ne "" && $item_points eq ""} {
    set item_points $item_minutes
  }
  #ns_log notice "get_pool_replacement_candidates filter"  "minutes '$minutes' <-> '$item_minutes',"  "points '$points ' <-> '$item_points'"
  if {$minutes ne "" && $item_minutes ne $minutes} {
    continue
  } elseif {$points ne "" && $item_points ne $points} {
    continue
  }

  dict set result $qn item_id [$item item_id]
  dict set result $qn item_type [dict get $ia item_type]
  #dict set result $qn question_dict $qa
}

#ns_log notice "=============== get_pool_replacement_candidates returns $result"
return $result
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: