本文整理汇总了PHP中ca_sets::setMode方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_sets::setMode方法的具体用法?PHP ca_sets::setMode怎么用?PHP ca_sets::setMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_sets
的用法示例。
在下文中一共展示了ca_sets::setMode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateDeleteSet
public function testCreateDeleteSet()
{
$o_db = new Db();
$qr_objects = $o_db->query('select object_id from ca_objects where deleted=0');
$va_object_ids = $qr_objects->getAllFieldValues('object_id');
//$t = new Timer();
$this->opt_set->addItems($va_object_ids);
//var_dump($t->getTime());
$this->assertSame(sizeof($va_object_ids), $this->opt_set->getItemCount());
$this->opt_set->setMode(ACCESS_WRITE);
//$t = new Timer();
$this->opt_set->delete(true);
//var_dump($t->getTime());
}
示例2: createSetFromResult
/**
* 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');
}
示例3: CreateNewOrderFromCommunication
/**
*
*/
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();
}
示例4: addNewSet
public function addNewSet()
{
if (!$this->request->isLoggedIn()) {
$this->response->setRedirect(caNavUrl($this->request, '', 'LoginReg', 'form'));
return;
}
global $g_ui_locale_id;
// current locale_id for user
$va_errors_new_set = array();
$t_new_set = new ca_sets();
$pn_set_id = $this->request->getParameter('set_id', pInteger);
$ps_name = $this->request->getParameter('name', pString);
if (!$ps_name) {
$va_errors_new_set["name"] = _t("Please enter the name of your collection");
}
$vs_desc = $this->request->getParameter('description', pString);
$t_list = new ca_lists();
$vn_set_type_user = $t_list->getItemIDFromList('set_types', 'user');
if (sizeof($va_errors_new_set) == 0) {
$t_new_set->setMode(ACCESS_WRITE);
$t_new_set->set('access', $this->request->getParameter('access', pInteger));
$t_new_set->set('table_num', 57);
// 57=ca_objects
$t_new_set->set('type_id', $vn_set_type_user);
// type="user"
$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->addAttribute(array('set_intro' => $vs_desc, 'locale_id' => $g_ui_locale_id), 'set_intro');
$t_new_set->insert();
if ($vn_new_set_id = $t_new_set->getPrimaryKey()) {
$t_new_set->addLabel(array('name' => $ps_name), $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);
}
}
$this->view->setVar('errors_new_set', $va_errors_new_set);
$this->index();
}
示例5: update
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;
}
示例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: importMediaFromDirectory
/**
* @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);
//.........这里部分代码省略.........
示例8: duplicateItemsInSet
/**
* 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;
}
示例9: importMediaFromDirectory
/**
* @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__)) {
//.........这里部分代码省略.........
示例10: tearDown
public function tearDown()
{
// clean up test records
$t_object = new ca_objects($this->opn_object_id);
$t_object->setMode(ACCESS_WRITE);
$vb_del = $t_object->delete(true, array('hard' => true));
$this->assertTrue($vb_del, 'Deleting the test record shouldnt fail');
$t_set = new ca_sets($this->opn_set_id);
$t_set->setMode(ACCESS_WRITE);
$vb_del = $t_set->delete(true, array('hard' => true));
$this->assertTrue($vb_del, 'Deleting the test record shouldnt fail');
}
示例11: removeSet
/**
* Removes specified set from database
*
* @param int $set_id
* @return boolean
* @throws SoapFault
*/
public function removeSet($set_id)
{
$t_set = new ca_sets();
if (!$t_set->load($set_id)) {
throw new SoapFault("Server", "Invalid set_id");
}
$t_set->setMode(ACCESS_WRITE);
$t_set->delete();
if ($t_set->numErrors() == 0) {
return true;
} else {
throw new SoapFault("Server", "There were errors while deleting the set: " . join(";", $t_set->getErrors()));
}
}