Exemplo n.º 1
0
	function addField ($name, $type, $value = null, $title = null, $linkfield = false, $properties = false)
	{
		$dataType = metaclass::create($type, 'datatypes');
		if ($dataType == null)
		{
			$dataType = metaclass::create('string', 'datatypes');
		}
		if (is_array($dataType->scripts))
		{
			foreach ($dataType->scripts as $k => $v)
			{
				$this->scripts[$k] = $v;
			}
		}
		$this->rows[] = $dataType->formField($name, $title, $value, $linkfield, $properties);
		$dataType = null;
	}
Exemplo n.º 2
0
	/**
	 * Loads a specific stored metaobject from the database table.
	 *
	 * @param string $class Type of the class.
	 * @param integer|string $id The Id of the specific instance.
	 * @return object The loaded object, ready for use.
	 */
	public static function load ($class, $id)
	{
		$object = metaclass::create($class);
		if (! metaclass::checkTable($object))
		{
			metaclass::createTable($object->table, $object->definitions);
		}
		$query = new query();
		$query->select()->from($object->table)->where('id', $id)->limit(1);
		$result = self::$db->query($query);
		$row = self::$db->assoc($result);
		$object->setId($id);
		foreach ($object->definitions as $k => $v)
		{
			$object->setProperty($k, $row[$k]);
			$object->setProperty($k, $row[$k], true);
		}
		$object->id = $id;
		return $object;
	}
Exemplo n.º 3
-1
	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;
		}
	}
Exemplo n.º 4
-1
	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;
		}
	}