/**
  * Creates a task
  *
  * @param object $task ["data"]
  * @return object
  *
  * @Access(callback='DocuWalkTaskResource::access', args={'create'}, appendArgs=false)
  */
 public static function create($task)
 {
     $attr = array('title', 'body');
     $node = (object) array('type' => 'docuwalk_task', 'created' => time(), 'modified' => time(), 'uid' => $user->uid);
     // Transfer attributes from
     foreach ($attr as $name) {
         if (isset($task->{$name})) {
             $node->{$name} = $task->{$name};
         } else {
             return services_error("Missing attribute {$name}", 406);
         }
     }
     node_save($node);
     return (object) array('nid' => $node->nid, 'uri' => services_resource_uri(array($type, $node->nid)), 'url' => url('node/' . $node->nid, array('absolute' => TRUE)));
 }
 /**
  * Creates a text
  *
  * @param object $text ["data"]
  * @return object
  *
  * @Access(callback='DocuWalkTextResource::access', args={'create'}, appendArgs=false)
  */
 public static function create($text)
 {
     global $user;
     $attr = array('body', 'solution', 'position');
     $node = (object) array('type' => 'docuwalk_text', 'created' => time(), 'modified' => time(), 'uid' => $user->uid);
     // Transfer attributes from
     foreach ($attr as $name) {
         if (isset($text->{$name})) {
             $node->{$name} = $text->{$name};
         } else {
             return services_error("Missing attribute {$name}", 406);
         }
     }
     $node->title = drupal_substr($node->body, 0, min(drupal_strlen($node->body), 40));
     // Format the solution nid for cck
     $node->field_docuwalk_solution = array(array('nid' => $node->solution));
     unset($node->solution);
     $node->simple_geo_position = $node->position;
     unset($node->position);
     node_save($node);
     return (object) array('nid' => $node->nid, 'uri' => services_resource_uri(array('docuwalk-text', $node->nid)), 'url' => url('node/' . $node->nid, array('absolute' => TRUE)));
 }
 /**
  * Controller method for writing waypoints to a solution
  *
  * @param int $nid ["path","0"]
  *  The nid of the solution to add the waypoint to
  * @param object $waypoint ["data"]
  *  The waypoint to add
  * @return object
  *
  * @Access(callback='DocuWalkSolutionResource::access', args={'update'}, appendArgs=true)
  */
 public static function addWaypoint($nid, $waypoint)
 {
     if (!isset($waypoint->position)) {
         return services_error("Missing attribute 'position'", 406);
     }
     if (!preg_match('/^-?\\d+(\\.\\d+)?\\s-?\\d+(\\.\\d+)?$/', $waypoint->position)) {
         return services_error("Invalid format for the position.");
     }
     db_query("INSERT INTO {docuwalk_waypoint}(nid, position)\n      VALUES(%d, GeomFromText('%s'))", $nid, simple_geo_to_wkt('point', $waypoint->position));
     $wid = db_last_insert_id('docuwalk_waypoint', 'wid');
     return (object) array('wid' => $wid);
 }
 /**
  * Helper function that maps incoming data to the proper node attributes
  *
  * @param object $node
  * @param object $data
  * @return object
  */
 private static function nodeWrite($node, $data)
 {
     $oauth_consumer = services_get_server_info('oauth_consumer');
     $source = conglomerate_source_from_consumer($oauth_consumer);
     $attr = array('title' => array('required' => TRUE), 'text' => array('to' => 'body', 'required' => TRUE), 'position' => array('to' => 'simple_geo_position', 'required' => TRUE), 'tags' => array('required' => FALSE, 'adapt' => 'adaptTags'), 'metadata' => array('required' => FALSE, 'to' => 'conglomerate_metadata'), 'picture' => array('required' => FALSE, 'adapt' => 'adaptPicture'), 'large_picture' => array('required' => FALSE, 'adapt' => 'adaptLargePicture'), 'url' => array('required' => TRUE, 'adapt' => 'adaptUrl'), 'fulltext' => array('required' => FALSE, 'adapt' => 'adaptFulltext'), 'type' => array('required' => TRUE), 'language' => array('required' => TRUE), 'comments' => array('required' => FALSE));
     switch ($data->type) {
         case 'event':
             $attr['starts'] = array('adapt' => 'adaptStartTime', 'required' => TRUE);
             break;
         case 'subpage':
             $attr['searchable'] = array('adapt' => 'adaptSearchable', 'required' => TRUE);
             break;
     }
     drupal_alter('conglomerate_node_write_attributes', $attr, $data, $source);
     // Transfer attributes from data
     foreach ($attr as $name => $info) {
         if (isset($data->{$name})) {
             $to = $name;
             if (!empty($info['to'])) {
                 $to = $info['to'];
             }
             $node->{$to} = $data->{$name};
             if (isset($info['adapt'])) {
                 call_user_func('ConglomerateContentResource::' . $info['adapt'], $node);
             }
         } else {
             if ($info['required']) {
                 return services_error("Missing attribute {$name}", 406);
             }
         }
     }
     // Add information about the conglomerate source
     $node->conglomerate_source = $source->sid;
     $the_language = $node->language;
     node_save($node);
     // Workaround to preserve language. TODO: Must find out what is happening to the language.
     if (!$node->language) {
         db_query("UPDATE {node} SET language='%s' WHERE nid = %d", array(':language' => $the_language, ':nid' => $node->nid));
     }
     return (object) array('nid' => $node->nid, 'uri' => services_resource_uri(array('conglomerate-content', $node->nid)), 'url' => url('node/' . $node->nid, array('absolute' => TRUE)));
 }
Example #5
0
 /**
  * Unlocks a platform
  *
  * @access  public
  * @static
  * @param   object  $data ["data"]
  * @return  object
  *
  * @Access(callback='PlatformsResource::access', args={'unlock'}, appendArgs=true)
  */
 public static function unlock($data)
 {
     // Todo: small query instead of node load to check node type
     $node = node_load(array('nid' => $data));
     if ($node->type !== 'platform') {
         services_error('Specified node is not a platform.' . $node->platform, 404);
     }
     hosting_add_task($node->nid, 'unlock');
     return himinglaeva_status(TRUE, 'Platform unlock task was successfully queued.');
 }