File indexing completed on 2024-12-22 05:33:34

0001 <?php
0002 /**
0003  *  ocs-webserver
0004  *
0005  *  Copyright 2016 by pling GmbH.
0006  *
0007  *    This file is part of ocs-webserver.
0008  *
0009  *    This program is free software: you can redistribute it and/or modify
0010  *    it under the terms of the GNU Affero General Public License as
0011  *    published by the Free Software Foundation, either version 3 of the
0012  *    License, or (at your option) any later version.
0013  *
0014  *    This program is distributed in the hope that it will be useful,
0015  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  *    GNU Affero General Public License for more details.
0018  *
0019  *    You should have received a copy of the GNU Affero General Public License
0020  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021  **/
0022 
0023 class SupportersController extends Local_Controller_Action_DomainSwitch
0024 {
0025 
0026     public function indexAction()
0027     {
0028         $section_id = (int)$this->getParam('id', 2);
0029         $products = self::fetchProducts($section_id);
0030         $creators = self::fetchCreators($section_id);
0031         $supporters = self::fetchSupporters($section_id);
0032 
0033         $model = new Default_Model_Section();
0034         $section = null;
0035         if ($section_id) {
0036             $section = $model->fetchSection($section_id);
0037             $this->view->section = $section;
0038             $this->view->section_id = $section_id;
0039         }
0040 
0041         $this->view->supporters = $supporters;
0042         $this->view->products = $products;
0043         $this->view->creators = $creators;
0044 
0045         $title = 'Section';
0046         if ($section) {
0047             $title = 'Section ' . $section['name'];
0048         }
0049         $this->view->headTitle($title . ' - ' . $this->getHeadTitle(), 'SET');
0050     }
0051 
0052     public function fetchProducts($section_id)
0053     {
0054         $model = new Default_Model_Section();
0055         $helpPrintDate = new Default_View_Helper_PrintDate();
0056         $helperImage = new Default_View_Helper_Image();
0057 
0058         $products = $model->fetchTopPlingedProductsPerSection($section_id);
0059         foreach ($products as &$p) {
0060             $p['image_small'] = $helperImage->Image($p['image_small'], array('width' => 200, 'height' => 200));
0061             $p['updated_at'] = $helpPrintDate->printDate(($p['changed_at'] == null ? $p['created_at'] : $p['changed_at']));
0062         }
0063 
0064         return $products;
0065     }
0066 
0067     public function fetchCreators($section_id)
0068     {
0069         $model = new Default_Model_Section();
0070         $helpPrintDate = new Default_View_Helper_PrintDate();
0071         $helperImage = new Default_View_Helper_Image();
0072 
0073         $creators = $model->fetchTopPlingedCreatorPerSection($section_id);
0074 
0075         foreach ($creators as &$p) {
0076             $p['profile_image_url'] = $helperImage->Image($p['profile_image_url'],
0077                 array('width' => 100, 'height' => 100));
0078 
0079         }
0080 
0081         return $creators;
0082 
0083     }
0084 
0085     public function fetchSupporters($section_id)
0086     {
0087         $info = new Default_Model_Info();
0088         $helperImage = new Default_View_Helper_Image();
0089         if ($section_id) {
0090             $supporters = $info->getNewActiveSupportersForSection($section_id, 1000);
0091         } else {
0092             $supporters = $info->getNewActiveSupportersForSectionAll(1000);
0093         }
0094 
0095         $s = array();
0096         foreach ($supporters as &$p) {
0097 
0098             $s[] = array(
0099                 'profile_image_url'    => $helperImage->Image($p['profile_image_url'],
0100                     array('width' => 100, 'height' => 100)),
0101                 'member_id'            => $p['member_id'],
0102                 'username'             => $p['username'],
0103                 'section_support_tier' => $p['section_support_tier'],
0104             );
0105 
0106             /*$p['profile_image_url'] = $helperImage->Image($p['profile_image_url'], array('width' => 100, 'height' => 100));*/
0107         }
0108 
0109         return $s;
0110     }
0111 
0112     public function topAction()
0113     {
0114         $this->_helper->layout->disableLayout();
0115         $this->_helper->viewRenderer->setNoRender(true);
0116         $section_id = (int)$this->getParam('id', null);
0117         $products = self::fetchProducts($section_id);
0118         $creators = self::fetchCreators($section_id);
0119         $this->_helper->json(array('status' => 'ok', 'products' => $products, 'creators' => $creators));
0120     }
0121 
0122     public function topcatAction()
0123     {
0124         $this->_helper->layout->disableLayout();
0125         $this->_helper->viewRenderer->setNoRender(true);
0126         $model = new Default_Model_Section();
0127         $helpPrintDate = new Default_View_Helper_PrintDate();
0128         $helperImage = new Default_View_Helper_Image();
0129         $cat_id = (int)$this->getParam('cat_id');
0130         $products = $model->fetchTopPlingedProductsPerCategory($cat_id);
0131 
0132 
0133         foreach ($products as &$p) {
0134             $p['image_small'] = $helperImage->Image($p['image_small'], array('width' => 200, 'height' => 200));
0135             $p['updated_at'] = $helpPrintDate->printDate(($p['changed_at'] == null ? $p['created_at'] : $p['changed_at']));
0136         }
0137 
0138         $creators = $model->fetchTopPlingedCreatorPerCategory($cat_id);
0139         foreach ($creators as &$p) {
0140             $p['profile_image_url'] = $helperImage->Image($p['profile_image_url'],
0141                 array('width' => 100, 'height' => 100));
0142 
0143         }
0144         $this->_helper->json(array('status'   => 'ok',
0145                                    'cat_id'   => $cat_id,
0146                                    'products' => $products,
0147                                    'creators' => $creators,
0148         ));
0149     }
0150 
0151     public function recentplingsAction()
0152     {
0153         $this->_helper->layout->disableLayout();
0154         $this->_helper->viewRenderer->setNoRender(true);
0155         $section_id = (int)$this->getParam('id', null);
0156         $model = new Default_Model_Section();
0157         $helpPrintDate = new Default_View_Helper_PrintDate();
0158         $helperImage = new Default_View_Helper_Image();
0159         $products = $model->getNewActivePlingProduct($section_id);
0160         foreach ($products as &$p) {
0161             $p['image_small'] = $helperImage->Image($p['image_small'],
0162                 array('width' => '115', 'height' => '75', 'crop' => 2));
0163             $p['created_at'] = $helpPrintDate->printDate($p['created_at']);
0164             $p['profile_image_url'] = $helperImage->Image($p['profile_image_url'],
0165                 array('width' => 100, 'height' => 100));
0166         }
0167         $this->_helper->json(array('status' => 'ok', 'products' => $products));
0168     }
0169 
0170     protected function setLayout()
0171     {
0172         $this->_helper->layout()->setLayout('layout_pling_home');
0173     }
0174 
0175 }