/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $parameters = $parameters->getObjects(); array_unshift($parameters, new Import($class_name)); $parameters[Template::TEMPLATE] = 'importForm'; return View::run($parameters, $form, $files, $class_name, Feature::F_IMPORT); }
/** * @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])]); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $current = User::current(); if ($current) { Authentication::disconnect(User::current()); } $parameters = $this->getViewParameters($parameters, $form, User::class); if (isset($form['login']) && isset($form['password'])) { $user = null; $errors_messages = Authentication::controlRegisterFormParameters($form); if (!$errors_messages && empty($errors_messages)) { if (Authentication::controlNameNotUsed($form['login'])) { $user = Authentication::register($form); } } if ($user) { $parameters[Template::TEMPLATE] = 'confirm'; return View::run($parameters, $form, $files, User::class, 'register'); } else { $parameters['errors'] = $errors_messages; $parameters[Template::TEMPLATE] = 'error'; return View::run($parameters, $form, $files, User::class, 'register'); } } else { $parameters['inputs'] = Authentication::getRegisterInputs(); return View::run($parameters, $form, $files, User::class, 'register'); } }
/** * @param $view_name string the view name is the associated data class name * @param $feature_names string[] feature and inherited feature which view will be searched * @param $template string if a specific template is set, the view named with it will be * searched into the view / feature namespace first * @return callable */ private static function getView($view_name, $feature_names, $template = null) { $view_engine_name = get_class(View::current()); $view_engine_name = Namespaces::shortClassName(Namespaces::of($view_engine_name)); if (isset($template)) { foreach ([$view_engine_name . '_View', 'View'] as $suffix) { foreach ($feature_names as $feature_name) { list($class, $method) = Getter::get($view_name, $feature_name, Names::methodToClass($template) . '_' . $suffix, 'php'); if (isset($class)) { break 2; } } } } if (!isset($class)) { foreach ([$view_engine_name . '_View', 'View'] as $suffix) { foreach ($feature_names as $feature_name) { list($class, $method) = Getter::get($view_name, $feature_name, $suffix, 'php'); if (isset($class)) { break 2; } } } } if (!isset($class)) { list($class, $method) = [__CLASS__ . BS . $view_engine_name . BS . 'Default_View', 'run']; } /** @noinspection PhpUndefinedVariableInspection if $class is set, then $method is set too */ return [$class, $method]; }
/** * @param $object object|string object or class name * @param $parameters string[] parameters * @return Button[] */ protected function getGeneralButtons($object, $parameters) { list($close_link, $follows) = $this->prepareThen($object, $parameters, View::link($object)); $buttons = parent::getGeneralButtons($object, $parameters); unset($buttons['edit']); $fill_combo = isset($parameters['fill_combo']) ? ['fill_combo' => $parameters['fill_combo']] : []; return array_merge($buttons, [Feature::F_CLOSE => new Button('Close', $close_link, Feature::F_CLOSE, [new Color(Feature::F_CLOSE), Target::MAIN]), Feature::F_WRITE => new Button('Write', View::link($object, Feature::F_WRITE, null, array_merge($fill_combo, $follows)), Feature::F_WRITE, [new Color(Color::GREEN), Target::MESSAGES, '.submit'])]); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters = $parameters->getObjects(); if (!reset($parameters) instanceof Menu) { array_unshift($parameters, Session::current()->plugins->get(Menu::class)); } return View::run($parameters, $form, $files, Menu::class, Feature::F_OUTPUT); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $sub_feature = $parameters->shiftUnnamed(); if (!$sub_feature) { $sub_feature = 'form'; } $get = $parameters->toGet(); return (new Main())->runController(View::link($class_name, Feature::F_IMPORT), $get, $form, $files, 'import' . ucfirst($sub_feature)); }
/** * Default run method for the class controller, when no runFeatureName() method was found in it. * * Class controllers must implement this method if you want the controller to work. * * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $object = $parameters->getMainObject(); $parameters = $parameters->getRawParameters(); $validator = new Object_Validator(); $validator->validate($object); $parameters['validator'] = $validator; return View::run($parameters, $form, $files, get_class($object), Validate::FEATURE); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $element_class_name = Set::elementClassNameOf($class_name); $parameters = $parameters->getObjects(); $list_controller = new Data_List_Controller(); $data_list_settings = Data_List_Settings::current($element_class_name); $list_controller->applyParametersToListSettings($data_list_settings, $parameters, $form); return View::run($parameters, $form, $files, $class_name, 'dataListSetting'); }
/** * Default run method for default 'view-typed' controller * * Loads data from objects given as parameters, then run the view associated to the first parameter class. * This is called when no other controller was found for the first parameter object. * * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @param $feature_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name, $feature_name) { $constructor = (new Reflection_Class($class_name))->getConstructor(); if (!$constructor || !$constructor->getMandatoryParameters()) { $parameters->getMainObject($class_name); } else { $parameters->getMainObject(StdClass::class); } $parameters = $parameters->getObjects(); return View::run($parameters, $form, $files, $class_name, $feature_name); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters = $parameters->getObjects(); if ($user = User::current()) { array_unshift($parameters, $user); return View::run($parameters, $form, $files, get_class($user), 'display'); } else { $user = new User(); array_unshift($parameters, $user); return View::run($parameters, $form, $files, get_class($user), 'login'); } }
/** * @param Parameters $parameters * @param array $form * @param array $files * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters = $parameters->getObjects(); $current_user = User::current(); if (!isset($current_user)) { $current_user = new User(); } Authentication::disconnect($current_user); array_unshift($parameters, $current_user); session_destroy(); return View::run($parameters, $form, $files, get_class($current_user), 'disconnect'); }
/** * Call this to remove an element from a given class + feature context * * @param $parameters Parameters removal parameters * - key 0 : context class name (ie a business class) * - key 1 : context feature name (ie Feature::F_OUTPUT, Feature::F_LIST) * - keys 2 and more : the identifiers of the removed elements (ie property names) * @param $form array not used * @param $files array not used * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters = $parameters->getObjects(); $parameters['class_name'] = array_shift($objects); $parameters['feature_name'] = array_shift($objects); array_unshift($objects, new StdClass()); /** * $objects for the view : * - first : an empty class object (ie Property) * - key 'class_name' : the context class name (ie a business class) * - key 'feature_name' : the context feature name (ie Feature::F_OUTPUT, Feature::F_LIST) */ $parameters[Template::TEMPLATE] = 'remove_unavailable'; return View::run($objects, $form, $files, get_class(reset($objects)), Feature::F_REMOVE); }
/** * This will be called for this controller, always. * * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { set_time_limit(900); $import = Import_Builder_Form::build($form, Session::current()->get(Files::class)->files); $import->class_name = $class_name; $parameters->getMainObject($import); $parameters = $parameters->getObjects(); foreach ($import->worksheets as $worksheet) { $array = $worksheet->file->getCsvContent(); $import_array = new Import_Array($worksheet->settings, $import->class_name); $import_array->importArray($array); } $parameters[Template::TEMPLATE] = 'importDone'; return View::run($parameters, $form, $files, $class_name, Feature::F_IMPORT); }
/** * Call this to add an element into a given class + feature context * * @param $parameters Parameters removal parameters * - key 0 : context class name (ie a business class) * - key 1 : context feature name (ie 'output', 'list') * - keys 2 and more : the identifiers of the removed elements (ie property names) * @param $form array not used * @param $files array not used * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters = $parameters->getObjects(); $parameters['class_name'] = array_shift($parameters); $parameters['feature_name'] = array_shift($parameters); $parameters['property_path'] = array_shift($parameters); array_unshift($parameters, new Property()); if ($parameters['feature_name'] == Feature::F_LIST) { $this->addPropertyToList($parameters['class_name'], $parameters['property_path']); } if ($parameters['feature_name'] == 'form') { // ... } $parameters[Template::TEMPLATE] = 'added'; return View::run($parameters, $form, $files, Property::class, Feature::F_ADD); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $replaced = $parameters->getMainObject(); $objects = $parameters->getObjects(); if ($id_replace_with = $parameters->getRawParameter('id_replace_with')) { $objects['replace_with'] = $replacement = Dao::read($id_replace_with, $class_name); Dao::begin(); if ((new Delete_And_Replace())->deleteAndReplace($replaced, $replacement)) { Dao::commit(); $objects['done'] = true; } else { Dao::rollback(); $objects['error'] = true; } } return View::run($objects, $form, $files, $class_name, 'deleteAndReplace'); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $parameters = $parameters->getObjects(); Dao::begin(); $deleted = 0; foreach ($parameters as $object) { if (is_object($object)) { if (!Dao::delete($object)) { $deleted = 0; break; } $deleted++; } } Dao::commit(); $parameters['deleted'] = $deleted ? true : false; return View::run($parameters, $form, $files, $class_name, Feature::F_DELETE); }
/** * This will be called for this controller, always. * * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $environment = Session::current()->get(Environment::class, true); $objects = $parameters->getObjects(); $set_value = isset($objects['']) ? $objects[''] : (isset($objects[1]) ? $objects[1] : null); $name = $objects[0]; $this->property = (new Reflection_Class($environment))->getProperty($name); if ($set_value) { $type = $this->property->getType(); $environment->{$name} = $type->isClass() ? Dao::read($set_value, $type->asString()) : $set_value; $parameters->set('selected', true); return (new Output_Controller())->run($parameters, $form, $files); } else { $objects['controller'] = $this; $objects['name'] = $name; $objects = array_merge([get_class($environment) => $environment], $objects); return View::run($objects, $form, $files, get_class($environment), Feature::F_SELECT); } }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters->set(Parameter::CONTAINER, 'inside_tree'); $search = $parameters->getRawParameter('search'); if (empty($search)) { return parent::run($parameters, $form, $files); } $search = strtolower(str_replace([DOT, '*', '?'], [BS . DOT, '.*', '.?'], strSimplify($search, '.*? ' . BS))); $class_name = Names::setToClass($parameters->shift()); $properties = $this->searchProperties($class_name, $search); $top_property = new Property(); $top_property->class = $class_name; $objects = $parameters->getObjects(); array_unshift($objects, $top_property); $objects['class_name'] = $class_name; $objects['properties'] = $properties; $objects['display_full_path'] = true; return View::run($objects, $form, $files, Property::class, 'select'); }
/** * @param $template_file string * @param $parameters array * @param $feature_name string * @return string */ protected function executeTemplate($template_file, $parameters, $feature_name) { if (isset($parameters[Template::TEMPLATE])) { unset($parameters[Template::TEMPLATE]); } if (isset($parameters[Template::TEMPLATE_CLASS])) { $template_class = $parameters[Template::TEMPLATE_CLASS]; } elseif (isset($parameters[Template::TEMPLATE_NAMESPACE])) { $template_class = $parameters[Template::TEMPLATE_NAMESPACE] . BS . 'Html_Template'; unset($parameters[Template::TEMPLATE_NAMESPACE]); } else { $template_class = Template::class; } /** @var $template Template */ $template = Builder::create($template_class, [reset($parameters), $template_file, $feature_name]); $template->setParameters($parameters); $current = Framework\View::current(); if ($current instanceof Engine && ($css = $current->getCss())) { $template->setCss($css); } return $template->parse(); }
/** * This will be called for this controller, always. * * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $environment = Session::current()->get(Environment::class, true); $parameters = array_merge([get_class($environment) => $environment], $parameters->getObjects()); return View::run($parameters, $form, $files, get_class($environment), Feature::F_OUTPUT); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function runFilesToDatabase(Parameters $parameters, $form, $files) { $maintainer = new Maintainer(); $maintainer->filesToDatabase(); return View::run($parameters->getObjects(), $form, $files, Plugin::class, 'filesToDatabase'); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed * @todo factorize */ public function run(Parameters $parameters, $form, $files, $class_name) { // convert form files to worksheets and session files if ($files) { /** @var $import Import */ $import = $parameters->getMainObject(Import::class); $import->class_name = $class_name; $form = (new Post_Files())->appendToForm($form, $files); foreach ($form as $file) { if ($file instanceof File) { if (!isset($session_files)) { /** @var $session_files Files */ $session_files = Builder::create(Files::class); } $excel = Spreadsheet_File::fileToArray($file->temporary_file_name, $errors); $worksheet_number = 0; foreach ($excel as $temporary_file_name => $worksheet) { if (filesize($temporary_file_name) > 1) { $import_worksheet = Builder::create(Import_Worksheet::class, [$worksheet_number++, Import_Settings_Builder::buildArray($worksheet, $class_name), $csv_file = Builder::create(File::class, [$temporary_file_name])]); $import_worksheet->errors = $errors; $session_files->files[] = $csv_file; $import->worksheets[] = $import_worksheet; } } // only one file once break; } } if (isset($session_files)) { Session::current()->set($session_files); } } else { /** @var $files File[] */ $files = Session::current()->get(Files::class)->files; $parameters->unshift($import = Import_Builder_Form::build($form, $files)); $import->class_name = $class_name; } // prepare parameters $parameters = $parameters->getObjects(); $general_buttons = $this->getGeneralButtons($class_name); if (isset($parameters['constant_remove']) && strtoupper($parameters['constant_remove'][0]) === $parameters['constant_remove'][0]) { $parameters['constant_remove'] = rParse($parameters['constant_remove'], DOT); } foreach ($import->worksheets as $worksheet) { // apply controller parameters if (isset($parameters['constant_add']) && isset($worksheet->settings->classes[$parameters['constant_add']])) { $worksheet->settings->classes[$parameters['constant_add']]->addConstant(); } if (isset($parameters['constant_remove']) && isset($worksheet->settings->classes[lLastParse($parameters['constant_remove'], DOT, 1, false)])) { $worksheet->settings->classes[lLastParse($parameters['constant_remove'], DOT, 1, false)]->removeConstant(rLastParse($parameters['constant_remove'], DOT, 1, true)); } Custom_Settings_Controller::applyParametersToCustomSettings($worksheet->settings, array_merge($form, $parameters)); } // recover empty Import_Settings (after loading empty one) /** @var $files File[] */ $files = Session::current()->get(Files::class)->files; foreach ($import->worksheets as $worksheet_number => $worksheet) { if (empty($worksheet->settings->classes)) { $file = $files[$worksheet_number]; $array = $file->getCsvContent(); $import->worksheets[$worksheet_number] = new Import_Worksheet($worksheet_number, Import_Settings_Builder::buildArray($array, $class_name), $file); } } // get general buttons and customized import settings foreach ($import->worksheets as $worksheet_number => $worksheet) { $customized_import_settings = $worksheet->settings->getCustomSettings(); $worksheet_general_buttons = $general_buttons; if (!isset($customized_import_settings[$worksheet->settings->name])) { unset($worksheet_general_buttons['delete']); } $parameters['custom'][$worksheet_number] = new StdClass(); $parameters['custom'][$worksheet_number]->customized_lists = $customized_import_settings; $parameters['custom'][$worksheet_number]->general_buttons = $worksheet_general_buttons; $parameters['custom'][$worksheet_number]->settings = $worksheet->settings; $parameters['custom'][$worksheet_number]->aliases_property = Import_Array::getPropertiesAlias($worksheet->settings->getClassName()); $parameters['custom'][$worksheet_number]->properties_alias = array_flip($parameters['custom'][$worksheet_number]->aliases_property); } // view $parameters[Template::TEMPLATE] = 'importPreview'; return View::run($parameters, $form, $files, $class_name, Feature::F_IMPORT); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $objects = $parameters->getObjects(); $objects['link'] = SL . str_replace(BS, SL, Session_File::class) . '/output/' . reset($objects); return View::run($objects, $form, $files, Session_File::class, 'image'); }
/** * Default run method for default 'write-typed' controller * * Save data from the posted form into the first parameter object using standard method. * Create a new instance of this object if no identifier was given. * * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return string * @throws Exception */ public function run(Parameters $parameters, $form, $files, $class_name) { $object = $parameters->getMainObject($class_name); Dao::begin(); try { $builder = new Post_Files(); $form = $builder->appendToForm($form, $files); $builder = new Object_Builder_Array(); $builder->null_if_empty_sub_objects = true; $builder->build($form, $object); $write_objects = []; foreach ($builder->getBuiltObjects() as $write_object) { if ($write_object == $object || Dao::getObjectIdentifier($write_object)) { $write_objects[] = $write_object; } } $write_error = false; foreach ($write_objects as $write_object) { if (!Dao::write($write_object)) { $write_error = true; break; } } $write_error ? Dao::rollback() : Dao::commit(); } catch (Exception $exception) { Dao::rollback(); throw $exception; } $parameters = $this->getViewParameters($parameters, $class_name, $write_error); return View::run($parameters, $form, $files, $class_name, Feature::F_WRITE); }
/** * @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; }
/** * Default run method for default 'list-typed' view controller * * @param $parameters Parameters * @param $form array * @param $files array * @param $class_name string * @return mixed */ public function run(Parameters $parameters, $form, $files, $class_name) { $parameters = $this->getViewParameters($parameters, $form, $class_name); return View::run($parameters, $form, $files, $class_name, Feature::F_LIST); }
/** * This will be called for this controller, always. * * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters = $this->getViewParameters($parameters); return View::run($parameters, $files, $form, Article::class, 'show'); }
/** * @param $parameters Parameters * @param $form array * @param $files array * @return mixed */ public function run(Parameters $parameters, $form, $files) { $parameters->unshift(Application::current()); return View::run($parameters->getObjects(), $form, $files, get_class(Application::current()), 'home'); }
/** * Property select controller, starting from a given root class * * @param $parameters Parameters * - first : the root reference class name (ie a business object) * - second : if set, the selected property path into the root reference class name * @param $form array not used * @param $files array not used * @return mixed */ public function run(Parameters $parameters, $form, $files) { $class_name = Set::elementClassNameOf($parameters->shiftUnnamed()); $property_path = $parameters->shiftUnnamed(); if (empty($property_path)) { $top_property = new Property(); $top_property->class = $class_name; $properties = $this->getProperties(new Reflection_Class($class_name)); foreach ($properties as $property) { $property->path = $property->name; } } else { $top_property = new Reflection_Property($class_name, $property_path); $properties = $this->getProperties(new Reflection_Class($top_property->getType()->getElementTypeAsString()), $top_property->final_class); foreach ($properties as $property) { $property->path = $property_path . DOT . $property->name; } if (!$parameters->getRawParameter(Parameter::CONTAINER)) { $parameters->set(Parameter::CONTAINER, 'subtree'); } } $objects = $parameters->getObjects(); array_unshift($objects, $top_property); $objects['properties'] = $properties; $objects['class_name'] = $class_name; $objects['display_full_path'] = false; /** * Objects for the view : * first Property the property object (with selected property name, or not) * 'properties' Reflection_Property[] all properties from the reference class */ return View::run($objects, $form, $files, Property::class, 'select'); }