Backend\Modules\ContentBlocks\Engine\Model::insert PHP Method

insert() public static method

Add a new item.
Deprecation: use doctrine instead
public static insert ( array $item ) : integer
$item array The data to insert.
return integer
    public static function insert(array $item)
    {
        trigger_error('Backend\\Modules\\ContentBlocks\\Engine is deprecated.
             Switch to doctrine instead.', E_USER_DEPRECATED);
        // insert extra
        $item['extra_id'] = BackendModel::insertExtra(ModuleExtraType::widget(), 'ContentBlocks', 'Detail');
        $item['revision_id'] = BackendModel::get('database')->insert('content_blocks', $item);
        // update data for the extra
        BackendModel::updateExtra($item['extra_id'], 'data', array('id' => $item['id'], 'extra_label' => $item['title'], 'language' => $item['language'], 'edit_url' => BackendModel::createURLForAction('Edit', 'ContentBlocks', $item['language']) . '&id=' . $item['id'], 'custom_template' => $item['template']));
        return $item['revision_id'];
    }

Usage Example

Example #1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $fields = $this->frm->getFields();
         // validate fields
         $fields['title']->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = BackendContentBlocksModel::getMaximumId() + 1;
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['template'] = count($this->templates) > 1 ? $fields['template']->getValue() : $this->templates[0];
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $fields['title']->getValue();
             $item['text'] = $fields['text']->getValue();
             $item['hidden'] = $fields['hidden']->getValue() ? 'N' : 'Y';
             $item['status'] = 'active';
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $item['revision_id'] = BackendContentBlocksModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('Index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }