Exemple #1
0
 public function executeIndex()
 {
     static $pf = array('android' => Package::PF_ANDROID, 'ios' => Package::PF_IOS, 'all' => null);
     $platform = mfwRequest::param('pf');
     if (!in_array($platform, array('android', 'ios', 'all'))) {
         $ua = mfwRequest::userAgent();
         if ($ua->isAndroid()) {
             $platform = 'android';
         } elseif ($ua->isIOS()) {
             $platform = 'ios';
         } else {
             $platform = 'all';
         }
     }
     $tags = mfwRequest::param('tags') ? explode(' ', mfwRequest::param('tags')) : array();
     $current_page = mfwRequest::param('page', 1);
     $offset = ($current_page - 1) * self::LINE_IN_PAGE;
     $pkgs = PackageDb::selectByAppIdPfTagsWithLimit($this->app->getId(), $pf[$platform], $tags, $offset, self::LINE_IN_PAGE + 1);
     $has_next_page = false;
     if ($pkgs->count() > self::LINE_IN_PAGE) {
         $pkgs = $pkgs->slice(0, self::LINE_IN_PAGE);
         $has_next_page = true;
     }
     $comment_count = CommentDb::selectCountByAppId($this->app->getId());
     $top_comments = CommentDb::selectByAppId($this->app->getId(), 2);
     $commented_package = PackageDb::retrieveByPKs($top_comments->getColumnArray('package_id'));
     $params = array('pf' => $platform, 'is_owner' => $this->app->isOwner($this->login_user), 'packages' => $pkgs, 'active_tags' => $tags, 'current_page' => $current_page, 'has_next_page' => $has_next_page, 'filter_open' => mfwRequest::param('filter_open'), 'top_comments' => $top_comments, 'comment_count' => $comment_count, 'commented_package' => $commented_package);
     return $this->build($params);
 }
Exemple #2
0
 public function executeIndex()
 {
     $current_page = mfwRequest::param('page', 1);
     $app_count = ApplicationDb::selectCount();
     $max_page = ceil($app_count / self::LINE_IN_PAGE);
     $offset = max(0, min($current_page, $max_page) - 1) * self::LINE_IN_PAGE;
     $apps = ApplicationDb::selectByUpdateOrderWithLimit($offset, self::LINE_IN_PAGE);
     $comments = CommentDb::selectCountsByAppIds($apps->getColumnArray('id'));
     $params = array('applications' => $apps, 'comments' => $comments, 'cur_page' => $current_page, 'max_page' => $max_page);
     return $this->build($params);
 }
Exemple #3
0
 public function executeComment_post()
 {
     $message = mfwRequest::param('message');
     $package_id = mfwRequest::param('package_id');
     $con = mfwDBConnection::getPDO();
     $con->beginTransaction();
     try {
         $this->app = ApplicationDb::retrieveByPkForUpdate($this->app->getId());
         $comment = CommentDb::post($this->login_user, $this->app, $package_id, $message);
         $this->app->updateLastCommented($comment->getCreated());
         $con->commit();
     } catch (Exception $e) {
         error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}");
         $con->rollback();
         throw $e;
     }
     $owners = $this->app->getOwners();
     $owners->noticeNewComment($comment, $this->app);
     return $this->redirect('/app/comment', array('id' => $this->app->getId()));
 }