public function addGetByIdMethod($methodName, $table, $primaryKey) { $primaryKeyVar = ThemeHouse_DataWriters_Helper_DataWriter::snakeCaseToCamelCase($primaryKey, true); $bodyArray = array('return $this->_getDb()->fetchRow(', "\t" . '\'', "\t" . 'SELECT *', "\t" . 'FROM ' . $table, "\t" . 'WHERE ' . $primaryKey . ' = ?', '\', $' . $primaryKeyVar . ');'); $body = implode("\n", $bodyArray); $this->addMethod($methodName, $body, '$' . $primaryKeyVar); }
protected function _createFunctionGetExistingData(array $options) { $function = $this->createFunction('_getExistingData'); $function->setPhpDoc(array('Gets the actual existing data out of data that was passed in.', 'See parent for explanation.', '', '@param mixed', '', '@return array|false')); $function->setSignature(array('$data')); $name = $options['name']; $method = $options['method']; $lcFirstName = lcfirst($options['name']); $primary = $options['primary_key']; $primaryKeyVar = ThemeHouse_DataWriters_Helper_DataWriter::snakeCaseToCamelCase($primary, true); $body = array('if (!$' . $primaryKeyVar . ' = $this->_getExistingPrimaryKey($data, \'' . $primary . '\')) {', ' return false;', '}', '', '$' . $lcFirstName . ' = $this->_get' . $name . 'Model()->' . $method . '($' . $primaryKeyVar . ');', 'if (!$' . lcfirst($options['name']) . ') {', ' return false;', '}', '', 'return $this->getTablesDataFromArray($' . $lcFirstName . ');'); $function->setBody($body); }