Ejemplo n.º 1
0
 public function toJSON($node)
 {
     $returnValue = '';
     $JSON_node = new stdClass();
     // handle subnodes
     foreach ($node->composites as $composite) {
         if (!is_array($JSON_node->{$composite->nodeName})) {
             $JSON_node->{$composite->nodeName} = array();
         }
         $JSON_node->{$composite->nodeName}[] = $composite->nodes;
     }
     if ($id = $node->getId()) {
         $JSON_node->id = $id;
     }
     if ($type = $node->getType()) {
         $JSON_node->type = $type;
     }
     // handle nodes
     foreach ($node->nodes as $name => $value) {
         $JSON_node->{$name} = $value;
     }
     $returnValue = MJSON::encode($JSON_node);
     //$returnValue = json_encode($JSON_node);
     return $returnValue;
 }
Ejemplo n.º 2
0
 public function asJSON($fields = null)
 {
     return \MJSON::encode($this->asObjectArray($fields));
 }
Ejemplo n.º 3
0
 private function getScripts()
 {
     if (count($this->events) > 0) {
         $events = MJSON::encode($this->events);
         $this->addOnload("manager.registerEvents(" . $events . ");");
     }
     $scripts = new \StdClass();
     foreach ($this->scripts as $key => $url) {
         $scripts->scripts .= "\n manager.loader.load('{$url}');";
     }
     foreach ($this->jsCode as $key => $code) {
         $scripts->code .= "\n {$code}";
     }
     foreach ($this->onload as $key => $code) {
         $scripts->onload .= "\n {$code}";
     }
     $onsubmit = '';
     foreach ($this->onsubmit as $idForm => $list) {
         $onsubmit .= "manager.onSubmit[\"{$idForm}\"] = function() { \n";
         $onsubmit .= "    var result = ";
         $onsubmit .= implode(" && ", $list) . ";\n";
         $onsubmit .= "    return result;\n};\n";
     }
     $scripts->onsubmit = $onsubmit;
     /*
             $submit = '';
             foreach ($this->submit as $idForm => $list) {
                 $submit .= "manager.submit[\"{$idForm}\"] = function(element, url, idForm) { \n";
                 $submit .= implode(" && ", $list) . ";\n";
                 $submit .= "\n};\n";
             }
             $scripts->submit = $submit;
     */
     return $scripts;
 }
Ejemplo n.º 4
0
 private function encode($value)
 {
     return substr($value, 0, 1) == '@' ? substr($value, 1) : MJSON::encode($value);
 }