本文整理匯總了PHP中ca_objects::setIdnoWithTemplate方法的典型用法代碼示例。如果您正苦於以下問題:PHP ca_objects::setIdnoWithTemplate方法的具體用法?PHP ca_objects::setIdnoWithTemplate怎麽用?PHP ca_objects::setIdnoWithTemplate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ca_objects
的用法示例。
在下文中一共展示了ca_objects::setIdnoWithTemplate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getObjectID
/**
* Returns object_id for the object with the specified name (and type) or idno (regardless of specified type.) If the object does not already
* exist then it will be created with the specified name, type and locale, as well as with any specified values in the $pa_values array.
* $pa_values keys should be either valid object fields or attributes.
*
* @param string $ps_object_name Object label name
* @param int $pn_parent_id The parent_id of the object; must be set to a non-null value
* @param int $pn_type_id The type_id of the object type to use if the object needs to be created
* @param int $pn_locale_id The locale_id to use if the object needs to be created (will be used for both the object locale as well as the label locale)
* @param array $pa_values An optional array of additional values to populate newly created object records with. These values are *only* used for newly created objects; they will not be applied if the object named already exists. The array keys should be names of ca_objects fields or valid object attributes. Values should be either a scalar (for single-value attributes) or an array of values for (multi-valued attributes)
* @param array $pa_options An optional array of options, which include:
* outputErrors - if true, errors will be printed to console [default=false]
* matchOn = optional list indicating sequence of checks for an existing record; values of array can be "label" and "idno". Ex. array("idno", "label") will first try to match on idno and then label if the first match fails.
* dontCreate - if true then new objects will not be created [default=false]
* transaction - if Transaction object is passed, use it for all Db-related tasks [default=null]
* returnInstance = return ca_objects instance rather than object_id. Default is false.
* generateIdnoWithTemplate = A template to use when setting the idno. The template is a value with automatically-set SERIAL values replaced with % characters. Eg. 2012.% will set the created row's idno value to 2012.121 (assuming that 121 is the next number in the serial sequence.) The template is NOT used if idno is passed explicitly as a value in $pa_values.
* importEvent = if ca_data_import_events instance is passed then the insert/update of the object will be logged as part of the import
* importEventSource = if importEvent is passed, then the value set for importEventSource is used in the import event log as the data source. If omitted a default value of "?" is used
* nonPreferredLabels = an optional array of nonpreferred labels to add to any newly created objects. Each label in the array is an array with required object label values.
* log = if KLogger instance is passed then actions will be logged
* @return bool|\ca_objects|mixed|null
*/
static function getObjectID($ps_object_name, $pn_parent_id, $pn_type_id, $pn_locale_id, $pa_values = null, $pa_options = null)
{
if (!is_array($pa_options)) {
$pa_options = array();
}
if (!isset($pa_options['outputErrors'])) {
$pa_options['outputErrors'] = false;
}
$pa_match_on = caGetOption('matchOn', $pa_options, array('label', 'idno'), array('castTo' => "array"));
/** @var ca_data_import_events $o_event */
$o_event = isset($pa_options['importEvent']) && $pa_options['importEvent'] instanceof ca_data_import_events ? $pa_options['importEvent'] : null;
$t_object = new ca_objects();
if (isset($pa_options['transaction']) && $pa_options['transaction'] instanceof Transaction) {
$t_object->setTransaction($pa_options['transaction']);
if ($o_event) {
$o_event->setTransaction($pa_options['transaction']);
}
}
$vs_event_source = isset($pa_options['importEventSource']) && $pa_options['importEventSource'] ? $pa_options['importEventSource'] : "?";
/** @var KLogger $o_log */
$o_log = isset($pa_options['log']) && $pa_options['log'] instanceof KLogger ? $pa_options['log'] : null;
$vs_idno = isset($pa_values['idno']) ? (string) $pa_values['idno'] : null;
if (preg_match('!\\%!', $vs_idno)) {
$pa_options['generateIdnoWithTemplate'] = $vs_idno;
$vs_idno = null;
}
if (!$vs_idno) {
if (isset($pa_options['generateIdnoWithTemplate']) && $pa_options['generateIdnoWithTemplate']) {
$vs_idno = $t_object->setIdnoWithTemplate($pa_options['generateIdnoWithTemplate'], array('dontSetValue' => true));
}
}
$vn_id = null;
foreach ($pa_match_on as $vs_match_on) {
switch (strtolower($vs_match_on)) {
case 'label':
case 'labels':
if (trim($ps_object_name)) {
if ($vn_id = ca_objects::find(array('preferred_labels' => array('name' => $ps_object_name), 'parent_id' => $pn_parent_id, 'type_id' => $pn_type_id), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']))) {
break 2;
}
}
break;
case 'idno':
if ($vs_idno == '%') {
break;
}
// don't try to match on an unreplaced idno placeholder
if ($vn_id = ca_objects::find(array('idno' => $vs_idno ? $vs_idno : $ps_object_name), array('returnAs' => 'firstId', 'transaction' => $pa_options['transaction']))) {
break 2;
}
break;
}
}
if (!$vn_id) {
if (isset($pa_options['dontCreate']) && $pa_options['dontCreate']) {
return false;
}
if ($o_event) {
$o_event->beginItem($vs_event_source, 'ca_objects', 'I');
}
$t_object->setMode(ACCESS_WRITE);
$t_object->set('locale_id', $pn_locale_id);
$t_object->set('type_id', $pn_type_id);
$t_object->set('parent_id', $pn_parent_id);
$t_object->set('source_id', isset($pa_values['source_id']) ? $pa_values['source_id'] : null);
$t_object->set('access', isset($pa_values['access']) ? $pa_values['access'] : 0);
$t_object->set('status', isset($pa_values['status']) ? $pa_values['status'] : 0);
$t_object->set('idno', $vs_idno);
$t_object->set('hier_object_id', isset($pa_values['hier_object_id']) ? $pa_values['hier_object_id'] : null);
$t_object->insert();
if ($t_object->numErrors()) {
if (isset($pa_options['outputErrors']) && $pa_options['outputErrors']) {
print "[Error] " . _t("Could not insert object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())) . "\n";
}
if ($o_log) {
$o_log->logError(_t("Could not insert object %1: %2", $ps_object_name, join('; ', $t_object->getErrors())));
}
//.........這裏部分代碼省略.........