本文整理汇总了PHP中ca_sets::addItem方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_sets::addItem方法的具体用法?PHP ca_sets::addItem怎么用?PHP ca_sets::addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_sets
的用法示例。
在下文中一共展示了ca_sets::addItem方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToSet
/**
* Add items to specified set
*/
public function addToSet()
{
$vn_added_items_count = $vn_dupe_item_count = 0;
$ps_rows = $this->request->getParameter('item_ids', pString);
$pa_row_ids = explode(';', $ps_rows);
if (!$ps_rows || !sizeof($pa_row_ids)) {
$this->view->setVar('error', _t('Nothing was selected'));
} else {
$t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true);
$pn_set_id = $this->request->getParameter('set_id', pInteger);
$t_set = new ca_sets($pn_set_id);
$this->view->setVar('set_id', $pn_set_id);
$this->view->setVar('set_name', $t_set->getLabelForDisplay());
$this->view->setVar('error', '');
if ($t_set->getPrimaryKey() && $t_set->get('table_num') == $t_model->tableNum()) {
$va_item_ids = $t_set->getItemRowIDs(array('user_id' => $this->request->getUserID()));
foreach ($pa_row_ids as $vn_row_id) {
if (!$vn_row_id) {
continue;
}
if (isset($va_item_ids[$vn_row_id])) {
$vn_dupe_item_count++;
continue;
}
if ($t_set->addItem($vn_row_id, array(), $this->request->getUserID())) {
$va_item_ids[$vn_row_id] = 1;
$vn_added_items_count++;
} else {
$this->view->setVar('error', join('; ', $t_set->getErrors()));
}
}
} else {
$this->view->setVar('error', _t('Invalid set'));
}
}
$this->view->setVar('num_items_added', $vn_added_items_count);
$this->view->setVar('num_items_already_in_set', $vn_dupe_item_count);
$this->render('Results/ajax_add_to_set_json.php');
}
示例2: addItem
/**
* Add item as specified in request body array. Can also be used to
* add item directly. If both parameters are set, the request data
* is ignored.
* @param null|string $ps_table optional table name. if not set, table name is taken from request
* @param null|array $pa_data optional array with item data. if not set, data is taken from request body
* @return array|bool
*/
public function addItem($ps_table = null, $pa_data = null)
{
if (!$ps_table) {
$ps_table = $this->ops_table;
}
if (!($t_instance = $this->_getTableInstance($ps_table))) {
return false;
}
$t_locales = new ca_locales();
if (!$pa_data || !is_array($pa_data)) {
$pa_data = $this->getRequestBodyArray();
}
// intrinsic fields
if (is_array($pa_data["intrinsic_fields"]) && sizeof($pa_data["intrinsic_fields"])) {
foreach ($pa_data["intrinsic_fields"] as $vs_field_name => $vs_value) {
$t_instance->set($vs_field_name, $vs_value);
}
} else {
$this->addError(_t("No intrinsic fields specified"));
return false;
}
// attributes
if (is_array($pa_data["attributes"]) && sizeof($pa_data["attributes"])) {
foreach ($pa_data["attributes"] as $vs_attribute_name => $va_values) {
foreach ($va_values as $va_value) {
if ($va_value["locale"]) {
$va_value["locale_id"] = $t_locales->localeCodeToID($va_value["locale"]);
unset($va_value["locale"]);
}
$t_instance->addAttribute($va_value, $vs_attribute_name);
}
}
}
$t_instance->setMode(ACCESS_WRITE);
$t_instance->insert();
if (!$t_instance->getPrimaryKey()) {
$this->opa_errors = array_merge($t_instance->getErrors(), $this->opa_errors);
return false;
}
// AFTER INSERT STUFF
// preferred labels
if (is_array($pa_data["preferred_labels"]) && sizeof($pa_data["preferred_labels"])) {
foreach ($pa_data["preferred_labels"] as $va_label) {
if ($va_label["locale"]) {
$vn_locale_id = $t_locales->localeCodeToID($va_label["locale"]);
unset($va_label["locale"]);
}
$t_instance->addLabel($va_label, $vn_locale_id, null, true);
}
}
// nonpreferred labels
if (is_array($pa_data["nonpreferred_labels"]) && sizeof($pa_data["nonpreferred_labels"])) {
foreach ($pa_data["nonpreferred_labels"] as $va_label) {
if ($va_label["locale"]) {
$vn_locale_id = $t_locales->localeCodeToID($va_label["locale"]);
unset($va_label["locale"]);
}
if ($va_label["type_id"]) {
$vn_type_id = $va_label["type_id"];
unset($va_label["type_id"]);
} else {
$vn_type_id = null;
}
$t_instance->addLabel($va_label, $vn_locale_id, $vn_type_id, false);
}
}
// relationships
if (is_array($pa_data["related"]) && sizeof($pa_data["related"]) > 0) {
foreach ($pa_data["related"] as $vs_table => $va_relationships) {
if ($vs_table == 'ca_sets') {
foreach ($va_relationships as $va_relationship) {
$t_set = new ca_sets();
if ($t_set->load($va_relationship)) {
$t_set->addItem($t_instance->getPrimaryKey());
}
}
} else {
foreach ($va_relationships as $va_relationship) {
$vs_source_info = isset($va_relationship["source_info"]) ? $va_relationship["source_info"] : null;
$vs_effective_date = isset($va_relationship["effective_date"]) ? $va_relationship["effective_date"] : null;
$vs_direction = isset($va_relationship["direction"]) ? $va_relationship["direction"] : null;
$t_rel_instance = $this->_getTableInstance($vs_table);
$vs_pk = isset($va_relationship[$t_rel_instance->primaryKey()]) ? $va_relationship[$t_rel_instance->primaryKey()] : null;
$vs_type_id = isset($va_relationship["type_id"]) ? $va_relationship["type_id"] : null;
$t_rel = $t_instance->addRelationship($vs_table, $vs_pk, $vs_type_id, $vs_effective_date, $vs_source_info, $vs_direction);
// deal with interstitial attributes
if ($t_rel instanceof BaseRelationshipModel) {
$vb_have_to_update = false;
if (is_array($va_relationship["attributes"]) && sizeof($va_relationship["attributes"])) {
foreach ($va_relationship["attributes"] as $vs_attribute_name => $va_values) {
foreach ($va_values as $va_value) {
if ($va_value["locale"]) {
//.........这里部分代码省略.........
示例3: saveBundlesForScreen
//.........这里部分代码省略.........
foreach ($va_sets as $vn_set_id => $va_set_info) {
$vn_item_id = $va_set_info['item_id'];
if ($po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}_set_id_{$vn_item_id}_delete", pString)) {
// delete
$t_set->load($va_set_info['set_id']);
$t_set->removeItem($this->getPrimaryKey(), $po_request->getUserID());
// remove *all* instances of the item in the set, not just the specified id
if ($t_set->numErrors()) {
$po_request->addActionErrors($t_set->errors(), $vs_f);
}
}
}
}
if ($vb_batch) {
$vs_batch_mode = $_REQUEST["{$vs_placement_code}{$vs_form_prefix}_batch_mode"];
if ($vs_batch_mode == '_disabled_') {
break;
}
if ($vs_batch_mode == '_replace_') {
$t_set->removeItemFromAllSets($this->tableNum(), $this->getPrimaryKey());
}
if ($vs_batch_mode == '_delete_') {
$t_set->removeItemFromAllSets($this->tableNum(), $this->getPrimaryKey());
break;
}
}
foreach ($_REQUEST as $vs_key => $vs_value) {
if (!preg_match("/{$vs_placement_code}{$vs_form_prefix}_set_id_new_([\\d]+)/", $vs_key, $va_matches)) {
continue;
}
$vn_c = intval($va_matches[1]);
if ($vn_new_set_id = $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}_set_id_new_{$vn_c}", pString)) {
$t_set->load($vn_new_set_id);
$t_set->addItem($this->getPrimaryKey(), null, $po_request->getUserID());
if ($t_set->numErrors()) {
$po_request->addActionErrors($t_set->errors(), $vs_f);
}
}
}
break;
# -------------------------------------
// This bundle is only available for types which support set membership
# -------------------------------------
// This bundle is only available for types which support set membership
case 'ca_set_items':
if ($vb_batch) {
break;
}
// not supported in batch mode
// check for existing labels to delete (no updating supported)
require_once __CA_MODELS_DIR__ . '/ca_sets.php';
require_once __CA_MODELS_DIR__ . '/ca_set_items.php';
$va_rids = explode(';', $po_request->getParameter("{$vs_placement_code}{$vs_form_prefix}setRowIDList", pString));
$this->reorderItems($va_rids, array('user_id' => $po_request->getUserID(), 'treatRowIDsAsRIDs' => true, 'deleteExcludedItems' => true));
break;
# -------------------------------------
// This bundle is only available for ca_search_forms
# -------------------------------------
// This bundle is only available for ca_search_forms
case 'ca_search_form_elements':
if ($vb_batch) {
break;
}
// not supported in batch mode
// save settings
$va_settings = $this->getAvailableSettings();
示例4: _processRelatedSets
/**
* @param RequestHTTP $po_request
* @param string $ps_form_prefix
* @param string $ps_placement_code
*/
public function _processRelatedSets($po_request, $ps_form_prefix, $ps_placement_code)
{
require_once __CA_MODELS_DIR__ . '/ca_sets.php';
foreach ($_REQUEST as $vs_key => $vs_value) {
// check for new relationships to add
if (preg_match("/^{$ps_placement_code}{$ps_form_prefix}_idnew_([\\d]+)/", $vs_key, $va_matches)) {
$vn_c = intval($va_matches[1]);
if ($vn_new_id = $po_request->getParameter("{$ps_placement_code}{$ps_form_prefix}_idnew_{$vn_c}", pString)) {
$t_set = new ca_sets($vn_new_id);
$t_set->addItem($this->getPrimaryKey(), null, $po_request->getUserID());
}
}
// check for delete keys
if (preg_match("/^{$ps_placement_code}{$ps_form_prefix}_([\\d]+)_delete/", $vs_key, $va_matches)) {
$vn_c = intval($va_matches[1]);
$t_set = new ca_sets($vn_c);
$t_set->removeItem($this->getPrimaryKey());
}
}
}
示例5: addItem
public function addItem()
{
global $g_ui_locale_id;
// current locale_id for user
if (!$this->request->isLoggedIn()) {
$this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
return;
}
if (!($t_set = $this->_getSet())) {
# --- if there is not a set for this user, make a new set for them
$t_new_set = new ca_sets();
$vn_new_set_id = null;
$t_new_set->setMode(ACCESS_WRITE);
$t_new_set->set('access', 0);
$t_new_set->set('table_num', 57);
// 57=ca_objects
$t_list = new ca_lists();
$vn_set_id = $t_list->getItemIDFromList('set_types', $this->request->config->get('user_set_type'));
$t_new_set->set('type_id', $vn_set_id);
$t_new_set->set('user_id', $this->request->getUserID());
$t_new_set->set('set_code', $this->request->getUserID() . '_' . time());
// create new attribute
$t_new_set->insert();
if (!$t_new_set->numErrors()) {
if ($vn_new_set_id = $t_new_set->getPrimaryKey()) {
$t_new_set->addLabel(array('name' => _t("Your first collection")), $g_ui_locale_id, null, true);
// select the current set
$this->request->user->setVar('current_set_id', $vn_new_set_id);
//clear t_new_set object so form appears blank and load t_set so edit form is populated
$t_new_set = new ca_sets();
$t_set = new ca_sets($vn_new_set_id);
}
}
}
if (!$t_set) {
$va_errors[] = _t('Could not create collection for user');
} else {
$pn_item_id = null;
$pn_object_id = $this->request->getParameter('object_id', pInteger);
if ($pn_item_id = $t_set->addItem($pn_object_id, array(), $this->request->getUserID())) {
$va_errors = array();
$this->view->setVar('message', _t("Successfully added item"));
} else {
$va_errors[] = _t('Could not add item to collection');
}
}
$t_row = new ca_objects($pn_object_id);
$this->view->setVar('errors', $va_errors);
$this->index();
}
示例6: AjaxAddItem
public function AjaxAddItem()
{
if (!$this->request->isLoggedIn()) {
$this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'loginForm'));
return;
}
global $g_ui_locale_id;
// current locale_id for user
$va_errors = array();
$o_purifier = new HTMLPurifier();
# --- set_id is passed through form, otherwise we're saving a new set, and adding the item to it
if ($this->request->getParameter('set_id', pInteger)) {
$t_set = $this->_getSet(__CA_EDIT_READ_ACCESS__);
if (!$t_set && ($t_set = $this->_getSet(__CA_SET_READ_ACCESS__))) {
$va_errors["general"] = _t("You can not add items to this lightbox. You have read only access.");
$this->view->setVar('errors', $va_errors);
$this->addItemForm();
return;
}
} else {
$t_set = new ca_sets();
# --- set name - if not sent, make a decent default
$ps_name = $o_purifier->purify($this->request->getParameter('name', pString));
if (!$ps_name) {
$ps_name = _t("Your lightbox");
}
# --- set description - optional
$ps_description = $o_purifier->purify($this->request->getParameter('description', pString));
$t_list = new ca_lists();
$vn_set_type_user = $t_list->getItemIDFromList('set_types', $this->request->config->get('user_set_type'));
$t_object = new ca_objects();
$vn_object_table_num = $t_object->tableNum();
$t_set->setMode(ACCESS_WRITE);
$t_set->set('access', 1);
#$t_set->set('access', $this->request->getParameter('access', pInteger));
$t_set->set('table_num', $vn_object_table_num);
$t_set->set('type_id', $vn_set_type_user);
$t_set->set('user_id', $this->request->getUserID());
$t_set->set('set_code', $this->request->getUserID() . '_' . time());
# --- create new attribute
if ($ps_description) {
$t_set->addAttribute(array('description' => $ps_description, 'locale_id' => $g_ui_locale_id), 'description');
}
$t_set->insert();
if ($t_set->numErrors()) {
$va_errors["general"] = join("; ", $t_set->getErrors());
$this->view->setVar('errors', $va_errors);
$this->addItemForm();
return;
} else {
# --- save name - add new label
$t_set->addLabel(array('name' => $ps_name), $g_ui_locale_id, null, true);
# --- select the current set
$this->request->user->setVar('current_set_id', $t_set->get("set_id"));
}
}
if ($t_set) {
$pn_item_id = null;
$pn_object_id = $this->request->getParameter('object_id', pInteger);
if ($pn_object_id) {
if (!$t_set->isInSet("ca_objects", $pn_object_id, $t_set->get("set_id"))) {
if ($pn_item_id = $t_set->addItem($pn_object_id, array(), $this->request->getUserID())) {
//
// Select primary representation
//
$t_object = new ca_objects($pn_object_id);
$vn_rep_id = $t_object->getPrimaryRepresentationID();
// get representation_id for primary
$t_item = new ca_set_items($pn_item_id);
$t_item->addSelectedRepresentation($vn_rep_id);
// flag as selected in item vars
$t_item->update();
$va_errors = array();
$this->view->setVar('message', _t("Successfully added item."));
$this->render("Form/reload_html.php");
} else {
$va_errors["message"] = _t('Could not add item to lightbox');
$this->render("Form/reload_html.php");
}
} else {
$this->view->setVar('message', _t("Item already in lightbox."));
$this->render("Form/reload_html.php");
}
} else {
$this->view->setVar('message', _t("Object ID is not defined"));
$this->render("Form/reload_html.php");
}
}
}
示例7: addItem
/**
*
*/
public function addItem()
{
global $g_ui_locale_id;
// current locale_id for user
if (!$this->request->isLoggedIn()) {
$this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
return;
}
if (!($t_set = $this->_getSet(__CA_SET_EDIT_ACCESS__))) {
if ($t_set = $this->_getSet(__CA_SET_READ_ACCESS__)) {
$this->view->setVar('message', _t("You can not add items to this set. You have read only access."));
$this->index();
return;
}
# --- if there is not a set for this user, make a new set for them
$t_new_set = new ca_sets();
$vn_new_set_id = null;
$t_new_set->setMode(ACCESS_WRITE);
$t_new_set->set('access', 0);
$t_new_set->set('table_num', 57);
// 57=ca_objects
$t_list = new ca_lists();
$vn_set_id = $t_list->getItemIDFromList('set_types', $this->request->config->get('user_set_type'));
$t_new_set->set('type_id', $vn_set_id);
$t_new_set->set('user_id', $this->request->getUserID());
$t_new_set->set('set_code', $this->request->getUserID() . '_' . time());
// create new attribute
$t_new_set->insert();
if (!$t_new_set->numErrors()) {
if ($vn_new_set_id = $t_new_set->getPrimaryKey()) {
$t_new_set->addLabel(array('name' => _t("Your first lightbox")), $g_ui_locale_id, null, true);
// select the current set
$this->request->user->setVar('current_set_id', $vn_new_set_id);
//clear t_new_set object so form appears blank and load t_set so edit form is populated
$t_new_set = new ca_sets();
$t_set = new ca_sets($vn_new_set_id);
}
}
}
if (!$t_set) {
$va_errors[] = _t('Could not create lightbox for user');
} else {
$pn_item_id = null;
$pn_object_id = $this->request->getParameter('object_id', pInteger);
if (!$t_set->isInSet("ca_objects", $pn_object_id, $t_set->get("set_id"))) {
if ($pn_item_id = $t_set->addItem($pn_object_id, array(), $this->request->getUserID())) {
//
// Select primary representation
//
$t_object = new ca_objects($pn_object_id);
$vn_rep_id = $t_object->getPrimaryRepresentationID();
// get representation_id for primary
$t_item = new ca_set_items($pn_item_id);
$t_item->addSelectedRepresentation($vn_rep_id);
// flag as selected in item vars
$t_item->update();
$va_errors = array();
$this->view->setVar('message', _t("Successfully added item. %1Click here to resume your search%2.", "<a href='" . caNavUrl($this->request, "Detail", "Object", "Show", array("object_id" => $pn_object_id)) . "'>", "</a>"));
} else {
$va_errors[] = _t('Could not add item to lightbox');
}
} else {
$this->view->setVar('message', _t("Item already in set. %1Click here to resume your search%2.", "<a href='" . caNavUrl($this->request, "Detail", "Object", "Show", array("object_id" => $pn_object_id)) . "'>", "</a>"));
}
}
//$t_row = new ca_objects($pn_object_id);
$this->view->setVar('errors', $va_errors);
$this->index();
}
示例8: importMediaFromDirectory
//.........这里部分代码省略.........
if ($t_instance->tableName() == 'ca_entities') {
// entity labels deserve special treatment
$t_instance->addLabel(array('surname' => $f), $vn_locale_id, null, true);
} else {
$t_instance->addLabel(array($t_instance->getLabelDisplayField() => $f), $vn_locale_id, null, true);
}
if ($t_instance->numErrors()) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => _t("Error creating record label while importing %1 from %2: %3", $f, $vs_relative_directory, join('; ', $t_instance->getErrors()))));
$va_errors[$vs_relative_directory . '/' . $f] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_instance->getLabelForDisplay(), 'errors' => $t_instance->errors(), 'message' => $vs_msg = _t("Error creating record label while importing %1 from %2: %3", $f, $vs_relative_directory, join('; ', $t_instance->getErrors())), 'status' => 'ERROR');
$o_log->logError($vs_msg);
$o_trans->rollback();
continue;
}
$t_new_rep = $t_instance->addRepresentation($vs_directory . '/' . $f, $vn_rep_type_id, $vn_locale_id, $vn_object_representation_status, $vn_object_representation_access, true, array('idno' => $vs_rep_idno), array('original_filename' => $f, 'returnRepresentation' => true, 'type_id' => $vn_rel_type_id));
if ($t_instance->numErrors()) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => _t("Error importing %1 from %2: ", $f, $vs_relative_directory, join('; ', $t_instance->getErrors()))));
$va_errors[$vs_relative_directory . '/' . $f] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_instance->getLabelForDisplay(), 'errors' => $t_instance->errors(), 'message' => $vs_msg = _t("Error importing %1 from %2: %3", $f, $vs_relative_directory, join('; ', $t_instance->getErrors())), 'status' => 'ERROR');
$o_log->logError($vs_msg);
$o_trans->rollback();
continue;
} else {
if ($vb_delete_media_on_import) {
@unlink($vs_directory . '/' . $f);
}
}
}
}
if ($t_instance->getPrimaryKey()) {
// Perform import of embedded metadata (if required)
if ($vn_mapping_id) {
ca_data_importers::importDataFromSource($vs_directory . '/' . $f, $vn_mapping_id, array('logLevel' => $vs_log_level, 'format' => 'exif', 'forceImportForPrimaryKeys' => array($t_instance->getPrimaryKey(), 'transaction' => $o_trans)));
}
if ($vn_object_representation_mapping_id) {
ca_data_importers::importDataFromSource($vs_directory . '/' . $f, $vn_object_representation_mapping_id, array('logLevel' => $vs_log_level, 'format' => 'exif', 'forceImportForPrimaryKeys' => array($t_new_rep->getPrimaryKey()), 'transaction' => $o_trans));
}
$va_notices[$t_instance->getPrimaryKey()] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_instance->getLabelForDisplay(), 'message' => $vs_msg = _t('Imported %1 as %2', $f, $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD'))), 'status' => 'SUCCESS');
$o_log->logInfo($vs_msg);
if ($vn_set_id) {
$t_set->addItem($t_instance->getPrimaryKey(), null, $po_request->getUserID());
}
$o_batch_log->addItem($t_instance->getPrimaryKey(), $t_instance->errors());
// Create relationships?
if (is_array($va_create_relationship_for) && sizeof($va_create_relationship_for) && is_array($va_extracted_idnos_from_filename) && sizeof($va_extracted_idnos_from_filename)) {
foreach ($va_extracted_idnos_from_filename as $vs_idno) {
foreach ($va_create_relationship_for as $vs_rel_table) {
if (!isset($va_relationship_type_id_for[$vs_rel_table]) || !$va_relationship_type_id_for[$vs_rel_table]) {
continue;
}
$t_rel = $t_instance->getAppDatamodel()->getInstanceByTableName($vs_rel_table);
if ($t_rel->load(array($t_rel->getProperty('ID_NUMBERING_ID_FIELD') => $vs_idno))) {
$t_instance->addRelationship($vs_rel_table, $t_rel->getPrimaryKey(), $va_relationship_type_id_for[$vs_rel_table]);
if (!$t_instance->numErrors()) {
$va_notices[$t_instance->getPrimaryKey() . '_rel'] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $vs_label = $t_instance->getLabelForDisplay(), 'message' => $vs_msg = _t('Added relationship between <em>%1</em> and %2 <em>%3</em>', $vs_label, $t_rel->getProperty('NAME_SINGULAR'), $t_rel->getLabelForDisplay()), 'status' => 'RELATED');
$o_log->logInfo($vs_msg);
} else {
$va_notices[$t_instance->getPrimaryKey()] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $vs_label = $t_instance->getLabelForDisplay(), 'message' => $vs_msg = _t('Could not add relationship between <em>%1</em> and %2 <em>%3</em>: %4', $vs_label, $t_rel->getProperty('NAME_SINGULAR'), $t_rel->getLabelForDisplay(), join("; ", $t_instance->getErrors())), 'status' => 'ERROR');
$o_log->logError($vs_msg);
}
}
}
}
}
} else {
$va_notices[$vs_relative_directory . '/' . $f] = array('idno' => '', 'label' => $f, 'message' => $vs_msg = $vs_import_mode == 'ALWAYS_MATCH' ? _t('Skipped %1 from %2 because it could not be matched', $f, $vs_relative_directory) : _t('Skipped %1 from %2', $f, $vs_relative_directory), 'status' => 'SKIPPED');
$o_log->logInfo($vs_msg);
}
if (isset($pa_options['progressCallback']) && ($ps_callback = $pa_options['progressCallback'])) {
$ps_callback($po_request, $vn_c, $vn_num_items, _t("[%3/%4] Processing %1 (%3)", caTruncateStringWithEllipsis($vs_relative_directory, 20) . '/' . caTruncateStringWithEllipsis($f, 30), $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), $vn_c, $vn_num_items), $t_new_rep, time() - $vn_start_time, memory_get_usage(true), $vn_c, sizeof($va_errors));
}
$vn_c++;
}
if (isset($pa_options['progressCallback']) && ($ps_callback = $pa_options['progressCallback'])) {
$ps_callback($po_request, $vn_num_items, $vn_num_items, _t("Processing completed"), null, time() - $vn_start_time, memory_get_usage(true), $vn_c, sizeof($va_errors));
}
$vn_elapsed_time = time() - $vn_start_time;
if (isset($pa_options['reportCallback']) && ($ps_callback = $pa_options['reportCallback'])) {
$va_general = array('elapsedTime' => $vn_elapsed_time, 'numErrors' => sizeof($va_errors), 'numProcessed' => $vn_c, 'batchSize' => $vn_num_items, 'table' => $t_instance->tableName(), 'set_id' => $t_set->getPrimaryKey(), 'setName' => $t_set->getLabelForDisplay());
$ps_callback($po_request, $va_general, $va_notices, $va_errors);
}
$o_batch_log->close();
if ($vb_we_set_transaction) {
if (sizeof($va_errors) > 0) {
$o_trans->rollback();
} else {
$o_trans->commit();
}
}
$vs_set_name = $t_set->getLabelForDisplay();
$vs_started_on = caGetLocalizedDate($vn_start_time);
if (isset($pa_options['sendMail']) && $pa_options['sendMail']) {
if ($vs_email = trim($po_request->user->get('email'))) {
caSendMessageUsingView($po_request, array($vs_email => $po_request->user->get('fname') . ' ' . $po_request->user->get('lname')), __CA_ADMIN_EMAIL__, _t('[%1] Batch media import completed', $po_request->config->get('app_display_name')), 'batch_media_import_completed.tpl', array('notices' => $va_notices, 'errors' => $va_errors, 'directory' => $vs_relative_directory, 'numErrors' => sizeof($va_errors), 'numProcessed' => $vn_c, 'subjectNameSingular' => _t('file'), 'subjectNamePlural' => _t('files'), 'startedOn' => $vs_started_on, 'completedOn' => caGetLocalizedDate(time()), 'setName' => $vn_set_id ? $vs_set_name : null, 'elapsedTime' => caFormatInterval($vn_elapsed_time)));
}
}
if (isset($pa_options['sendSMS']) && $pa_options['sendSMS']) {
SMS::send($po_request->getUserID(), _t("[%1] Media import processing for directory %2 with %3 %4 begun at %5 is complete", $po_request->config->get('app_display_name'), $vs_relative_directory, $vn_num_items, $vn_num_items == 1 ? _t('file') : _t('files'), $vs_started_on));
}
$o_log->logInfo(_t("Media import processing for directory %1 with %2 %3 begun at %4 is complete", $vs_relative_directory, $vn_num_items, $vn_num_items == 1 ? _t('file') : _t('files')));
return array('errors' => $va_errors, 'notices' => $va_notices, 'processing_time' => caFormatInterval($vn_elapsed_time));
}
示例9: importMediaFromDirectory
//.........这里部分代码省略.........
// Calculate identifier using numbering plugin
$o_numbering_plugin = $t_object->getIDNoPlugInInstance();
if (!($vs_sep = $o_numbering_plugin->getSeparator())) {
$vs_sep = '';
}
if (!is_array($va_idno_values = $o_numbering_plugin->htmlFormValuesAsArray('idno', $vs_object_idno, false, false, true))) {
$va_idno_values = array();
}
$t_object->set('idno', join($vs_sep, $va_idno_values));
// true=always set serial values, even if they already have a value; this let's us use the original pattern while replacing the serial value every time through
break;
}
$t_object->insert();
if ($t_object->numErrors()) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Error creating new object while importing {$f} from {$vs_relative_directory}: " . join('; ', $t_object->getErrors())));
$va_errors[$vs_relative_directory . '/' . $f] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_object->getLabelForDisplay(), 'errors' => $t_object->errors(), 'message' => _t("Error creating new object while importing %1 from %2: %3", $f, $vs_relative_directory, join('; ', $t_object->getErrors())), 'status' => 'ERROR');
$o_trans->rollback();
continue;
}
$t_object->addLabel(array('name' => $f), $vn_locale_id, null, true);
if ($t_object->numErrors()) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Error creating object label while importing {$f} from {$vs_relative_directory}: " . join('; ', $t_object->getErrors())));
$va_errors[$vs_relative_directory . '/' . $f] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_object->getLabelForDisplay(), 'errors' => $t_object->errors(), 'message' => _t("Error creating object label while importing %1 from %2: %3", $f, $vs_relative_directory, join('; ', $t_object->getErrors())), 'status' => 'ERROR');
$o_trans->rollback();
continue;
}
$t_new_rep = $t_object->addRepresentation($vs_directory . '/' . $f, $vn_rep_type_id, $vn_locale_id, $vn_object_representation_status, $vn_object_representation_access, true, array(), array('original_filename' => $f, 'returnRepresentation' => true));
if ($t_object->numErrors()) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Error importing {$f} from {$vs_relative_directory}: " . join('; ', $t_object->getErrors())));
$va_errors[$vs_relative_directory . '/' . $f] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_object->getLabelForDisplay(), 'errors' => $t_object->errors(), 'message' => _t("Error importing %1 from %2: %3", $f, $vs_relative_directory, join('; ', $t_object->getErrors())), 'status' => 'ERROR');
$o_trans->rollback();
continue;
} else {
if ($vb_delete_media_on_import) {
@unlink($vs_directory . '/' . $f);
}
}
}
}
if ($t_object->getPrimaryKey()) {
$va_notices[$t_object->getPrimaryKey()] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_object->getLabelForDisplay(), 'message' => _t('Imported %1 as %2', $f, $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD'))), 'status' => 'SUCCESS');
if ($vn_set_id) {
$t_set->addItem($t_object->getPrimaryKey(), null, $po_request->getUserID());
}
$o_log->addItem($t_object->getPrimaryKey(), $t_object->getErrors());
// Create relationships?
if (is_array($va_create_relationship_for) && sizeof($va_create_relationship_for) && is_array($va_extracted_idnos_from_filename) && sizeof($va_extracted_idnos_from_filename)) {
foreach ($va_extracted_idnos_from_filename as $vs_idno) {
foreach ($va_create_relationship_for as $vs_rel_table) {
if (!isset($va_relationship_type_id_for[$vs_rel_table]) || !$va_relationship_type_id_for[$vs_rel_table]) {
continue;
}
$t_rel = $t_object->getAppDatamodel()->getInstanceByTableName($vs_rel_table);
if ($t_rel->load(array($t_rel->getProperty('ID_NUMBERING_ID_FIELD') => $vs_idno))) {
$t_object->addRelationship($vs_rel_table, $t_rel->getPrimaryKey(), $va_relationship_type_id_for[$vs_rel_table]);
if (!$t_object->numErrors()) {
$va_notices[$t_object->getPrimaryKey() . '_rel'] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $vs_label = $t_object->getLabelForDisplay(), 'message' => _t('Added relationship between <em>%1</em> and %2 <em>%3</em>', $vs_label, $t_rel->getProperty('NAME_SINGULAR'), $t_rel->getLabelForDisplay()), 'status' => 'RELATED');
} else {
$va_notices[$t_object->getPrimaryKey()] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $vs_label = $t_object->getLabelForDisplay(), 'message' => _t('Could not add relationship between <em>%1</em> and %2 <em>%3</em>: %4', $vs_label, $t_rel->getProperty('NAME_SINGULAR'), $t_rel->getLabelForDisplay(), join("; ", $t_object->getErrors())), 'status' => 'ERROR');
}
}
}
}
}
} else {
$va_notices[$vs_relative_directory . '/' . $f] = array('idno' => '', 'label' => $f, 'message' => $vs_import_mode == 'ALWAYS_MATCH' ? _t('Skipped %1 from %2 because it could not be matched', $f, $vs_relative_directory) : _t('Skipped %1 from %2', $f, $vs_relative_directory), 'status' => 'SKIPPED');
}
if (isset($pa_options['progressCallback']) && ($ps_callback = $pa_options['progressCallback'])) {
$ps_callback($po_request, $vn_c, $vn_num_items, _t("[%3/%4] Processing %1 (%3)", caTruncateStringWithEllipsis($vs_relative_directory, 20) . '/' . caTruncateStringWithEllipsis($f, 30), $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), $vn_c, $vn_num_items), $t_new_rep, time() - $vn_start_time, memory_get_usage(true), sizeof($va_notices), sizeof($va_errors));
}
$vn_c++;
}
if (isset($pa_options['progressCallback']) && ($ps_callback = $pa_options['progressCallback'])) {
$ps_callback($po_request, $vn_num_items, $vn_num_items, _t("Processing completed"), null, time() - $vn_start_time, memory_get_usage(true), sizeof($va_notices), sizeof($va_errors));
}
$vn_elapsed_time = time() - $vn_start_time;
if (isset($pa_options['reportCallback']) && ($ps_callback = $pa_options['reportCallback'])) {
$va_general = array('elapsedTime' => $vn_elapsed_time, 'numErrors' => sizeof($va_errors), 'numProcessed' => sizeof($va_notices), 'batchSize' => $vn_num_items, 'table' => 'ca_objects', 'set_id' => $t_set->getPrimaryKey(), 'setName' => $t_set->getLabelForDisplay());
$ps_callback($po_request, $va_general, $va_notices, $va_errors);
}
$o_log->close();
if ($vb_we_set_transaction) {
if (sizeof($va_errors) > 0) {
$o_trans->rollback();
} else {
$o_trans->commit();
}
}
$vs_set_name = $t_set->getLabelForDisplay();
$vs_started_on = caGetLocalizedDate($vn_start_time);
if (isset($pa_options['sendMail']) && $pa_options['sendMail']) {
if ($vs_email = trim($po_request->user->get('email'))) {
caSendMessageUsingView($po_request, array($vs_email => $po_request->user->get('fname') . ' ' . $po_request->user->get('lname')), __CA_ADMIN_EMAIL__, _t('[%1] Batch media import completed', $po_request->config->get('app_display_name')), 'batch_media_import_completed.tpl', array('notices' => $va_notices, 'errors' => $va_errors, 'directory' => $vs_relative_directory, 'numErrors' => sizeof($va_errors), 'numProcessed' => sizeof($va_notices), 'subjectNameSingular' => _t('file'), 'subjectNamePlural' => _t('files'), 'startedOn' => $vs_started_on, 'completedOn' => caGetLocalizedDate(time()), 'setName' => $vn_set_id ? $vs_set_name : null, 'elapsedTime' => caFormatInterval($vn_elapsed_time)));
}
}
if (isset($pa_options['sendSMS']) && $pa_options['sendSMS']) {
SMS::send($po_request->getUserID(), _t("[%1] Media import processing for directory %2 with %3 %4 begun at %5 is complete", $po_request->config->get('app_display_name'), $vs_relative_directory, $vn_num_items, $vn_num_items == 1 ? _t('file') : _t('files'), $vs_started_on));
}
return array('errors' => $va_errors, 'notices' => $va_notices, 'processing_time' => caFormatInterval($vn_elapsed_time));
}
示例10: testAddAndGetSetItem
/**
* @link http://clangers.collectiveaccess.org/jira/browse/PROV-434
*/
public function testAddAndGetSetItem()
{
$t_set = new ca_sets($this->opn_set_id);
$t_set->setMode(ACCESS_WRITE);
// "quick" add object (this method uses direct INSERT queries)
$t_set->addItems(array($this->opn_object_id));
$va_set_items = $t_set->getItems();
// get rid of unneeded nesting in array. we should only have one label in one locale.
$this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
$va_set_items = array_shift($va_set_items);
$this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
$va_set_items = array_shift($va_set_items);
// basic checks
$this->assertArrayHasKey('caption', $va_set_items, 'Set item must have empty/blank label');
$this->assertEquals('[BLANK]', $va_set_items['caption'], 'Set item must have empty/blank label');
$this->assertArrayHasKey('row_id', $va_set_items, 'Set item must be related to object');
$this->assertEquals($this->opn_object_id, $va_set_items['row_id'], 'Set item must be related to object');
//
// this is (hopefully was?) the actual PROV-434 bug
// @see http://clangers.collectiveaccess.org/jira/browse/PROV-434
//
$va_items = $t_set->get('ca_set_items', array('returnWithStructure' => true));
$this->assertEquals(1, sizeof($va_items));
$va_item = array_shift($va_items);
$this->assertArrayHasKey('caption', $va_item, 'Set item must have empty/blank label');
$this->assertEquals('[BLANK]', $va_item['caption'], 'Set item must have empty/blank label');
$this->assertArrayHasKey('record_id', $va_item, 'Set item must be related to object');
$this->assertEquals($this->opn_object_id, $va_item['record_id'], 'Set item must be related to object');
// try text (no return as array)
$vs_ret = $t_set->get('ca_set_items.item_id');
// what comes out is a string with the primary key
$this->assertRegExp("/^[0-9]+\$/", $vs_ret);
$vs_ret = $t_set->get('ca_set_items.preferred_labels');
$this->assertEquals("[BLANK]", $vs_ret);
$vs_ret = $t_set->get('ca_set_items.row_id');
$this->assertEquals((string) $this->opn_object_id, $vs_ret);
// remove item
$t_set->removeItem($this->opn_object_id);
$this->assertEmpty($t_set->getItems());
// re-add object using model method (as opposed to direct insert addItems() above)
$t_set->addItem($this->opn_object_id);
// basic checks (again)
$va_set_items = $t_set->getItems();
// get rid of unneeded nesting in array. we should only have one label in one locale.
$this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
$va_set_items = array_shift($va_set_items);
$this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
$va_set_items = array_shift($va_set_items);
$this->assertArrayHasKey('caption', $va_set_items, 'Set item must have empty/blank label');
$this->assertEquals('[BLANK]', $va_set_items['caption'], 'Set item must have empty/blank label');
$this->assertArrayHasKey('row_id', $va_set_items, 'Set item must be related to object');
$this->assertEquals($this->opn_object_id, $va_set_items['row_id'], 'Set item must be related to object');
//
// this is (hopefully was?) the actual PROV-434 bug
// @see http://clangers.collectiveaccess.org/jira/browse/PROV-434
//
$va_items = $t_set->get('ca_set_items', array('returnWithStructure' => true));
$this->assertEquals(1, sizeof($va_items));
$va_item = array_shift($va_items);
$this->assertArrayHasKey('caption', $va_item, 'Set item must have empty/blank label');
$this->assertEquals('[BLANK]', $va_item['caption'], 'Set item must have empty/blank label');
$this->assertArrayHasKey('record_id', $va_item, 'Set item must be related to object');
$this->assertEquals($this->opn_object_id, $va_item['record_id'], 'Set item must be related to object');
}