Exemplo n.º 1
0
 public function showView($sources = null)
 {
     if (!isset($sources)) {
         $sources = $this->sources;
     }
     $href = Main::encodeURL($this->class, $this->construct_params, $this->method, $this->method_params);
     $content = vsprintf(array_shift($sources), $this->sourcesToValues($sources));
     return Main::$DEFAULT_RENDERER->link($content, $href);
 }
Exemplo n.º 2
0
 /**
  * 
  * @param type $sources
  * @return type
  */
 public function val($sources = null)
 {
     // verify if $sources is not an array if it's true then $sources is stored into $this->sources
     if (!is_array($sources)) {
         $sources = $this->sources;
     }
     // @href save the URL to the class indicated with the parameters to initialize it
     $href = Main::encodeURL($this->class, $this->construct_params, $this->method, $this->method_params);
     // $content save $sources with the correct format
     $content = vsprintf(array_shift($sources), $this->sourcesToValues($sources));
     // return the <a> tag with the correct href.
     return Main::$DEFAULT_RENDERER->link($content, $href);
 }
Exemplo n.º 3
0
 function showView($template = null)
 {
     if ($template) {
         $template = Main::loadDom($template);
         $template = $this->element->showView($template[$this->cssSelector() . ' ' . $this->element->cssSelector()], true);
     } else {
         // creates a dummy template
         $element = $this->element->getClass();
         $element = new $element($this->element->getId());
         $template = $element->showView(null, true);
     }
     $template = $template . '';
     $dom = \phpQuery::newDocument($template);
     if (@$element) {
         $this->nestingLevelFix($dom);
     }
     return $dom . '';
 }
Exemplo n.º 4
0
 public function __construct($id_or_elementsTypes = null, $storage = null, &$specialDataStorage = null)
 {
     $this->construct($id_or_elementsTypes, $specialDataStorage);
     //Asings the storage element for the SimplOnelement. (a global one : or a particular one)
     if (!$specialDataStorage) {
         $this->dataStorage = Main::dataStorage();
     } else {
         $this->dataStorage =& $specialDataStorage;
     }
     //On heirs put here the asignation of SimplOndata and attributes
     if (is_array($id_or_elementsTypes)) {
         if (array_values($id_or_elementsTypes) === $id_or_elementsTypes) {
             $this->elementsTypes = new DArray('', 'vclsR', $id_or_elementsTypes);
         } else {
             $this->fillFromArray($id_or_elementsTypes);
         }
     } else {
         if (isset($id_or_elementsTypes)) {
             $id = $id_or_elementsTypes;
             $this->dataStorage->ensureElementStorage($this);
             $this->fillFromDSById($id);
         }
     }
     //checking if there is already a dataStorage and storage for this element
     //if there is a storage and an ID it fills the element with the proper info.
     if (!$this->storage()) {
         $storages = array();
         foreach ($this->elementsTypes() as $elementType) {
             $dummy_class = new $elementType();
             $storages[$elementType] = $dummy_class->storage();
         }
         $this->storage($storages);
     }
     $this->getFields();
     $this->viewAction = new Datas\ViewAction('', array('View'));
     // @todo: make it possible to create a new Search using an HTML form
     $this->createAction = new Datas\CreateAction('', array('Create'));
     $this->updateAction = new Datas\UpdateAction('', array('Update'));
     $this->deleteAction = new Datas\DeleteAction('', array('Delete'));
     // Tells the SimplOndata whose thier "container" in case any of it has context dependent info or functions.
     $this->assignAsDatasParent();
     $this->assignDatasName();
 }
