/** * generates method initFilters for grid * * @param \Zend\Code\Generator\ClassGenerator $class * @param DataSetDescriptorInterface $dataSet */ protected function generateInitFiltersMehod(ClassGenerator $class, DataSetDescriptorInterface $dataSet) { $body = ""; foreach ($dataSet->listGenerator() as $column) { $name = $column->getName(); $type = $this->getFieldType($column); $body .= sprintf($this->codeLibrary()->get('grid.initFilters.' . $type), $name, $name); } $method = new MethodGenerator("initFilters"); $method->setBody($body); $method->setFlags(\Zend\Code\Generator\MethodGenerator::FLAG_PROTECTED); $parameter = new \Zend\Code\Generator\ParameterGenerator("query"); $parameter->setType("\\Zend\\Db\\Sql\\Select"); $method->setParameter($parameter); $class->addMethodFromGenerator($method); }
/** * creates setter method for given field * * @param FieldDescriptorInterface $column * @param string $name * @return \Zend\Code\Generator\MethodGenerator */ protected function createSetMethod(FieldDescriptorInterface $column, $name) { $propertyName = lcfirst($name); $parameter = new \Zend\Code\Generator\ParameterGenerator(); $parameter->setName("value"); $method = new MethodGenerator(); $method->setParameter($parameter); $type = $this->getFieldType($column); $method->setBody(sprintf($this->codeLibrary()->get('model.setMethod' . ucfirst($type) . '.body'), $propertyName)); $method->setName("set" . $name); $docblock = new \Zend\Code\Generator\DocblockGenerator(sprintf($this->codeLibrary()->get('model.setMethod.description'), $propertyName)); $docblock->setTag(array("name" => "param", "description" => $type)); $method->setDocBlock($docblock); return $method; }