/** * @param $object object|string object or class name * @param $parameters string[] parameters * @return Button[] */ protected function getGeneralButtons($object, $parameters) { $buttons = parent::getGeneralButtons($object, $parameters); $close_link = View::link(Names::classToSet(get_class($object))); list($close_link) = $this->prepareThen($object, $parameters, $close_link); return array_merge($buttons, [Feature::F_CLOSE => new Button('Close', $close_link, Feature::F_CLOSE, [new Color('close'), Target::MAIN])]); }
/** * Gets the store name for records typed as $class_name * * @param $class_name string * @return string */ public function storeNameOf($class_name) { return strtolower(Namespaces::shortClassName(Names::classToSet($class_name))); }
public function testDeleteControllers() { $controller_uri = new Uri('/SAF/Framework/Widget/Tab/remove/' . Names::classToSet(Order::class) . SL . Feature::F_LIST . '/date/number', [Parameter::AS_WIDGET => true, '_' => 2]); $this->assume(__METHOD__, ['controller_name' => $controller_uri->controller_name, 'feature_name' => $controller_uri->feature_name, 'parameters' => $controller_uri->parameters->getRawParameters()], ['controller_name' => Tab::class, 'feature_name' => Feature::F_REMOVE, 'parameters' => (new Parameters())->addValue(Names::classToSet(Order::class))->addValue(Feature::F_LIST)->addValue('date')->addValue('number')->set(Parameter::AS_WIDGET, true)->set('_', 2)->getRawParameters()]); }
/** * Prepare close link and follows links for buttons * * @example Call this from getGeneralButtons() : * list($close_link, $follows) = $this->prepareThen($object, $parameters); * Then use $close_link and $follows as needed * @param $object object * @param $parameters array * @param $default_close_link string * @return array first element is the close link, second element is an array of a link parameter */ protected function prepareThen($object, $parameters, $default_close_link = null) { if (isset($parameters[Controller::THEN])) { $close_link = $parameters[Controller::THEN]; $follows = [Controller::THEN => $parameters[Controller::THEN]]; } else { $close_link = $default_close_link ?: View::link(Names::classToSet(get_class($object))); $follows = []; } return [$close_link, $follows]; }
/** * Generates a link for to an object and feature, using parameters if needed * * @param $object object|string linked object or class name * @param $feature string linked feature name * @param $parameters string|string[]|object|object[] optional parameters list * @param $arguments string|string[] optional arguments list * @return string */ public function link($object, $feature = null, $parameters = null, $arguments = null) { // class name : not Built, not Set $class_names = is_string($object) ? $object : get_class($object); $class_name = Names::setToClass($class_names, false); $set_class = $class_name != $class_names; while (Builder::isBuilt($class_name)) { $class_name = get_parent_class($class_name); } if ($set_class) { $class_name = Names::classToSet($class_name); } // build uri $link = str_replace(BS, SL, is_object($object) && Dao::getObjectIdentifier($object) ? $class_name . SL . Dao::getObjectIdentifier($object) : $class_name); if (isset($feature)) { $link .= SL . $feature; } if (isset($parameters)) { if (!is_array($parameters)) { $parameters = [$parameters]; } foreach ($parameters as $key => $value) { if (!is_numeric($key)) { $link .= SL . $key; } if (is_object($value)) { $link .= SL . Names::classToUri(get_class($value)) . SL . Dao::getObjectIdentifier($value); } else { $link .= SL . $value; } } } // build arguments if (!empty($arguments)) { if (!is_array($arguments)) { $link .= '?' . urlencode($arguments); } else { $link .= '?'; $first = true; foreach ($arguments as $key => $value) { if ($first) { $first = false; } else { $link .= '&'; } $link .= $key . '=' . urlencode($value); } } } return SL . $link; }
/** * @param $conditions string[] the key is the name of the condition, the value is the name of the * value that enables the condition * @param $filters string[] the key is the name of the filter, the value is the name of the form * element containing its value * @return string */ public function buildObject($conditions = null, $filters = null) { $class_name = $this->type->asString(); // visible input $input = new Input(null, strval($this->value)); $input->setAttribute('autocomplete', 'off'); $input->setAttribute('data-combo-class', Names::classToSet($class_name)); if (!$this->readonly) { if ($filters) { $html_filters = []; $old_name = $this->name; foreach ($filters as $filter_name => $filter_value) { $this->name = $filter_value; $name = $this->getFieldName('', false); $html_filters[] = $filter_name . '=' . $name; } $this->name = $old_name; $input->setAttribute('data-combo-filters', join(',', $html_filters)); } if ($conditions) { $html_conditions = []; $old_name = $this->name; foreach ($conditions as $condition_name => $condition_value) { $this->name = $condition_name; $name = $this->getFieldName('', false); $html_conditions[] = $name . '=' . $condition_value; } $this->name = $old_name; $input->setAttribute('data-conditions', join(';', $html_conditions)); } $input->addClass('autowidth'); $input->addClass('combo'); // id input $id_input = new Input($this->getFieldName('id_'), $this->value ? Dao::getObjectIdentifier($this->value) : ''); $id_input->setAttribute('type', 'hidden'); $id_input->addClass('id'); // 'add' / 'edit' anchor $fill_combo = isset($this->template) ? ['fill_combo' => $this->template->getFormId() . DOT . $this->getFieldName('id_', false)] : ''; $edit = new Anchor(View::current()->link($this->value ? get_class($this->value) : $class_name, Feature::F_ADD, null, $fill_combo), 'edit'); $edit->addClass('edit'); $edit->setAttribute('target', Target::BLANK); $edit->setAttribute('title', '|Edit ¦' . Names::classToDisplay($class_name) . '¦|'); // 'more' button $more = new Button('more'); $more->addClass('more'); $more->setAttribute('tabindex', -1); $this->setOnChangeAttribute($id_input); return $id_input . $input . $more . $edit; } return $input; }
/** * Returns object's class name * * @param $template Template * @return string */ public function getClass(Template $template) { $object = reset($template->objects); return is_object($object) ? $object instanceof Set ? new Displayable(Names::classToSet($object->element_class_name), Displayable::TYPE_CLASS) : new Displayable(get_class($object), Displayable::TYPE_CLASS) : new Displayable($object, Displayable::TYPE_CLASS); }