/** * Get a list of all the forms * * @param int $limit The maximum number of items to retrieve. * @param int $offset The offset. * @return array */ public static function getAll($limit = 30, $offset = 0) { if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('GET')) { // redefine $limit = (int) $limit; $offset = (int) $offset; // validate if ($limit > 10000) { return BaseAPI::output(BaseAPI::ERROR, array('message' => 'Limit can\'t be larger than 10000.')); } $forms = (array) BackendModel::getContainer()->get('database')->getRecords('SELECT i.id, i.language, i.name, i.method, UNIX_TIMESTAMP(i.created_on) AS created_on, UNIX_TIMESTAMP(i.edited_on) AS edited_on FROM forms AS i ORDER BY i.created_on DESC LIMIT ?, ?', array($offset, $limit)); $return = array('forms' => null); foreach ($forms as $row) { $item['form'] = array(); // set attributes $item['form']['@attributes']['id'] = $row['id']; $item['form']['@attributes']['created_on'] = date('c', $row['created_on']); $item['form']['@attributes']['language'] = $row['language']; // set content $item['form']['name'] = $row['name']; $item['form']['method'] = $row['method']; $return['forms'][] = $item; } return $return; } }
/** * Remove a device from a user. * * @param string $uri The uri of the channel opened for the device. * @param string $email The emailaddress for the user to link the device to. */ public static function microsoftRemoveDevice($uri, $email) { if (BaseAPI::isAuthorized()) { // redefine $uri = (string) $uri; // validate if ($uri == '') { BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No uri-parameter provided.')); } if ($email == '') { BaseAPI::output(BaseAPI::BAD_REQUEST, array('message' => 'No email-parameter provided.')); } try { // load user $user = new User(null, $email); // get current uris $uris = (array) $user->getSetting('microsoft_channel_uri'); // not already in array? $index = array_search($uri, $uris); if ($index !== false) { // remove from array unset($uris[$index]); // save it $user->setSetting('microsoft_channel_uri', $uris); } } catch (Exception $e) { BaseAPI::output(BaseAPI::FORBIDDEN, array('message' => 'Can\'t authenticate you.')); } } }
/** * Update a comment * * @param int $id The id of the comment. * @param string $status The new status for the comment. Possible values are: published, moderation, spam. * @param string $text The new text for the comment. * @param string $authorName The new author for the comment. * @param string $authorEmail The new email for the comment. * @param string $authorWebsite The new website for the comment. * * @return null|bool */ public static function commentsUpdate($id, $status = null, $text = null, $authorName = null, $authorEmail = null, $authorWebsite = null) { // authorize if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('POST')) { // redefine $id = (int) $id; if ($status !== null) { $status = (string) $status; } if ($text !== null) { $text = (string) $text; } if ($authorName !== null) { $authorName = (string) $authorName; } if ($authorEmail !== null) { $authorEmail = (string) $authorEmail; } if ($authorWebsite !== null) { $authorWebsite = (string) $authorWebsite; } // validate if ($status === null && $text === null && $authorName === null && $authorEmail === null && $authorWebsite === null) { return BaseAPI::output(BaseAPI::ERROR, array('message' => 'No data provided.')); } // update if ($text !== null || $authorName !== null || $authorEmail != null || $authorWebsite !== null) { $item['id'] = (int) $id; if ($text !== null) { $item['text'] = $text; } if ($authorName !== null) { $item['author'] = $authorName; } if ($authorEmail !== null) { $item['email'] = $authorEmail; } if ($authorWebsite !== null) { $item['website'] = $authorWebsite; } // update the comment BackendBlogModel::updateComment($item); } // change the status if needed if ($status !== null) { BackendBlogModel::updateCommentStatuses(array($id), $status); } } }