예제 #1
0
 /**
  * Add a list of row_ids to the currently loaded set with minimal overhead.
  * Note: this method doesn't check access rights for the set
  *
  * @param int $pa_row_ids
  * @return int Returns item_id of newly created set item entry. The item_id is a unique identifier for the row_id in the city at the specified position (rank). It is *not* the same as the row_id.
  */
 public function addItems($pa_row_ids)
 {
     $vn_set_id = $this->getPrimaryKey();
     if (!$vn_set_id) {
         return false;
     }
     if (!is_array($pa_row_ids)) {
         return false;
     }
     if (!sizeof($pa_row_ids)) {
         return false;
     }
     $vn_table_num = $this->get('table_num');
     $vn_type_id = $this->get('type_id');
     $vn_c = 0;
     foreach ($pa_row_ids as $vn_row_id) {
         // Add it to the set
         $t_item = new ca_set_items();
         $t_item->setMode(ACCESS_WRITE);
         $t_item->set('set_id', $vn_set_id);
         $t_item->set('table_num', $vn_table_num);
         $t_item->set('row_id', $vn_row_id);
         $t_item->set('type_id', $vn_type_id);
         $t_item->insert();
         if ($t_item->numErrors()) {
             $this->errors = $t_item->errors;
             //return false;
         } else {
             $vn_c++;
         }
     }
     return $vn_c;
 }
예제 #2
0
 /**
  * Add item to currently loaded set
  *
  * @param int $pn_row_id The row_id to add to the set. Assumed to be a key to a record in the sets's content type's table.
  * @param array $pa_labels An array of ca_set_item label values to create. The array is keyed on locale_id; each value is an array with keys set to ca_set_item_labels fields with associated values.
  * @param int $pn_user_id user_id of user adding the item. Used to check if the user has editing access to the set. If omitted no checking of access is done.
  * @param int $pn_rank position in the set of the newly added item
  * @return int Returns item_id of newly created set item entry. The item_id is a unique identifier for the row_id in the city at the specified position (rank). It is *not* the same as the row_id.
  */
 public function addItem($pn_row_id, $pa_labels = null, $pn_user_id = null, $pn_rank = null)
 {
     if (!($vn_set_id = $this->getPrimaryKey())) {
         return null;
     }
     if ($pn_user_id && !$this->haveAccessToSet($pn_user_id, __CA_SET_EDIT_ACCESS__)) {
         return false;
     }
     $vn_table_num = $this->get('table_num');
     $o_trans = null;
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
     }
     // Verify existance of row before adding to set
     $t_instance = $this->getAppDatamodel()->getInstanceByTableNum($vn_table_num, true);
     if ($o_trans) {
         $t_instance->setTransaction($o_trans);
     }
     if (!$t_instance->load($pn_row_id)) {
         $this->postError(750, _t('Item does not exist'), 'ca_sets->addItem()');
         return false;
     }
     // Add it to the set
     $t_item = new ca_set_items();
     if ($o_trans) {
         $t_item->setTransaction($o_trans);
     }
     $t_item->setMode(ACCESS_WRITE);
     $t_item->set('set_id', $this->getPrimaryKey());
     $t_item->set('table_num', $vn_table_num);
     $t_item->set('row_id', $pn_row_id);
     $t_item->set('type_id', $this->get('type_id'));
     $t_item->insert();
     if (!is_null($pn_rank)) {
         $t_item->set('rank', $pn_rank);
         $t_item->update();
     }
     if ($t_item->numErrors()) {
         $this->errors = $t_item->errors;
         return false;
     }
     if (is_array($pa_labels) && sizeof($pa_labels)) {
         foreach ($pa_labels as $vn_locale_id => $va_label) {
             if (!isset($va_label['caption']) || !trim($va_label['caption'])) {
                 continue;
             }
             $t_item->addLabel($va_label, $vn_locale_id);
             if ($t_item->numErrors()) {
                 $this->errors = $t_item->errors;
                 return false;
             }
         }
     } else {
         global $g_ui_locale_id;
         if (!$g_ui_locale_id) {
             $g_ui_locale_id = 1;
         }
         $t_item->addLabel(array('caption' => _t('[BLANK]')), $g_ui_locale_id);
         if ($t_item->numErrors()) {
             $t_item->delete();
             $this->errors = $t_item->errors;
             return false;
         }
     }
     return (int) $t_item->getPrimaryKey();
 }
 /**
  * Adds specified item (row_id) to set
  *
  * @param int $set_id
  * @param string $type
  * @param int $item_id
  * @param array $set_item_info_array
  * @return int the set_item_id of the newly created record
  * @throws SoapFault
  */
 public function addItemToSet($set_id, $type, $item_id, $set_item_info_array)
 {
     if (!($vn_tablenum = $this->opo_dm->getTableNum($type))) {
         throw new SoapFault("Server", "Invalid type");
     }
     $t_set_item = new ca_set_items();
     $t_set_item->setMode(ACCESS_WRITE);
     $t_set_item->set("set_id", $set_id);
     $t_set_item->set("row_id", $item_id);
     $t_set_item->set("table_num", $vn_tablenum);
     $t_set_item->set($set_item_info_array);
     $vn_item_id = $t_set_item->insert();
     if ($t_set_item->numErrors() == 0) {
         return $vn_item_id;
     } else {
         throw new SoapFault("Server", "There were errors while adding the item: " . join(";", $t_set_item->getErrors()));
     }
 }