/** * 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; }
/** * check if action can be triggered * * @param string $trigger * @param string $target * @param int $action * * @return bool */ protected function isTrigger($trigger, $target, $action = Wrapper::TRIGGER_CREATE) { $config = $GLOBALS['BOOTSTRAP']['wrappers'][$this->objModel->getGroup()]; $key = $action == static::TRIGGER_DELETE ? 'triggerDelete' : 'triggerCreate'; if (isset($config[$trigger][$key]) && $config[$trigger][$key]) { $key = $action == static::TRIGGER_DELETE ? 'autoDelete' : 'autoCreate'; // check if count callback is defined if ($target == ContentWrapper\Model::TYPE_SEPARATOR) { if (!isset($config[$target]['countExisting']) || !isset($config[$target]['countRequired'])) { return false; } } return isset($config[$target][$key]) && $config[$target][$key]; } return false; }
/** * 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); }