Esempio n. 1
0
 /**
  * Add bundle placement to currently loaded form
  *
  * @param string $ps_bundle_name Name of bundle to add (eg. ca_objects.idno, ca_objects.preferred_labels.name)
  * @param array $pa_settings Placement settings array; keys should be valid setting names
  * @param int $pn_rank Optional value that determines sort order of bundles in the form. If omitted, placement is added to the end of the form.
  * @param array $pa_options Optional array of options. Supports the following options:
  * 		user_id = if specified then add will fail if specified user does not have edit access for the form
  * @return int Returns placement_id of newly created placement on success, false on error
  */
 public function addPlacement($ps_bundle_name, $pa_settings, $pn_rank = null, $pa_options = null)
 {
     if (!($vn_form_id = $this->getPrimaryKey())) {
         return null;
     }
     unset(ca_search_forms::$s_placement_list_cache[$vn_form_id]);
     $pn_user_id = isset($pa_options['user_id']) ? $pa_options['user_id'] : null;
     if ($pn_user_id && !$this->haveAccessToForm($pn_user_id, __CA_SEARCH_FORM_EDIT_ACCESS__)) {
         return null;
     }
     $t_placement = new ca_search_form_placements(null, is_array($pa_options['additional_settings']) ? $pa_options['additional_settings'] : null);
     $t_placement->setMode(ACCESS_WRITE);
     $t_placement->set('form_id', $vn_form_id);
     $t_placement->set('bundle_name', $ps_bundle_name);
     $t_placement->set('rank', $pn_rank);
     if (is_array($pa_settings)) {
         foreach ($pa_settings as $vs_key => $vs_value) {
             $t_placement->setSetting($vs_key, $vs_value);
         }
     }
     $t_placement->insert();
     if ($t_placement->numErrors()) {
         $this->errors = array_merge($this->errors, $t_placement->errors);
         return false;
     }
     return $t_placement->getPrimaryKey();
 }