Exemplo n.º 5
0
 function showView($template = null)
 {
     if ($template) {
         $dom = Main::loadDom($template);
         $tempTemplate = $dom[$this->cssSelector()];
         $elementsViews = '';
         foreach ($this->elements as $element) {
             $selector = $element->cssSelector();
             $tmp = $tempTemplate . '';
             $elementTemplate = $tempTemplate[$element->cssSelector()];
             $elementsViews .= $element->showView($elementTemplate, true);
         }
         $tempTemplate->html($elementsViews);
         return $tempTemplate->html();
     } else {
         // creates a dummy template
         foreach ($this->allowedClassesInstances as $classInstance) {
             $template .= $classInstance->nestingLevel(1)->showView(null, true);
         }
         $dom = \phpQuery::newDocument($template);
         $this->nestingLevelFix($dom);
         return $dom . '';
     }
 }
Exemplo n.º 6
0
 function encodeURL($method = null, array $method_params = array())
 {
     return Main::encodeURL($this->parent->parentClass(), array($this->parent->parentId()), $method, $method_params, $this->parent->dataName());
 }
Exemplo n.º 7
0
 function encodeURL(array $construct_params = array(), $method = null, array $method_params = array())
 {
     if (empty($construct_params) && $this->getId()) {
         $construct_params = array($this->getId());
     }
     return Main::encodeURL($this->getClass(), $construct_params, $method, $method_params);
 }
Exemplo n.º 8
0
 static function decodeURL()
 {
     $string_delimiter = '"';
     $server_request = urldecode(substr($_SERVER['REQUEST_URI'], strlen(self::$REMOTE_ROOT)));
     $qs = self::$URL_METHOD_SEPARATOR;
     $sd = $string_delimiter;
     $offset = 0;
     $parameterDecoder = function ($what, $encapsulated = false) use($sd, $qs, $server_request, &$offset) {
         $regexes = array('class' => '\\/ (?<raw>[^' . $sd . $qs . '\\/]+) ', 'construct_params' => '(?:\\/(?: (?<raw>[^' . $sd . $qs . '\\/]+) | ' . $sd . '(?<string>[^' . $sd . ']*)' . $sd . ' ))', 'dataName' => '\\/?' . $qs . ' (?<raw>[^' . $sd . $qs . '\\/]+) (?=' . $qs . ')', 'method' => '\\/?' . $qs . ' (?<raw>[^' . $sd . $qs . '\\/]+) ', 'method_params' => '(?:\\/(?: (?<raw>[^' . $sd . $qs . '\\/]+) | ' . $sd . '(?<string>[^' . $sd . ']*)' . $sd . ' ))');
         if (preg_match('/^' . $regexes[$what] . '/x', substr($server_request, $offset), $matches, PREG_OFFSET_CAPTURE)) {
             $offset += $matches[0][1] + strlen($matches[0][0]);
             $raw = @$matches['raw'][0];
             $string = @$matches['string'][0];
             if (empty($raw) && empty($string)) {
                 $return = '';
             } else {
                 if (!empty($raw) && empty($string)) {
                     if ($raw == 'null') {
                         $return = null;
                     } else {
                         if ($raw == 'false') {
                             $return = array(false);
                         } else {
                             if (is_numeric($raw)) {
                                 $return = floatval($raw) == intval($raw) ? intval($raw) : floatval($raw);
                             } else {
                                 $return = $raw;
                             }
                         }
                     }
                 } else {
                     if (empty($raw) && !empty($string)) {
                         $return = urldecode(\SimplOn\Main::fixCode($string, false));
                     }
                 }
             }
             return $encapsulated ? array($return) : $return;
         } else {
             return false;
         }
     };
     self::$class = strtr($parameterDecoder('class'), '-', '\\') ?: Main::$DEFAULT_ELEMENT;
     self::$construct_params = array();
     while (($param = $parameterDecoder('construct_params', true)) !== false) {
         self::$construct_params[] = $param[0];
     }
     self::$dataName = $parameterDecoder('dataName');
     self::$method = $parameterDecoder('method') ?: Main::$DEFAULT_METHOD;
     self::$method_params = array();
     while (($param = $parameterDecoder('method_params', true)) !== false) {
         self::$method_params[] = $param[0];
     }
 }