private function parsePages() { $this->pagedir = $this->basedir . "/apps/" . $this->args['application'] . "/config/pages"; $data = array(); $files = scandir($this->pagedir); foreach ($files as $file) { if (strtolower(substr($file, strrpos($file, ".") + 1)) == "xml") { $xp = XmlParser::readDocumentByPath($this->pagedir . "/" . $file); $nodes = $xp->evaluate("//i:component[child::i:params]"); if (!$nodes->length) { continue; } else { foreach ($nodes as $node) { $key = $node->getAttribute("module") . "/" . $node->getAttribute("name"); $params = $xp->evaluate("./i:params/i:param", $node); $param_arr = array(); foreach ($params as $k => $param) { $param_arr[$param->getAttribute("name") ? $param->getAttribute("name") : "noname" . $k] = trim($param->nodeValue); } $data[$key]["combos"][$file] = $param_arr; } } } } $this->pages = $data; }
private function generateWidgets(array $data, $model, $module) { // Replace basic tokens. for edit / show.. if (isset($data["_attributes"])) { unset($data["_attributes"]); } $visible = trim(implode(",", array_keys($data)), ","); $tokens = array("TITLE" => "Edit / Create " . $model, "DATACLASS" => $model . "Peer", "UPDATE_URL" => $module . "/update", "LIST_URL" => $module . "/list", "DELETE_URL" => $module . "/delete", "ADD_URL" => $module . "/edit", "ADD_TITLE" => "Add new item", "VISIBLE" => $visible); $templates = array("list", "edit"); foreach ($templates as $key => $template) { $path = $this->path . "/config/" . $template . ".xml"; $this->getFilesystem()->replaceTokens($path, '##', '##', $tokens); // Add fields and columns.. $xpath = XmlParser::readDocumentByPath($path); $document = $xpath->document; $document->formatOutput = true; $document->normalizeDocument(); $ns = $document->lookupNamespaceUri("i"); $fields = $xpath->evaluate("//i:fields")->item(0); foreach ($data as $column => $type) { $coltype = $this->getFieldType($column, $type); if (!$key) { $elem = $document->createElementNS($ns, "column"); } else { $elem = $document->createElementNS($ns, "field"); $elem->setAttribute("type", $coltype->type); if (property_exists($coltype, "default") && $coltype->type == "checkbox") { $elem->setAttribute("checked", "true"); } else { if (property_exists($coltype, "foreignTable")) { $table = $this->schema["propel"][$coltype->foreignTable]; $peer = $table["_attributes"]["phpName"] . "Peer"; unset($table["_attributes"]); $id_column = $coltype->foreignReference; if (isset($table["name"])) { $name_column = "name"; } else { if (isset($table["title"])) { $name_column = "title"; } else { foreach ($table as $colname => $thecol) { $c = is_array($thecol) ? $thecol["type"] : $thecol; if (strstr($c, "varchar")) { $name_column = $colname; break; } } if (!$name_column) { $name_column = $id_column; } } } $child = $document->createElementNS($ns, "value"); $child->setAttribute("type", "orm"); $vchild = $document->createElementNS($ns, "class", "afGenerator"); $child->appendChild($vchild); $vchild = $document->createElementNS($ns, "method"); $vchild->setAttribute("name", "asCombo"); $child->appendChild($vchild); $values = array(1 => array($peer, "peer"), array($name_column, "name"), array($id_column, "id")); $i = 1; while ($i < 4) { $vchild = $document->createElementNS($ns, "param", $values[$i][0]); $vchild->setAttribute("name", $values[$i][1]); $child->lastChild->appendChild($vchild); $i++; } $elem->appendChild($child); $elem->setAttribute("selected", "{" . $column . "}"); } } if (!property_exists($coltype, "foreignTable")) { $value = $document->createElementNS($ns, "value"); $value->setAttribute("type", "orm"); $source = $document->createElementNS($ns, "source"); $source->setAttribute("name", "get" . sfInflector::camelize($column)); $value->appendChild($source); $elem->appendChild($value); } } $elem->setAttribute("label", $column); $elem->setAttribute("name", $column); $fields->appendChild($elem); } $document->save($path); } }
public function executeStructinfo() { //Console::profile('struct start'); // Params of call $expression = $this->getRequestParameter("node", null); $type = $this->getRequestParameter("type", "edit"); $lang = $this->getRequestParameter("lang", "en"); $do = $this->getRequestParameter("do", "nodes"); // Read Schema $root = sfConfig::get("sf_root_dir"); $this->schema = XmlParser::readDocumentByPath($root . "/plugins/appFlowerPlugin/schema/appflower.xsd", true, array("prefix" => "xs", "uri" => "http://www.w3.org/2001/XMLSchema")); // Data types if ($do == "types") { $result = $this->schema->evaluate("//xs:simpleType"); foreach ($result as $dtype) { $data = $this->schema->evaluate("./descendant::xs:restriction|./descendant::xs:union|./descendant::xs:documentation[@xml:lang='" . $lang . "']", $dtype); $type_name = $dtype->getAttribute("name"); if (!$type_name) { continue; } foreach ($data as $info) { if ($info->nodeName == "xs:documentation") { $this->data_types[$type_name]["docs"] = $info->nodeValue; continue; } else { if ($info->nodeName == "xs:union") { $this->data_types[$type_name]["union"] = str_replace("i:", "", $info->getAttribute("memberTypes")); continue; } } $base = $info->getAttribute("base"); foreach ($info->childNodes as $child) { if (!$child instanceof DOMElement || $child->nodeName != "xs:enumeration" && $child->nodeName != "xs:maxInclusive" && $child->nodeName != "xs:minInclusive" && $child->nodeName != "xs:pattern") { continue; } if ($child->nodeName == "xs:maxInclusive" || $child->nodeName == "xs:minInclusive") { $this->data_types[$type_name]["type"] = "range"; $this->data_types[$type_name]["base"] = str_replace("xs:", "", $base); } else { if ($child->nodeName == "xs:enumeration") { $this->data_types[$type_name]["type"] = "enum"; } else { $this->data_types[$type_name]["type"] = "pattern"; continue; } } $this->data_types[$type_name]["values"][] = $child->getAttribute("value"); } } } $result = json_encode($this->data_types); return $this->renderText($result); } // Imported namespaces $result = $this->schema->evaluate("//xs:import"); foreach ($result as $ns) { $this->imported_namespaces[$ns->getAttribute("namespace")] = $ns->getAttribute("i:name"); } // Attribute and element groups $groups = array("element", "attribute"); foreach ($groups as $k => $prefix) { $result = $this->schema->evaluate($prefix == "element" ? "//xs:group" : "//xs:attributeGroup"); foreach ($result as $group) { $attrs = $this->schema->evaluate("./descendant::xs:" . $prefix, $group); foreach ($attrs as $attr) { if (!$k) { $this->element_groups[$group->getAttribute("name")][] = $attr->getAttribute("ref"); } else { $this->attribute_groups[$group->getAttribute("name")][] = $this->getAttribute($attr); } } } } if ($expression === null) { $result = $this->getElement("i:view", $type, $lang); } else { $result = $this->getElement($expression, $type, $lang); } $result = json_encode($result); //Console::profile('struct end'); return $this->renderText($result); }