/** * Create a new application * * @param string $application_id id op the app * @param string $title name of the app * @param string $description description of the app * @param string $icon_url url to an icon * @param array $application_info array containing additional data about the application * * @return APIApplication|boolean */ function ws_pack_create_application($application_id, $title, $description = "", $icon_url = "", $application_info = array()) { $result = false; if (!($application = ws_pack_get_application_from_id($application_id))) { // check if api registration is allowed if (elgg_get_plugin_setting("allow_registration", "ws_pack") == "yes") { if (!empty($application_id) && !empty($title)) { $application = new APIApplication(); $application->title = $title; $application->application_id = $application_id; // set a description if (!empty($description)) { $application->description = $description; } if (!empty($icon_url)) { $application->icon_url = $icon_url; } if (!empty($application_info) && is_array($application_info)) { $application->extended_information = json_encode($application_info); } // make sure we can save the application $ia = elgg_set_ignore_access(true); if ($application->save()) { $result = $application; } // restore access elgg_set_ignore_access($ia); } } else { // registration is not allowed $result = -1; } } else { // already existed, shouldn't happen $result = $application; } return $result; }
/** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function application() { return $this->belongsTo(APIApplication::getClass(), 'application_id'); }
/** * Returns application specific user settings * * @param ElggUser $user user entity * @param APIApplication $api_application application entity * * @return false|APIApplicationUserSetting */ function ws_pack_get_application_user_settings(ElggUser $user, APIApplication $api_application) { if (!$user instanceof ElggUser || !$api_application instanceof APIApplication) { return false; } $options = ["type" => "object", "subtype" => APIApplicationUserSetting::SUBTYPE, "limit" => 1, "owner_guid" => $user->getGUID(), "container_guid" => $api_application->getGUID()]; $entities = elgg_get_entities($options); if (!empty($entities)) { return $entities[0]; } else { $entity = new APIApplicationUserSetting(); $entity->owner_guid = $user->getGUID(); $entity->container_guid = $api_application->getGUID(); if ($entity->save()) { return $entity; } } return false; }