/**
  * Generate a constructor
  */
 private function _generateGetServiceConfig($className, $tables)
 {
     $this->_data .= "\t/**\n";
     $this->_data .= "\t* getServiceConfig\n";
     $this->_data .= "\t*\n";
     $this->_data .= "\t**/\n";
     $this->_data .= "\tpublic function getServiceConfig()\n";
     $this->_data .= "\t{\n";
     $this->_data .= "\t\treturn array(\n";
     $this->_data .= "\t\t\t'shared' => array(\n";
     $this->_data .= "\t\t\t),\n";
     $this->_data .= "\t\t\t'factories' => array(\n";
     // First add mappers
     $this->_data .= "\t\t\t\t// Adding all mappers for namespace\n";
     foreach ($tables as $table => $data) {
         $this->_data .= "\t\t\t\t'" . ZendModelCreator::getNamespace() . "\\Mapper\\" . ZendModelCreator::toCamelCase(ucfirst(strtolower($table))) . "Mapper' => function(\$sm) {\n";
         $this->_data .= "\t\t\t\t\t\$mapper = new Mapper\\" . ZendModelCreator::toCamelCase(ucfirst(strtolower($table))) . "Mapper;\n";
         $this->_data .= "\t\t\t\t\t\$mapper->setDbAdapter(\$sm->get('" . strtolower(ZendModelCreator::getNamespace()) . "_zend_db_adapter'));\n";
         $this->_data .= "\t\t\t\t\treturn \$mapper;\n";
         $this->_data .= "\t\t\t\t},\n";
     }
     $this->_data .= "\n";
     $this->_data .= "\t\t\t\t// Adding all services for namespace\n";
     // Then add Services
     foreach ($tables as $table => $data) {
         $this->_data .= "\t\t\t\t'" . ZendModelCreator::getNamespace() . "\\Service\\" . ZendModelCreator::toCamelCase(ucfirst(strtolower($table))) . "' => function(\$sm) {\n";
         $this->_data .= "\t\t\t\t\t\$service = new Service\\" . ZendModelCreator::toCamelCase(ucfirst(strtolower($table))) . ";\n";
         $this->_data .= "\t\t\t\t\t\$service->setMapper(\$sm->get('" . ZendModelCreator::getNamespace() . "\\Mapper\\" . ZendModelCreator::toCamelCase(ucfirst(strtolower($table))) . "Mapper'));\n";
         $this->_data .= "\t\t\t\t\t\$service->setOptions(\$sm->get('" . ZendModelCreator::getNamespace() . "\\Options\\ModuleOptions'));\n";
         $this->_data .= "\t\t\t\t\treturn \$service;\n";
         $this->_data .= "\t\t\t\t},\n";
     }
     // Add module options
     $this->_data .= "\n";
     $this->_data .= "\t\t\t\t// Adding module options\n";
     $this->_data .= "\t\t\t\t'" . ZendModelCreator::getNamespace() . "\\Options\\ModuleOptions' => function(\$sm) {\n";
     $this->_data .= "\t\t\t\t\t\$config = \$sm->get('Configuration');\n";
     $this->_data .= "\t\t\t\t\t\$moduleConfig = isset(\$config['" . strtolower(ZendModelCreator::getNamespace()) . "']) ? \$config['" . strtolower(ZendModelCreator::getNamespace()) . "'] : array();\n";
     $this->_data .= "\t\t\t\t\treturn new Options\\ModuleOptions(\$moduleConfig);\n";
     $this->_data .= "\t\t\t\t},\n";
     $this->_data .= "\t\t\t),\n";
     $this->_data .= "\t\t);\n";
     $this->_data .= "\t}\n\n";
 }
 /**
  * Generate getters and setters used in the entity class
  *
  */
 private function _generateClassGettersSetters($params)
 {
     foreach ($params as $param) {
         foreach ($param as $name => $type) {
             switch ($type[0]) {
                 case self::$STRING:
                     $this->_data .= $this->_getGetComment($type[0], $name);
                     $this->_data .= "\tpublic function get" . ZendModelCreator::toCamelCase($name) . "()\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\treturn \$this->{$name};";
                     $this->_data .= "\n\t}\n\n";
                     $this->_data .= $this->_getSetComment($type[0], $name);
                     $this->_data .= "\tpublic function set" . ZendModelCreator::toCamelCase($name) . "(\${$name})\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\t\$this->{$name} = \${$name};";
                     $this->_data .= "\n\t}\n\n";
                     break;
                 case self::$INTEGER:
                     $this->_data .= $this->_getGetComment($type[0], $name);
                     $this->_data .= "\tpublic function get" . ZendModelCreator::toCamelCase($name) . "()\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\treturn \$this->{$name};";
                     $this->_data .= "\n\t}\n\n";
                     $this->_data .= $this->_getSetComment($type[0], $name);
                     $this->_data .= "\tpublic function set" . ZendModelCreator::toCamelCase($name) . "(\${$name})\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\t\$this->{$name} = \${$name};";
                     $this->_data .= "\n\t}\n\n";
                     break;
                 case self::$DATETIME:
                     $this->_data .= $this->_getGetComment($type[0], $name);
                     $this->_data .= "\tpublic function get" . ZendModelCreator::toCamelCase($name) . "()\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\treturn \$this->{$name};";
                     $this->_data .= "\n\t}\n\n";
                     $this->_data .= $this->_getSetComment($type[0], $name);
                     $this->_data .= "\tpublic function set" . ZendModelCreator::toCamelCase($name) . "(\${$name})\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\t\$this->{$name} = \${$name};";
                     $this->_data .= "\n\t}\n\n";
                     break;
                 case self::$DOUBLE:
                     $this->_data .= $this->_getGetComment($type[0], $name);
                     $this->_data .= "\tpublic function get" . ZendModelCreator::toCamelCase($name) . "()\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\treturn \$this->{$name};";
                     $this->_data .= "\n\t}\n\n";
                     $this->_data .= $this->_getSetComment($type[0], $name);
                     $this->_data .= "\tpublic function set" . ZendModelCreator::toCamelCase($name) . "(\${$name})\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\t\$this->{$name} = \${$name};";
                     $this->_data .= "\n\t}\n\n";
                     break;
                 case self::$ARRAY:
                     $this->_data .= $this->_getGetComment($type[0], $name);
                     $this->_data .= "\tpublic function get" . ZendModelCreator::toCamelCase($name) . "()\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\treturn \$this->{$name};";
                     $this->_data .= "\n\t}\n\n";
                     $this->_data .= $this->_getSetComment($type[0], $name);
                     $this->_data .= "\tpublic function set" . ZendModelCreator::toCamelCase($name) . "(array \${$name})\n";
                     $this->_data .= "\t{\n";
                     $this->_data .= "\t\t\$this->{$name} = \${$name};";
                     $this->_data .= "\n\t}\n\n";
                     break;
             }
         }
     }
 }
 /**
  * Generate delete method
  *
  */
 private function _generateDelete($className)
 {
     // Set fetch function headers
     $this->_data .= "\t/**\n";
     $this->_data .= "\t* Delete a record\n";
     $this->_data .= "\t*\n";
     $this->_data .= "\t* @param int/object \$" . strtolower($className) . "\n";
     $this->_data .= "\t* @return bool\n";
     $this->_data .= "\t**/\n";
     $this->_data .= "\tpublic function delete(\$" . strtolower($className) . ")\n";
     $this->_data .= "\t{\n";
     $this->_data .= "\t\t// If the variable \$" . strtolower($className) . " is an instance of " . ucfirst(strtolower($className)) . "Entity, get the " . $this->_primary_key . " out of the object\n";
     $this->_data .= "\t\tif (\$" . strtolower($className) . " instanceof " . ucfirst(strtolower($className)) . "Entity) {\n";
     $this->_data .= "\t\t\t\$" . strtolower($className) . " = \$" . strtolower($className) . "->get" . ZendModelCreator::toCamelCase($this->_primary_key) . "();\n";
     $this->_data .= "\t\t}\n";
     $this->_data .= "\n";
     $this->_data .= "\t\t// Ge the event manager\n";
     $this->_data .= "\t\t\$events = \$this->getEventManager();\n";
     $this->_data .= "\n";
     $this->_data .= "\t\t// Trigger event for deleting a record\n";
     $this->_data .= "\t\t\$events->trigger(" . ucfirst(strtolower($className)) . "Event::EVENT_DELETE_" . strtoupper($className) . "_POST, \$this, array('" . strtolower($className) . "' => \$" . strtolower($className) . "));\n";
     $this->_data .= "\n";
     $this->_data .= "\t\t// Return the result of deleting the record\n";
     $this->_data .= "\t\treturn \$this->mapper->delete(\$" . strtolower($className) . ");\n";
     $this->_data .= "\t}\n\n";
 }
 /**
  * Generate persist method
  *
  */
 private function _generatePersist($className)
 {
     // Set fetch function headers
     $this->_data .= "\t/**\n";
     $this->_data .= "\t* Save a record\n";
     $this->_data .= "\t*\n";
     $this->_data .= "\t* @param object " . ZendModelCreator::getNamespace() . "\\Entity\\" . ucfirst(strtolower($className)) . "\n";
     $this->_data .= "\t* @return object " . ZendModelCreator::getNamespace() . "\\Entity\\" . ucfirst(strtolower($className)) . "\n";
     $this->_data .= "\t**/\n";
     $this->_data .= "\tpublic function persist(" . ucfirst(strtolower($className)) . " \$" . strtolower($className) . ")\n";
     $this->_data .= "\t{\n";
     $this->_data .= "\t\tif (\$" . strtolower($className) . "->get" . ZendModelCreator::toCamelCase($this->_primary_key) . "() > 0) {\n";
     $this->_data .= "\t\t\t\$where = new Where;\n";
     $this->_data .= "\t\t\t\$where->equalTo('" . $this->_primary_key . "', \$" . strtolower($className) . "->get" . ZendModelCreator::toCamelCase($this->_primary_key) . "());\n";
     $this->_data .= "\t\t\t\$this->update(\$" . strtolower($className) . ", \$where, '" . strtolower($className) . "');\n";
     $this->_data .= "\t\t} else {\n";
     $this->_data .= "\t\t\t\$result = \$this->insert(\$" . strtolower($className) . ", '" . strtolower($className) . "');\n";
     $this->_data .= "\t\t\t\$" . strtolower($className) . "->set" . ZendModelCreator::toCamelCase($this->_primary_key) . "(\$result->getGeneratedValue());\n";
     $this->_data .= "\t\t}\n";
     $this->_data .= "\t\treturn \$" . strtolower($className) . ";\n";
     $this->_data .= "\t}\n\n";
 }