function getSmartyTextblockArray($textblockArray)
{
    $smartyTextblockArray = array();
    foreach ($textblockArray as $textblock) {
        $smartyTextblockArray[] = array('id' => $textblock->id, 'name' => $textblock->name, 'description' => $textblock->description, 'textblock_id' => oqc_EditedTextBlock::getFromId($textblock->id) != null && !empty($textblock->textblock_id) ? $textblock->textblock_id : "");
    }
    return $smartyTextblockArray;
}
 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;
 }