当前位置: 首页>>代码示例>>PHP>>正文


PHP ca_sets::addItems方法代码示例

本文整理汇总了PHP中ca_sets::addItems方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_sets::addItems方法的具体用法?PHP ca_sets::addItems怎么用?PHP ca_sets::addItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ca_sets的用法示例。


在下文中一共展示了ca_sets::addItems方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:14,代码来源:SetDeleteTest.php

示例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');
 }
开发者ID:ffarago,项目名称:pawtucket2,代码行数:40,代码来源:BaseFindController.php

示例3: testAddAndGetSetItem

 /**
  * @link http://clangers.collectiveaccess.org/jira/browse/PROV-434
  */
 public function testAddAndGetSetItem()
 {
     $t_set = new ca_sets($this->opn_set_id);
     $t_set->setMode(ACCESS_WRITE);
     // "quick" add object (this method uses direct INSERT queries)
     $t_set->addItems(array($this->opn_object_id));
     $va_set_items = $t_set->getItems();
     // get rid of unneeded nesting in array. we should only have one label in one locale.
     $this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
     $va_set_items = array_shift($va_set_items);
     $this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
     $va_set_items = array_shift($va_set_items);
     // basic checks
     $this->assertArrayHasKey('caption', $va_set_items, 'Set item must have empty/blank label');
     $this->assertEquals('[BLANK]', $va_set_items['caption'], 'Set item must have empty/blank label');
     $this->assertArrayHasKey('row_id', $va_set_items, 'Set item must be related to object');
     $this->assertEquals($this->opn_object_id, $va_set_items['row_id'], 'Set item must be related to object');
     //
     // this is (hopefully was?) the actual PROV-434 bug
     // @see http://clangers.collectiveaccess.org/jira/browse/PROV-434
     //
     $va_items = $t_set->get('ca_set_items', array('returnWithStructure' => true));
     $this->assertEquals(1, sizeof($va_items));
     $va_item = array_shift($va_items);
     $this->assertArrayHasKey('caption', $va_item, 'Set item must have empty/blank label');
     $this->assertEquals('[BLANK]', $va_item['caption'], 'Set item must have empty/blank label');
     $this->assertArrayHasKey('record_id', $va_item, 'Set item must be related to object');
     $this->assertEquals($this->opn_object_id, $va_item['record_id'], 'Set item must be related to object');
     // try text (no return as array)
     $vs_ret = $t_set->get('ca_set_items.item_id');
     // what comes out is a string with the primary key
     $this->assertRegExp("/^[0-9]+\$/", $vs_ret);
     $vs_ret = $t_set->get('ca_set_items.preferred_labels');
     $this->assertEquals("[BLANK]", $vs_ret);
     $vs_ret = $t_set->get('ca_set_items.row_id');
     $this->assertEquals((string) $this->opn_object_id, $vs_ret);
     // remove item
     $t_set->removeItem($this->opn_object_id);
     $this->assertEmpty($t_set->getItems());
     // re-add object using model method (as opposed to direct insert addItems() above)
     $t_set->addItem($this->opn_object_id);
     // basic checks (again)
     $va_set_items = $t_set->getItems();
     // get rid of unneeded nesting in array. we should only have one label in one locale.
     $this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
     $va_set_items = array_shift($va_set_items);
     $this->assertEquals(1, sizeof($va_set_items), 'Set should only have one item in one locale');
     $va_set_items = array_shift($va_set_items);
     $this->assertArrayHasKey('caption', $va_set_items, 'Set item must have empty/blank label');
     $this->assertEquals('[BLANK]', $va_set_items['caption'], 'Set item must have empty/blank label');
     $this->assertArrayHasKey('row_id', $va_set_items, 'Set item must be related to object');
     $this->assertEquals($this->opn_object_id, $va_set_items['row_id'], 'Set item must be related to object');
     //
     // this is (hopefully was?) the actual PROV-434 bug
     // @see http://clangers.collectiveaccess.org/jira/browse/PROV-434
     //
     $va_items = $t_set->get('ca_set_items', array('returnWithStructure' => true));
     $this->assertEquals(1, sizeof($va_items));
     $va_item = array_shift($va_items);
     $this->assertArrayHasKey('caption', $va_item, 'Set item must have empty/blank label');
     $this->assertEquals('[BLANK]', $va_item['caption'], 'Set item must have empty/blank label');
     $this->assertArrayHasKey('record_id', $va_item, 'Set item must be related to object');
     $this->assertEquals($this->opn_object_id, $va_item['record_id'], 'Set item must be related to object');
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:67,代码来源:ca_setsTest.php

示例4: 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;
 }
开发者ID:samrahman,项目名称:providence,代码行数:58,代码来源:ca_sets.php

示例5: 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 %1.  You have read only access.", $this->ops_lightbox_display_name);
             $this->view->setVar('errors', $va_errors);
             $this->addItemForm();
             return;
         }
     } else {
         $t_set = new ca_sets();
         $t_set->purify(true);
         # --- 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 %1", $this->ops_lightbox_display_name);
         }
         # --- 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();
         $t_object->purify(true);
         $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 %1', $this->ops_lightbox_display_name);
                     $this->render("Form/reload_html.php");
                 }
             } else {
                 $this->view->setVar('message', _t("Item already in %1.", $this->ops_lightbox_display_name));
                 $this->render("Form/reload_html.php");
             }
         } else {
             if (($pb_saveLastResults = $this->request->getParameter('saveLastResults', pString)) || ($ps_object_ids = $this->request->getParameter('object_ids', pString))) {
                 if ($pb_saveLastResults) {
                     # --- get object ids from last result
                     $o_context = ResultContext::getResultContextForLastFind($this->request, "ca_objects");
                     $va_object_ids = $o_context->getResultList();
                 } else {
                     $va_object_ids = explode(";", $ps_object_ids);
                 }
                 if (is_array($va_object_ids) && sizeof($va_object_ids)) {
                     # --- check for those already in set
                     $va_object_ids_in_set = $t_set->areInSet("ca_objects", $va_object_ids, $t_set->get("set_id"));
                     $va_object_ids = array_diff($va_object_ids, $va_object_ids_in_set);
                     # --- insert items
                     $t_set->addItems($va_object_ids);
//.........这里部分代码省略.........
开发者ID:kai-iak,项目名称:pawtucket2,代码行数:101,代码来源:SetsController.php


注:本文中的ca_sets::addItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。