コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: Condition.php プロジェクト: bit3/contao-xnavigation
 public function pasteButton(\DataContainer $dc, $row, $table, $cr, $arrClipboard = null)
 {
     $html = '';
     if ($row['id'] > 0) {
         if ($row['pid'] > 0) {
             $parentCondition = ConditionModel::findByPk($row['pid']);
             $disabled = $parentCondition->type != 'or' && $parentCondition->type != 'and' && ($parentCondition->type != 'parent' || (bool) ConditionModel::findBy('pid', $row['id']));
         } else {
             $disabled = false;
         }
         if ($disabled) {
             $html .= \Image::getHtml('pasteafter_.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id']));
         } else {
             $html .= sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', \Backend::addToUrl('act=' . $arrClipboard['mode'] . '&amp;mode=1&amp;pid=' . $row['id'] . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')), specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])), \Image::getHtml('pasteafter.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])));
         }
     }
     if ($row['id'] == 0 || $row['type'] == 'or' || $row['type'] == 'and' || $row['type'] == 'parent' && !ConditionModel::findBy('pid', $row['id'])) {
         $html .= sprintf('<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ', \Backend::addToUrl('act=' . $arrClipboard['mode'] . '&amp;mode=2&amp;pid=' . $row['id'] . (!is_array($arrClipboard['id']) ? '&amp;id=' . $arrClipboard['id'] : '')), specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])), \Image::getHtml('pasteinto.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])));
     } else {
         $html .= \Image::getHtml('pasteinto_.gif', sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id']));
     }
     return $html;
 }