コード例 #1
0
function getTextblocks($textblockIds, $idoffreetextblock, $view)
{
    global $app_list_strings;
    if (empty($textblockIds) && $view == 'DetailView') {
        return array();
    }
    $textblocks = array();
    if ($idoffreetextblock) {
        if (!in_array($idoffreetextblock, $textblockIds)) {
            $freetext = new oqc_EditedTextBlock();
            $freetext->retrieve($idoffreetextblock);
            $textblocks[] = $freetext;
        }
    }
    if (!empty($textblockIds)) {
        foreach ($textblockIds as $id) {
            $textblock = new oqc_Textblock();
            $editedTextblock = new oqc_EditedTextBlock();
            if ($textblock->retrieve($id)) {
                $textblocks[] = $textblock;
            } else {
                if ($editedTextblock->retrieve($id)) {
                    $textblocks[] = $editedTextblock;
                }
            }
        }
    } else {
        //	$GLOBALS['log']->error("creating empty textblock");
        $newTextblock = new oqc_EditedTextBlock();
        $newTextblock->id = create_guid();
        $newTextblock->name = $app_list_strings["oqc"]["Textblocks"]["freeText"];
        $newTextblock->description = '';
        $textblocks[0] = $newTextblock;
    }
    return $textblocks;
}
コード例 #2
0
 protected function updateTextblockDescriptions()
 {
     global $sugar_version;
     $sequence = $_POST['textblockSequence'];
     $textblockIds = explode(' ', trim($sequence));
     foreach ($textblockIds as $textblockId) {
         $key = "description_{$textblockId}";
         $userEditedDescription = $_POST[$key];
         if ($userEditedDescription == '') {
             //$GLOBALS['log']->error('skipping texblock save- empty description');
             $sequence = trim(str_replace($textblockId, '', $sequence));
             //do not save if it is empty
             continue;
         }
         if ($originalTextblock = oqc_TextBlock::getFromId($textblockId)) {
             // it is a TextBlock instance
             // if the user changed the description copy the information from the TextBlock instance into a new instance of EditedTextBlock
             if ($originalTextblock->description != $userEditedDescription) {
                 $changes = array('field_name' => $originalTextblock->name, 'data_type' => 'text', 'before' => $originalTextblock->description, 'after' => $userEditedDescription);
                 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);
                 }
                 $editedTextblock = new oqc_EditedTextBlock();
                 $editedTextblock->name = $originalTextblock->name;
                 $editedTextblock->textblock_id = $originalTextblock->id;
                 $editedTextblock->description = $userEditedDescription;
                 $editedTextblock->save();
                 //$GLOBALS['log']->error('saved as edited original template texblock');
                 if (!empty($textblockId) && !empty($editedTextblock->id)) {
                     $sequence = str_replace($textblockId, $editedTextblock->id, $sequence);
                 } else {
                     $GLOBALS['log']->fatal('textblockId or editedTextblock->id is empty');
                 }
             }
             // check if textBlock is newly added
             if (strpos($this->bean->textblocksequence, $textblockId) === false) {
                 $changes = array('field_name' => $originalTextblock->name, 'data_type' => 'text', 'before' => '<n/a>', 'after' => $userEditedDescription);
                 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);
                 }
             }
         } else {
             if ($editedTextblock = oqc_EditedTextBlock::getFromId($textblockId)) {
                 // it has to be an EditedTextBlock instance
                 // update the description and save it
                 if ($editedTextblock->description != $userEditedDescription) {
                     //$GLOBALS['log']->error('saved as edited template texblock that was saved before');
                     $changes = array('field_name' => $editedTextblock->name, 'data_type' => 'text', 'before' => $editedTextblock->description, 'after' => $userEditedDescription);
                     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);
                     }
                     $editedTextblock->id = '';
                     //1.7.6 avoid Quotes inheriting textblock from linked Contract and vice versa
                     $editedTextblock->description = $userEditedDescription;
                     $editedTextblock->save();
                     //1.7.6 getting new id
                     if (!empty($textblockId) && !empty($editedTextblock->id)) {
                         $sequence = str_replace($textblockId, $editedTextblock->id, $sequence);
                     }
                 }
             } else {
                 //2.0 this is former free text saving part
                 global $app_list_strings;
                 //$GLOBALS['log']->error('saving as free text edited texblock');
                 $changes = array('field_name' => $app_list_strings["oqc"]["Textblocks"]["freeText"], 'data_type' => 'text', 'before' => '<n/a>', 'after' => $userEditedDescription);
                 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);
                 }
                 $newTextblock = new oqc_EditedTextBlock();
                 $newTextblock->name = $app_list_strings["oqc"]["Textblocks"]["freeText"];
                 $newTextblock->id = '';
                 //$newTextblock->id = $textblockId;
                 $newTextblock->textblock_id = '';
                 $newTextblock->description = $userEditedDescription;
                 $newTextblock->save();
                 if (!empty($textblockId) && !empty($newTextblock->id)) {
                     $sequence = str_replace($textblockId, $newTextblock->id, $sequence);
                 } else {
                     $GLOBALS['log']->fatal('textblockId or editedTextblock->id is empty');
                 }
             }
         }
     }
     return $sequence;
 }
コード例 #3
0
 public static function getFromId($id)
 {
     $editedtextblock = new oqc_EditedTextBlock();
     return $editedtextblock->retrieve($id);
 }
コード例 #4
0
 function get_all_linked_textblocks()
 {
     // return array_merge($this->get_linked_textblocks(), $this->get_linked_edited_textblocks());
     $textblockIds = explode(' ', trim($this->textblocksequence));
     $textblocks = array();
     foreach ($textblockIds as $id) {
         $textblock = new oqc_Textblock();
         $editedTextblock = new oqc_EditedTextBlock();
         if ($textblock->retrieve($id)) {
             $textblocks[] = $textblock;
         } else {
             if ($editedTextblock->retrieve($id)) {
                 $textblocks[] = $editedTextblock;
             }
         }
     }
     return $textblocks;
 }