예제 #1
0
 public function exportAsFilter(array $modelNamespace, array $namespace = array(), $className = NULL)
 {
     if (empty($namespace)) {
         $namespace = array($this->namespace, 'filter');
     }
     $className = trim($className);
     $className = empty($className) ? $this->className : $className;
     $namespace = implode("\\", $namespace);
     $modelNS = implode("\\", $modelNamespace);
     $mapTo = "\\{$modelNS}\\{$className}";
     $nsObj = new NamespaceBlock($namespace);
     $classObj = new ClassBlock($className);
     $nsObj->addAlias('\\apf\\iface\\data\\Filter', 'FilterInterface');
     $nsObj->addAlias($mapTo, 'BaseFilter');
     $classObj->setExtendsTo('BaseFilter')->addInterface('FilterInterface')->addTrait('\\apf\\traits\\data\\Filter');
     $columns = array();
     $textFields = array();
     foreach ($this->table->getFields() as $field) {
         if (in_array($field->type, array('text', 'char', 'varchar'))) {
             $classObj->addAttribute(new Attribute('private', sprintf('%sLike', StringUtil::toCamelCase($field->name))))->addMethod((new Method(sprintf('set%sLike', StringUtil::toUpperCamelCase($field->name))))->l(sprintf('$this->%sLike = $like;', StringUtil::toCamelCase($field->name)))->l('return $this;'))->addMethod((new Method(sprintf('get%sLike', StringUtil::toUpperCamelCase($field->name))))->l(sprintf('return $this->%sLike = $like;', StringUtil::toCamelCase($field->name))));
         }
     }
     $classObj->addMethod((new Method('getMap'))->l("return Array('class'=>'{$mapTo}')"));
     $nsObj->addClass($classObj);
     return $nsObj;
 }
예제 #2
0
 public function exportAsFilter(array $modelNamespace, array $namespace = array())
 {
     if (empty($namespace)) {
         $namespace = array(StringUtil::toCamelCase($this->getSchema()), 'filter');
     }
     $className = StringUtil::toUpperCamelCase($this->name);
     $schema = StringUtil::toCamelCase($this->getSchema());
     $mapTo = sprintf('\\%s\\%s', implode('\\', $modelNamespace), $className);
     $class = sprintf('%snamespace %s{', "\t", implode("\\", $namespace));
     $class = "{$class}\n\n\t\tuse\t\\apf\\iface\\data\\Filter as FilterInterface;\n";
     $class = "{$class}\t\tuse\t{$mapTo} as BaseFilter;\n\n";
     $class = "{$class}\t\tclass {$className} extends BaseFilter implements FilterInterface{\n\n";
     $class = "{$class}\t\t\tuse \\apf\\traits\\data\\Filter;\n\n";
     $columns = array();
     $textFields = array();
     foreach ($this->getFields() as $field) {
         if (in_array($field->type, array('text', 'char', 'varchar'))) {
             $columns[] = sprintf('%sprivate%s$%sLike = NULL;', "\t\t\t", "\t", StringUtil::toCamelCase($field->name));
             $textFields[] = $field;
         }
     }
     $class = sprintf('%s%s%s', $class, implode("\n", $columns), "\n\n");
     foreach ($textFields as $field) {
         $parameter = $field->name;
         $upperCamelParam = StringUtil::toUpperCamelCase($field->name);
         $lowerCamelParam = StringUtil::toCamelCase($field->name);
         $setter = sprintf('%spublic function set%sLike($like=NULL){%s', "\t\t\t", $upperCamelParam, "\n\n");
         $setter = sprintf('%s%s$this->%sLike = $like;%s', $setter, "\t\t\t\t", StringUtil::toCamelCase($field->name), "\n");
         $setter = sprintf('%s%sreturn $this;%s', $setter, "\t\t\t\t", "\n\t\t\n\t\t\t}\n");
         $getter = sprintf('%spublic function get%sLike(){%s', "\n\t\t\t", $upperCamelParam, "\n\n");
         $getter = sprintf('%s%sreturn $this->%sLike;%s%s', $getter, "\t\t\t\t", StringUtil::toCamelCase($field->name), "\n", "\t\t\n\t\t\t}\n\n");
         $class = sprintf('%s%s', $class, $setter);
         $class = sprintf('%s%s', $class, $getter);
     }
     $getMap = "\t\t\tpublic function getMap(){\n\n";
     $getMap = "{$getMap}\t\t\t\treturn Array('class'=>'{$mapTo}')";
     $class = sprintf('%s%s', "{$class}{$getMap}", "\n\t\t\t}\n");
     $class = sprintf('%s%s', "{$class}", "\n\t\t}\n");
     $class = sprintf('%s%s', $class, "\n\t}\n");
     return $class;
 }
예제 #3
0
 public function render($indent = NULL)
 {
     parent::reset();
     $className = StringUtil::toUpperCamelCase($this->name);
     //class $name extends $extends implements $interfaces
     if ($this->extendsTo && sizeof($this->interfaces)) {
         $header = sprintf('class %s extends %s implements %s', $className, $this->extendsTo, implode(',', $this->interfaces));
         //class $name implements $interfaces
     } elseif (!$this->extendsTo && sizeof($this->interfaces)) {
         $header = sprintf('class %s implements %s ', $className, implode(',', $this->interfaces));
         //class $name extends $extends
     } elseif ($this->extendsTo) {
         $header = sprintf('class %s extends %s ', $className, $this->extendsTo);
         //class $name
     } else {
         $header = sprintf('class %s ', $className);
     }
     $this->setHeader($header);
     foreach ($this->attributes as $key => $attribute) {
         $this->l($attribute);
     }
     foreach ($this->methods as $method) {
         $this->l($method);
     }
     return parent::render($indent);
 }