public static function autoLoad($reload = false) { if (is_null(self::$options) || $reload) { $data = self::repository()->findAll(array('where' => 'option_autoload = 1')); self::$options = sy_array_to_options($data, 'option_name'); } return self::$options; }
/** * (non-PHPdoc) * * @see \Simplify\Form\Provider::getData() */ public function getData() { if ($this->data === false) { $query = $this->query; if (is_array($query)) { $query = \Simplify::db()->query()->select($this->value)->select($this->label)->setParams($query); } elseif (is_string($query)) { $query = \Simplify::db()->query()->select($this->value)->select($this->label)->from($query); } $data = $query->execute()->fetchAll(); $this->data = sy_array_to_options($data, $this->value, $this->label); } return $this->data; }
/** * * @param unknown_type $data * @return multitype:multitype:Ambigous <unknown, ArrayAccess> multitype:unknown */ public function getOptions($data) { $t = $this->getTable(); $pk = $this->getPrimaryKey(); $fk = $this->getForeignKey(); $at = $this->getAssociationTable(); $apk = $this->getAssociationPrimaryKey(); $afk = $this->getAssociationForeignKey(); $q = \Simplify::db()->query()->select("{$t}.{$fk}")->select("{$t}.{$this->labelField}")->select("{$at}.{$afk} AS checked")->from($t)->leftJoin("{$at} ON ({$t}.{$fk} = {$at}.{$afk} AND {$at}.{$apk} = :{$pk})"); $data = $q->execute(array($pk => $data[\Simplify\Form::ID]))->fetchAll(); $options = sy_array_to_options($data, $fk, $this->labelField); $checked = array(); foreach ($data as $row) { if ($row['checked']) { $checked[] = $row[$fk]; } } return array('options' => $options, 'checked' => $checked); }
/** * (non-PHPdoc) * * @see \Simplify\Form::execute() */ public function execute($action = null) { $Action = $this->getAction($action); $label = $this->getLabel(); $pk = $this->getPrimaryKey(); $parent = $this->getParent(); $left = $this->getLeft(); $right = $this->getRight(); /** * order */ if ($Action->show(\Simplify\Form::ACTION_LIST)) { $listAction = \Simplify::request()->get('listAction'); if ($listAction == self::LIST_ACTION_SORT) { $id = \Simplify::request()->get(\Simplify\Form::ID); $index = \Simplify::request()->get('index'); $this->repository()->moveTo($id, $index); } } /** * filter by parent */ if ($Action->show(\Simplify\Form::ACTION_LIST)) { $q = $this->repository()->mptt()->query()->select(false)->select("node.{$pk}")->select("CONCAT(REPEAT('–', (COUNT(parent.{$pk}) - 1)), ' ', node.{$label}) AS {$label}")->select("(COUNT(parent.{$pk}) - 1) AS depth"); $data = $q->execute()->fetchAll(); $parents = array(0 => __('Nenhum')); $parents += sy_array_to_options($data, $pk, $label); $filter = new \Simplify\Form\Filter\Select($parent, __('Pai')); $filter->showEmpty = false; $filter->defaultValue = \Simplify::request()->get($parent, '0'); $filter->options = $parents; $this->addFilter($filter); } /** * edit parent */ if ($Action->show(\Simplify\Form::ACTION_EDIT || \Simplify\Form::ACTION_CREATE)) { $q = $this->repository()->mptt()->query()->select(false)->select("node.{$pk}")->select("CONCAT(REPEAT('–', (COUNT(parent.{$pk}) - 1)), ' ', node.{$label}) AS {$label}")->select("(COUNT(parent.{$pk}) - 1) AS depth"); $id = $this->getId(); if (!empty($id[0])) { $row = $this->repository()->find($id[0]); $q->where("node.{$left} NOT BETWEEN {$row[$left]} AND {$row[$right]}"); } $data = $q->execute()->fetchAll(); $parents = array(0 => __('Nenhum')); $parents += sy_array_to_options($data, $pk, $label); $parentSelect = new \Simplify\Form\Element\Select($parent, __('Pai')); $parentSelect->showEmpty = false; $parentSelect->defaultValue = \Simplify::request()->get($parent, '0'); $parentSelect->options = $parents; $this->addElement($parentSelect, \Simplify\Form::ACTION_EDIT | \Simplify\Form::ACTION_CREATE, 0); } return parent::execute($action); }