/**
  * handle content element deletion, called by ondelete_callback
  * @param $dc
  */
 public function delete($dc)
 {
     $model = \ContentModel::findByPk($dc->id);
     $this->objModel = new ContentWrapper\Model($model);
     // getType will throw an exception if type is not found. use it to detect non content wrapper elements
     try {
         $type = $this->objModel->getType();
     } catch (\Exception $e) {
         return;
     }
     if ($this->objModel->getType() == ContentWrapper\Model::TYPE_START) {
         $deleteTypes = array();
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_SEPARATOR, static::TRIGGER_DELETE)) {
             $deleteTypes[] = $this->objModel->getTypeName(ContentWrapper\Model::TYPE_SEPARATOR);
         }
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_STOP, static::TRIGGER_DELETE)) {
             $deleteTypes[] = $this->objModel->getTypeName(ContentWrapper\Model::TYPE_STOP);
         }
         if (!empty($deleteTypes)) {
             $this->Database->prepare(sprintf('DELETE FROM tl_content WHERE bootstrap_parentId=? AND type IN(\'%s\')', implode('\',\'', $deleteTypes)))->execute($this->objModel->id);
         }
     } elseif ($this->objModel->getType() == ContentWrapper\Model::TYPE_STOP) {
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_SEPARATOR, static::TRIGGER_DELETE)) {
             $this->Database->prepare('DELETE FROM tl_content WHERE bootstrap_parentId=? AND type=?')->execute($this->objModel->bootstrap_parentId, $this->objModel->getTypeName(ContentWrapper\Model::TYPE_SEPARATOR));
         }
         if ($this->isTrigger($this->objModel->getType(), ContentWrapper\Model::TYPE_START, static::TRIGGER_DELETE)) {
             $query = sprintf('DELETE FROM %s WHERE id=?', $this->objModel->getModel()->getTable());
             \Database::getInstance()->prepare($query)->execute($this->objModel->bootstrap_parentId);
         }
     } else {
         // todo: handle seperator delete actions
     }
 }
 /**
  * count required tab separator elements
  *
  * @param ContentWrapper\Model $model
  *
  * @return int
  */
 public function countRequiredTabSeparators(ContentWrapper\Model $model)
 {
     if ($model->getType() != ContentWrapper\Model::TYPE_START) {
         $model = \ContentModel::findByPk($model->bootstrap_parentId);
     }
     $tabs = array();
     if ($model->bootstrap_tabs) {
         $tabs = deserialize($model->bootstrap_tabs, true);
     } elseif (\Input::post('bootstrap_tabs')) {
         $tabs = \Input::post('bootstrap_tabs');
     }
     $count = 0;
     foreach ($tabs as $tab) {
         if ($tab['type'] != 'dropdown') {
             $count++;
         }
     }
     return $count > 0 ? $count - 1 : 0;
 }
 /**
  * try to find previous element of same type or specified type
  *
  * @param Model $model
  * @param null $type
  *
  * @return \Model|null
  */
 public static function findPreviousElement(Model $model, $type = null)
 {
     if ($type === null) {
         $type = $model->getType();
     }
     $column = array('pid=?', 'ptable=?', 'type=?', 'sorting<?');
     $values = array($model->pid, $model->ptable, $model->getTypeName($type), $model->sorting);
     return \ContentModel::findOneBy($column, $values);
 }