Exemplo n.º 1
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     /** @var $session_files Files */
     $raw_parameters = $parameters->getRawParameters();
     $file_key = reset($raw_parameters);
     $session_files = Session::current()->get(Files::class);
     // numeric (session files index) file key
     if (isset($session_files->files[$file_key])) {
         $file = $session_files->files[$file_key];
     } else {
         foreach ($session_files->files as $file) {
             if ($file->name === $file_key) {
                 break;
             }
         }
     }
     // output
     if (isset($file)) {
         header('Content-Type: ' . $file->getType());
         if (isset($raw_parameters['size'])) {
             $image = Image::createFromString($file->content);
             $image->resize($raw_parameters['size'], $raw_parameters['size'])->display();
         } else {
             echo $file->content;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * 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');
 }
Exemplo n.º 4
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $class_name string
  * @return mixed[]
  */
 protected function getViewParameters(Parameters $parameters, $form, $class_name)
 {
     $object = $parameters->getMainObject($class_name);
     $duplicator = new Duplicator();
     $duplicator->createDuplicate($object);
     return parent::getViewParameters($parameters, $form, $class_name);
 }
Exemplo n.º 5
0
 /**
  * @param Parameters $parameters
  * @return array
  */
 protected function getViewParameters(Parameters $parameters)
 {
     $article = $parameters->getMainObject(Article::class);
     $articles = Dao::readAll(Article::class);
     $parameters = $parameters->getObjects();
     $parameters = array_merge($parameters, ['articles' => $articles, 'uri' => $this->imageUri() . 'images/', 'general_buttons' => $this->getGeneralButtons($article, $parameters)]);
     return $parameters;
 }
Exemplo n.º 6
0
 /**
  * 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);
 }
Exemplo n.º 7
0
 /**
  * @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));
 }
Exemplo n.º 8
0
 /**
  * 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);
 }
Exemplo n.º 9
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     $class_name = $parameters->shift();
     $method_name = $parameters->shift();
     if (empty($class_name)) {
         (new Tests())->run();
     } elseif (empty($method_name)) {
         (new Tests())->runClass($class_name);
     } else {
         (new Tests())->runClass($class_name, $method_name);
     }
     return '<h3>ALL DONE</h3>';
 }
Exemplo n.º 10
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $class_name string
  * @return mixed[]
  */
 protected function getViewParameters(Parameters $parameters, $form, $class_name)
 {
     $object = $parameters->getMainObject($class_name);
     foreach ((new Reflection_Class($class_name))->getProperties() as $property) {
         $property->setValue($object, $property->getDefaultValue());
     }
     $objects = $parameters->getObjects();
     if (count($objects) > 1) {
         foreach (array_slice($objects, 1) as $property_name => $value) {
             $object->{$property_name} = $value;
         }
     }
     return parent::getViewParameters($parameters, $form, $class_name);
 }
Exemplo n.º 11
0
 /**
  * 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);
 }
 /**
  * @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');
 }
Exemplo n.º 13
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $class_name string
  * @return mixed[]
  */
 protected function getViewParameters(Parameters $parameters, $form, $class_name)
 {
     $object = $parameters->getMainObject($class_name);
     $parameters = $parameters->getObjects();
     $parameters['general_buttons'] = $this->getGeneralButtons($object, $parameters);
     $parameters[Parameter::PROPERTIES_FILTER] = $this->getPropertiesList($class_name);
     $parameters['tabs'] = $this->getTabs($object, $parameters[Parameter::PROPERTIES_FILTER]);
     return $parameters;
 }
Exemplo n.º 14
0
 /**
  * @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');
 }
Exemplo n.º 15
0
 /**
  * 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);
     }
 }
Exemplo n.º 16
0
 /**
  * Parse URI text elements to transform them into parameters, feature name and controller name
  *
  * @example $uri = ['order', 148, 'form') will result on controller 'Order_Form' with parameter 'Order' = 148
  * @param $uri string[]
  */
 private function parseUri($uri)
 {
     // get main object = controller name
     $key = 0;
     $controller_element = '';
     foreach ($uri as $key => $controller_element) {
         if (ctype_lower($controller_element[0]) || is_numeric($controller_element)) {
             break;
         }
     }
     if ($controller_element && ctype_upper($controller_element[0])) {
         $key++;
     }
     $this->controller_name = join(BS, array_slice($uri, 0, $key));
     $uri = array_splice($uri, $key);
     // get main object (as first parameter) and feature name
     $this->feature_name = array_shift($uri);
     $this->parameters = new Parameters($this);
     if (is_numeric($this->feature_name)) {
         $this->parameters->set($this->controller_name, intval($this->feature_name));
         $this->feature_name = array_shift($uri);
         if (!$this->feature_name) {
             $this->feature_name = Feature::F_OUTPUT;
         }
     } elseif ($this->controller_name && !$this->feature_name) {
         if (@class_exists($this->controller_name)) {
             $this->feature_name = Feature::F_ADD;
         } elseif (@class_exists(Names::setToClass($this->controller_name))) {
             $this->feature_name = Feature::F_LIST;
         } else {
             $this->feature_name = Feature::F_DEFAULT;
         }
     }
     // get main parameters
     $controller_elements = [];
     foreach ($uri as $uri_element) {
         if (ctype_upper($uri_element[0])) {
             $controller_elements[] = $uri_element;
         } else {
             if (is_numeric($uri_element)) {
                 $this->parameters->set(join(BS, $controller_elements), intval($uri_element));
             } else {
                 if ($controller_elements) {
                     $this->parameters->addValue(join(BS, $controller_elements));
                 }
                 $this->parameters->addValue($uri_element);
             }
             $controller_elements = [];
         }
     }
     if ($controller_elements) {
         $this->parameters->addValue(join(BS, $controller_elements));
     }
 }
Exemplo n.º 17
0
 /**
  * @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');
 }
Exemplo n.º 18
0
 /**
  * @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);
 }
Exemplo n.º 19
0
 /**
  * @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');
 }
Exemplo n.º 20
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $files      array
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     $trash = $parameters->GetUnnamedParameters();
     $objects = $parameters->getObjects();
     return count($trash) <= 1 ? $this->deleteObject($objects) : $this->parseAndRun($objects);
 }
Exemplo n.º 21
0
 /**
  * @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');
 }
Exemplo n.º 22
0
 /**
  * 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)
 {
     Session::current()->get(Settings::class, true)->add($parameters->getRawParameter('code'), $parameters->getRawParameter('value'));
 }
 /**
  * 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
  * @return mixed
  */
 public function run(Parameters $parameters, $form, $files)
 {
     echo 'check this out man';
     echo '<pre>' . print_r($parameters->getObjects(), true) . '</pre>';
 }
Exemplo n.º 24
0
 /**
  * @param $parameters Parameters
  * @param $form       array
  * @param $class_name string
  * @return mixed[]
  */
 protected function getViewParameters(Parameters $parameters, $form, $class_name)
 {
     $this->class_names = $class_name;
     $class_name = $parameters->getMainObject()->element_class_name;
     $parameters = $parameters->getObjects();
     $list_settings = Data_List_Settings::current($class_name);
     $list_settings->cleanup();
     $this->applyParametersToListSettings($list_settings, $parameters, $form);
     $customized_list_settings = $list_settings->getCustomSettings();
     $count = new Count();
     $data = $this->readData($class_name, $list_settings, $count);
     $displayed_lines_count = min($data->length(), $list_settings->maximum_displayed_lines_count);
     $less_twenty = $displayed_lines_count > 20;
     $more_hundred = $displayed_lines_count < 1000 && $displayed_lines_count < $count->count;
     $more_thousand = $displayed_lines_count < 1000 && $displayed_lines_count < $count->count;
     $parameters = array_merge([$class_name => $data], $parameters, ['customized_lists' => $customized_list_settings, 'displayed_lines_count' => $displayed_lines_count, 'less_twenty' => $less_twenty, 'more_hundred' => $more_hundred, 'more_thousand' => $more_thousand, 'reversed' => $this->getReverseClasses($list_settings), 'rows_count' => $count->count, 'search' => $this->getSearchValues($list_settings), 'search_summary' => $this->getSearchSummary($list_settings), 'settings' => $list_settings, 'short_titles' => $this->getShortTitles($list_settings), 'sort_options' => $this->getSortLinks($list_settings), 'sorted' => $this->getSortClasses($list_settings), 'display_start' => $list_settings->start_display_line_number, 'title' => $list_settings->title(), 'titles' => $this->getTitles($list_settings)]);
     // buttons
     $parameters['general_buttons'] = $this->getGeneralButtons($class_name, $parameters);
     $parameters['selection_buttons'] = $this->getSelectionButtons($class_name);
     if (!isset($customized_list_settings[$list_settings->name])) {
         unset($parameters['general_buttons']['delete']);
     }
     return $parameters;
 }