Format code, fixing table definitions.

1.9.x
Julio Montoya 10 years ago
parent dc784cfe99
commit 3ba2c6f50d
  1. 71
      main/inc/lib/extra_field_value.lib.php

@ -31,9 +31,8 @@ class ExtraFieldValue extends Model
switch ($this->type) {
case 'calendar_event':
$this->table = Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD);
$this->table_field_values = Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD);
$this->table_field_values = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
$this->table = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_CALENDAR_EVENT_FIELD);
$this->author_id = 'user_id';
break;
case 'course':
@ -84,12 +83,14 @@ class ExtraFieldValue extends Model
public function get_count()
{
$row = Database::select('count(*) as count', $this->table, array(), 'first');
return $row['count'];
}
/**
* Saves a series of records given as parameter into the coresponding table
* @param array Structured parameter for the insertion into the *_field_values table
* Saves a series of records given as parameter into the corresponding table
* @param array $params array for the insertion into the *_field_values table
*
* @return mixed false on empty params, void otherwise
* @assert (array()) === false
*/
@ -140,13 +141,13 @@ class ExtraFieldValue extends Model
}
foreach ($value as $optionId) {
$new_params = array(
$this->handler_id => $params[$this->handler_id],
'field_id' => $extra_field_info['id'],
'field_value' => $optionId,
'comment' => $comment
$newParams = array(
$this->handler_id => $params[$this->handler_id],
'field_id' => $extra_field_info['id'],
'field_value' => $optionId,
'comment' => $comment
);
self::save($new_params);
self::save($newParams);
}
if (!empty($deleteItems)) {
@ -160,13 +161,13 @@ class ExtraFieldValue extends Model
}
break;
default;
$new_params = array(
$this->handler_id => $params[$this->handler_id],
'field_id' => $extra_field_info['id'],
'field_value' => $value,
'comment' => $comment
$newParams = array(
$this->handler_id => $params[$this->handler_id],
'field_id' => $extra_field_info['id'],
'field_value' => $value,
'comment' => $comment
);
self::save($new_params);
self::save($newParams);
}
}
}
@ -374,9 +375,9 @@ class ExtraFieldValue extends Model
/**
* Returns the value of the given extra field on the given resource
* @param int Item ID (It could be a session_id, course_id or user_id)
* @param int Field ID (the ID from the *_field table)
* @param bool Whether to transform the result to a human readable strings
* @param int $item_id Item ID (It could be a session_id, course_id or user_id)
* @param int $field_id Field ID (the ID from the *_field table)
* @param bool $transform Whether to transform the result to a human readable strings
* @return mixed A structured array with the field_id and field_value, or false on error
* @assert (-1,-1) === false
*/
@ -387,7 +388,7 @@ class ExtraFieldValue extends Model
$sql = "SELECT s.*, field_type FROM {$this->table} s
INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)
WHERE {$this->handler_id} = '$item_id' AND
WHERE {$this->handler_id} = '$item_id' AND
field_id = '".$field_id."'
ORDER BY id";
$result = Database::query($sql);
@ -457,8 +458,9 @@ class ExtraFieldValue extends Model
/**
* Gets a structured array of the original item and its extra values, using
* a specific original item and a field name (like "branch", or "birthdate")
* @param int Item ID from the original table
* @param string The name of the field we are looking for
* @param int $item_id Item ID from the original table
* @param string $field_variable The name of the field we are looking for
* @param bool $transform
* @return mixed Array of results, or false on error or not found
* @assert (-1,'') === false
*/
@ -501,10 +503,10 @@ class ExtraFieldValue extends Model
/**
* Gets the ID from the item (course, session, etc) for which
* the given field is defined with the given value
* @param string Field (type of data) we want to check
* @param string Data we are looking for in the given field
* @param bool Whether to transform the result to a human readable strings
* @param bool Whether to return the last element or simply the first one we get
* @param string $field_variable Field (type of data) we want to check
* @param string $field_value Data we are looking for in the given field
* @param bool $transform Whether to transform the result to a human readable strings
* @param bool $last Whether to return the last element or simply the first one we get
* @return mixed Give the ID if found, or false on failure or not found
* @assert (-1,-1) === false
*/
@ -544,7 +546,7 @@ class ExtraFieldValue extends Model
/**
* Get all values for a specific field id
* @param int Field ID
* @param int $field_id
* @return mixed Array of values on success, false on failure or not found
* @assert (-1) === false
*/
@ -614,7 +616,7 @@ class ExtraFieldValue extends Model
/**
* Deletes all the values related to a specific field ID
* @param int Field ID
* @param int $field_id
* @return void
* @assert ('a') == null
*/
@ -627,8 +629,8 @@ class ExtraFieldValue extends Model
/**
* Deletes values of a specific field for a specific item
* @param int Item ID (session id, course id, etc)
* @param int Field ID
* @param int $item_id (session id, course id, etc)
* @param int $field_id
* @return void
* @assert (-1,-1) == null
*/
@ -636,7 +638,8 @@ class ExtraFieldValue extends Model
{
$field_id = intval($field_id);
$item_id = Database::escape_string($item_id);
$sql = "DELETE FROM {$this->table} WHERE {$this->handler_id} = '$item_id' AND field_id = '".$field_id."' ";
$sql = "DELETE FROM {$this->table}
WHERE {$this->handler_id} = '$item_id' AND field_id = '".$field_id."' ";
Database::query($sql);
}
@ -661,8 +664,8 @@ class ExtraFieldValue extends Model
/**
* Not yet implemented - Compares the field values of two items
* @param int Item 1
* @param int Item 2
* @param int $item_id Item 1
* @param int $item_to_compare Item 2
* @return mixed Differential array generated from the comparison
*/
public function compare_item_values($item_id, $item_to_compare)

Loading…
Cancel
Save