/** * Create a new wrapper element * * @param int $sorting * @param string $type * * @return ContentWrapper\Model */ protected function createElement(&$sorting, $type = ContentWrapper\Model::TYPE_SEPARATOR) { $model = new \ContentModel(); if ($type == ContentWrapper\Model::TYPE_START) { $sorting = $sorting - 2; } else { $sorting = $sorting + 2; $model->bootstrap_parentId = $this->objModel->id; } $model->tstamp = time(); $model->pid = $this->objModel->pid; $model->ptable = $this->objModel->ptable; $model->type = $this->objModel->getTypeName($type); $model->sorting = $sorting; $model->save(); return $model; }
/** * 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); }
/** * count existing tab separators elements * * @param ContentWrapper\Model $model * * @return int */ public function countExistingTabSeparators(ContentWrapper\Model $model) { $id = $model->getType() == ContentWrapper\Model::TYPE_START ? $model->id : $model->bootstrap_parentId; $number = \ContentModel::countBy('type=? AND bootstrap_parentId', array($model->getTypeName(ContentWrapper\Model::TYPE_SEPARATOR), $id)); return $number; }