public function setUp() { $t_list = new ca_lists(); // add a minimal object for testing $va_object_types = $t_list->getItemsForList('object_types', array('idsOnly' => true, 'enabledOnly' => true)); $t_object = new ca_objects(); $t_object->setMode(ACCESS_WRITE); $t_object->set('type_id', array_shift($va_object_types)); $t_object->insert(); $this->opn_object_id = $t_object->getPrimaryKey(); $this->assertGreaterThan(0, $this->opn_object_id, 'Object should have a primary key after insert'); // add minimal set $va_set_types = $t_list->getItemsForList('set_types', array('idsOnly' => true, 'enabledOnly' => true)); $t_set = new ca_sets(); $t_set->setMode(ACCESS_WRITE); $t_set->set('type_id', array_shift($va_set_types)); $t_set->set('table_num', $t_object->tableNum()); $t_set->insert(); $this->opn_set_id = $t_set->getPrimaryKey(); $this->assertGreaterThan(0, $this->opn_set_id, 'Set should have a primary key after insert'); }
/** * */ public function insert($pa_options = null) { $t_trans = new ca_commerce_transactions($this->get('transaction_id')); if ($t_trans->getPrimaryKey()) { if ($vn_set_id = $t_trans->get('set_id')) { $t_set = new ca_sets($vn_set_id); if ($t_set->getPrimaryKey()) { $va_row_ids = $t_set->getItemRowIDs(); $this->set('set_snapshot', array('table_num' => $t_set->get('table_num'), 'set_id' => $vn_set_id, 'datetime' => time(), 'items' => $va_row_ids)); } } return parent::insert($pa_options); } else { $this->postError(1500, _t('Transaction does not exist'), 'ca_commerce_communications->insert()'); return false; } }
public function getSetXML() { $pn_set_id = $this->request->getParameter('set_id', pInteger); $t_set = new ca_sets($pn_set_id); if (!$t_set->getPrimaryKey()) { $this->notification->addNotification(_t("The collection does not exist"), __NOTIFICATION_TYPE_ERROR__); $this->Edit(); return; } if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_READ_ACCESS__)) { $this->notification->addNotification(_t("You cannot view this collection"), __NOTIFICATION_TYPE_INFO__); $this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form')); return; } if ($this->request->config->get("dont_enforce_access_settings")) { $va_access_values = array(); } else { $va_access_values = caGetUserAccessValues($this->request); } $this->view->setVar('set_id', $pn_set_id); $this->view->setVar('t_set', $t_set); $this->view->setVar('items', caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersion' => 'large', 'checkAccess' => $va_access_values, 'user_id' => $this->request->getUserID())))); $this->render('Sets/xml_set_items.php'); }
/** * Uses _getSetID() to figure out the ID of the current set, then returns a ca_sets object for it * and also sets the 'current_set_id' user variable */ private function _getSet($vs_access_level = __CA_SET_EDIT_ACCESS__) { $t_set = new ca_sets(); $vn_set_id = $this->_getSetID(); if ($vn_set_id) { $t_set->load($vn_set_id); if ($t_set->getPrimaryKey() && $t_set->haveAccessToSet($this->request->getUserID(), $vs_access_level)) { $this->request->user->setVar('current_set_id', $vn_set_id); # --- pass the access level the user has to the set - needed to display the proper controls in views $vb_write_access = false; if ($t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) { $vb_write_access = true; } $this->view->setVar("write_access", $vb_write_access); return $t_set; } } return null; }
/** * Sets up view variables for upper-left-hand info panel (aka. "inspector"). Actual rendering is performed by calling sub-class. * * @param array $pa_parameters Array of parameters as specified in navigation.conf, including primary key value and type_id */ public function info($pa_parameters) { $vn_set_id = $this->request->getParameter('set_id', pInteger); $o_dm = Datamodel::load(); $t_set = new ca_sets($vn_set_id); if (!$t_set->getPrimaryKey()) { die("Invalid set"); } // Does user have access to set? if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_READ_ACCESS__)) { die("You don't have access to the set"); } $t_item = $o_dm->getInstanceByTableNum($t_set->get('table_num'), true); $this->view->setVar('t_set', $t_set); $this->view->setVar('t_item', $t_item); $this->view->setVar('screen', $this->request->getActionExtra()); // name of screen $this->view->setVar('result_context', $this->getResultContext()); return $this->render('editor/widget_batch_info_html.php', true); }
/** * @param array $pa_options * progressCallback = * reportCallback = * sendMail = */ public static function importMediaFromDirectory($po_request, $pa_options = null) { global $g_ui_locale_id; $t_object = new ca_objects(); $o_eventlog = new Eventlog(); $t_set = new ca_sets(); $va_notices = $va_errors = array(); $vb_we_set_transaction = false; $o_trans = isset($pa_options['transaction']) && $pa_options['transaction'] ? $pa_options['transaction'] : null; if (!$o_trans) { $vb_we_set_transaction = true; $o_trans = new Transaction(); } $o_log = new Batchlog(array('user_id' => $po_request->getUserID(), 'batch_type' => 'MI', 'table_num' => (int) $t_object->tableNum(), 'notes' => '', 'transaction' => $o_trans)); if (!is_dir($pa_options['importFromDirectory'])) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Specified import directory is invalid")); return null; } $vs_batch_media_import_root_directory = $po_request->config->get('batch_media_import_root_directory'); if (!preg_match("!^{$vs_batch_media_import_root_directory}!", $pa_options['importFromDirectory'])) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Specified import directory is invalid")); return null; } if (preg_match("!/\\.\\.!", $vs_directory) || preg_match("!\\.\\./!", $pa_options['importFromDirectory'])) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => "Specified import directory is invalid")); return null; } $vb_include_subdirectories = (bool) $pa_options['includeSubDirectories']; $vb_delete_media_on_import = (bool) $pa_options['deleteMediaOnImport']; $vs_import_mode = $pa_options['importMode']; $vs_match_mode = $pa_options['matchMode']; $vn_object_type_id = $pa_options['ca_objects_type_id']; $vn_rep_type_id = $pa_options['ca_object_representations_type_id']; $vn_object_access = $pa_options['ca_objects_access']; $vn_object_representation_access = $pa_options['ca_object_representations_access']; $vn_object_status = $pa_options['ca_objects_status']; $vn_object_representation_status = $pa_options['ca_object_representations_status']; $vs_idno_mode = $pa_options['idnoMode']; $vs_idno = $pa_options['idno']; $vs_set_mode = $pa_options['setMode']; $vs_set_create_name = $pa_options['setCreateName']; $vn_set_id = $pa_options['set_id']; $vn_locale_id = $pa_options['locale_id']; $vs_skip_file_list = $pa_options['skipFileList']; $va_relationship_type_id_for = array(); if (is_array($va_create_relationship_for = $pa_options['create_relationship_for'])) { foreach ($va_create_relationship_for as $vs_rel_table) { $va_relationship_type_id_for[$vs_rel_table] = $pa_options['relationship_type_id_for_' . $vs_rel_table]; } } if (!$vn_locale_id) { $vn_locale_id = $g_ui_locale_id; } $va_files_to_process = caGetDirectoryContentsAsList($pa_options['importFromDirectory'], $vb_include_subdirectories); if ($vs_set_mode == 'add') { $t_set->load($vn_set_id); } else { if ($vs_set_mode == 'create' && $vs_set_create_name) { $va_set_ids = $t_set->getSets(array('user_id' => $po_request->getUserID(), 'table' => 'ca_objects', 'access' => __CA_SET_EDIT_ACCESS__, 'setIDsOnly' => true, 'name' => $vs_set_create_name)); $vn_set_id = null; if (is_array($va_set_ids) && sizeof($va_set_ids) > 0) { $vn_possible_set_id = array_shift($va_set_ids); if ($t_set->load($vn_possible_set_id)) { $vn_set_id = $t_set->getPrimaryKey(); } } else { $vs_set_code = mb_substr(preg_replace("![^A-Za-z0-9_\\-]+!", "_", $vs_set_create_name), 0, 100); if ($t_set->load(array('set_code' => $vs_set_code))) { $vn_set_id = $t_set->getPrimaryKey(); } } if (!$t_set->getPrimaryKey()) { $t_set->setMode(ACCESS_WRITE); $t_set->set('user_id', $po_request->getUserID()); $t_set->set('type_id', $po_request->config->get('ca_sets_default_type')); $t_set->set('table_num', $t_object->tableNum()); $t_set->set('set_code', $vs_set_code); $t_set->insert(); if ($t_set->numErrors()) { $va_notices['create_set'] = array('idno' => '', 'label' => _t('Create set %1', $vs_set_create_name), 'message' => _t('Failed to create set %1: %2', $vs_set_create_name, join("; ", $t_set->getErrors())), 'status' => 'SET ERROR'); } else { $t_set->addLabel(array('name' => $vs_set_create_name), $vn_locale_id, null, true); if ($t_set->numErrors()) { $va_notices['add_set_label'] = array('idno' => '', 'label' => _t('Add label to set %1', $vs_set_create_name), 'message' => _t('Failed to add label to set: %1', join("; ", $t_set->getErrors())), 'status' => 'SET ERROR'); } $vn_set_id = $t_set->getPrimaryKey(); } } } else { $vn_set_id = null; // no set } } if ($t_set->getPrimaryKey() && !$t_set->haveAccessToSet($po_request->getUserID(), __CA_SET_EDIT_ACCESS__)) { $va_notices['set_access'] = array('idno' => '', 'label' => _t('You do not have access to set %1', $vs_set_create_name), 'message' => _t('Cannot add to set %1 because you do not have edit access', $vs_set_create_name), 'status' => 'SET ERROR'); $vn_set_id = null; $t_set = new ca_sets(); } $vn_num_items = sizeof($va_files_to_process); // Get list of regex packages that user can use to extract object idno's from filenames $va_regex_list = $po_request->config->getAssoc('mediaFilenameToObjectIdnoRegexes'); if (!is_array($va_regex_list)) { $va_regex_list = array(); } // Get list of files (or file name patterns) to skip $va_skip_list = preg_split("![\r\n]+!", $vs_skip_file_list); foreach ($va_skip_list as $vn_i => $vs_skip) { if (!strlen($va_skip_list[$vn_i] = trim($vs_skip))) { unset($va_skip_list[$vn_i]); } } $vn_c = 0; $vn_start_time = time(); $va_report = array(); foreach ($va_files_to_process as $vs_file) { $va_tmp = explode("/", $vs_file); $f = array_pop($va_tmp); $d = array_pop($va_tmp); array_push($va_tmp, $d); $vs_directory = join("/", $va_tmp); // Skip file names using $vs_skip_file_list if (BatchProcessor::_skipFile($f, $va_skip_list)) { continue; } $vs_relative_directory = preg_replace("!{$vs_batch_media_import_root_directory}[/]*!", "", $vs_directory); // does representation already exist? if (ca_object_representations::mediaExists($vs_file)) { $va_notices[$vs_relative_directory . '/' . $f] = array('idno' => '', 'label' => $f, 'message' => _t('Skipped %1 from %2 because it already exists', $f, $vs_relative_directory), 'status' => 'SKIPPED'); continue; } $t_object = new ca_objects(); $t_object->setTransaction($o_trans); $vs_modified_filename = $f; $va_extracted_idnos_from_filename = array(); if (in_array($vs_import_mode, array('TRY_TO_MATCH', 'ALWAYS_MATCH')) || is_array($va_create_relationship_for) && sizeof($va_create_relationship_for)) { foreach ($va_regex_list as $vs_regex_name => $va_regex_info) { foreach ($va_regex_info['regexes'] as $vs_regex) { $va_names_to_match = array(); switch ($vs_match_mode) { case 'DIRECTORY_NAME': $va_names_to_match = array($d); break; case 'FILE_AND_DIRECTORY_NAMES': $va_names_to_match = array($f, $d); break; default: case 'FILE_NAME': $va_names_to_match = array($f); break; } foreach ($va_names_to_match as $vs_match_name) { if (preg_match('!' . $vs_regex . '!', $vs_match_name, $va_matches)) { if (!$vs_idno || strlen($va_matches[1]) < strlen($vs_idno)) { $vs_idno = $va_matches[1]; } if (!$vs_modified_filename || strlen($vs_modified_filename) > strlen($va_matches[1])) { $vs_modified_filename = $va_matches[1]; } $va_extracted_idnos_from_filename[] = $va_matches[1]; if (in_array($vs_import_mode, array('TRY_TO_MATCH', 'ALWAYS_MATCH'))) { if ($t_object->load(array('idno' => $va_matches[1], 'deleted' => 0))) { $va_notices[$vs_relative_directory . '/' . $vs_match_name . '_match'] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_object->getLabelForDisplay(), 'message' => _t('Matched media %1 from %2 to object using %2', $f, $vs_relative_directory, $vs_regex_name), 'status' => 'MATCHED'); break 3; } } } } } } } if (!$t_object->getPrimaryKey()) { // Use filename as idno if all else fails if ($t_object->load(array('idno' => $f, 'deleted' => 0))) { $va_notices[$vs_relative_directory . '/' . $f . '_match'] = array('idno' => $t_object->get($t_object->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_object->getLabelForDisplay(), 'message' => _t('Matched media %1 from %2 to object using filename', $f, $vs_relative_directory), 'status' => 'MATCHED'); } } $t_new_rep = null; if ($t_object->getPrimaryKey()) { // found existing object $t_object->setMode(ACCESS_WRITE); $t_new_rep = $t_object->addRepresentation($vs_directory . '/' . $f, $vn_rep_type_id, $vn_locale_id, $vn_object_representation_status, $vn_object_representation_access, false, 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_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); } } } else { // should we create new object? if (in_array($vs_import_mode, array('TRY_TO_MATCH', 'DONT_MATCH'))) { $t_object->setMode(ACCESS_WRITE); $t_object->set('type_id', $vn_object_type_id); $t_object->set('locale_id', $vn_locale_id); $t_object->set('status', $vn_object_status); $t_object->set('access', $vn_object_access); switch ($vs_idno_mode) { case 'filename': // use the filename as identifier $t_object->set('idno', $f); break; case 'directory_and_filename': // use the directory + filename as identifier $t_object->set('idno', $d . '/' . $f); break; default: // 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)); }
/** * Download (accessible) media for all records in this set */ public function getSetMedia() { set_time_limit(600); // allow a lot of time for this because the sets can be potentially large $o_dm = Datamodel::load(); $t_set = new ca_sets($this->request->getParameter('set_id', pInteger)); if (!$t_set->getPrimaryKey()) { $this->notification->addNotification(_t('No set defined'), __NOTIFICATION_TYPE_ERROR__); $this->opo_response->setRedirect(caEditorUrl($this->opo_request, 'ca_sets', $t_set->getPrimaryKey())); return false; } $va_record_ids = array_keys($t_set->getItemRowIDs(array('limit' => 100000))); if (!is_array($va_record_ids) || !sizeof($va_record_ids)) { $this->notification->addNotification(_t('No media is available for download'), __NOTIFICATION_TYPE_ERROR__); $this->opo_response->setRedirect(caEditorUrl($this->opo_request, 'ca_sets', $t_set->getPrimaryKey())); return false; } $vs_subject_table = $o_dm->getTableName($t_set->get('table_num')); $t_instance = $o_dm->getInstanceByTableName($vs_subject_table); $qr_res = $vs_subject_table::createResultSet($va_record_ids); $qr_res->filterNonPrimaryRepresentations(false); $va_paths = array(); while ($qr_res->nextHit()) { $va_original_paths = $qr_res->getMediaPaths('ca_object_representations.media', 'original'); if (sizeof($va_original_paths) > 0) { $va_paths[$qr_res->get($t_instance->primaryKey())] = array('idno' => $qr_res->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'paths' => $va_original_paths); } } if (sizeof($va_paths) > 0) { $vs_tmp_name = caGetTempFileName('DownloadSetMedia', 'zip'); $o_phar = new PharData($vs_tmp_name, null, null, Phar::ZIP); foreach ($va_paths as $vn_pk => $va_path_info) { $vn_c = 1; foreach ($va_path_info['paths'] as $vs_path) { if (!file_exists($vs_path)) { continue; } $vs_filename = $va_path_info['idno'] ? $va_path_info['idno'] : $vn_pk; $vs_filename .= "_{$vn_c}"; if ($vs_ext = pathinfo($vs_path, PATHINFO_EXTENSION)) { $vs_filename .= ".{$vs_ext}"; } $o_phar->addFile($vs_path, $vs_filename); $vn_c++; } } $o_view = new View($this->request, $this->request->getViewsDirectoryPath() . '/bundles/'); // send download $vs_set_code = $t_set->get('set_code'); $o_view->setVar('tmp_file', $vs_tmp_name); $o_view->setVar('download_name', 'media_for_' . mb_substr(preg_replace('![^A-Za-z0-9]+!u', '_', $vs_set_code ? $vs_set_code : $t_set->getPrimaryKey()), 0, 20) . '.zip'); $this->response->addContent($o_view->render('ca_sets_download_media.php')); return; } else { $this->notification->addNotification(_t('No media is available for download'), __NOTIFICATION_TYPE_ERROR__); $this->opo_response->setRedirect(caEditorUrl($this->opo_request, 'ca_sets', $t_set->getPrimaryKey())); return; } return $this->Edit(); }
/** * Returns content for overlay containing details for object representation linked to occurrence */ public function getSetsOverlay() { $this->view->setVar('display_type', 'media_overlay'); $pn_set_id = $this->request->getParameter('set_id', pInteger); $pn_object_id = $this->request->getParameter('object_id', pInteger); $this->view->setVar('object_id', $pn_object_id); $pn_representation_id = $this->request->getParameter('representation_id', pInteger); $this->opo_plugin_config = Configuration::load($this->request->getAppConfig()->get('application_plugins') . '/simpleGallery/conf/simpleGallery.conf'); $this->view->setVar('set_id', $pn_set_id); $t_set = new ca_sets($pn_set_id); $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger); $this->view->setVar('set_item_id', $pn_set_item_id); $ps_set_item_description_code = $this->opo_plugin_config->get('set_item_description_element_code'); $this->view->setVar('set_item_description', $ps_set_item_description_code); $this->view->setVar('object_id', $pn_object_id); $t_object = new ca_objects($pn_object_id); $this->view->setVar('t_object', $t_object); $t_rep = new ca_object_representations($pn_representation_id); $this->view->setVar('representation_id', $pn_representation_id); $this->view->setVar('t_object_representation', $t_rep); if ($this->request->config->get("dont_enforce_access_settings")) { $va_access_values = array(); } else { $va_access_values = caGetUserAccessValues($this->request); } if (!$t_set->getPrimaryKey()) { die("Invalid set_id"); } if (!$t_object->getPrimaryKey()) { die("Invalid object_id"); } if (!$t_rep->getPrimaryKey()) { die("Invalid representation_id"); } if (sizeof($va_access_values) && !in_array($t_set->get('access'), $va_access_values)) { die("Invalid set_id"); } if (sizeof($va_access_values) && !in_array($t_object->get('access'), $va_access_values)) { die("Invalid object_id"); } if (sizeof($va_access_values) && !in_array($t_rep->get('access'), $va_access_values)) { die("Invalid rep_id"); } // Get media for display using configured rules $va_rep_display_info = caGetMediaDisplayInfo("media_overlay", $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE')); // set version $this->view->setVar('version', $va_rep_display_info['display_version']); unset($va_display_info['display_version']); // set other options $this->view->setVar('display_options', $va_rep_display_info); if (!($ps_containerID = trim($this->request->getParameter('containerID', pString)))) { $ps_containerID = 'caMediaPanelContentArea'; } $this->view->setVar("containerID", $ps_containerID); // Get all objects asscoiated with this set and show primary reps as icons for navigation $va_set_items = $t_set->getItems(array("checkAccess" => $va_access_values)); #print "<pre>"; #print_r($va_set_items); #print "</pre>"; if (sizeof($va_set_items) > 0) { $t_image_objects = new ca_objects(); $i = 1; foreach ($va_set_items as $vn_rel_id => $va_inter) { foreach ($va_inter as $id => $va_info) { $t_image_objects->load($va_info["row_id"]); if ($t_primary_rep = $t_image_objects->getPrimaryRepresentationInstance()) { $va_temp = array(); if (!sizeof($va_access_values) || in_array($t_primary_rep->get('access'), $va_access_values)) { $va_temp["representation_id"] = $t_primary_rep->get("representation_id"); $va_temp["rep_icon"] = $t_primary_rep->getMediaTag('media', 'icon'); $va_temp["rep_tinyicon"] = $t_primary_rep->getMediaTag('media', 'tinyicon'); $va_temp["object_id"] = $va_info["object_id"]; $va_temp["set_item_id"] = $va_info['item_id']; $va_thumbnails[$va_info["object_id"]] = $va_temp; if ($vn_getNext == 1) { $this->view->setVar("next_object_id", $va_info["object_id"]); $this->view->setVar("next_representation_id", $t_primary_rep->get("representation_id")); $vn_getNext = 0; } if ($va_info["object_id"] == $pn_object_id) { $this->view->setVar("representation_index", $i); $this->view->setVar("previous_object_id", $vn_prev_obj_id); $this->view->setVar("previous_representation_id", $vn_prev_rep_id); $this->view->setVar("set_item_id", $va_info['item_id']); $vn_getNext = 1; } $vn_prev_obj_id = $va_info["object_id"]; $vn_prev_rep_id = $t_primary_rep->get("representation_id"); $i++; } } } } } $this->view->setVar('reps', $va_thumbnails); return $this->render($this->ops_theme . "/ajax_ca_sets_media_overlay_html.php"); }
function Index() { // Remove any browse criteria previously set $this->opo_browse->removeAllCriteria(); parent::Index(true); JavascriptLoadManager::register('imageScroller'); JavascriptLoadManager::register('browsable'); JavascriptLoadManager::register('tabUI'); $t_object = new ca_objects(); $t_featured = new ca_sets(); if ($this->request->config->get("dont_enforce_access_settings")) { $va_access_values = array(); } else { $va_access_values = caGetUserAccessValues($this->request); } # --- featured items set - set name assigned in app.conf $featured_sets = $this->request->config->get('featured_sets'); $len = count($featured_sets); if ($len > 3) { $len = 3; } for ($i = 0; $i < $len; $i++) { $t_featured->load(array('set_code' => $featured_sets[$i])); $set_id = $t_featured->getPrimaryKey(); $set_title = $t_featured->getLabelForDisplay(); $set_desc = $t_featured->getAttributeFromSets('description', array(0 => $set_id)); $va_featured_ids = array_keys(is_array($va_tmp = $t_featured->getItemRowIDs(array('checkAccess' => $va_access_values, 'shuffle' => 0))) ? $va_tmp : array()); // These are the object ids in the set if (is_array($va_featured_ids) && sizeof($va_featured_ids) > 0) { $t_object = new ca_objects($va_featured_ids[0]); $va_rep = $t_object->getPrimaryRepresentation(array('thumbnail', 'small', 'medium', 'mediumlarge', 'preview', 'widepreview'), null, array('return_with_access' => $va_access_values)); $featured_set_id_array[$i] = array('featured_set_code' => $featured_sets[$i], 'featured_content_id' => $va_featured_ids[0], 'featured_content_small' => $va_rep["tags"]["small"], 'featured_content_label' => $set_title, 'featured_content_description' => $set_desc[$set_id][0], 'featured_set_id' => $set_id); } } $this->view->setVar('featured_set_id_array', $featured_set_id_array); # --- user favorites get the highest ranked objects to display $va_user_favorites_items = $t_object->getHighestRated(true, 12, $va_access_values); if (sizeof($va_user_favorites_items) > 0) { if (is_array($va_user_favorites_items) && sizeof($va_user_favorites_items) > 0) { $t_object = new ca_objects($va_user_favorites_items[0]); $va_rep = $t_object->getPrimaryRepresentation(array('thumbnail', 'small', 'preview', 'widepreview'), null, array('return_with_access' => $va_access_values)); $this->view->setVar('user_favorites_id', $va_user_favorites_items[0]); $this->view->setVar('user_favorites_thumb', $va_rep["tags"]["thumbnail"]); $this->view->setVar('user_favorites_small', $va_rep["tags"]["small"]); $this->view->setVar('user_favorites_preview', $va_rep["tags"]["preview"]); $this->view->setVar('user_favorites_widepreview', $va_rep["tags"]["widepreview"]); } } else { $this->view->setVar('user_favorites_is_random', 1); # if no ranks set, choose a random object $va_random_items = $t_object->getRandomItems(1, array('checkAccess' => $va_access_values, 'hasRepresentations' => 1)); $va_labels = $t_object->getPreferredDisplayLabelsForIDs(array_keys($va_random_items)); $va_media = $t_object->getPrimaryMediaForIDs(array_keys($va_random_items), array('small', 'thumbnail', 'preview', 'medium', 'widepreview'), array("checkAccess" => $va_access_values)); foreach ($va_random_items as $vn_object_id => $va_object_info) { $va_object_info['title'] = $va_labels[$vn_object_id]; $va_object_info['media'] = $va_media[$vn_object_id]; $va_random_items[$vn_object_id] = $va_object_info; } $this->view->setVar('random_objects', $va_random_items); if (is_array($va_random_items) && sizeof($va_random_items) > 0) { $va_object_info = array_shift($va_random_items); $this->view->setVar('user_favorites_id', $va_object_info['object_id']); $this->view->setVar('user_favorites_thumb', $va_media[$va_object_info['object_id']]["tags"]["thumbnail"]); $this->view->setVar('user_favorites_small', $va_media[$va_object_info['object_id']]["tags"]["small"]); $this->view->setVar('user_favorites_preview', $va_media[$va_object_info['object_id']]["tags"]["preview"]); $this->view->setVar('user_favorites_widepreview', $va_media[$va_object_info['object_id']]["tags"]["widepreview"]); $this->view->setVar('user_favorites_medium', $va_media[$va_object_info['object_id']]["tags"]["medium"]); } } #---- new 'recently added' $t_set = new ca_sets(); $ra_set_code = $this->request->config->get('recently_added_set_id'); $t_set->load(array('set_code' => $ra_set_code)); $set_id = $t_set->getPrimaryKey(); $ra_items = caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersions' => array('thumbnail', 'preview'), "checkAccess" => 1))); $va_recently_added = array(); foreach ($ra_items as $va_item_info) { $vn_r_object_id = $va_item_info['object_id']; $t_object->load($vn_r_object_id); $va_reps = $t_object->getPrimaryRepresentation(array('thumbnail', 'preview'), null, array('return_with_access' => $va_access_values)); $va_recently_added[$vn_r_object_id] = $va_reps["tags"]["preview"]; } # --- get the 12 most recently added objects to display /*$va_recently_added_ids = $t_object->getRecentlyAddedItems(15, array('checkAccess' => $va_access_values, 'hasRepresentations' => 1)); if(is_array($va_recently_added_ids) && sizeof($va_recently_added_ids) > 0){ $va_recently_added = array(); foreach($va_recently_added_ids as $va_item_info){ $vn_r_object_id = $va_item_info['object_id']; $t_object->load($vn_r_object_id); $va_reps = $t_object->getPrimaryRepresentation(array('thumbnail', 'preview'), null, array('return_with_access' => $va_access_values)); $va_recently_added[$vn_r_object_id] = $va_reps["tags"]["preview"]; } }*/ $this->view->setVar('recently_added', $va_recently_added); $this->render('Splash/splash_html.php'); }
public function update($pa_options = null) { if (!$this->_preSaveActions()) { return false; } $vn_old_status = $this->getOriginalValue('order_status'); $vn_old_ship_date = $this->getOriginalValue('shipping_date'); $vn_old_shipped_on_date = $this->getOriginalValue('shipped_on_date'); // Move order status automatically to reflect business logic switch ($this->get('order_status')) { case 'PROCESSED': if ($this->get('shipped_on_date') && $this->changed('shipped_on_date') && !$this->requiresDownload()) { // If it shipped and there's nothing left to fulfill by download then ship status to "complete" $this->set('order_status', 'COMPLETED'); } break; case 'AWAITING_PAYMENT': if ($this->get('payment_received_on') && $this->changed('payment_received_on') || $this->getTotal() == 0) { if ($this->get('order_type') == 'L') { // LOANS $this->set('order_status', 'PROCESSED'); } else { // SALES ORDERS // If it paid for then flip status to "PROCESSED" (if it's all ready to go) or "PROCESSED_AWAITING_DIGITIZATION" if stuff needs to be digitized if (sizeof($va_items_with_no_media = $this->itemsWithNoDownloadableMedia()) > 0) { $this->set('order_status', 'PROCESSED_AWAITING_DIGITIZATION'); } else { // If "original" files are missing then mark as PROCESSED_AWAITING_MEDIA_ACCESS if (sizeof($va_items_missing_media = $this->itemsMissingDownloadableMedia('original'))) { $this->set('order_status', 'PROCESSED_AWAITING_MEDIA_ACCESS'); } else { $this->set('order_status', 'PROCESSED'); } } } } break; } $vb_status_changed = $this->changed('order_status'); $this->set('order_number', ca_commerce_orders::generateOrderNumber($this->getPrimaryKey(), $this->get('created_on', array('GET_DIRECT_DATE' => true)))); if ($vn_rc = parent::update($pa_options)) { if ($vb_status_changed) { $this->sendStatusChangeEmailNotification($vn_old_status, $vn_old_ship_date, $vn_old_shipped_on_date); } if (in_array($this->get('order_status'), array('PROCESSED', 'PROCESSED_AWAITING_DIGITIZATION', 'PROCESSED_AWAITING_MEDIA_ACCESS', 'COMPLETED'))) { // Delete originating set if configured to do so if ($this->opo_client_services_config->get('set_disposal_policy') == 'DELETE_WHEN_ORDER_PROCESSED') { $t_trans = new ca_commerce_transactions($this->get('transaction_id')); if ($t_trans->getPrimaryKey()) { $t_set = new ca_sets($t_trans->get('set_id')); if ($t_set->getPrimaryKey()) { $t_set->setMode(ACCESS_WRITE); $t_set->delete(true); } } } } } return $vn_rc; }
/** * @param RequestHTTP $po_request * @param null|array $pa_options * progressCallback = * reportCallback = * sendMail = * log = log directory path * logLevel = KLogger constant for minimum log level to record. Default is KLogger::INFO. Constants are, in descending order of shrillness: * KLogger::EMERG = Emergency messages (system is unusable) * KLogger::ALERT = Alert messages (action must be taken immediately) * KLogger::CRIT = Critical conditions * KLogger::ERR = Error conditions * KLogger::WARN = Warnings * KLogger::NOTICE = Notices (normal but significant conditions) * KLogger::INFO = Informational messages * KLogger::DEBUG = Debugging messages * @return array */ public static function importMediaFromDirectory($po_request, $pa_options = null) { global $g_ui_locale_id; $vs_log_dir = caGetOption('log', $pa_options, __CA_APP_DIR__ . "/log"); $vs_log_level = caGetOption('logLevel', $pa_options, "INFO"); if (!is_writeable($vs_log_dir)) { $vs_log_dir = caGetTempDirPath(); } $vn_log_level = BatchProcessor::_logLevelStringToNumber($vs_log_level); $o_log = new KLogger($vs_log_dir, $vn_log_level); $vs_import_target = caGetOption('importTarget', $pa_options, 'ca_objects'); $t_instance = $po_request->getAppDatamodel()->getInstance($vs_import_target); $o_eventlog = new Eventlog(); $t_set = new ca_sets(); $va_notices = $va_errors = array(); $vb_we_set_transaction = false; $o_trans = isset($pa_options['transaction']) && $pa_options['transaction'] ? $pa_options['transaction'] : null; if (!$o_trans) { $vb_we_set_transaction = true; $o_trans = new Transaction($t_set->getDb()); } $o_batch_log = new Batchlog(array('user_id' => $po_request->getUserID(), 'batch_type' => 'MI', 'table_num' => (int) $t_instance->tableNum(), 'notes' => '', 'transaction' => $o_trans)); if (!is_dir($pa_options['importFromDirectory'])) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => $vs_msg = _t("Specified import directory '%1' is invalid", $pa_options['importFromDirectory']))); $o_log->logError($vs_msg); return null; } $vs_batch_media_import_root_directory = $po_request->config->get('batch_media_import_root_directory'); if (!preg_match("!^{$vs_batch_media_import_root_directory}!", $pa_options['importFromDirectory'])) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => $vs_msg = _t("Specified import directory '%1' is invalid", $pa_options['importFromDirectory']))); $o_log->logError($vs_msg); return null; } if (preg_match("!\\.\\./!", $pa_options['importFromDirectory'])) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => $vs_msg = _t("Specified import directory '%1' is invalid", $pa_options['importFromDirectory']))); $o_log->logError($vs_msg); return null; } $vb_include_subdirectories = (bool) $pa_options['includeSubDirectories']; $vb_delete_media_on_import = (bool) $pa_options['deleteMediaOnImport']; $vs_import_mode = $pa_options['importMode']; $vs_match_mode = $pa_options['matchMode']; $vn_type_id = $pa_options[$vs_import_target . '_type_id']; $vn_rep_type_id = $pa_options['ca_object_representations_type_id']; $va_limit_matching_to_type_ids = $pa_options[$vs_import_target . '_limit_matching_to_type_ids']; $vn_access = $pa_options[$vs_import_target . '_access']; $vn_object_representation_access = $pa_options['ca_object_representations_access']; $vn_status = $pa_options[$vs_import_target . '_status']; $vn_object_representation_status = $pa_options['ca_object_representations_status']; $vn_rel_type_id = isset($pa_options[$vs_import_target . '_representation_relationship_type']) ? $pa_options[$vs_import_target . '_representation_relationship_type'] : null; $vn_mapping_id = $pa_options[$vs_import_target . '_mapping_id']; $vn_object_representation_mapping_id = $pa_options['ca_object_representations_mapping_id']; $vs_idno_mode = $pa_options['idnoMode']; $vs_idno = $pa_options['idno']; $vs_representation_idno_mode = $pa_options['representationIdnoMode']; $vs_representation_idno = $pa_options['representation_idno']; $vs_set_mode = $pa_options['setMode']; $vs_set_create_name = $pa_options['setCreateName']; $vn_set_id = $pa_options['set_id']; $vn_locale_id = $pa_options['locale_id']; $vs_skip_file_list = $pa_options['skipFileList']; $vs_skip_file_list = $pa_options['skipFileList']; $vb_allow_duplicate_media = $pa_options['allowDuplicateMedia']; $va_relationship_type_id_for = array(); if (is_array($va_create_relationship_for = $pa_options['create_relationship_for'])) { foreach ($va_create_relationship_for as $vs_rel_table) { $va_relationship_type_id_for[$vs_rel_table] = $pa_options['relationship_type_id_for_' . $vs_rel_table]; } } if (!$vn_locale_id) { $vn_locale_id = $g_ui_locale_id; } $va_files_to_process = caGetDirectoryContentsAsList($pa_options['importFromDirectory'], $vb_include_subdirectories); $o_log->logInfo(_t('Found %1 files in directory \'%2\'', sizeof($va_files_to_process), $pa_options['importFromDirectory'])); if ($vs_set_mode == 'add') { $t_set->load($vn_set_id); } else { if ($vs_set_mode == 'create' && $vs_set_create_name) { $va_set_ids = $t_set->getSets(array('user_id' => $po_request->getUserID(), 'table' => $t_instance->tableName(), 'access' => __CA_SET_EDIT_ACCESS__, 'setIDsOnly' => true, 'name' => $vs_set_create_name)); $vn_set_id = null; if (is_array($va_set_ids) && sizeof($va_set_ids) > 0) { $vn_possible_set_id = array_shift($va_set_ids); if ($t_set->load($vn_possible_set_id)) { $vn_set_id = $t_set->getPrimaryKey(); } } else { $vs_set_code = mb_substr(preg_replace("![^A-Za-z0-9_\\-]+!", "_", $vs_set_create_name), 0, 100); if ($t_set->load(array('set_code' => $vs_set_code))) { $vn_set_id = $t_set->getPrimaryKey(); } } if (!$t_set->getPrimaryKey()) { $t_set->setMode(ACCESS_WRITE); $t_set->set('user_id', $po_request->getUserID()); $t_set->set('type_id', $po_request->config->get('ca_sets_default_type')); $t_set->set('table_num', $t_instance->tableNum()); $t_set->set('set_code', $vs_set_code); $t_set->insert(); if ($t_set->numErrors()) { $va_notices['create_set'] = array('idno' => '', 'label' => _t('Create set %1', $vs_set_create_name), 'message' => $vs_msg = _t('Failed to create set %1: %2', $vs_set_create_name, join("; ", $t_set->getErrors())), 'status' => 'SET ERROR'); $o_log->logError($vs_msg); } else { $t_set->addLabel(array('name' => $vs_set_create_name), $vn_locale_id, null, true); if ($t_set->numErrors()) { $va_notices['add_set_label'] = array('idno' => '', 'label' => _t('Add label to set %1', $vs_set_create_name), 'message' => $vs_msg = _t('Failed to add label to set: %1', join("; ", $t_set->getErrors())), 'status' => 'SET ERROR'); $o_log->logError($vs_msg); } $vn_set_id = $t_set->getPrimaryKey(); } } } else { $vn_set_id = null; // no set } } if ($t_set->getPrimaryKey() && !$t_set->haveAccessToSet($po_request->getUserID(), __CA_SET_EDIT_ACCESS__)) { $va_notices['set_access'] = array('idno' => '', 'label' => _t('You do not have access to set %1', $vs_set_create_name), 'message' => $vs_msg = _t('Cannot add to set %1 because you do not have edit access', $vs_set_create_name), 'status' => 'SET ERROR'); $o_log->logError($vs_msg); $vn_set_id = null; $t_set = new ca_sets(); } $vn_num_items = sizeof($va_files_to_process); // Get list of regex packages that user can use to extract object idno's from filenames $va_regex_list = caBatchGetMediaFilenameToIdnoRegexList(array('log' => $o_log)); // Get list of replacements that user can use to transform file names to match object idnos $va_replacements_list = caBatchGetMediaFilenameReplacementRegexList(array('log' => $o_log)); // Get list of files (or file name patterns) to skip $va_skip_list = preg_split("![\r\n]+!", $vs_skip_file_list); foreach ($va_skip_list as $vn_i => $vs_skip) { if (!strlen($va_skip_list[$vn_i] = trim($vs_skip))) { unset($va_skip_list[$vn_i]); } } $vn_c = 0; $vn_start_time = time(); $va_report = array(); foreach ($va_files_to_process as $vs_file) { $va_tmp = explode("/", $vs_file); $f = array_pop($va_tmp); $d = array_pop($va_tmp); array_push($va_tmp, $d); $vs_directory = join("/", $va_tmp); // Skip file names using $vs_skip_file_list if (BatchProcessor::_skipFile($f, $va_skip_list)) { $o_log->logInfo(_t('Skipped file %1 because it was on the skipped files list', $f)); continue; } $vs_relative_directory = preg_replace("!{$vs_batch_media_import_root_directory}[/]*!", "", $vs_directory); // does representation already exist? if (!$vb_allow_duplicate_media && ($t_dupe = ca_object_representations::mediaExists($vs_file))) { $va_notices[$vs_relative_directory . '/' . $f] = array('idno' => '', 'label' => $f, 'message' => $vs_msg = _t('Skipped %1 from %2 because it already exists %3', $f, $vs_relative_directory, caEditorLink($po_request, _t('(view)'), 'button', 'ca_object_representations', $t_dupe->getPrimaryKey())), 'status' => 'SKIPPED'); $o_log->logInfo($vs_msg); continue; } $t_instance = $po_request->getAppDatamodel()->getInstance($vs_import_target, false); $t_instance->setTransaction($o_trans); $vs_modified_filename = $f; $va_extracted_idnos_from_filename = array(); if (in_array($vs_import_mode, array('TRY_TO_MATCH', 'ALWAYS_MATCH')) || is_array($va_create_relationship_for) && sizeof($va_create_relationship_for)) { foreach ($va_regex_list as $vs_regex_name => $va_regex_info) { $o_log->logDebug(_t("Processing mediaFilenameToObjectIdnoRegexes entry %1", $vs_regex_name)); foreach ($va_regex_info['regexes'] as $vs_regex) { switch ($vs_match_mode) { case 'DIRECTORY_NAME': $va_names_to_match = array($d); $o_log->logDebug(_t("Trying to match on directory '%1'", $d)); break; case 'FILE_AND_DIRECTORY_NAMES': $va_names_to_match = array($f, $d); $o_log->logDebug(_t("Trying to match on directory '%1' and file name '%2'", $d, $f)); break; default: case 'FILE_NAME': $va_names_to_match = array($f); $o_log->logDebug(_t("Trying to match on file name '%1'", $f)); break; } // are there any replacements? if so, try to match each element in $va_names_to_match AND all results of the replacements if (is_array($va_replacements_list) && sizeof($va_replacements_list) > 0) { $va_names_to_match_copy = $va_names_to_match; foreach ($va_names_to_match_copy as $vs_name) { foreach ($va_replacements_list as $vs_replacement_code => $va_replacement) { if (isset($va_replacement['search']) && is_array($va_replacement['search'])) { $va_replace = caGetOption('replace', $va_replacement); $va_search = array(); foreach ($va_replacement['search'] as $vs_search) { $va_search[] = '!' . $vs_search . '!'; } $vs_replacement_result = @preg_replace($va_search, $va_replace, $vs_name); if (is_null($vs_replacement_result)) { $o_log->logError(_t("There was an error in preg_replace while processing replacement %1.", $vs_replacement_code)); } if ($vs_replacement_result && strlen($vs_replacement_result) > 0) { $o_log->logDebug(_t("The result for replacement with code %1 applied to value '%2' is '%3' and was added to the list of file names used for matching.", $vs_replacement_code, $vs_name, $vs_replacement_result)); $va_names_to_match[] = $vs_replacement_result; } } else { $o_log->logDebug(_t("Skipped replacement %1 because no search expression was defined.", $vs_replacement_code)); } } } } $o_log->logDebug("Names to match: " . print_r($va_names_to_match, true)); foreach ($va_names_to_match as $vs_match_name) { if (preg_match('!' . $vs_regex . '!', $vs_match_name, $va_matches)) { $o_log->logDebug(_t("Matched name %1 on regex %2", $vs_match_name, $vs_regex)); if (!$vs_idno || strlen($va_matches[1]) < strlen($vs_idno)) { $vs_idno = $va_matches[1]; } if (!$vs_modified_filename || strlen($vs_modified_filename) > strlen($va_matches[1])) { $vs_modified_filename = $va_matches[1]; } $va_extracted_idnos_from_filename[] = $va_matches[1]; if (in_array($vs_import_mode, array('TRY_TO_MATCH', 'ALWAYS_MATCH'))) { if (!is_array($va_fields_to_match_on = $po_request->config->getList('batch_media_import_match_on')) || !sizeof($va_fields_to_match_on)) { $batch_media_import_match_on = array('idno'); } $vs_bool = 'OR'; $va_values = array(); foreach ($va_fields_to_match_on as $vs_fld) { if (in_array($vs_fld, array('preferred_labels', 'nonpreferred_labels'))) { $va_values[$vs_fld] = array($vs_fld => array('name' => $va_matches[1])); } else { $va_values[$vs_fld] = $va_matches[1]; } } if (is_array($va_limit_matching_to_type_ids) && sizeof($va_limit_matching_to_type_ids) > 0) { $va_values['type_id'] = $va_limit_matching_to_type_ids; $vs_bool = 'AND'; } $o_log->logDebug("Trying to find records using boolean {$vs_bool} and values " . print_r($va_values, true)); if (class_exists($vs_import_target) && ($vn_id = $vs_import_target::find($va_values, array('returnAs' => 'firstId', 'boolean' => $vs_bool)))) { if ($t_instance->load($vn_id)) { $va_notices[$vs_relative_directory . '/' . $vs_match_name . '_match'] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_instance->getLabelForDisplay(), 'message' => $vs_msg = _t('Matched media %1 from %2 to %3 using expression "%4"', $f, $vs_relative_directory, caGetTableDisplayName($vs_import_target, false), $va_regex_info['displayName']), 'status' => 'MATCHED'); $o_log->logInfo($vs_msg); } break 3; } } } else { $o_log->logDebug(_t("Couldn't match name %1 on regex %2", $vs_match_name, $vs_regex)); } } } } } if (!$t_instance->getPrimaryKey()) { // Use filename as idno if all else fails if ($t_instance->load(array('idno' => $f, 'deleted' => 0))) { $va_notices[$vs_relative_directory . '/' . $f . '_match'] = array('idno' => $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD')), 'label' => $t_instance->getLabelForDisplay(), 'message' => $vs_msg = _t('Matched media %1 from %2 to %3 using filename', $f, $vs_relative_directory, caGetTableDisplayName($vs_import_target, false)), 'status' => 'MATCHED'); $o_log->logInfo($vs_msg); } } switch ($vs_representation_idno_mode) { case 'filename': // use the filename as identifier $vs_rep_idno = $f; break; case 'filename_no_ext': // use filename without extension as identifier $vs_rep_idno = preg_replace('/\\.[^.\\s]{3,4}$/', '', $f); break; case 'directory_and_filename': // use the directory + filename as identifier $vs_rep_idno = $d . '/' . $f; break; default: // use idno from form $vs_rep_idno = $vs_representation_idno; break; } $t_new_rep = null; if ($t_instance->getPrimaryKey() && $t_instance instanceof RepresentableBaseModel) { // found existing object $t_instance->setMode(ACCESS_WRITE); $t_new_rep = $t_instance->addRepresentation($vs_directory . '/' . $f, $vn_rep_type_id, $vn_locale_id, $vn_object_representation_status, $vn_object_representation_access, false, 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 {$f} from {$vs_directory}: %1", 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); } } } else { // should we create new record? if (in_array($vs_import_mode, array('TRY_TO_MATCH', 'DONT_MATCH'))) { $t_instance->setMode(ACCESS_WRITE); $t_instance->set('type_id', $vn_type_id); $t_instance->set('locale_id', $vn_locale_id); $t_instance->set('status', $vn_status); $t_instance->set('access', $vn_access); // for places, take first hierarchy we can find. in most setups there is but one. we might wanna make this configurable via setup screen at some point if ($t_instance->hasField('hierarchy_id')) { $va_hierarchies = $t_instance->getHierarchyList(); reset($va_hierarchies); $vn_hierarchy_id = key($va_hierarchies); $t_instance->set('hierarchy_id', $vn_hierarchy_id); } switch ($vs_idno_mode) { case 'filename': // use the filename as identifier $t_instance->set('idno', $f); break; case 'filename_no_ext': // use filename without extension as identifier $f_no_ext = preg_replace('/\\.[^.\\s]{3,4}$/', '', $f); $t_instance->set('idno', $f_no_ext); break; case 'directory_and_filename': // use the directory + filename as identifier $t_instance->set('idno', $d . '/' . $f); break; default: // Calculate identifier using numbering plugin $o_numbering_plugin = $t_instance->getIDNoPlugInInstance(); if (!($vs_sep = $o_numbering_plugin->getSeparator())) { $vs_sep = ''; } if (!is_array($va_idno_values = $o_numbering_plugin->htmlFormValuesAsArray('idno', null, false, false, true))) { $va_idno_values = array(); } $t_instance->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_instance->insert(); if ($t_instance->numErrors()) { $o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => _t("Error creating new record 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 new record 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; } 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)); }
public function RecordRepresentationSelection() { $pn_item_id = $this->request->getParameter('item_id', pInteger); $pn_representation_id = $this->request->getParameter('representation_id', pInteger); $pn_selected = $this->request->getParameter('selected', pInteger); $va_errors = array(); $t_set_item = new ca_set_items($pn_item_id); $t_set = new ca_sets($t_set_item->get('set_id')); if (!$t_set->getPrimaryKey() || !$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) { // TODO: proper error reporting or redirect? return; } if (!$t_set_item->getPrimaryKey()) { $va_errors[] = _t("Invalid set item"); } if (!sizeof($va_errors)) { $t_set = new ca_sets($t_set_item->get('set_id')); if (!$t_set->getPrimaryKey()) { $va_errors[] = _t("Invalid set"); } if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) { $va_errors[] = _t("You do not have access to this set"); } if (!sizeof($va_errors)) { if ((bool) $pn_selected) { $t_set_item->addSelectedRepresentation($pn_representation_id); } else { $t_set_item->removeSelectedRepresentation($pn_representation_id); } $t_set_item->update(); $va_errors = $t_set_item->getErrors(); } } $this->view->setVar("errors", $va_errors); $this->view->setVar('representation_id', $pn_representation_id); $this->view->setVar('item_id', $pn_item_id); $this->render("ajax_select_representation_json.php"); }
/** * Duplicate all items in this set * @param int $pn_user_id * @param array $pa_options * @return ca_sets|bool */ public function duplicateItemsInSet($pn_user_id, $pa_options = array()) { if (!$this->getPrimaryKey()) { return false; } if ($this->getItemCount() < 1) { return false; } $t_user = new ca_users($pn_user_id); if (!$t_user->getPrimaryKey()) { return false; } // we need a user for duplication global $g_ui_locale_id; if (caGetOption('addToCurrentSet', $pa_options, false)) { $t_set_to_add_dupes_to = $this; } else { // create new set for dupes $t_set_to_add_dupes_to = new ca_sets(); $t_set_to_add_dupes_to->set('type_id', $this->get('type_id')); $t_set_to_add_dupes_to->set('table_num', $this->get('table_num')); $t_set_to_add_dupes_to->set('user_id', $this->get('user_id')); $t_set_to_add_dupes_to->set('set_code', $this->get('set_code') . '-' . _t('dupes')); $t_set_to_add_dupes_to->setMode(ACCESS_WRITE); $t_set_to_add_dupes_to->insert(); if (!$t_set_to_add_dupes_to->getPrimaryKey()) { $this->errors = $t_set_to_add_dupes_to->errors; return false; } $t_set_to_add_dupes_to->addLabel(array('name' => $this->getLabelForDisplay() . ' ' . _t('[Duplicates]')), $g_ui_locale_id, null, true); } $va_items = array_keys($this->getItemRowIDs()); $va_dupes = array(); foreach ($va_items as $vn_row_id) { /** @var BundlableLabelableBaseModelWithAttributes $t_instance */ $t_instance = $this->getAppDatamodel()->getInstance($this->get('table_num')); if (!$t_user->canDoAction('can_duplicate_' . $t_instance->tableName())) { $this->postError(2580, _t('You do not have permission to duplicate these items'), 'ca_sets->duplicateItemsInSet()'); return false; } if (!$t_instance->load($vn_row_id)) { continue; } // let's dupe $t_dupe = $t_instance->duplicate(array('user_id' => $pn_user_id, 'duplicate_nonpreferred_labels' => $t_user->getPreference($t_instance->tableName() . '_duplicate_nonpreferred_labels'), 'duplicate_attributes' => $t_user->getPreference($t_instance->tableName() . '_duplicate_attributes'), 'duplicate_relationships' => $t_user->getPreference($t_instance->tableName() . '_duplicate_relationships'), 'duplicate_media' => $t_user->getPreference($t_instance->tableName() . '_duplicate_media'), 'duplicate_subitems' => $t_user->getPreference($t_instance->tableName() . '_duplicate_subitems'))); if ($t_dupe instanceof BaseModel) { $va_dupes[] = $t_dupe->getPrimaryKey(); } } $t_set_to_add_dupes_to->addItems($va_dupes); return $t_set_to_add_dupes_to; }
<div style="clear:left;"></div> --> <!-- <h2>Highlights from the Collection</h2> <?php $t_featured = new ca_sets(); $featured_sets = $this->request->config->get('featured_sets'); $len = count($featured_sets); if ($len > 3) { $len = 3; } for ($i = 0; $i < $len; $i++) { $t_featured->load(array('set_code' => $featured_sets[$i])); $set_id = $t_featured->getPrimaryKey(); $set_title = $t_featured->getLabelForDisplay(); $set_desc = $t_featured->getAttributeFromSets('description', array(0 => $set_id)); $va_featured_ids = array_keys(is_array($va_tmp = $t_featured->getItemRowIDs(array('checkAccess' => $va_access_values, 'shuffle' => 0))) ? $va_tmp : array()); // These are the object ids in the set if (is_array($va_featured_ids) && sizeof($va_featured_ids) > 0) { $t_object = new ca_objects($va_featured_ids[0]); $va_rep = $t_object->getPrimaryRepresentation(array('preview', 'preview170'), null, array('return_with_access' => $va_access_values)); $featured_set_id_array[$i] = array('featured_set_code' => $featured_sets[$i], 'featured_content_id' => $va_featured_ids[0], 'featured_content_small' => $va_rep["tags"]["preview"], 'featured_content_label' => $set_title, 'featured_content_description' => $set_desc[$set_id][0], 'featured_set_id' => $set_id); } } ?> <?php if (isset($featured_set_id_array)) { ?>
/** * Returns set_id corresponding to set code, or passed back set_id if input in numeric (it doesn't actually verify that a numeric set_id is actually valid) * * @param mixed $pm_set_code_or_id * @return int set_id corresponding to $pm_set_code_or_id */ private function _getSetID($pm_set_code_or_id) { if (is_numeric($pm_set_code_or_id)) { $vn_set_id = intval($pm_set_code_or_id); } else { $t_set = new ca_sets(); if (!$t_set->load(array('set_code' => $pm_set_code_or_id))) { return null; } $vn_set_id = $t_set->getPrimaryKey(); } return $vn_set_id; }
/** * */ public function CreateNewOrderFromCommunication() { if ($pn_communication_id = $this->request->getParameter('communication_id', pInteger)) { $t_comm = new ca_commerce_communications($pn_communication_id); if (!$t_comm->getPrimaryKey()) { $this->notification->addNotification(_t('Invalid message'), __NOTIFICATION_TYPE_ERROR__); $this->CustomerInfo(); return; } $t_trans = new ca_commerce_transactions($t_comm->get('transaction_id')); if (!$t_trans->getPrimaryKey()) { $this->notification->addNotification(_t('Message is not associated with a transaction'), __NOTIFICATION_TYPE_ERROR__); $this->CustomerInfo(); return; } $t_user = new ca_users($t_trans->get('user_id')); $this->opt_order->setMode(ACCESS_WRITE); $this->opt_order->set('transaction_id', $t_trans->getPrimaryKey()); if ($t_user->getPrimaryKey()) { $this->opt_order->set('billing_fname', $t_user->get('fname')); $this->opt_order->set('billing_lname', $t_user->get('lname')); $this->opt_order->set('billing_email', $t_user->get('email')); $this->opt_order->set('shipping_fname', $t_user->get('fname')); $this->opt_order->set('shipping_lname', $t_user->get('lname')); $this->opt_order->set('shipping_email', $t_user->get('email')); // Pre-populate order with user's profile address $va_mapping = array('billing_organization' => 'user_profile_organization', 'billing_address1' => 'user_profile_address1', 'billing_address2' => 'user_profile_address2', 'billing_city' => 'user_profile_city', 'billing_zone' => 'user_profile_state', 'billing_postal_code' => 'user_profile_postalcode', 'billing_country' => 'user_profile_country', 'billing_phone' => 'user_profile_phone', 'billing_fax' => 'user_profile_fax', 'shipping_organization' => 'user_profile_organization', 'shipping_address1' => 'user_profile_address1', 'shipping_address2' => 'user_profile_address2', 'shipping_city' => 'user_profile_city', 'shipping_zone' => 'user_profile_state', 'shipping_postal_code' => 'user_profile_postalcode', 'shipping_country' => 'user_profile_country', 'shipping_phone' => 'user_profile_phone', 'shipping_fax' => 'user_profile_fax'); foreach ($va_mapping as $vs_field => $vs_pref) { $this->opt_order->set($vs_field, $t_user->getPreference($vs_pref)); } } $this->opt_order->set('order_type', 'L'); // L=loan $this->opt_order->insert(); $this->request->setParameter('order_id', $this->opt_order->getPrimaryKey()); if (!$this->opt_order->numErrors()) { $this->notification->addNotification(_t('Saved changes'), __NOTIFICATION_TYPE_INFO__); // Add items $t_set = new ca_sets($t_trans->get('set_id')); if ($t_set->getPrimaryKey()) { $va_items = $t_set->getItems(); foreach ($va_items as $va_item_list) { foreach ($va_item_list as $vn_i => $va_item) { if (!is_array($va_item['selected_services'])) { //$va_item['selected_services'] = array('DIGITAL_COPY'); // TODO: make default configurable } foreach ($va_item['selected_services'] as $vs_service) { if ($t_item = $this->opt_order->addItem($va_item['row_id'], array('service' => $vs_service), array('representations_ids' => is_array($va_item['selected_representations']) && sizeof($va_item['selected_representations']) ? $va_item['selected_representations'] : null))) { $t_item->updateFee(); } } } } // Delete originating set if configured to do so if ($this->opo_client_services_config->get('set_disposal_policy') == 'DELETE_WHEN_ORDER_CREATED') { $t_set->setMode(ACCESS_WRITE); $t_set->delete(true); } } } else { $va_errors['general'] = $this->opt_order->errors(); $this->notification->addNotification(_t('Errors occurred: %1', join('; ', $this->opt_order->getErrors())), __NOTIFICATION_TYPE_ERROR__); } $this->view->setVar('errors', $va_errors); } $this->OrderOverview(); }
/** * */ public function GetSelectedRepresentationCount() { $pn_item_id = $this->request->getParameter('item_id', pInteger); $t_set_item = new ca_set_items($pn_item_id); $t_set = new ca_sets($t_set_item->get('set_id')); if (!$t_set->getPrimaryKey() || !$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_EDIT_ACCESS__)) { // TODO: proper error reporting or redirect? return; } $vn_num_reps_selected = $t_set_item->getSelectedRepresentationCount(); $vn_num_reps = $t_set_item->getRepresentationCount(); $vs_msg = $vn_num_reps == 1 ? _t("%1/%2 page selected", $vn_num_reps_selected, $vn_num_reps) : _t("%1/%2 pages selected", $vn_num_reps_selected, $vn_num_reps); $this->response->addContent($vs_msg); }
public function DuplicateItems() { $t_set = new ca_sets($this->getRequest()->getParameter('set_id', pInteger)); if (!$t_set->getPrimaryKey()) { return; } if ($this->getRequest()->getParameter('setForDupes', pString) == 'current') { $pa_dupe_options = array('addToCurrentSet' => true); } else { $pa_dupe_options = array('addToCurrentSet' => false); } unset($_REQUEST['form_timestamp']); $t_dupe_set = $t_set->duplicateItemsInSet($this->getRequest()->getUserID(), $pa_dupe_options); if (!$t_dupe_set) { $this->notification->addNotification(_t('Could not duplicate items in set: %1', join(';', $t_set->getErrors())), __NOTIFICATION_TYPE_ERROR__); $this->Edit(); return; } $this->notification->addNotification(_t('Records have been successfully duplicated and added to set'), __NOTIFICATION_TYPE_INFO__); $this->opo_response->setRedirect(caEditorUrl($this->getRequest(), 'ca_sets', $t_dupe_set->getPrimaryKey())); return; }
public function displaySet() { # --- set info $t_set = new ca_sets($pn_set_id = $this->request->getParameter('set_id', pInteger)); if (!$t_set->getPrimaryKey()) { $this->notification->addNotification(_t("This set does not exist"), "message"); $this->response->setRedirect(caNavUrl($this->request, "", "", "", "")); return; } $va_access_values = caGetUserAccessValues($this->request); # Enforce access control if (sizeof($va_access_values) && !in_array($t_set->get("access"), $va_access_values)) { $this->notification->addNotification(_t("This set is not available for view"), "message"); $this->response->setRedirect(caNavUrl($this->request, "", "", "", "")); return; } if (!$t_set->haveAccessToSet($this->request->getUserID(), __CA_SET_READ_ACCESS__)) { $this->notification->addNotification(_t("This set is not available for view"), "message"); $this->response->setRedirect(caNavUrl($this->request, "", "", "", "")); return; } $this->view->setVar('t_set', $t_set); $va_items = caExtractValuesByUserLocale($t_set->getItems(array('thumbnailVersions' => array('widepreview', 'medium'), 'access' => __CA_SET_READ_ACCESS__, "checkAccess" => $va_access_values, 'user_id' => $this->request->getUserID()))); $this->view->setVar('items', $va_items); $va_row_ids = array(); foreach ($va_items as $vn_item_id => $va_item_info) { $va_row_ids[] = $va_item_info['row_id']; } # --- all featured sets - for display in right hand column // get sets for public display $t_list = new ca_lists(); $vn_public_set_type_id = $t_list->getItemIDFromList('set_types', $t_list->getAppConfig()->get('bristol_set_type')); $t_set = new ca_sets($pn_set_id); $va_sets = caExtractValuesByUserLocale($t_set->getSets(array('table' => 'ca_objects', 'access' => __CA_SET_READ_ACCESS__, 'setType' => $vn_public_set_type_id, 'user_id' => $this->request->getUserID()))); $va_set_first_items = array(); $va_set_first_items = $t_set->getFirstItemsFromSets(array_keys($va_sets), array("version" => "icon", "checkAccess" => $va_access_values)); $this->view->setVar('sets', $va_sets); $this->view->setVar('first_items_from_sets', $va_set_first_items); $this->view->setVar('set_title', $t_set->getLabelForDisplay()); $this->view->setVar('set_description', $t_set->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLinkBreaks' => true))); $this->view->setVar('set_creator', $t_set->get('setcreator', array('convertLinkBreaks' => true))); $this->view->setVar('set_date', $t_set->get('setdate', array('convertLinkBreaks' => true))); $va_exp_dates = $t_set->getAccessExpirationDates($this->request->getUserID(), __CA_SET_READ_ACCESS__, $pn_set_id); $this->view->setVar('set_expiration_date', $va_exp_dates[$pn_set_id]); // Needed to figure out what result context to use on details $this->opo_result_context->setParameter('set_id', $pn_set_id); $this->opo_result_context->setResultList($va_row_ids); $this->opo_result_context->setAsLastFind(); $this->opo_result_context->saveContext(); $this->render($this->ops_theme . '/set_info_html.php'); }
/** * Add items to specified set */ public function createSetFromResult() { global $g_ui_locale_id; $vs_mode = $this->request->getParameter('mode', pString); if ($vs_mode == 'from_checked') { $va_row_ids = explode(";", $this->request->getParameter('item_ids', pString)); } else { $va_row_ids = $this->opo_result_context->getResultList(); } $vs_set_code = null; $vn_added_items_count = 0; if (is_array($va_row_ids) && sizeof($va_row_ids)) { $t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); $vs_set_name = $this->request->getParameter('set_name', pString); if (!$vs_set_name) { $vs_set_name = $this->opo_result_context->getSearchExpression(); } $t_set = new ca_sets(); $t_set->setMode(ACCESS_WRITE); $t_set->set('user_id', $this->request->getUserID()); $t_set->set('type_id', $this->request->config->get('ca_sets_default_type')); $t_set->set('table_num', $t_model->tableNum()); $t_set->set('set_code', $vs_set_code = mb_substr(preg_replace("![^A-Za-z0-9_\\-]+!", "_", $vs_set_name), 0, 100)); $t_set->insert(); if ($t_set->numErrors()) { $this->view->setVar('error', join("; ", $t_set->getErrors())); } $t_set->addLabel(array('name' => $vs_set_name), $g_ui_locale_id, null, true); $vn_added_items_count = $t_set->addItems($va_row_ids); $this->view->setVar('set_id', $t_set->getPrimaryKey()); $this->view->setVar('t_set', $t_set); } $this->view->setVar('set_name', $vs_set_name); $this->view->setVar('set_code', $vs_set_code); $this->view->setVar('num_items_added', $vn_added_items_count); $this->render('Results/ajax_create_set_from_result_json.php'); }
/** * Returns content for overlay containing details for object representation linked to occurrence */ public function getSetsOverlay() { $pn_set_id = $this->request->getParameter('set_id', pInteger); $pn_object_id = $this->request->getParameter('object_id', pInteger); $this->view->setVar('object_id', $pn_object_id); $pn_representation_id = $this->request->getParameter('representation_id', pInteger); $this->view->setVar('set_id', $pn_set_id); $t_set = new ca_sets($pn_set_id); $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger); $this->view->setVar('set_item_id', $pn_set_item_id); $this->view->setVar('object_id', $pn_object_id); $t_object = new ca_objects($pn_object_id); $this->view->setVar('t_object', $t_object); $t_rep = new ca_object_representations($pn_representation_id); $this->view->setVar('representation_id', $pn_representation_id); $this->view->setVar('t_object_representation', $t_rep); if ($this->request->config->get("dont_enforce_access_settings")) { $va_access_values = array(); } else { $va_access_values = caGetUserAccessValues($this->request); } if (!$t_set->getPrimaryKey()) { die("Invalid set_id"); } if (!$t_object->getPrimaryKey()) { die("Invalid object_id"); } if (!$t_rep->getPrimaryKey()) { die("Invalid representation_id"); } if (sizeof($va_access_values) && !in_array($t_set->get('access'), $va_access_values)) { die("Invalid set_id"); } if (sizeof($va_access_values) && !in_array($t_object->get('access'), $va_access_values)) { die("Invalid object_id"); } if (sizeof($va_access_values) && !in_array($t_rep->get('access'), $va_access_values)) { die("Invalid rep_id"); } // Get media for display using configured rules $va_rep_display_info = caGetMediaDisplayInfo("media_overlay", $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE')); // set version $this->view->setVar('version', $va_rep_display_info['display_version']); unset($va_display_info['display_version']); // set poster frame URL //$va_rep_display_info['poster_frame_url'] = $t_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']); //unset($va_display_info['poster_frame_version']); //$va_rep_display_info['viewer_base_url'] = $t_rep->getAppConfig()->get('ca_url_root'); // set other options $this->view->setVar('display_options', $va_rep_display_info); if (!($ps_display_type = trim($this->request->getParameter('display_type', pString)))) { $ps_display_type = 'media_overlay'; } if (!($ps_containerID = trim($this->request->getParameter('containerID', pString)))) { $ps_containerID = 'caMediaPanelContentArea'; } $this->view->setVar("display_type", $ps_display_type); $this->view->setVar("containerID", $ps_containerID); // Get all objects asscoiated with this set and show primary reps as icons for navigation //****THIS WONT WORK #$va_exhibition_images = $t_set->get("ca_objects", array('restrict_to_relationship_types' => array('describes'), "returnAsArray" => 1, 'checkAccess' => $va_access_values)); $va_exhibition_images = $t_set->getItems(array("checkAccess" => $va_access_values)); #print "<pre>"; #print_r($va_exhibition_images); #print "</pre>"; if (sizeof($va_exhibition_images) > 0) { $t_image_objects = new ca_objects(); $i = 1; foreach ($va_exhibition_images as $vn_rel_id => $va_inter) { foreach ($va_inter as $id => $va_info) { $t_image_objects->load($va_info["row_id"]); if ($t_primary_rep = $t_image_objects->getPrimaryRepresentationInstance()) { $va_temp = array(); if (!sizeof($va_access_values) || in_array($t_primary_rep->get('access'), $va_access_values)) { $va_temp["representation_id"] = $t_primary_rep->get("representation_id"); $va_temp["rep_icon"] = $t_primary_rep->getMediaTag('media', 'icon'); $va_temp["rep_tinyicon"] = $t_primary_rep->getMediaTag('media', 'tinyicon'); $va_temp["object_id"] = $va_info["object_id"]; $va_temp["set_item_id"] = $va_info['item_id']; $va_thumbnails[$va_info["object_id"]] = $va_temp; if ($vn_getNext == 1) { $this->view->setVar("next_object_id", $va_info["object_id"]); $this->view->setVar("next_representation_id", $t_primary_rep->get("representation_id")); $vn_getNext = 0; } if ($va_info["object_id"] == $pn_object_id) { $this->view->setVar("representation_index", $i); $this->view->setVar("previous_object_id", $vn_prev_obj_id); $this->view->setVar("previous_representation_id", $vn_prev_rep_id); $this->view->setVar("set_item_id", $va_info['item_id']); $vn_getNext = 1; } $vn_prev_obj_id = $va_info["object_id"]; $vn_prev_rep_id = $t_primary_rep->get("representation_id"); $i++; } } } } } $this->view->setVar('reps', $va_thumbnails); return $this->render("ns11mm/ajax_ca_sets_media_overlay_html.php"); }