Esempio n. 1
0
 public function getusercontentsAction()
 {
     $output = "";
     // Get requests
     $params = $this->getRequest()->getParams();
     $userId = isset($params['search']) ? $params['search'] : null;
     $start = isset($params['start']) ? $params['start'] : null;
     $cache = Zend_Registry::get('cache');
     if (is_numeric($userId) && is_numeric($start)) {
         // Load user locations from cache
         if ($resultList = $cache->load('UserContentsList_' . $userId)) {
             $newContents = array();
             $userModel = new Default_Model_User();
             for ($i = $start; $i < $start + 3; $i++) {
                 if (isset($resultList[$i])) {
                     $newContents[] = $resultList[$i];
                 }
             }
             if (!sizeof($newContents) == 0) {
                 $contentList = $userModel->getUserContentList($newContents, 3);
             } else {
                 $contentList = array();
             }
         }
         $output = json_encode($contentList);
     } elseif (is_numeric($userId) && !$start) {
         // Load user locations from cache
         if ($resultList = $cache->load('UserContentsList_' . $userId)) {
             $userModel = new Default_Model_User();
             $contentList = $userModel->getWholeUserContentList($userId, $resultList);
         }
         $output = json_encode($contentList);
     }
     $this->view->output = $output;
 }
Esempio n. 2
0
 function userlistAction()
 {
     // assuming that the CleanQuery plugin has already stripped empty parameters
     if (isset($_GET) && is_array($_GET) && !empty($_GET)) {
         $path = '';
         array_walk($_GET, array('AccountController', 'encodeParam'));
         foreach ($_GET as $key => $value) {
             if ($key != 'filter' && $key != 'submit_user_filter') {
                 $path .= '/' . $key . '/' . $value;
             }
         }
         $uri = $_SERVER['REQUEST_URI'];
         $path = substr($uri, 0, strpos($uri, '?')) . $path;
         $this->getResponse()->setRedirect($path, $this->_permanent ? 301 : 302);
         $this->getResponse()->sendResponse();
         return;
     }
     $url_array = array('controller' => 'account', 'action' => 'userlist', 'language' => $this->view->language);
     $url = $this->_urlHelper->url($url_array, 'lang_default', true);
     // Get requests
     $params = $this->getRequest()->getParams();
     // Get page nummber and items per page
     $page = isset($params['page']) ? $params['page'] : 1;
     $count = isset($params['count']) ? $params['count'] : 10;
     $order = isset($params['order']) ? $params['order'] : null;
     $list = isset($params['list']) ? $params['list'] : null;
     if ($list != "asc" && $list != "desc") {
         $list = null;
     }
     // Filter form data
     $formData['username'] = isset($params['username']) ? $params['username'] : '';
     $formData['city'] = isset($params['city']) ? $params['city'] : '';
     $formData['country'] = isset($params['country']) ? $params['country'] : 0;
     $formData['group'] = isset($params['group']) ? $params['group'] : '';
     $formData['exactg'] = isset($params['exactg']) ? $params['exactg'] : 0;
     //$formData['contentlimit'] = isset($params['contentlimit']) ? $params['contentlimit'] : null;
     //$formData['counttype'] = isset($params['counttype']) ? $params['counttype'] : 0;
     if ($list == "asc") {
         $listName = "ascending";
     } elseif ($list == "desc") {
         $listName = "descending";
     } else {
         $listName = "ascending";
     }
     $orderList = array("username" => $this->view->translate('userlist-orderlist-username', $listName), "login" => $this->view->translate('userlist-orderlist-login', $listName), "joined" => $this->view->translate('userlist-orderlist-joined', $listName), "content" => $this->view->translate('userlist-orderlist-content', $listName), "views" => $this->view->translate('userlist-orderlist-views', $listName), "rating" => $this->view->translate('userlist-orderlist-rating', $listName), "popularity" => $this->view->translate('userlist-orderlist-popularity', $listName), "comments" => $this->view->translate('userlist-orderlist-comments', $listName));
     $userCountries = null;
     $userCities = null;
     $userLocations = $this->getAllCitiesAndCountries();
     if (isset($userLocations['countries'])) {
         $userCountries = json_encode($userLocations['countries']);
     }
     if (isset($userLocations['cities'])) {
         $userCities = json_encode($userLocations['cities']);
     }
     $formData['countries'][] = $this->view->translate('userlist-filter-country-all');
     if (isset($userLocations['countries'])) {
         foreach ($userLocations['countries'] as $country) {
             $formData['countries'][$country['countryIso']] = $country['name'];
         }
     }
     $pat_sql = array("%", "_");
     $pat_def = array("*", "?");
     //Replace * and ? characters to % and _ characters for mysql LIKE
     $formData['username'] = str_replace($pat_def, $pat_sql, $formData['username']);
     $formData['city'] = str_replace($pat_def, $pat_sql, $formData['city']);
     $formData['group'] = str_replace($pat_def, $pat_sql, $formData['group']);
     $userModel = new Default_Model_User();
     //variable initializations (to avoid notice errors :p)
     $pageCount = null;
     $userContents = null;
     $listSize = null;
     $userIdList = null;
     $userListing = null;
     $topNames = null;
     $topList = null;
     $topCountry = null;
     $topGroup = null;
     $topCity = null;
     //This is code to fetch search results
     if ($url != $this->_urlHelper->url()) {
         $listSize = 1;
         // Get user listing
         $userListing = $userModel->getUserListing($formData, $page, $count, $order, $list, $listSize);
         $userContents = array();
         $cache = Zend_Registry::get('short_cache');
         foreach ($userListing as $user) {
             // Get cache from registry
             if (is_array($user['contents']) && sizeof($user['contents']) > 0) {
                 //Content ID:s are saved to cache which is used by ajax in user search
                 $cache->save($user['contents'], 'UserContentsList_' . $user['id_usr']);
                 $contentsArray = $userModel->getUserContentList($user['contents'], 3);
             } else {
                 $contentsArray = null;
             }
             if (!is_array($contentsArray) || sizeof($contentsArray) < 1) {
                 $userContents[$user['id_usr']] = array();
             } else {
                 $userContents[$user['id_usr']] = $contentsArray;
             }
         }
         $userIdList = array();
         foreach ($userListing as $u) {
             $userIdList[] = $u['id_usr'];
         }
         // Calculate total page count
         $pageCount = ceil($listSize / $count);
     } else {
         //Here is Top list code :)
         $auth = Zend_Auth::getInstance();
         $userid = null;
         if ($auth->hasIdentity()) {
             $userid = $auth->getIdentity()->user_id;
         }
         $topListClasses = $userModel->getUserTopList();
         $topListUsers = $topListClasses['Users'];
         $topListCountries = $topListClasses['Countries'];
         $topListCities = $topListClasses['Cities'];
         $topListGroups = $topListClasses['Groups'];
         if ($userid) {
             $topListUsers->addUser($userid);
         }
         $topList = $topListUsers->getTopList();
         if ($userid) {
             $topListCountries->addUser($userid);
         }
         $topCountry = $topListCountries->getTopList();
         if ($userid) {
             $topListCities->addUser($userid);
         }
         $topCity = $topListCities->getTopList();
         $topGroup = $topListGroups->getTopList();
     }
     if (!$topNames) {
         $topNames[] = "Count";
         $topNames[] = "View";
         $topNames[] = "Popularity";
         $topNames[] = "Rating";
         $topNames[] = "Comment";
         $topNames[] = "Amount";
     }
     $topListBoxes = array('Users' => $topList, 'Groups' => $topGroup, 'Cities' => $topCity, 'Countries' => $topCountry);
     //print_r($topListBoxes);die;
     // User list search form
     $userSearch = new Default_Form_UserListSearchForm(null, $formData);
     $order = isset($order) ? $order : "username";
     $list = isset($list) ? $list : "asc";
     $form_url_path = array_merge($url_array, array('order' => $order, 'list' => $list));
     $form_url = $this->_urlHelper->url($form_url_path, 'lang_default', true);
     $userSearch->setAction($form_url)->setMethod('get');
     $parsedUrl = "";
     foreach ($params as $key => $param) {
         if ($key == "controller" || $key == "action" || $key == "module" || $key == "language") {
             continue;
         }
         $parsedUrl .= "/{$key}/{$param}";
     }
     $parsedUrl = str_replace("%", "%25", $parsedUrl);
     $this->view->userSearch = $userSearch;
     // Custom pagination to fix memory error on large amount of data
     $paginator = new Zend_View();
     $paginator->setScriptPath('../application/views/scripts');
     $paginator->pageCount = $pageCount;
     $paginator->currentPage = $page;
     $paginator->pagesInRange = 10;
     // Set to view
     $this->view->userPaginator = $paginator;
     $this->view->userListData = $userListing;
     $this->view->userList = $userIdList;
     $this->view->count = $count;
     $this->view->userCount = $listSize;
     $this->view->list = $listName;
     $this->view->top = $topList;
     $this->view->topListBoxes = $topListBoxes;
     $this->view->topCountry = $topCountry;
     $this->view->parsedUrl = $parsedUrl;
     $this->view->topNames = $topNames;
     $this->view->page = $page;
     $this->view->order = $orderList;
     $this->view->lastOrder = $order;
     $this->view->cities = $userCities;
     $this->view->countries = $userCountries;
     $this->view->userContents = $userContents;
 }
Esempio n. 3
0
 public function getusercontentsAction()
 {
     $output = "";
     // Get requests
     $params = $this->getRequest()->getParams();
     $search = isset($params['search']) ? $params['search'] : null;
     $search = (int) $search;
     if (is_int($search) && $search != 0) {
         // Get cache from registry
         $cache = Zend_Registry::get('cache');
         // Load user locations from cache
         if (!($resultList = $cache->load('UserContentsList_' . $search))) {
             $userModel = new Default_Model_User();
             $contentList = $userModel->getUserContentList($search);
             $cache->save($contentList, 'UserContentsList_' . $search);
         } else {
             $contentList = $resultList;
         }
         $output = json_encode($contentList);
         //$output = $contentList;
     }
     $this->view->output = $output;
 }