Commit c267c052 authored by Nicolò Caruso's avatar Nicolò Caruso

Improve services for Units

parent 3999a832
...@@ -128,11 +128,11 @@ function bat_api_services_resources() { ...@@ -128,11 +128,11 @@ function bat_api_services_resources() {
'optional' => FALSE, 'optional' => FALSE,
), ),
array( array(
'name' => 'bat_unit', 'name' => 'bat_unit',
'type' => 'array', 'type' => 'array',
'description' => t('The unit data to update'), 'description' => t('The unit data to update'),
'source' => 'data', 'source' => 'data',
'optional' => FALSE, 'optional' => FALSE,
), ),
), ),
), ),
...@@ -157,6 +157,20 @@ function bat_api_services_resources() { ...@@ -157,6 +157,20 @@ function bat_api_services_resources() {
'source' => array('data' => 'type'), 'source' => array('data' => 'type'),
'optional' => FALSE, 'optional' => FALSE,
), ),
array(
'name' => 'type_id',
'type' => 'integer',
'description' => t('Type ID'),
'source' => array('data' => 'type_id'),
'optional' => FALSE,
),
array(
'name' => 'uid',
'type' => 'integer',
'description' => t('UID'),
'source' => array('data' => 'uid'),
'optional' => FALSE,
),
array( array(
'name' => 'status', 'name' => 'status',
'type' => 'integer', 'type' => 'integer',
...@@ -503,7 +517,7 @@ function bat_api_services_units_index($unit_ids, $offset, $limit) { ...@@ -503,7 +517,7 @@ function bat_api_services_units_index($unit_ids, $offset, $limit) {
$ids = array_filter(explode(',', $unit_ids)); $ids = array_filter(explode(',', $unit_ids));
$query = db_select('bat_units', 'n') $query = db_select('bat_units', 'n')
->fields('n', array('unit_id', 'type', 'name', 'language', 'status', 'uid')); ->fields('n', array('unit_id', 'type', 'type_id', 'name', 'language', 'status', 'uid'));
if (!empty($ids)) { if (!empty($ids)) {
$query->condition('unit_id', $ids, 'IN'); $query->condition('unit_id', $ids, 'IN');
} }
...@@ -515,8 +529,9 @@ function bat_api_services_units_index($unit_ids, $offset, $limit) { ...@@ -515,8 +529,9 @@ function bat_api_services_units_index($unit_ids, $offset, $limit) {
foreach ($bat_units as $unit) { foreach ($bat_units as $unit) {
$units[$unit->unit_id] = array( $units[$unit->unit_id] = array(
'properties' => array( 'properties' => array(
'type' => $unit->type,
'name' => $unit->name, 'name' => $unit->name,
'type' => $unit->type,
'type_id' => $unit->type_id,
'language' => $unit->language, 'language' => $unit->language,
'status' => $unit->status, 'status' => $unit->status,
'uid' => $unit->uid, 'uid' => $unit->uid,
...@@ -548,19 +563,22 @@ function bat_api_services_units_index($unit_ids, $offset, $limit) { ...@@ -548,19 +563,22 @@ function bat_api_services_units_index($unit_ids, $offset, $limit) {
* *
* @param $name * @param $name
* @param $type * @param $type
* @param $type_id
* @param $uid
* @param $status * @param $status
*/ */
function bat_api_services_add_unit($name, $type, $status) { function bat_api_services_add_unit($name, $type, $type_id, $uid, $status) {
$return = new stdClass(); $return = new stdClass();
$return->sessid = session_id(); $return->sessid = session_id();
if (bat_type_load($type) !== FALSE && $name != '') { if (bat_unit_bundle_load($type) !== FALSE && bat_type_load($type_id) !== FALSE && $name != '') {
$unit = bat_unit_create( $unit = bat_unit_create(
array( array(
'name' => $name, 'name' => $name,
'type' => $type, 'type' => $type,
'type_id' => $type_id,
'status' => $status, 'status' => $status,
'uid' => 0, 'uid' => $uid,
'created' => REQUEST_TIME, 'created' => REQUEST_TIME,
'changed' => REQUEST_TIME, 'changed' => REQUEST_TIME,
) )
...@@ -588,13 +606,11 @@ function bat_api_services_edit_unit($unit_id, $bat_unit_data) { ...@@ -588,13 +606,11 @@ function bat_api_services_edit_unit($unit_id, $bat_unit_data) {
$return = new stdClass(); $return = new stdClass();
$return->sessid = session_id(); $return->sessid = session_id();
$unit = bat_unit_load($unit_id); if ($unit = bat_unit_load($unit_id)) {
if ($unit !== FALSE) {
$unit->name = (isset($bat_unit_data['name'])) ? $bat_unit_data['name'] : $unit->name; $unit->name = (isset($bat_unit_data['name'])) ? $bat_unit_data['name'] : $unit->name;
$unit->default_state = (isset($bat_unit_data['default_state'])) ? $bat_unit_data['default_state'] : $unit->default_state;
$unit->status = (isset($bat_unit_data['status'])) ? $bat_unit_data['status'] : $unit->status; $unit->status = (isset($bat_unit_data['status'])) ? $bat_unit_data['status'] : $unit->status;
$unit->uid = (isset($bat_unit_data['uid'])) ? $bat_unit_data['uid'] : $unit->uid; $unit->uid = (isset($bat_unit_data['uid'])) ? $bat_unit_data['uid'] : $unit->uid;
$unit->data = (isset($bat_unit_data['data'])) ? $bat_unit_data['data'] : $unit->data;
$unit->changed = REQUEST_TIME; $unit->changed = REQUEST_TIME;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment