public function create(ConditionModel $conditionModel) { $eventDispatcher = $this->getEventDispatcher(); $event = new CreateConditionEvent($conditionModel); $eventDispatcher->dispatch(EVENT_XNAVIGATION_CREATE_CONDITION, $event); if ($event->getCondition()) { return $event->getCondition(); } $row = $conditionModel->row(); $type = $conditionModel->type; $className = $this->getConditionClassName($type); $class = new \ReflectionClass($className); $condition = $class->newInstance(); $rgxp = '~^' . preg_quote($type, '~') . '_(.*)$~'; foreach ($row as $key => $value) { if ($value && preg_match($rgxp, $key, $matches)) { $property = $matches[1]; $property = explode('_', $property); $property = array_map('ucfirst', $property); $property = implode('', $property); $setterName = 'set' . $property; if ($class->hasMethod($setterName)) { $setter = $class->getMethod($setterName); $parameters = $setter->getParameters(); if (count($parameters)) { $firstParameter = $parameters[0]; // unserialize magic if ($firstParameter->isArray()) { $value = deserialize($value, true); } $setter->invoke($condition, $value); } } } } if ($condition instanceof ChainConditionInterface) { $childConditionCollection = ConditionModel::findBy('pid', $conditionModel->id, array('order' => 'sorting')); if ($childConditionCollection) { while ($childConditionCollection->next()) { $childCondition = $this->create($childConditionCollection->current()); $condition->addCondition($childCondition); } } } if ($condition instanceof ParentCondition) { $childConditionCollection = ConditionModel::findBy('pid', $conditionModel->id, array('order' => 'sorting')); if ($childConditionCollection && $childConditionCollection->next()) { $childCondition = $this->create($childConditionCollection->current()); $condition->setCondition($childCondition); } } if ($conditionModel->invert) { $condition = new NotCondition($condition); } return $condition; }
protected function createCondition($conditionId, MenuModel $menu, ConditionFactory $conditionFactory) { $conditionModel = ConditionModel::findByPk($conditionId); if ($conditionModel) { return $conditionFactory->create($conditionModel); } return null; }
public function getCondition() { $conditionModel = ConditionModel::findByPk($this->conditionId); if ($conditionModel) { $conditionFactory = new ConditionFactory(); $condition = $conditionFactory->create($conditionModel); return $condition; } return null; }
public function getConditionOptions() { $options = array(); $conditionFactory = new ConditionFactory(); $conditionCollection = ConditionModel::findBy('pid', '0', array('order' => 'sorting')); if ($conditionCollection) { while ($conditionCollection->next()) { if ($conditionCollection->title) { $title = $conditionCollection->title; } else { $condition = $conditionFactory->create($conditionCollection->current()); $title = $condition->describe(); } $options[$conditionCollection->id] = $title; } } return $options; }
public function getLabel($row, $label) { try { $session = \Session::getInstance()->getData(); $tree = $session['tl_xnavigation_condition_tree']; $type = $GLOBALS['TL_LANG']['xnavigation_condition'][$row['type']][0]; $title = $row['title']; $factory = new ConditionFactory(); $conditionModel = ConditionModel::findByPk($row['id']); $condition = $factory->create($conditionModel); if (isset($tree[$row['id']]) && $tree[$row['id']]) { $html = sprintf('<span style="color:#b3b3b3;padding-left:3px">%s</span>', $type); } else { $describe = $condition->describe(); $html = sprintf('<span style="color:#b3b3b3;padding-left:3px">%s</span> <span class="condition_describe">%s</span>', $type, $describe); } if ($title) { $html = sprintf('%s<div style="text-indent:-23px">%s</div>', $title, $html); } } catch (\Exception $e) { $html = $e->getMessage(); } return $html; }
public function createDefaultCondition(CreateDefaultConditionEvent $event) { $root = new ConditionModel(); $root->pid = $event->getCondition()->id; $root->sorting = 128; $root->type = 'and'; $root->save(); // page type $condition = new ConditionModel(); $condition->pid = $root->id; $condition->sorting = 128; $condition->type = 'item_type'; $condition->item_type_accepted_type = 'page'; $condition->save(); // page published $condition = new ConditionModel(); $condition->pid = $root->id; $condition->sorting = 256; $condition->type = 'page_published'; $condition->save(); // page hidden $condition = new ConditionModel(); $condition->pid = $root->id; $condition->sorting = 512; $condition->type = 'page_hide'; $condition->page_hide_accepted_hide_status = ''; $condition->save(); // page type $or = new ConditionModel(); $or->pid = $root->id; $or->sorting = 1024; $or->type = 'or'; $or->save(); $condition = new ConditionModel(); $condition->pid = $or->id; $condition->sorting = 128; $condition->type = 'page_type'; $condition->page_type_accepted_type = 'regular'; $condition->save(); $condition = new ConditionModel(); $condition->pid = $or->id; $condition->sorting = 256; $condition->type = 'page_type'; $condition->page_type_accepted_type = 'forward'; $condition->save(); $condition = new ConditionModel(); $condition->pid = $or->id; $condition->sorting = 512; $condition->type = 'page_type'; $condition->page_type_accepted_type = 'redirect'; $condition->save(); // login status $or = new ConditionModel(); $or->pid = $root->id; $or->sorting = 2048; $or->type = 'or'; $or->save(); // unprotected pages $and = new ConditionModel(); $and->pid = $or->id; $and->sorting = 128; $and->type = 'and'; $and->save(); // login status -> not protected $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 128; $condition->type = 'page_protected'; $condition->page_protected_accepted_protected_status = ''; $condition->save(); // login status -> OR ... $or = new ConditionModel(); $or->pid = $and->id; $or->sorting = 256; $or->type = 'or'; $or->save(); // login status -> OR -> not logged in $condition = new ConditionModel(); $condition->pid = $or->id; $condition->sorting = 128; $condition->type = 'member_login'; $condition->member_login_accepted_login_status = 'logged_out'; $condition->save(); // login status -> OR -> page not guests only $condition = new ConditionModel(); $condition->pid = $or->id; $condition->sorting = 256; $condition->type = 'page_guests'; $condition->page_guests_accepted_guests_status = ''; $condition->save(); // protected pages $and = new ConditionModel(); $and->pid = $or->id; $and->sorting = 256; $and->type = 'and'; $and->save(); // login status -> protected $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 128; $condition->type = 'page_protected'; $condition->page_protected_accepted_protected_status = ''; $condition->save(); // login status -> page groups $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 256; $condition->type = 'page_groups'; $condition->save(); }
public function createDefaultCondition(CreateDefaultConditionEvent $event) { $root = new ConditionModel(); $root->pid = $event->getCondition()->id; $root->sorting = 128; $root->type = 'and'; $root->save(); // article type $condition = new ConditionModel(); $condition->pid = $root->id; $condition->sorting = 128; $condition->type = 'item_type'; $condition->item_type_accepted_type = 'article'; $condition->save(); // article published $condition = new ConditionModel(); $condition->pid = $root->id; $condition->sorting = 256; $condition->type = 'article_published'; $condition->save(); // login status $or = new ConditionModel(); $or->pid = $root->id; $or->sorting = 512; $or->type = 'or'; $or->save(); // unprotected articles $and = new ConditionModel(); $and->pid = $or->id; $and->sorting = 128; $and->type = 'and'; $and->save(); // login status -> not protected $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 128; $condition->type = 'article_protected'; $condition->article_members_accepted_protected_status = ''; $condition->save(); // login status -> not logged in $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 256; $condition->type = 'member_login'; $condition->member_login_accepted_login_status = 'logged_out'; $condition->save(); // login status -> article guests only $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 512; $condition->type = 'article_guests'; $condition->article_guests_accepted_guests_status = ''; $condition->save(); // protected articles $and = new ConditionModel(); $and->pid = $or->id; $and->sorting = 256; $and->type = 'and'; $and->save(); // login status -> protected $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 128; $condition->type = 'article_protected'; $condition->article_members_accepted_protected_status = ''; $condition->save(); // login status -> article groups $condition = new ConditionModel(); $condition->pid = $and->id; $condition->sorting = 256; $condition->type = 'article_groups'; $condition->save(); }