Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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();
 }
 public function RecordRepresentationSelection()
 {
     $pn_item_id = $this->request->getParameter('item_id', pInteger);
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pn_selected = $this->request->getParameter('selected', pInteger);
     $va_errors = array();
     $t_order_item = new ca_commerce_order_items($pn_item_id);
     if (!$t_order_item->getPrimaryKey()) {
         $va_errors[] = _t("Invalid set item");
     }
     if (!sizeof($va_errors)) {
         $t_order = new ca_commerce_orders($t_order_item->get('order_id'));
         if (!$t_order->getPrimaryKey()) {
             $va_errors[] = _t("Invalid order");
         }
         if (!sizeof($va_errors)) {
             if ((bool) $pn_selected) {
                 $t_order_item->addRepresentations(array($pn_representation_id));
             } else {
                 $t_order_item->removeRepresentations(array($pn_representation_id));
             }
             $va_errors = $t_order_item->getErrors();
         }
     }
     $this->view->setVar("errors", $va_errors);
     $this->view->setVar('representation_id', $pn_representation_id);
     $this->view->setVar('item_id', $pn_item_id);
     $this->render("ajax_select_representation_json.php");
 }