function getPositionsArray()
 {
     $positionsArray = array();
     $positionIds = explode(' ', $this->positions);
     foreach ($positionIds as $id) {
         $position = new oqc_ExternalContractPositions();
         if ($position->retrieve($id)) {
             $positionsArray[] = $position->toArray();
         } else {
             $GLOBALS['log']->warn('external contract references invalid position entity.');
         }
     }
     return $positionsArray;
 }
 private function savePositions($isDuplicate)
 {
     $this->auditDeletedPositions();
     if (isset($_REQUEST['positionIds']) && is_array($_REQUEST['positionIds'])) {
         $positionIds = array();
         $numberOfPositions = count($_REQUEST['positionIds']);
         for ($i = 0; $i < $numberOfPositions; $i++) {
             $id = $_REQUEST['positionIds'][$i];
             $name = $_REQUEST["positionName_{$id}"];
             $type = $_REQUEST['positionType'][$i];
             $qty = $_REQUEST["positionQuantity_{$id}"];
             $price = $_REQUEST["positionPrice_{$id}"];
             $desc = $_REQUEST["positionDescription_{$id}"];
             $position = new oqc_ExternalContractPositions();
             $beforeText = null;
             if (!$isDuplicate && $position->retrieve($id)) {
                 // position could be successfully found in db, it is initialized with old values from database
                 if ($position->name != $name || $position->type != $type || $position->quantity != $qty || $position->price != $price || $position->description != $desc) {
                     $beforeText = $position->as_plain_text();
                 }
             } else {
                 $beforeText = '<n/a>';
             }
             // set new values for position
             $position->name = $name;
             $position->type = $type;
             $position->quantity = $qty;
             $position->description = $desc;
             $position->price = $price;
             // does an update if the position already existed or an insert if it is a new position
             $position->save();
             // add the position id to the list of positions for this external contract instance
             $positionIds[] = $position->id;
             if (isset($beforeText)) {
                 $changes = array('field_name' => translate('LBL_POSITIONS'), 'data_type' => 'text', 'before' => $beforeText, 'after' => $position->as_plain_text());
                 global $sugar_version;
                 if (floatval(substr($sugar_version, 0, 3)) > 6.3) {
                     $this->bean->db->save_audit_records($this->bean, $changes);
                 } else {
                     $this->bean->dbManager->helper->save_audit_records($this->bean, $changes);
                 }
             }
         }
         if ($numberOfPositions > 0) {
             $this->bean->positions = implode(' ', $positionIds);
         } else {
             $this->bean->positions = '';
         }
     } else {
         $this->bean->positions = '';
     }
 }