コード例 #1
0
 public function Save()
 {
     $vn_checkin_count = 0;
     foreach ($_REQUEST as $vs_k => $vs_v) {
         if (preg_match('!^caClientLibraryCheckin_item_id_([\\d]+)$!', $vs_k, $va_matches)) {
             if (isset($_REQUEST['caClientLibraryCheckin_' . $va_matches[1] . '_delete'])) {
                 continue;
             }
             $vn_item_id = $va_matches[1];
             $t_order_item = new ca_commerce_order_items($vn_item_id);
             if ($t_order_item->getPrimaryKey()) {
                 $t_order_item->setMode(ACCESS_WRITE);
                 $t_order_item->set('loan_return_date', time(), array('SET_DIRECT_DATE' => true));
                 $t_order_item->set('notes', $this->request->getParameter('caClientLibraryCheckin_notes_' . $vn_item_id, pString));
                 $t_order_item->update();
                 if ($t_order_item->numErrors()) {
                     $this->notification->addNotification(_t('Could not check in item %1: %2', $vn_item_id, join("; ", $t_order_item->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                     continue;
                 }
                 $vn_checkin_count++;
             }
         }
     }
     $this->notification->addNotification($vn_checkin_count == 1 ? _t('Checked in %1 item', $vn_checkin_count) : _t('Checked in %1 items', $vn_checkin_count), __NOTIFICATION_TYPE_INFO__);
     $this->Index();
 }
コード例 #2
0
 /**
  * Sets order of items in the currently loaded order to the order of item_ids as set in $pa_item_ids
  *
  * @param array $pa_item_ids A list of item_ids in the order, in the order in which they should be displayed in the order
  * @param array $pa_options An optional array of options. Supported options include:
  *			NONE
  * @return array An array of errors. If the array is empty then no errors occurred
  */
 public function reorderItems($pa_item_ids, $pa_options = null)
 {
     if (!($vn_order_id = $this->getPrimaryKey())) {
         return null;
     }
     $va_item_ranks = $this->getItemIDRanks($pa_options);
     // get current ranks
     $vn_i = 0;
     $o_trans = new Transaction();
     $t_item = new ca_commerce_order_items();
     $t_item->setTransaction($o_trans);
     $t_item->setMode(ACCESS_WRITE);
     $va_errors = array();
     // rewrite ranks
     foreach ($pa_item_ids as $vn_rank => $vn_item_id) {
         if (isset($va_item_ranks[$vn_item_id]) && $t_item->load(array('order_id' => $vn_order_id, 'item_id' => $vn_item_id))) {
             if ($va_item_ranks[$vn_item_id] != $vn_rank) {
                 $t_item->set('rank', $vn_rank);
                 $t_item->update();
                 if ($t_item->numErrors()) {
                     $va_errors[$vn_item_id] = _t('Could not reorder item %1: %2', $vn_item_id, join('; ', $t_item->getErrors()));
                 }
             }
         }
     }
     if (sizeof($va_errors)) {
         $o_trans->rollback();
     } else {
         $o_trans->commit();
     }
     return $va_errors;
 }