public static function action_getList($args, &$returncode, &$profile, &$auth = false, $format = false) { if ($auth) { $returncode = ResponseCode::BAD_REQUEST; return false; } if (!$profile->perm_category_list) { $returncode = ResponseCode::ACTION_NOT_ALLOWED; return false; } $acm = AppCategoryModel::getInstance(); $cats = $acm->getAllCached(); $data = array('categories' => array()); foreach ($cats as $cat) { $i = count($data['categories']); $data['categories'][$i] = array('id' => $cat->id, 'name' => $cat->category_name); } $returncode = ResponseCode::OK; return $data; }
<?php /* * AppDB * api/getcategories.php * Kyek * September 25, 2008 */ // Includes require_once __DIR__ . '/../lib/appdb/appdb.inc.php'; use appdb\models\AppCategoryModel; use hydrogen\errorhandler\ErrorHandler; ErrorHandler::attachErrorString(json_encode(array('successful' => 0, 'error' => 'Server error'))); // Start us up header('Content-type: text/plain; charset=utf-8'); $acm = AppCategoryModel::getInstance(); $cats = $acm->getAllCached(); $result = array(); if (!$cats) { $result['successful'] = 0; $result['error'] = 'Unable to retrieve categories'; } else { $result['successful'] = 1; foreach ($cats as $cat) { $result["{$cat->id}"] = $cat->category_name; } } die(json_encode($result));
public function createFromITunesScraper($appinfo, $iconsPreSaved = false) { $bean = new ApplicationBean(); $bean->itunes_id = $appinfo->getITunesID(); $bean->name = $appinfo->getName(); $bean->releasedate = $appinfo->getReleaseDate(); $bean->seller = $appinfo->getSeller(); $bean->company = $appinfo->getCompany() ?: $bean->seller; $bean->size = $appinfo->getSize(); $bean->price = $appinfo->getPrice(); $bean->description = $appinfo->getDescription(); $bean->languages = $appinfo->getLanguages(); $bean->requirements = $appinfo->getRequirements(); $smallicon = $appinfo->getITunesID() . 'icon-57x57.png'; $bigicon = $appinfo->getITunesID() . 'icon-100x100.png'; if ($iconsPreSaved || $this->saveIconsLocally($appinfo->getIconUrlPNG(), $smallicon, $bigicon)) { $bean->smallicon_url = '%BASE_URL%/appimages/icons/' . $smallicon; $bean->bigicon_url = '%BASE_URL%/appimages/icons/' . $bigicon; } $bean->set('date_added', 'NOW()', true); $bean->set('last_updated', 'NOW()', true); $catname = $appinfo->getCategory() ?: 'Unknown'; $acm = AppCategoryModel::getInstance(); $cat = $acm->getByName($catname); if (!$cat) { $acm->create($catname); if (!($cat = $acm->getByName($catname))) { return false; } } $bean->category_id = $cat->id; try { $bean->insert(); } catch (QueryFailedException $e) { return false; } $shots = $appinfo->getScreenshots(); if ($shots) { if (!($bean = $this->getDetailsByITunesID($appinfo->getITunesID(), false))) { return false; } $sm = ScreenshotModel::getInstance(); $sm->setScreenshots($bean->id, $bean->itunes_id, $shots); } $this->indexName($bean->name, $bean->id); $this->cm->clearGroup('applist'); return true; }