public function addObject()
 {
     if (!$_GET['sell_id']) {
         ilUtil::sendInfo($this->lng->txt('paya_no_object_selected'));
         return $this->showObjectSelector();
     }
     if (!(int) $_POST['vendor']) {
         ilUtil::sendInfo($this->lng->txt('paya_no_vendor_selected'));
         return $this->showSelectedObject();
     }
     include_once 'Services/Payment/classes/class.ilPaymentObject.php';
     $p_obj = new ilPaymentObject($this->user_obj);
     if ($check_subtypes = ilPaymentObject::_checkExcSubtype($_GET['sell_id'])) {
         if (!in_array('download', $check_subtypes)) {
             $p_obj->setSubtype('download');
         } else {
             if (!in_array('upload', $check_subtypes)) {
                 $p_obj->setSubtype('upload');
             }
         }
     } else {
         if (ilPaymentObject::_isPurchasable($_GET['sell_id'])) {
             // means that current object already exits in payment_objects _table ...
             ilUtil::sendInfo($this->lng->txt('paya_object_not_purchasable'));
             return $this->showObjectSelector();
         }
     }
     $p_obj->setRefId((int) $_GET['sell_id']);
     $p_obj->setStatus($p_obj->STATUS_NOT_BUYABLE);
     $p_obj->setPayMethod($p_obj->PAY_METHOD_NOT_SPECIFIED);
     $p_obj->setVendorId((int) $_POST['vendor']);
     $p_obj->setTopicId((int) $_POST['topic_id']);
     $p_obj->setVatId((int) $_POST['vat_id']);
     $new_id = $p_obj->add();
     if ($new_id) {
         ilUtil::sendInfo($this->lng->txt('paya_added_new_object'));
         $_GET['pobject_id'] = $new_id;
         $this->editPrices();
         return true;
     } else {
         ilUtil::sendInfo($this->lng->txt('paya_err_adding_object'));
         return $this->showObjects();
     }
 }
 public function getResultsForPresentation()
 {
     global $lng;
     $results = array();
     $offset_counter = 0;
     $counter = 0;
     $objects_with_topics = array();
     $objects_with_no_topcis = array();
     foreach ($this->getResults() as $result) {
         if ($this->getMaxHits() * ($this->getResultPageNumber() - 1) > $offset_counter) {
             ++$offset_counter;
             continue;
         }
         $results[] = $result;
         ++$counter;
         if ($counter >= $this->getMaxHits()) {
             break;
         }
     }
     foreach ($this->getTopics() as $oTopic) {
         foreach ($results as $result) {
             $topic_id = ilPaymentObject::_lookupTopicId($result['ref_id']);
             if (!(int) $topic_id && !array_key_exists($result['ref_id'], $objects_with_no_topcis)) {
                 $objects_with_no_topcis[$result['ref_id']] = $result;
                 continue;
             }
             if ((int) $topic_id != $oTopic->getId()) {
                 continue;
             }
             if (!array_key_exists($result['ref_id'], $objects_with_topics)) {
                 $objects_with_topics[$result['ref_id']] = $result;
             }
             switch ($result['type']) {
                 // learning material
                 case "sahs":
                 case "lm":
                 case "dbk":
                 case "htlm":
                     $type = "lres";
                     break;
                 default:
                     $type = $result['type'];
                     break;
             }
             $title = ilObject::_lookupTitle($result['obj_id']);
             $description = ilObject::_lookupDescription($result['obj_id']);
             $subtype = '';
             if ($result['type'] == 'exc') {
                 $check_sub = ilPaymentObject::_checkExcSubtype($result['ref_id']);
                 $subtype = ' (' . $lng->txt($check_sub[0]) . ')';
             }
             $presentation_results[$oTopic->getId()][$type][] = array('ref_id' => $result['ref_id'], 'title' => $title . ' ' . $subtype, 'description' => $description, 'type' => $result['type'], 'obj_id' => $result['obj_id'], 'topic_id' => $topic_id, 'child' => $result['child']);
             $this->addPresentationResult($presentation_results[$oTopic->getId()][$type][count($presentation_results[$oTopic->getId()][$type]) - 1]);
         }
     }
     foreach ($results as $result) {
         if (!array_key_exists($result['ref_id'], $objects_with_topics) && !array_key_exists($result['ref_id'], $objects_with_no_topcis)) {
             $objects_with_no_topcis[$result['ref_id']] = $result;
         }
     }
     foreach ($objects_with_no_topcis as $result) {
         switch ($result['type']) {
             // learning material
             case "sahs":
             case "lm":
             case "dbk":
             case "htlm":
                 $type = "lres";
                 break;
             default:
                 $type = $result['type'];
                 break;
         }
         $title = ilObject::_lookupTitle($result['obj_id']);
         $description = ilObject::_lookupDescription($result['obj_id']);
         $presentation_results[0][$type][] = array('ref_id' => $result['ref_id'], 'title' => $title, 'description' => $description, 'type' => $result['type'], 'obj_id' => $result['obj_id'], 'child' => $result['child']);
         $this->addPresentationResult($presentation_results[0][$type][count($presentation_results[0][$type]) - 1]);
     }
     return $presentation_results ? $presentation_results : array();
 }