本文整理汇总了PHP中ca_sets::addLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_sets::addLabel方法的具体用法?PHP ca_sets::addLabel怎么用?PHP ca_sets::addLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_sets
的用法示例。
在下文中一共展示了ca_sets::addLabel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: 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();
}
示例3: 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");
}
}
}
示例4: importMediaFromDirectory
//.........这里部分代码省略.........
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();
示例5: 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;
}
示例6: 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__)) {
//.........这里部分代码省略.........