diff options
author | Benoit Tremblay <bentremblay@benoit-tremblays-macbook-pro.local> | 2009-12-01 17:56:58 (GMT) |
---|---|---|
committer | Benoit Tremblay <bentremblay@benoit-tremblays-macbook-pro.local> | 2009-12-01 17:56:58 (GMT) |
commit | 9eb79a6bea83bcb96408a7632dc4f860445b318c (patch) | |
tree | 2aa87d6a061f2dd98b57fb555f4446a22c95a4d6 | |
parent | 46977aa2f06191761a60015b7c701edc30ca83cc (diff) |
-rw-r--r-- | site/app/controllers/tutorius_api_controller.php | 405 |
1 files changed, 274 insertions, 131 deletions
diff --git a/site/app/controllers/tutorius_api_controller.php b/site/app/controllers/tutorius_api_controller.php index dcec552..290c727 100644 --- a/site/app/controllers/tutorius_api_controller.php +++ b/site/app/controllers/tutorius_api_controller.php @@ -48,10 +48,18 @@ class TutoriusApiController extends AppController { var $name = 'TutoriusApi'; + /** + * Current API version + * Could eventually be used if we have to support different + * API versions with different functionalities + */ var $newest_api_version = 0.1; var $beforeFilter = array(); + /** + * Here we specify the Models this controller requires + */ var $uses = array( 'Addon', 'Appversion', 'Review', 'TestResult', 'Addonlog', 'AddonCollection', 'Addontype', 'ApiAuthToken', 'Application', 'Collection', 'File', 'Platform', 'Category', 'Translation', @@ -65,6 +73,9 @@ class TutoriusApiController extends AppController 'Html', 'Link', 'Time', 'Localization' ); + /* + * HTML statuses used by some functions + */ const STATUS_OK = '200 OK'; const STATUS_CREATED = '201 Created'; const STATUS_NOT_MODIFIED = '304 Not Modified'; @@ -82,8 +93,8 @@ class TutoriusApiController extends AppController } /** - * This is executed for every request to the API - * + * This is executed for every request to the API and + * it is called before the requested function */ function beforeFilter() { Configure::write('Session.checkAgent', false); @@ -105,8 +116,11 @@ class TutoriusApiController extends AppController $this->SimpleAuth->enabled = false; $this->SimpleAcl->enabled = false; - // extract API version - $url = $_SERVER['REQUEST_URI']; + /* + * Here we extract the API version provided in the request URL. + * We could eventually support different API versions. + */ + $url = $_SERVER['REQUEST_URI']; $matches = array(); if (preg_match('/TutoriusApi\/([\d\.]*)\//', $url, $matches)) { @@ -119,8 +133,10 @@ class TutoriusApiController extends AppController $this->api_version = $this->newest_api_version; } - // Establish a base URL for this request. - $this->base_url = ( empty($_SERVER['HTTPS']) ? 'http' : 'https' ) . + /* + * Establish a base URL for this request. + */ + $this->base_url = ( empty($_SERVER['HTTPS']) ? 'http' : 'https' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; if ( ($qpos = strpos($this->base_url, '?')) !== FALSE) { // Toss out any query parameters. @@ -128,11 +144,15 @@ class TutoriusApiController extends AppController } $this->_sendToView('base_url', $this->base_url); - // Trying to get the current authenticated user + // Now try to get the current authenticated user $this->auth_user = $this->_getAuthUser(); $this->_sendToView('auth_user', $this->auth_user); } + /********************************************** + /*************** INDEX (Default) ************* + /*********************************************/ + /** * This is the main function for this controller * its role is to list all available functions via the API @@ -147,7 +167,15 @@ class TutoriusApiController extends AppController /*********************************************/ /* - * Search addons + * Search addons by keywords. The category, maximum number of results per page + * and 'sort by' criterias can also be specified + * + * @param string $terms terms to search for + * @param int $category limit search results to specified category. 'all' is + * the default. + * @param int $page page number to fetch + * @param int $limit maximum number of results per page + * @param string $sortBy Specify how results should be sorted * */ function search($terms, $category='all', $page=1, $limit=20, $sortBy='name') { @@ -159,7 +187,7 @@ class TutoriusApiController extends AppController /* - * Search for addons + * Invoked when the search function is called using HTTP GET. * */ function search_GET($context, $terms, $category='all', $page=1, $limit=20, $sortBy='name') { @@ -167,14 +195,19 @@ class TutoriusApiController extends AppController global $valid_status, $app_shortnames; + // The search options array we'll fill with search criterias $search_options = array(); + // Other tables linked with the addons table we want to fetch $associations = array( 'all_categories', 'all_tags', 'authors', 'compatible_apps', 'contrib_details', 'files', 'latest_version', 'list_details' ); - // collection search is a special case + /* + * We don't support collections search for now, but it + * is possible to search in collections eventually. + */ if ($category == 'collections') { // special case for collections return; @@ -187,19 +220,30 @@ class TutoriusApiController extends AppController $search_options['type'] = ADDON_TUTORIUS; - //if advanced search sort_order set, use it - $sort = ""; + /** + * Different sort orders are supported. Default is by entry order + * in the DB. + */ + $sort = ""; // Default + $sort_orders = array('newest', 'name', 'averagerating', 'weeklydownloads'); + if (isset($sortBy) && in_array($sortBy, $sort_orders) ) { $search_options['sort'] = $sortBy; } - // execute this search + /** + * Prepare for search. + */ $as = new AddonsSearch($this->Addon); $_result_ids = array(); $total = 0; + /** + * Execute the search with the specified terms and search + * Options / criterias + */ if ($terms) { try { list($_result_ids, $total) = $as->query($terms, $search_options); @@ -210,12 +254,14 @@ class TutoriusApiController extends AppController } } - // cut the appropriate slice out of the results array + /** + * slice the results to get the page specified by the user + * With the appropriate number of results + */ $offset = ($page-1)*$limit; $_result_ids = array_slice($_result_ids, $offset, $limit); if (!empty($_result_ids)) { - $results = $this->Addon->getAddonList($_result_ids, $associations); $this->_getTutorials($_result_ids); } else { $results = array(); @@ -227,6 +273,17 @@ class TutoriusApiController extends AppController $this->render('tutorials'); } + + /* + * Returns a list of tutorials without any keywords constraints. + * + * @param int $category limit search results to specified category. 'all' is + * the default. + * @param int $page page number to fetch + * @param int $limit maximum number of results per page + * @param string $sortBy Specify how results should be sorted + * + */ function tutorials($category='all', $page=1, $limit=10, $sort_by='') { $args = func_get_args(); @@ -236,6 +293,17 @@ class TutoriusApiController extends AppController } + function gee() { + $app_names = $this->Application->getIDList(); + $guids = array_flip($this->Application->getGUIDList()); + + print_r($app_names); + print_r($guids); + } + + /** + * This function is called then "tutorials" is called using a HTTP GET + */ function tutorials_GET($context, $category='all', $page=1, $limit=10, $sort_by='') { extract($context); @@ -244,7 +312,9 @@ class TutoriusApiController extends AppController $app_names = $this->Application->getIDList(); $guids = array_flip($this->Application->getGUIDList()); - // By default, we're getting all categories + /** + * By default, we're getting all categories + */ $this_category = array(); if ($category != 'all') { @@ -274,8 +344,9 @@ class TutoriusApiController extends AppController $ids = array(); - // Build an array with all found ids so we can get - // more information about these tutorials + /** Build an array with all found ids so we can get + * more information about these tutorials + */ foreach($tutorials as $tutorial) { $ids[sizeof($ids)] = $tutorial['Addon']['id']; } @@ -293,10 +364,10 @@ class TutoriusApiController extends AppController /*************** AUTHENTICATION ************* /*********************************************/ - /* + /** * Authenticate a user and then - * return an authentication key so the user doesn't have to authenticate with its - * username/password every request + * return an authentication key so the user doesn't have to authenticate + * with its username/password on every request * */ function auth() { @@ -308,19 +379,26 @@ class TutoriusApiController extends AppController } /** - * Generate a new auth token for the authenticated user. + * This function is called when "auth()" is called using a HTTP POST. + * Generate a new auth token for the authenticated user. */ function auth_POST($context) { extract($context); - // Create the User array and map it with the POST variables - // that contains the username (email) and password + /** + * Create the User array and map it with the POST variables + * that contains the username (email) and password + */ $user = $this->getParams(array( 'username' => '', 'password' => '', )); - // Check HTTP basic auth + + /** + * Start the authentication process by verifying the supplied + * credentials against the Database information + */ if (null == $this->auth_user && !empty($user['username']) && !empty($user['password'])) { @@ -335,12 +413,18 @@ class TutoriusApiController extends AppController } } - // If authentification was successful, this will allow - // the function to continue. Otherwise, an access denied - // message will be displayed. + /** + * If authentification was successful, _checkLoggedIn() will + * return true. Otherwise, an access denied message will + * be displayed. + */ $this->_checkLoggedIn(); $token_value = $this->ApiAuthToken->generateTokenValue(); + /** + * All good, now we can save the newly created token + * To the database. + */ $data = array( 'ApiAuthToken' => array( 'token' => $token_value, @@ -350,6 +434,10 @@ class TutoriusApiController extends AppController $this->Amo->clean($data); + /** + * If the save is not successful, we'll return an error message. + * Otherwise, we'll return the token information + */ if (!$this->ApiAuthToken->save($data)) { return $this->renderStatus( self::STATUS_ERROR, 'error', @@ -397,6 +485,9 @@ class TutoriusApiController extends AppController /************** USER REGISTRATION ************* /*********************************************/ + /** + * Register a new user (auto-approved) + */ function registerNewUser() { $args = func_get_args(); @@ -413,19 +504,19 @@ class TutoriusApiController extends AppController function registerNewUser_POST($context) { extract($context); - // Create the User array and map it with the POST variables + /** + * Create the User array and map it with the POST variables + */ $data['User'] = $this->getParams(array( 'nickname' => '', 'password' => '', 'email' => '', )); - - // filter nickname characters - //$this->data['User']['nickname'] = $this->_filterNick($this->data['User']['nickname']); - - // No confirmation code. We want to simplify the process for now. - // User is auto-approved + /** + * No confirmation code. We want to simplify the process for now. + * User is auto-approved. + */ $data['User']['confirmationcode'] = ''; $this->User->data = $data; @@ -438,7 +529,9 @@ class TutoriusApiController extends AppController if ($data['User']['password'] == '') $this->User->invalidate('password'); - // email has to be unique + /** + * The email address specified has to be unique + */ $allemail = $this->User->findAll("email='{$this->User->data['User']['email']}'"); if (!empty($allemail)) { $this->User->invalidate('email'); @@ -450,7 +543,9 @@ class TutoriusApiController extends AppController ); } - // if nickname is defined it has to be unique + /** + * Just like the email address, the nickname has to be unique + */ if (!$data['User']['nickname'] == '') { $allnicks = $this->User->findAll("nickname='{$this->User->data['User']['nickname']}'"); if (!empty($allnicks)) { @@ -464,7 +559,9 @@ class TutoriusApiController extends AppController } } - // any errors? Get out of here. + /** + * Oops, unable to save the user. Return and XML error. + */ if (!$this->User->save()) { return $this->_renderError( array( @@ -479,9 +576,9 @@ class TutoriusApiController extends AppController /*********************************************/ /** - * Dispatcher for the publish method - * - */ + * Publish a new tutorial. Supported requests are + * POST (create) and PUT (update) + */ function publish($id = 0) { $args = array(0 => $id); @@ -493,15 +590,22 @@ class TutoriusApiController extends AppController } /** - * Publish a new tutorial + * Publish a new tutorial when the "publish" method is invoked + * using HTTP POST * */ function publish_POST($context, $id) { extract($context); + /** + * You need to be logged in to publish a tutorial + */ $this->_checkLoggedIn(); - // In this case, it means we want to re-activate a tutorial + /** + * If a tutorial ID is specified (existing tutorial), we simply + * re-publish a previously un-published tutorial + */ if ($id != 0) { $tutorial = $this->Addon->findById($id, array('id', 'addontype_id', 'nominationmessage', 'status', 'higheststatus'), null, -1); @@ -516,10 +620,11 @@ class TutoriusApiController extends AppController return; } - // This will store all data to be saved $addon = array(); - // Create the User array and map it with the POST variables + /** + * Create the params array and map it with the POST variables + */ $params = $this->getParams(array( 'name' => '', 'summary' => '', @@ -531,6 +636,9 @@ class TutoriusApiController extends AppController 'cat3' => '' )); + /** + * Only 3 categories are supported by REMORA. + */ $categories = array( APP_TUTORIUS => array( 1 => $params['cat1'], @@ -539,7 +647,9 @@ class TutoriusApiController extends AppController ) ); - // Make sure a file was uploaded + /** + * Make sure a file was uploaded. Return + */ if (empty($_FILES['file']['name'])) { return $this->_renderError( array( @@ -548,21 +658,24 @@ class TutoriusApiController extends AppController ); } - // We just received a Tutorial $addon['Addon']['addontype_id'] = ADDON_TUTORIUS; - // Validate file upload for basic errors and get some info + /** + * Validate the uploaded file for some basic errors + * and return an error if unable to validate. + */ $validate = $this->Developers->validateFile($_FILES['file'], $addon); if (is_string($validate)) { - // If a string is returned, there was an error + return $this->_renderError( array( 'reason' => $validate ) ); + } else { - // If an array is returned, there were no errors + $addon['File']['details'] = $validate; $addon['File']['db'] = array( 'platform_id' => !empty($this->data['File']['platform_id']) ? $this->data['File']['platform_id'] : array(PLATFORM_ALL), @@ -572,13 +685,20 @@ class TutoriusApiController extends AppController 'status' => STATUS_PUBLIC, 'datestatuschanged' => $this->Amo->getNOW() ); + } - // Clear duplicates + /** + * Delete from the test results cache duplicates + */ $filename = $validate['filename']; $this->Amo->clean($filename); $this->Addon->execute("DELETE FROM `test_results_cache` WHERE `key` = '{$filename}'"); + /** + * Fill the Addon array with the information supplied + * by the user + */ $addon['Addon']['guid'] = $params['guid']; $addon['Addon']['name'] = $params['name']; $addon['Addon']['summary'] = $params['summary']; @@ -587,7 +707,11 @@ class TutoriusApiController extends AppController $addon['Addon']['higheststatus'] = STATUS_PUBLIC; $addon['Version']['version'] = $params['version']; - // Validate target applications + /** + * Validate target applications. This is a 'hack' for now as the + * tutorials received don't specify which version of Tutorius they + * are built for. Also, the Tutorius application GUID is hardcoded + */ $application['{c0385ef9-1828-4340-961a-e769a9f0a986}'] = array( 'minVersion' => 0.1, 'maxVersion' => 0.1 @@ -596,56 +720,59 @@ class TutoriusApiController extends AppController $validate = $this->Validation->validateTargetApplications($application); if (is_string($validate)) { - // If a string is returned, there was an error + return $this->_renderError( - array( - 'reason' => 'No valid application was found for this tutorial' - ) -); + array( + 'reason' => 'No valid application was found for this tutorial' + ) + ); + } else { - // If an array is returned, there were no errors $addon['appversions'] = $validate; } // Unbind add-ons $this->Addon->unbindFully(); - $additional = 'new'; - // Make sure GUID doesn't exist already + /** + * Check if the GUID supplied with the tutorial doesn't already exists. + */ if ($existing = $this->Addon->findAll(array('Addon.guid' => $addon['Addon']['guid']), array('guid'))) { return $this->_renderError( array( - 'reason' => sprintf(___('This add-on ID (%1$s) already exists in the database. If this is your add-on, you can <a href="%2$s">upload a new version</a>.'), $addon['Addon']['guid'], $this->url("/developers/versions/add/{$existing[0]['Addon']['id']}")) + 'reason' => 'This add-on already exists in the database.' ) ); } $addon['error'] = 0; - - // Save some additional data for later $addon['Addon']['id'] = $this->data['Addon']['id']; $addon['Version']['id'] = $this->data['Version']['id']; $addon['License'] = $this->data['License']; - //$addon['Version.License.text'] = getitem($this->data, 'Version.License.text'); - //$addon['form.data.Version.License'] = getitem($this->params, 'form.data.Version.License'); - // Save this data for insertion if/when things pass $data = serialize($addon); $this->Amo->clean($data); $filename = $addon['File']['db']['filename']; $this->Amo->clean($filename); + /** + * Put the tutorial in cache for now. + */ $this->TestResult->execute("INSERT INTO `test_results_cache` (`date`, `key`, `test_case_id`, `value`) VALUES (NOW(), '{$filename}', -1, '{$data}')"); - // Now, let's publish the tutorial with public status + /** + * Now, let's publish the tutorial with public status + */ $this->_registerTutorial($filename, $categories); } /* - * Delete a tutorial + * Unpublish a tutorial, doesn't actually delete it from the filesystem + * + * @param string $id id of the tutorial to unpublish * */ function publish_DELETE($context, $id) { @@ -756,6 +883,7 @@ class TutoriusApiController extends AppController $addon['Version']['version'] = $params['version']; // Validate target applications + // Again, same as publish $application['{c0385ef9-1828-4340-961a-e769a9f0a986}'] = array( 'minVersion' => 0.1, 'maxVersion' => 0.1 @@ -794,8 +922,6 @@ class TutoriusApiController extends AppController $addon['Addon']['id'] = $id; $addon['Version']['id'] = $this->data['Version']['id']; $addon['License'] = $this->data['License']; - //$addon['Version.License.text'] = getitem($this->data, 'Version.License.text'); - //$addon['form.data.Version.License'] = getitem($this->params, 'form.data.Version.License'); // Save this data for insertion if/when things pass $data = serialize($addon); @@ -817,21 +943,23 @@ class TutoriusApiController extends AppController */ function _registerTutorial($filename = '', $categories) { - // Grab the data from our cache, and then de-serialize it + /** + * Grab the data from the cache and unserialize it + */ $this->Amo->clean($filename); $data = $this->Addon->query("SELECT value FROM `test_results_cache` WHERE `key` = '{$filename}' AND `test_case_id` = -1"); $data = $data[0]['test_results_cache']['value']; $this->Amo->unclean($data); $data = unserialize($data); - // Insert new add-on row + /** + * We're now ready to save the tutorial + */ $this->Addon->id = 0; $this->Addon->save($data['Addon']); $data['Addon']['id'] = $this->Addon->getLastInsertId(); - if ($data['Addon']['id']) { - //$this->Addonlog->logCreateAddon($this, $data['Addon']['id']); - } - else { + + if ( !$data['Addon']['id'] ) { return $this->_renderError( array( 'reason' => 'Could not save the addon.' . print_r($data) @@ -839,50 +967,60 @@ class TutoriusApiController extends AppController ); } - // Add user as author + /** + * Add the logged in user as author + */ $this->Addon->saveAuthor($data['Addon']['id'], $this->auth_user['id']); - // Save License - //$license_id = $this->Developers->saveLicense( - //$this->data['License'], - //getitem($this->data, 'License.text'), - //getitem($this->params, 'form.data.License')); $this->Addon->saveField('dev_agreement', 1); - // Add Version + /** + * Add Version number for this tutorial + */ $this->Version->id = 0; $data['Version']['addon_id'] = $data['Addon']['id']; - //$data['Version']['license_id'] = $license_id; $this->Version->save($data['Version']); $data['Version']['id'] = $this->Version->getLastInsertId(); - // Save appversions + /** + * Save appversions + */ if (!empty($data['appversions'])) { foreach ($data['appversions'] as $appversion) { $this->Version->addCompatibleApp($data['Version']['id'], $appversion['application_id'], $appversion['min'], $appversion['max']); } } - // Add Files + /** + * Move the file from the temp directory to the official + * tutorials directory and publish this file information to + * the DB. + */ $data['File']['db']['version_id'] = $data['Version']['id']; $platforms = $data['File']['db']['platform_id']; - foreach ($platforms as $platform_id) { + + foreach ($platforms as $platform_id) { $this->File->id = 0; $data['File']['db']['platform_id'] = $platform_id; $validate = $this->Developers->moveFile($data); if (is_string($validate)) { - // If a string is returned, there was an error + return $this->_renderError( array( 'reason' => $validate ) ); + } + $data['File']['db']['filename'] = $validate['filename']; $this->File->save($data['File']['db']); $file_id = $this->File->id; } - // Remove temp file + + /** + * Remove the temps file that was stored on the file system + */ $tempFile = $data['File']['details']['path']; if (file_exists($tempFile)) { unlink($tempFile); @@ -890,8 +1028,10 @@ class TutoriusApiController extends AppController $addon_id = $data['Addon']['id']; - // now get the newly created tutorial, associate it with - // categories and return it + /** + * now get the newly created tutorial, associate it with + * categories and return it + */ $this->_getTutorials(array($addon_id)); if (isset($this->viewVars['addonsdata'][$addon_id])) { @@ -899,9 +1039,6 @@ class TutoriusApiController extends AppController $this->Category->saveCategories($addon_id, $categories); - // log addon action - //$this->Addonlog->logEditCategories($this, $addon_id); - // flush cached add-on objects if (QUERY_CACHE) $this->Addon->Cache->markListForFlush("addon:{$addon_id}"); } @@ -917,9 +1054,12 @@ class TutoriusApiController extends AppController $this->_sendToView('api_version', $this->api_version); } else { + $error = ___('Add-on not found!'); $this->_sendToView('error', $error); + return; + } } @@ -935,7 +1075,7 @@ class TutoriusApiController extends AppController $data = unserialize($data); $addon_id = $data['Addon']['id']; - $version_id = $data['Version']['id']; // This will fail if there's a new version, but this is OK + $version_id = $data['Version']['id']; $addon = $this->Addon->findById($addon_id); @@ -944,13 +1084,9 @@ class TutoriusApiController extends AppController // Add Version $this->Version->id = 0; $data['Version']['addon_id'] = $addon_id; - //$data['Version']['license_id'] = $license_id; $this->Version->save($data['Version']); $version_id = $this->Version->getLastInsertId(); - // Log addon action - //$this->Addonlog->logAddVersion($this, $addon_id, $version_id, $data['Version']['version']); - // If add-on is public, cancel any pending files if ($addon['Addon']['status'] == STATUS_PUBLIC) { $this->Addon->execute("UPDATE files SET status = ".STATUS_SANDBOX." WHERE files.version_id IN (SELECT id FROM versions WHERE versions.addon_id={$addon_id}) AND files.status = ".STATUS_PENDING); @@ -967,34 +1103,25 @@ class TutoriusApiController extends AppController $data['File']['db']['version_id'] = $version_id; $platforms = $data['File']['db']['platform_id']; - // Make trusted add-ons public - if ($addon['Addon']['trusted'] == 1) { - $data['File']['db']['status'] = STATUS_PUBLIC; - } - elseif ($addon['Addon']['status'] == STATUS_PUBLIC) { - $data['File']['db']['status'] = STATUS_PUBLIC; // Override pending for our needs - } - else { - $data['File']['db']['status'] = STATUS_PUBLIC; // Override sandbax for our needs - } + // Make tutorial public + $data['File']['db']['status'] = STATUS_PUBLIC; foreach ($platforms as $platform_id) { $this->File->id = 0; $data['File']['db']['platform_id'] = $platform_id; $validate = $this->Developers->moveFile($data); if (is_string($validate)) { - // If a string is returned, there was an error - + return $this->_renderError( + array( + 'reason' => 'Could not move file' + ) + ); } $data['File']['db']['filename'] = $validate['filename']; $this->File->save($data['File']['db']); $file_id = $this->File->id; - // only log file creation if separate from version creation - if (!empty($data['Version']['id'])) { - //$this->Addonlog->logAddFileToVersion($this, $addon_id, $file_id, $validate['filename'], $version_id, //$data['Version']['version']); - } } // Remove temp file @@ -1002,9 +1129,6 @@ class TutoriusApiController extends AppController if (file_exists($tempFile)) { unlink($tempFile); } - - $pending = $this->Addon->query("SELECT COUNT(*) AS pending FROM files WHERE status=".STATUS_PENDING." GROUP BY status"); - $pendingCount = (!empty($pending[0][0]['pending']) ? ($pending[0][0]['pending'] - 1) : 0); } @@ -1028,22 +1152,32 @@ class TutoriusApiController extends AppController function review_POST($context, $id) { extract($context); - // Restricted part of the api + /** + * The user has to be logged in to review a tutorial + */ $this->_checkLoggedIn(); - // First, search for the addon we want to rate + /** + * First, search for the addon we want to rate + */ $this->_getTutorials(array($id)); - // Check if the tutorial we are looking for exist - // the viewVars is set via _getTutorials function + /** + * Check if the tutorial we are looking for exist + * the viewVars is set via _getTutorials function + */ if (isset($this->viewVars['addonsdata'][$id])) { - // The addon we want to rate is found + /** + * The addon we want to rate is found + */ $addon = $this->viewVars['addonsdata'][$id]; $this->_sendToView('addon', $addon); - // check if the current user owns this Addon - // A user can't review his own add-on + /** + * Check if the current user owns this Addon. + * A user can't review his own add-on. + */ $isauthor = $this->_checkOwnership($id); if($isauthor) { @@ -1054,12 +1188,13 @@ class TutoriusApiController extends AppController ); } - // Start the review process + /** + * No error, start the review process + */ $this->_saveOrUpdateReview($addon); } else { - // Output error to view if tutorial not found return $this->_renderError( array('reason' => 'Tutorial not found') ); @@ -1071,6 +1206,9 @@ class TutoriusApiController extends AppController /****************** CATEGORIES **************** /*********************************************/ + /** + * Get all the categories in the store + */ function categories() { $args = func_get_args(); @@ -1082,11 +1220,10 @@ class TutoriusApiController extends AppController /** * Retrieves the available categories for Tutorius - * + * Called using HTTP GET */ function categories_GET() { - // All categories for add-on's type and supported applications $categoryDescriptions = array(); $sortedCategories = array(); @@ -1102,6 +1239,7 @@ class TutoriusApiController extends AppController $categories[$index]['id'] = $category['Category']['id']; $categories[$index]['name'] = $category['Translation']['name']['string']; $categories[$index]['description'] = $category['Translation']['description']['string']; + $index++; } asort($categories); } @@ -1116,13 +1254,18 @@ class TutoriusApiController extends AppController /*********************************************/ /** - * This function execute the review process for a particular addon + * This function execute the review process for a particular tutorial + * + * @param $addon The addon we want to review * + * @return Renders the appropriate view */ function _saveOrUpdateReview($addon) { global $valid_status; - // Create the Review array and map it with the POST variables + /** + * Create the Review array and map it with the POST variables + */ $data['Review'] = $this->getParams(array( 'rating' => '', 'title' => '', |