Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ IMPORTANT
Jelly requires the following Kohana versions per Git branch:

* `3.1/develop` and `3.1/master` branches: Kohana 3.1.3+
* `3.2/develop` and `3.2/master` branches: Kohana 3.2+
* `3.2/develop` and `3.2/master` branches: Kohana 3.2
* `3.3/master` branch: Kohana 3.3+

**Useful stuff**:

Expand Down Expand Up @@ -58,4 +59,4 @@ Remember:
* **No circular references** — Fields are well-designed to prevent the
infinite loop problem that sometimes plagues Sprig. It's even possible to
have same-table child/parent references out of the box without intermediate
models.
models.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 11 additions & 2 deletions classes/jelly/core.php → classes/Jelly/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ public static function class_name($model)
{
if ($model instanceof Jelly_Model)
{
return strtolower(get_class($model));
return get_class($model);
}
else
{
return strtolower(Jelly::$_model_prefix.$model);
return Jelly::get_class_name(Jelly::$_model_prefix.$model);
}
}

Expand Down Expand Up @@ -256,4 +256,13 @@ public static function behavior_prefix()
return Jelly::$_behavior_prefix;
}

public static function get_class_name ($class_name)
{
$class_name = explode ('_', $class_name);
foreach ($class_name as &$name) {
$name = UTF8::ucfirst ($name);
}

return implode ('_', $class_name);
}
} // End Jelly_Core
File renamed without changes.
26 changes: 24 additions & 2 deletions classes/jelly/core/builder.php → classes/Jelly/Core/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public function count($db = NULL)

// Find the count
$result = (int) $query
->select(array('COUNT("*")', 'total'))
->select(array(DB::expr('COUNT(*)'), 'total'))
->execute($db)
->get('total');

Expand Down Expand Up @@ -337,7 +337,7 @@ public function execute($db = NULL, $type = NULL, $ignored = NULL)
* @param string|null $type
* @return string
*/
public function compile(Database $db, $type = NULL)
public function compile($db = NULL, $type = NULL)
{
$type === NULL AND $type = $this->_type;

Expand Down Expand Up @@ -1011,6 +1011,28 @@ protected function _field_alias($field, $value = NULL, $join_if_sure = TRUE)
return $join ? ($alias.'.'.$column) : $column;
}

public function field_alias($field)
{
return $this->_field_alias($field);
}

/**
* Return table name in query, table alias and table model
*
* @param $field
* @return mixed
*/
public function with_alias($field)
{
$field = $this->_meta->field($field);

$table = $this->_meta->table();

$key = $field->foreign['model'].'.'.$table.':'.$field->name;

return $this->_model_cache[$key];
}

/**
* Resolves meta-aliases.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,39 @@ public function meta()
}

/**
* Return all of the rows in the result as an array.
* Return all of the models in array.
*
* @param string $key column for associative keys
* @param string $value column for values
* @return array
*/
public function as_array($key = NULL, $value = NULL)
{
return $this->_result->as_array($key, $value);
if ($value === NULL)
{
$result = array();

if ($key === NULL)
{
foreach ($this as $obj)
{
$result[] = $obj;
}
}
else
{
foreach ($this as $obj)
{
$result[$obj->$key] = $obj;
}
}

return $result;
}
else
{
return $this->_result->as_array($key, $value);
}
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions classes/Jelly/Core/Field/DateTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php defined('SYSPATH') or die('No direct script access.');


class Jelly_Core_Field_DateTime extends Jelly_Field
{
/**
* @var boolean convert empty values to null
*/

public $convert_empty = true;
/**
* @var boolean default to converting empty values to NULL
*/
public $allow_null = true;

/**
* @var int default is NULL
*/
public $default = null;

public function __construct($options = array())
{
parent::__construct($options);
}

public function get($model, $value)
{
if ($value === null) {
return null;
}
if ($value instanceof DateTime) {
return $value;
}
return new DateTime($value);
}

public function save($model, $value, $loaded)
{
if ($value instanceof DateTime) {
return $value->format('Y-m-d H:i:s');
}
return $value;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function initialize($model, $column)
// of this field, and the field defaults to this field's model's foreign key
if (empty($this->foreign))
{
$this->foreign = inflector::singular($this->name).'.'.$model.':foreign_key';
$this->foreign = Inflector::singular($this->name).'.'.$model.':foreign_key';
}
// We have a model? Default the field to this field's model's foreign key
elseif (FALSE === strpos($this->foreign, '.'))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 47 additions & 1 deletion classes/jelly/core/model.php → classes/Jelly/Core/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,36 @@ public function get($name)
}
}

/**
* Gets the value from db for a field, no relationships supports,
* returned raw data only.
*
* @param string $name The field's name
* @return string
*/
public function get_raw($name)
{
if ($field = $this->_meta->field($name))
{
// Alias the name to its actual name
$name = $field->name;

if (array_key_exists($name, $this->_changed))
{
return $this->_changed[$name];
}
else
{
return $this->original_raw($name);
}
}
// Return unmapped data from custom queries
elseif (isset($this->_unmapped[$name]))
{
return $this->_unmapped[$name];
}
}

/**
* Returns the original value of a field, before it was changed.
*
Expand All @@ -283,6 +313,22 @@ public function original($field)
}
}

/**
* Returns the original value of a field, before it was changed,
* no relationships supports, returned raw data only.
*
* @param string $field The field's or alias name
* @return string
*/
public function original_raw($field)
{
if ($field = $this->_meta->field($field))
{
// Alias the name to its actual name
return $this->_original[$field->name];
}
}

/**
* Returns an array of values in the fields.
*
Expand Down Expand Up @@ -633,7 +679,7 @@ public function save($validation = NULL)
$value = $field->save($this, $value, $key);

// Only set the value to be saved if it's changed from the original
if ($value !== $this->_original[$column])
if ($field->set($value) !== $this->_original[$column])
{
$values[$field->name] = $value;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions classes/Jelly/Field/DateTime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');

class Jelly_Field_DateTime extends Jelly_Core_Field_DateTime {}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.