/** * Count required tab separator elements. * * @param \Database\Result $model Current row. * @param Helper $helper Wrapper helper. * * @return int */ public function countRequiredTabSeparators(\Database\Result $model, Helper $helper) { if (!$helper->isTypeOf(Helper::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; }
/** * Create separator elements. * * @param Helper $wrapper Wrapper helper. * @param \Database\Result $record Database result. * @param int $sorting Sorting index. * * @return array|int */ private function createSeparators($wrapper, $record, $sorting) { $config = Bootstrap::getConfigVar(sprintf('wrappers.%s.%s', $wrapper->getGroup(), Helper::TYPE_SEPARATOR)); $callback = $config['count-existing']; $instance = \Controller::importStatic($callback[0]); $existing = $instance->{$callback}[1]($record, $wrapper); $callback = $config['count-required']; $instance = \Controller::importStatic($callback[0]); $required = $instance->{$callback}[1]($record, $wrapper); if ($existing < $required) { if ($this->isTrigger($wrapper->getType(), Helper::TYPE_SEPARATOR)) { $count = $required - $existing; for ($i = 0; $i < $count; $i++) { $this->createElement($record, $sorting, Helper::TYPE_SEPARATOR); } $end = $wrapper->findRelatedElement(Helper::TYPE_STOP); if ($end && $end->sorting <= $sorting) { $sorting = $sorting + 2; $end->sorting = $sorting; $end->save(); return array($sorting, $end); } } } elseif ($required < $existing) { if ($this->isTrigger($wrapper->getType(), Helper::TYPE_SEPARATOR, static::TRIGGER_DELETE)) { $count = $existing - $required; $parentId = $wrapper->isTypeOf(Helper::TYPE_START) ? $record->id : $record->bootstrap_parentId; \Database::getInstance()->prepare('DELETE FROM tl_content WHERE bootstrap_parentId=? AND type=? ORDER BY sorting DESC')->limit($count)->execute($parentId, $wrapper->getTypeName(Helper::TYPE_SEPARATOR)); } } return $sorting; }