/** * Method methodGetFt * Gera método geters para foreign table * @author Bruno Oliveira <*****@*****.**> */ private function methodGetFt($property, $ft, $ftPhpName = null, $class) { $ftName = empty($ftPhpName) ? $ft : $ftPhpName; $ftName = Utils::snakeToCamelCase($ftName); $ft = Utils::snakeToCamelCase($ft); $property = lcfirst(Utils::snakeToCamelCase($property)); $v = "\t/**"; $v .= "\n\t * Method get{$ftName}"; $v .= "\n\t * Obtêm o objeto " . lcfirst($ft); $v .= "\n\t */"; $v .= "\n\tpublic function get{$ftName} ()"; $v .= "\n\t{"; $v .= "\n\t\treturn new {$class}(\$this->{$property});"; $v .= "\n\t}"; $v .= "\n\n"; $this->methodsGeters .= $v; }
/** * Method update * Deleta o objeto do banco de dados * @author Bruno Oliveira <*****@*****.**> * @return bool */ public function update() { $primaryKey = $this->getPrimaryKey(); $class = get_class($this); $class = explode('\\', $class); $class = "{$class['0']}\\Traits\\Trait{$class['1']}"; $r = new ReflectionClass($class); $vars = get_object_vars($this); $varsDB = array(); foreach ($vars as $key => $val) { if ($r->hasProperty($key) && isset($val) && $key != $primaryKey) { $varsDB[Utils::camelToSnakeCase($key)] = $val; } } $conn = self::conn(); $conn->table($this->getTable()); if (!is_null($primaryKey) && isset($vars[lcfirst(Utils::snakeToCamelCase($primaryKey))])) { $conn->where($primaryKey, $vars[lcfirst(Utils::snakeToCamelCase($primaryKey))]); } $conn->update($varsDB); $conn->cleanQuery(); }