Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Default_AppsController extends Vrench_Controller_Action_Default
- {
- use Vrench_Trait_Apps;
- public function appAction()
- {
- var_dump([]);die();
- $this->viewOptions['cart'] = [
- 'button' => 'ui small green icon labeled button',
- 'icon' => 'icon shopping cart',
- 'html' => 'Added to cart'
- ];
- $req = $this->getRequest();
- $id = (int) $req->getParam('id');
- $db = Zend_Db_Table::getDefaultAdapter();
- $last_version_select = $db->select()
- ->from('app_releases',[new Zend_Db_Expr('MAX(version) as latestversion')])
- ->where('app_id = ?', $id);
- # ->where('status = ?', Default_Model_Release::STATUS_ACCEPTED);
- #$last_version = $db->fetchRow($last_version_select);
- #$last_version = $last_version['latestversion'];
- $select = $db->select()
- ->distinct()
- ->from(['a' => 'apps'], ['id' => 'app_id', 'type', 'user_id', 'name', 'data', 'copyright', 'legal', 'setup', 'additional_notes', 'release_time', 'website', 'adult_content', 'cont_keyboard', 'cont_mouse', 'cont_xbox', 'cont_pad'])
- ->joinInner(['r' => 'app_releases'], 'a.app_id = r.app_id', ['open_video', 'rating', 'comfort'])
- ->joinLeft(['c' => 'cart'], 'c.id = a.app_id AND c.is_bundle = 0 and c.user_id = ' . (int) $this->user->user_id, null)
- ->joinLeft(['p' => 'purchases'], 'p.app_id = a.app_id AND p.user_id = ' . (int) $this->user->user_id, null)
- ->joinLeft(['d' => 'app_discounts'], 'd.app_id = a.app_id AND (NOW() BETWEEN FROM_UNIXTIME(d.create_time) AND FROM_UNIXTIME(d.end_time))', ['discount_start' => 'create_time', 'discount_end' => 'end_time'])
- ->columns([
- 'in_cart' => 'IF(c.is_bundle IS NULL, 0, 1)',
- 'purchased' => 'IF(p.create_time IS NULL, 0, 1)',
- 'price' => 'IFNULL(d.price, a.price)',
- 'discount' => 'IF(d.price IS NULL, NULL, 100 - 100 * d.price / a.price)',
- 'old_price' => 'IF(d.price IS NULL, NULL, a.price)',
- ])
- # ->where('r.version = ?', $last_version)
- ->where('a.app_id = ?', $id)
- ->where('a.status = ' . Default_Model_App::STATUS_PUBLISHED . ' OR a.status = ' . Default_Model_App::STATUS_PUBLISHED_REMOVED);
- $app = $db->fetchRow($select);
- if ($app === false) {
- throw new Zend_Controller_Action_Exception('Invalid parameters', 404);
- }
- // Ask user to sign in or sign up if he want's to access Adult Content section
- // if bot allow scraping
- if ($app['adult_content'] && !$this->view->user_id && !$this->ua->isBot()) {
- $this->redirect($this->view->url(['controller' => 'apps', 'action' => 'adult-content'], 'default', true));
- }
- // log view record
- $db->query("INSERT INTO stats_app_views (date, app_id, views) VALUES ('" . date("Y-m-d") . "','" . (int) $id . "', 1) ON DUPLICATE KEY UPDATE views = views + 1;");
- // Fetch media
- $select = $db->select()
- ->from('app_media', ['type', 'source', 'thumbnail'])
- ->where('app_id = ?', $id)
- ->where('type != ?', Default_Model_Media::TYPE_PROCESSING)
- ->order('type DESC');
- $media = $db->fetchAll($select);
- // Get cover and unset app cover
- foreach ($media as $k => $m) {
- if ($m['type'] == Default_Model_Media::TYPE_COVER) {
- $cover = $m;
- unset($media[$k]);
- }
- if ($m['type'] == Default_Model_Media::TYPE_VRENCH_APP_COVER)
- unset($media[$k]);
- }
- $media = array_values($media);
- // Get current user locale
- $lang = Zend_Registry::get('Zend_Translate')->getLocale();
- // Description check
- $select = $db->select()
- ->from('app_descriptions', ['count' => 'COUNT(*)'])
- ->where('app_id = ?', $id)
- ->where('language = ?', $lang);
- $noLocale = !$db->fetchRow($select)['count'];
- if ($noLocale) {
- $lang = 'en';
- }
- // Fetch description
- $select = $db->select()
- ->from('app_descriptions', ['description'])
- ->where('app_id = ?', $id)
- ->where('language = ?', $lang);
- // Assing description to app
- $app['description'] = $db->fetchRow($select)['description'];
- // Platforms select query
- $select = $db->select()
- ->from(['r' => 'app_releases'], ['platform_id'])
- ->joinInner(['p' => 'platforms'], 'r.platform_id = p.platform_id', ['platform_name'])
- ->where('r.status = ?', Default_Model_Release::STATUS_ACCEPTED)
- ->where('r.app_id = ?', $id)
- ->group('r.platform_id');
- // Platforms array
- $platforms = [];
- // List all platforms
- foreach ($db->fetchAll($select) as $row) {
- $platforms[$row['platform_id']] = $row['platform_name'];
- }
- // Fetch platform requirements
- $select = $db->select()
- ->from('app_platform_requirements', ['platform_id', 'type', 'os', 'disk_space', 'memory', 'processor', 'graphics', 'notes'])
- ->where('platform_id in (?)', array_keys($platforms))
- ->where('app_id = ?', $id);
- // Requirements array
- $requirements = [];
- // Parse requirements
- foreach ($db->fetchAll($select) as $row) {
- $p = $row['platform_id'];
- $t = $row['type'];
- // Unset unnecessary values
- unset($row['platform_id'], $row['type']);
- // Check if requirements platform array exists
- if (!isset($requirements[$p])) {
- $requirements[$p] = [];
- }
- // Set rest of the row as requirements value
- $requirements[$p][$t] = $row;
- }
- // check if user ever launched this app
- $select = $db->select()
- ->from('stats_launches')
- #->where('user_id = ?', $this->user->user_id)
- ->where('user_id = ?', 8)
- ->where('app_id = ?', $id)
- ->where('version = ?', $last_version);
- $this->view->allowRating = $db->fetchRow($select);
- $this->view->app = (object) $app;
- $this->view->media = $media;
- $this->view->cover = $cover;
- $this->view->requirements = $requirements;
- $this->view->platforms = $platforms;
- }
- public function adultContentAction()
- {
- if (!$this->user->user_id)
- $this->view->signUpNow = true;
- $db = Zend_Db_Table::getDefaultAdapter();
- $baseSelect = $this->getAppsQuery()->limit(16)->where("adult_content = 1");
- // Get free games
- $select = clone $baseSelect;
- $this->view->free = $db->fetchAll($select->where('a.price = 0'));
- $select = clone $baseSelect;
- $this->view->discounted = $db->fetchAll($select->having('old_price IS NOT NULL'));
- $select = clone $baseSelect;
- $this->view->games = $db->fetchAll($select->having('old_price IS NULL')->where('a.price != 0'));
- }
- public function rateAction()
- {
- if($this->getRequest()->isXmlHttpRequest())
- {
- $db = Zend_Db_Table::getDefaultAdapter();
- $data = array(
- 'app_id' => $this->getRequest()->getParam('id'),
- 'version' => '1',
- 'user_id' => $this->user->user_id,
- 'date' => date('Y-m-d H:i:s'),
- 'rate' => $this->getRequest()->getPost('rate')
- );
- $select = $db->select()
- ->from('app_ratings')
- ->where('app_id = ?', $this->getRequest()->getParam('id'))
- ->where('app_id = ?', 1)
- $db->insert('app_ratings', $data);
- $id = $this->getRequest()->getParam('id');
- }
- dme('not ok'.$id);die();
- }
- public function searchAction()
- {
- $db = Zend_Db_Table::getDefaultAdapter();
- $form = new Default_Form_Search();
- $rangeSelect = $db->select()
- ->from(['a' => 'apps'], null)
- ->joinLeft(['d' => 'app_discounts'], 'd.app_id = a.app_id AND (UNIX_TIMESTAMP() BETWEEN d.create_time AND d.end_time)', null)
- ->columns(['price' => 'IFNULL(d.price, a.price)']);
- // Fetch price range
- $range = $db->fetchAll($db->select()->from($rangeSelect, null)->columns(['min' => 'FLOOR(MIN(price))', 'max' => 'CEIL(MAX(price))']));
- $range = isset($range[0]) ? $range[0] : null;
- if ($range === null) {
- $form->removeSubForm('Price');
- } else {
- if ($range['min'] == $range['max']) {
- $range['max'] += 1;
- }
- // Set default values for price
- $priceForm = $form->getSubForm('Price');
- $priceForm->getElement('min')->setValue(0);
- $priceForm->getElement('max')->setValue($range['max']);
- }
- // Populate values from $_GET
- $form->populate($_GET);
- // Fetch $_GET keys and form keys
- $getKeys = array_keys($_GET);
- $formKeys = array_keys($form->getElements());
- $result = null;
- $select = null;
- // Check if form values are submitted
- if (count(array_diff($formKeys, $getKeys)) !== count($formKeys)) {
- $form->isValid($form->getValues());
- $select = $this->getAppsQuery();
- $query = $form->getValue('query');
- // Escape query - disable wildcards
- if (!empty($query)) {
- $query = str_replace(['%', '_'], ['\%', '\_'], $db->quote($query));
- $query = substr($query, 1, strlen($query) - 2);
- $select->where("name LIKE '%{$query}%' ESCAPE '\\\\'");
- }
- if ($range !== null) {
- $select->having('price BETWEEN ' . $priceForm->getValue('min') . ' AND ' . $priceForm->getValue('max'));
- }
- }
- if ($select !== null) {
- if ($this->getRequest()->isXmlHttpRequest()) {
- $this->disableView();
- $data = $db->fetchAll($select->limit(10));
- if (empty($data)) {
- $result = ['error' => $this->translate('No results found')];
- } else {
- $result = [];
- foreach ($data as $app) {
- $result[] = [
- 'name' => $app['name'],
- 'price' => $app['price'],
- 'formattedPrice' => $this->view->formatNumber($app['price']),
- 'platforms' => explode("\n", $app['platforms']),
- 'url' => $this->getServerUrl() . $this->view->url(['controller' => 'apps', 'action' => $app['is_bundle'] ? 'bundle' : 'app', 'id' => $app['id']], 'default', true)
- ];
- }
- }
- $this->getHelper('json')->direct($result);
- } else {
- $result = $db->fetchAll($select);
- }
- }
- // Add view options
- if ($range !== null) {
- $this->viewOptions['sliderRange'] = $range;
- $this->viewOptions['sliderValues'] = [$priceForm->getValue('min'), $priceForm->getValue('max')];
- }
- $this->view->result = $result;
- $this->view->form = $form;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement