/** * @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 $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 $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); }
/** * 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 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'); }
/** * @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'); } }
/** * 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); }
/** * @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'); }
/** * 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 runFilesToDatabase(Parameters $parameters, $form, $files) { $maintainer = new Maintainer(); $maintainer->filesToDatabase(); return View::run($parameters->getObjects(), $form, $files, Plugin::class, 'filesToDatabase'); }
/** * @param $object object * @param $only string[] only property names * @return string */ private function notValidated($object, $only = []) { $parameters = [$this, 'object' => $object, 'only' => $only, Parameter::AS_WIDGET => true, View\Html\Template::TEMPLATE => 'not_validated']; return View::run($parameters, [], [], get_class($object), 'validate'); }
/** * @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'); }
/** * 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 * @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); }
/** * 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'); }
/** * @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'); }
/** * 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); }
/** * 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); }