/** * Creates a table in the image of the property definitions supplied to it. * * @param string $tableName What the table will be called. * @param array $propertyDefinitions The structure of the table. * * @todo Need to make this use the query class. */ private static function createTable ($tableName, $propertyDefinitions) { $query .= " CREATE TABLE `" . metaclass::$db->getProperty('database') . "`.`$tableName` (\n"; $query .= " `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n"; foreach ($propertyDefinitions as $k => $v) { $vars = metaclass::getClassVars($v['type'], 'datatypes'); $querylines[] .= "`$k` " . (janitor::notNull($vars['fieldtype']) ? $vars['fieldtype'] : 'VARCHAR( 255 )') . " NOT NULL "; } $query .= implode(",\n", $querylines); $query .= ")"; metaclass::$db->query($query); metaclass::$tablesLoaded[] = $tableName; }
function formField ($name, $title, $value = null, $linkfield, $properties) { $cvs = metaclass::getClassVars($properties['requirements']['real']); if (metaclass::$db->tableExists($cvs['table'])) { $query = new query(); $query->select(array ( 'id' , 'title' ))->from($cvs['table']); $result = metaclass::$db->query($query); $return .= '<label for="' . $name . '"> ' . $title . ' </label><br/> <select id="' . $name . '" name="' . $name . '">'; while ($row = metaclass::$db->assoc($result)) { $return .= '<option value="' . $row['id'] . '"' . ($row['id'] == $value ? ' selected' : null) . '>' . $row['title'] . '</option>'; } $return .= '</select> <br/>'; } else { $return .= '<label for="' . $name . '"> ' . $title . ' </label><br/>'; $return .= '<p class="error">' . text::get('form/foreignTableNotExist', $cvs['title']) . '</p>'; } return $return; }
function exec ($object) { $this->object = $object; $this->db = $db; $classVars = metaclass::getClassVars(get_class($object)); foreach ($classVars['propertyDefinitions'] as $k => $v) { $dataType = metaclass::create($v['type'], 'datatypes'); if ($dataType == null) { $dataType = metaclass::create('string', 'datatypes'); } $this->check($dataType, $object->properties[$k], $v['title'], $object->id, $k, $classVars['table'], $v['requirements']); $dataType = null; } if ($this->invalid) { $this->valid = false; } else { $this->valid = true; } }
public function process ($input) { $this->populate(janitor::unCleanData($input)); switch ($this->action) { case 'creating': $object = metaclass::create($this->type); break; case 'updating': $object = metaclass::load($this->type, $this->id); break; } foreach ($this->definitions as $k => $v) { $object->setProperty($k, $input[$k]); } if ($object->save()) { return true; } else { foreach ($object->invalid as $k => $v) { foreach ($v as $y => $z) { $obVars = metaclass::getClassVars($this->type); $this->invalid[] = text::get('validation/error_' . $y, array ( $obVars['propertyDefinitions'][$k]['title'] )); } } return false; } }