diff --git a/application/modules/default/controllers/UserController.php b/application/modules/default/controllers/UserController.php index 0aeb8faca..7eac22736 100644 --- a/application/modules/default/controllers/UserController.php +++ b/application/modules/default/controllers/UserController.php @@ -1,1474 +1,1475 @@ . **/ class UserController extends Local_Controller_Action_DomainSwitch { protected $_memberId; protected $_userName; /** @var Zend_Db_Table_Row */ protected $_memberSettings; public function init() { parent::init(); if ($this->hasParam('user_name')) { $this->_userName = $this->getParam('user_name'); $this->_userName = urldecode($this->_userName); $modelMember = new Default_Model_Member(); $this->_memberId = $modelMember->fetchActiveUserByUsername($this->_userName); } else { $this->_memberId = (int)$this->getParam('member_id'); } $action = $this->getRequest()->getActionName(); $title = ''; if ($action == 'index') { $title = 'aboutme'; } else { $title = $action; } $this->view->headTitle($title . ' - ' . $this->getHeadTitle(), 'SET'); } public function indexAction() { $this->_helper->viewRenderer('aboutme'); $this->aboutmeAction(); } public function aboutmeAction() { $tableMember = new Default_Model_Member(); $tableProject = new Default_Model_Project(); $earnModel = new Default_Model_StatDownload(); $helperUserRole = new Backend_View_Helper_UserRole(); $pageLimit = 500; $projectpage = (int)$this->getParam('projectpage', 1); $this->view->authMember = $this->_authMember; $this->view->member = $tableMember->fetchMemberData($this->_memberId); if (null == $this->view->member) { $this->redirect("/"); } if ($this->view->member->is_deleted == 1 or $this->view->member->is_active == 0) { $this->redirect("/"); } $this->view->headTitle($this->view->member->username . ' - ' . $this->getHeadTitle(), 'SET'); $this->view->mainProject = $this->view->member->findDependentRowset($tableProject, 'MainProject')->current(); $this->view->userProjectCategories = $tableProject->getUserCreatingCategorys($this->_memberId); $this->view->aboutmeUserInfo = $this->getAboutmeUserInfo($this->_memberId, $this->view->member->username); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $amount = $earnModel->getLastMonthEarn($this->_memberId); if ($amount && $amount['amount']) { $this->view->earnInfo = ' Last month I earned $' . number_format($amount['amount'], 2, '.', '') . '.'; } else { $this->view->earnInfo = ' Last month I earned 0.'; } } else { $this->view->earnInfo = ''; } // ajax load more products if ($this->getParam('projectpage', null)) { $total_records = $tableProject->countAllProjectsForMemberCatFilter($this->_memberId, true, null); $this->view->pageLimit = $pageLimit; $this->view->projectpage = $projectpage; $this->view->total_records = $total_records; // get last project category id $lastproject = $tableProject->getUserActiveProjects($this->_memberId, 1, (($projectpage - 1) * $pageLimit - 1)); foreach ($lastproject as $value) { $this->view->lastcatid = $value['project_category_id']; } $this->view->userProducts = $tableProject->getUserActiveProjects($this->_memberId, $pageLimit, ($projectpage - 1) * $pageLimit); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/aboutmeProducts'); //$this->forward('showmoreproductsajax', 'user', null, $this->getAllParams()); return; } else { $total_records = $tableProject->countAllProjectsForMemberCatFilter($this->_memberId, true, null); $this->view->pageLimit = $pageLimit; $this->view->projectpage = $projectpage; $this->view->total_records = $total_records; //$this->view->userProducts = $tableProject->fetchAllProjectsForMember($this->_memberId, $pageLimit, ($projectpage - 1) * $pageLimit,true); $this->view->userProducts = $tableProject->getUserActiveProjects($this->_memberId, $pageLimit, ($projectpage - 1) * $pageLimit); $this->view->userFeaturedProducts = $tableProject->fetchAllFeaturedProjectsForMember($this->_memberId); $this->view->userCollections = $tableProject->fetchAllCollectionsForMember($this->_memberId); $paginationComments = $tableMember->fetchComments($this->_memberId); if ($paginationComments) { $offset = (int)$this->getParam('page'); $paginationComments->setItemCountPerPage(50); $paginationComments->setCurrentPageNumber($offset); $this->view->comments = $paginationComments; } // favs Currently no paging... $this->view->paramLikePageId = (int)$this->getParam('likepage'); $model = new Default_Model_DbTable_ProjectFollower(); $offset = $this->view->paramLikePageId; $list = $model->fetchLikesForMember($this->_memberId); $list->setItemCountPerPage(1000); $list->setCurrentPageNumber($offset); $this->view->likes = $list; // plings Currently no paging... $plingmodel = new Default_Model_ProjectPlings(); $offset = null; $plist = $plingmodel->fetchPlingsForMember($this->_memberId); $plist->setItemCountPerPage(1000); $plist->setCurrentPageNumber($offset); $this->view->plings = $plist; // plings Currently no paging... $plingmodel = new Default_Model_ProjectPlings(); $offset = null; $pslist = $plingmodel->fetchPlingsForSupporter($this->_memberId); $pslist->setItemCountPerPage(1000); $pslist->setCurrentPageNumber($offset); $this->view->supportersplings = $pslist; // rated $ratemodel = new Default_Model_DbTable_ProjectRating(); $this->view->rated = $ratemodel->getRatedForMember($this->_memberId); $stat = array(); $stat['cntProducts'] = $total_records; if ($this->view->userFeaturedProducts) { $cnt = 0; foreach ($this->view->userFeaturedProducts as $tmp) { $cnt++; } $stat['cntFProducts'] = $cnt; } else { $stat['cntFProducts'] = 0; } if ($this->view->userCollections) { $cnt = 0; foreach ($this->view->userCollections as $tmp) { $cnt++; } $stat['cntCollections'] = $cnt; } else { $stat['cntCollections'] = 0; } $stat['cntOrinalProducts'] = $tableProject->getOriginalProjectsForMemberCnt($this->_memberId); $stat['cntComments'] = $paginationComments->getTotalItemCount(); $tblFollower = new Default_Model_DbTable_ProjectFollower(); $stat['cntLikesHeGave'] = $tblFollower->countLikesHeGave($this->_memberId); $stat['cntLikesHeGot'] = $tblFollower->countLikesHeGot($this->_memberId); $tblPling = new Default_Model_DbTable_ProjectPlings(); $stat['cntPlingsHeGave'] = $tblPling->countPlingsHeGave($this->_memberId); $stat['cntPlingsHeGot'] = $tblPling->countPlingsHeGot($this->_memberId); $donationinfo = $tableMember->fetchSupporterDonationInfo($this->_memberId); if ($donationinfo) { $stat['donationIssupporter'] = $donationinfo['issupporter']; $stat['donationMax'] = $donationinfo['active_time_max']; $stat['donationMin'] = $donationinfo['active_time_min']; $stat['donationCnt'] = $donationinfo['cnt']; } $subscriptioninfo = $tableMember->fetchSupporterSubscriptionInfo($this->_memberId); if ($subscriptioninfo) { $stat['subscriptionIssupporter'] = true; $stat['subscriptionStart'] = $subscriptioninfo['create_time']; $stat['subscriptionAmount'] = $subscriptioninfo['amount']; $stat['subscriptionPeriod'] = $subscriptioninfo['period']; if ($subscriptioninfo['period'] == 'M') { $stat['subscriptionPeriodText'] = 'monthly'; } else { if ($subscriptioninfo['period'] == 'Y') { $stat['subscriptionPeriodText'] = 'yearly'; } else { $stat['subscriptionPeriodText'] = ''; } } $stat['subscriptionPeriodFreq'] = $subscriptioninfo['period_frequency']; } else { $stat['subscriptionIssupporter'] = false; } // $cntmb = $tableMember->fetchCntSupporters($this->_memberId); // $stat['cntSupporters'] = $cntmb; $stat['userLastActiveTime'] = $tableMember->fetchLastActiveTime($this->_memberId); $stat['cntDuplicateSourceurl'] = 0; $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $stat['cntDuplicateSourceurl'] = $tableProject->getCountProjectsDuplicateSourceurl($this->_memberId); $stat['cntUnpublished'] = $tableProject->getUnpublishedProjectsForMemberCnt($this->_memberId); } $this->view->stat = $stat; } } public function getAboutmeUserInfo($member_id, $username) { $tableProject = new Default_Model_Project(); $userProjectCategories = $tableProject->getUserCreatingCategorys($member_id); $cnt = sizeof($userProjectCategories); $userinfo = ''; $isAdmin = false; $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $isAdmin = true; } if ($cnt > 0) { $userinfo = "Hi, I am " . $username . " and I create "; if ($cnt == 1) { $userinfo = $userinfo . ' ' . $userProjectCategories[0]['category1'] . '.'; }elseif($cnt == 2) { $userinfo = $userinfo . ' ' . $userProjectCategories[0]['category1'] . '' . ' and ' . $userProjectCategories[1]['category1'] . '.'; }elseif($cnt == 3) { $userinfo = $userinfo . ' ' . $userProjectCategories[0]['category1'] . '' . ', ' . $userProjectCategories[1]['category1'] . '' . ' and ' . $userProjectCategories[2]['category1'] . '.'; }else{ $userinfo = $userinfo . ' ' . $userProjectCategories[0]['category1'] . '' . ', ' . $userProjectCategories[1]['category1'] . '' . ', ' . $userProjectCategories[2]['category1'] . '' . ' and more.'; } }else{ $userinfo = "Hi, I am " . $username . "."; } $mModel = new Default_Model_Member(); $supportSections = $mModel->fetchSupporterSectionInfo($member_id); if($supportSections && $supportSections['sections']) { $userinfo = $userinfo." I ".($cnt==0?" ":" also ")."support"; $sections = explode(",", $supportSections['sections']); foreach ($sections as $s) { $userinfo.=" ".$s.", "; } $userinfo = trim($userinfo); $userinfo = substr($userinfo, 0, -1); } if(substr($userinfo, strlen($userinfo)-1) <> ".") { $userinfo.="."; } return $userinfo; } public function duplicatesAction() { $tableProject = new Default_Model_Project(); $pageLimit = 1000; $projectpage = 1; $total_records = $tableProject->countAllProjectsForMemberCatFilter($this->_memberId, true, null); $this->view->pageLimit = $pageLimit; $this->view->projectpage = $projectpage; $this->view->total_records = $total_records; $this->view->userProducts = $tableProject->getUserActiveProjectsDuplicatedSourceurl($this->_memberId, $pageLimit, ($projectpage - 1) * $pageLimit); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/aboutmeProducts'); } public function unpublishedAction() { $tableProject = new Default_Model_Project(); $projectpage = $this->getParam('projectpage', 1); $pageLimit = 1000; $total_records = 1000; $this->view->pageLimit = $pageLimit; $this->view->projectpage = $projectpage; $this->view->total_records = $total_records; $this->view->userProducts = $tableProject->getUnpublishedProjectsForMember($this->_memberId, $pageLimit, ($projectpage - 1) * $pageLimit); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/aboutmeProducts'); } public function showoriginalAction() { $tableProject = new Default_Model_Project(); $projectpage = $this->getParam('projectpage', 1); $pageLimit = 100; $total_records = $tableProject->getOriginalProjectsForMemberCnt($this->_memberId); $this->view->pageLimit = $pageLimit; $this->view->projectpage = $projectpage; $this->view->total_records = $total_records; if($projectpage>1) { $lastproject = $tableProject->getOriginalProjectsForMember($this->_memberId, 1, (($projectpage - 1) * $pageLimit - 1)); foreach ($lastproject as $value) { $this->view->lastcatid = $value['project_category_id']; } } $this->view->userProducts = $tableProject->getOriginalProjectsForMember($this->_memberId, $pageLimit, ($projectpage - 1) * $pageLimit); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('partials/aboutmeProducts'); } /** * to get an avatar picture you can call * /member/avatar/:emailhash/:size * or * /member/u/:user_name/avatar/size/:size * * @throws Zend_Exception */ public function avatarAction() { $this->_helper->layout->disableLayout(); $size = (int)$this->getParam("size", 200); $width = (int)$this->getParam("width", ($size / 2)); $emailHash = $this->getParam("emailhash", null); $username = $this->getParam('user_name', null); $avatar = new Default_Model_Avatar(); $img_url = $avatar->getAvatarUrl($emailHash, $username, $width); $this->redirect($img_url); } public function aboutAction() { $modelMember = new Default_Model_Member(); $this->view->member = $modelMember->fetchMember($this->_memberId)->toArray(); $this->view->currentPageOffset = (int)$this->getParam('page'); } public function showmoreproductsajaxAction() { $this->_helper->layout->disableLayout(); $tableProject = new Default_Model_Project(); $pageLimit = 21; $page = (int)$this->getParam('page', 1); $total_records = $tableProject->countAllProjectsForMemberCatFilter($this->_memberId, true, null); $this->view->pageLimit = $pageLimit; $this->view->page = $page; $this->view->total_records = $total_records; $this->view->userProducts = $tableProject->fetchAllProjectsForMember($this->_memberId, $pageLimit, ($page - 1) * $pageLimit, true); $this->_helper->viewRenderer('/partials/aboutmeProducts'); } public function userdataajaxAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $resultArray = array(); header('Access-Control-Allow-Origin: *'); $this->getResponse()->setHeader('Access-Control-Allow-Origin', '*')->setHeader('Access-Control-Allow-Credentials', 'true') ->setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') ->setHeader('Access-Control-Allow-Headers', 'origin, content-type, accept'); $userid = $this->getParam('id'); $modelMember = new Default_Model_Member(); $user = $modelMember->find($userid)->current(); if (Zend_Auth::getInstance()->hasIdentity()) { $auth = Zend_Auth::getInstance(); $user = $auth->getStorage()->read(); $resultArray['member_id'] = $user->member_id; $resultArray['username'] = $user->username; $resultArray['mail'] = $user->mail; $resultArray['avatar'] = $user->profile_image_url; } else { if (null != $userid && null != $user) { $resultArray['member_id'] = $user['member_id']; $resultArray['username'] = $user['username']; $resultArray['mail'] = $user['mail']; $resultArray['avatar'] = $user['profile_image_url']; } else { $resultArray['member_id'] = null; $resultArray['username'] = null; $resultArray['mail'] = null; $resultArray['avatar'] = null; } } $resultAll = array(); $resultAll['status'] = "success"; $resultAll['data'] = $resultArray; $this->_helper->json($resultAll); } public function followsAction() { $this->redirect($this->_helper->url('follows', 'member', null, $this->getAllParams())); } public function followAction() { $this->_helper->layout->disableLayout(); $this->view->authMember = $this->_authMember; $this->view->member_id = $this->_memberId; if ($this->_memberId == $this->_authMember->member_id) { return; } $memberFollowTable = new Default_Model_DbTable_MemberFollower(); $newVals = array('member_id' => $this->_memberId, 'follower_id' => (int)$this->_authMember->member_id); $where = $memberFollowTable->select()->where('member_id = ?', $this->_memberId) ->where('follower_id = ?', $this->_authMember->member_id, 'INTEGER'); $result = $memberFollowTable->fetchRow($where); if (null === $result) { $memberFollowTable->createRow($newVals)->save(); } } public function unfollowAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('follow'); $memberFollowTable = new Default_Model_DbTable_MemberFollower(); $memberFollowTable->delete('member_id=' . $this->_memberId . ' AND follower_id=' . $this->_authMember->member_id); $this->view->authMember = $this->_authMember; $this->view->member_id = $this->_memberId; } public function newsAction() { $this->productsAction(); $this->render('products'); } public function productsAction() { $pageLimit = 25; $page = (int)$this->getParam('page', 1); //create ppload download hash: secret + collection_id + expire-timestamp $salt = PPLOAD_DOWNLOAD_SECRET; $timestamp = time() + 3600; // one hour valid $hash = md5($salt . $timestamp); // order isn't important at all... just do the same when verifying $this->view->download_hash = $hash; $this->view->download_timestamp = $timestamp; $this->view->member_id = null; if (null != $this->_authMember && null != $this->_authMember->member_id) { $this->view->member_id = $this->_authMember->member_id; } $modelProject = new Default_Model_Project(); $userProjects = $modelProject->fetchAllProjectsForMember($this->_authMember->member_id, $pageLimit, ($page - 1) * $pageLimit); $paginator = Local_Paginator::factory($userProjects); $paginator->setItemCountPerPage($pageLimit); $paginator->setCurrentPageNumber($page); $paginator->setTotalItemCount($modelProject->countAllProjectsForMember($this->_authMember->member_id)); $this->view->products = $paginator; $modelMember = new Default_Model_Member(); $this->view->member = $modelMember->fetchMemberData($this->_authMember->member_id); } public function collectionsAction() { $pageLimit = 25; $page = (int)$this->getParam('page', 1); $this->view->member_id = null; if (null != $this->_authMember && null != $this->_authMember->member_id) { $this->view->member_id = $this->_authMember->member_id; } $modelProject = new Default_Model_Collection(); $userProjects = $modelProject->fetchAllCollectionsForMember($this->_authMember->member_id, $pageLimit, ($page - 1) * $pageLimit); $paginator = Local_Paginator::factory($userProjects); $paginator->setItemCountPerPage($pageLimit); $paginator->setCurrentPageNumber($page); $paginator->setTotalItemCount($modelProject->countAllCollectionsForMember($this->_authMember->member_id)); $this->view->products = $paginator; $modelMember = new Default_Model_Member(); $this->view->member = $modelMember->fetchMemberData($this->_authMember->member_id); } public function activitiesAction() { $modelInfo = new Default_Model_Info(); $this->view->member = $this->_authMember; $this->view->comments = $modelInfo->getLastCommentsForUsersProjects($this->_authMember->member_id); $this->view->votes = $modelInfo->getLastVotesForUsersProjects($this->_authMember->member_id); $this->view->donations = $modelInfo->getLastDonationsForUsersProjects($this->_authMember->member_id); + $this->view->featured = $modelInfo->getFeaturedProductsForUser($this->_authMember->member_id,100); } public function settingsAction() { $this->_helper->layout()->setLayout('settings'); } public function reportAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer('product/add'); $this->forward('report', 'product', null, $this->getAllParams()); } public function paymentsAction() { $this->view->headScript()->setFile(''); $this->view->headLink()->setStylesheet(''); $member_id = $this->_authMember->member_id; $this->view->member = $this->_authMember; $tableMember = new Default_Model_Member(); $this->view->hits = $tableMember->fetchPlingedProjects($member_id); } public function incomeAction() { $this->view->member = $this->_authMember; $tableMember = new Default_Model_Member(); $modelPlings = new Default_Model_Pling(); $this->view->donations = $modelPlings->fetchRecentDonationsForUser($this->_authMember->member_id); } public function tooltipAction() { $this->_helper->layout->disableLayout(); $info = new Default_Model_Info(); $data = $info->getTooptipForMember($this->_memberId); $this->_helper->json(array('status' => 'ok', 'data' => $data)); } public function shareAction() { $this->_helper->layout->disableLayout(); $modelProduct = new Default_Model_Member(); $memberInfo = $modelProduct->fetchMemberData($this->_memberId); $form = new Default_Form_ProjectShare(); $form->setAction('/member/' . $this->_memberId . '/share/'); // $helperBaseUrl = new Default_View_Helper_BaseUrl(); // $helperServerUrl = new Zend_View_Helper_ServerUrl(); $helpMemberUrl = new Default_View_Helper_BuildMemberUrl(); $this->view->permaLink = $helpMemberUrl->buildMemberUrl($memberInfo->username); // $this->view->permaLink = $helperServerUrl->serverUrl() . $helperBaseUrl->baseUrl() . '/member/' . $this->_memberId . '/'; if ($this->_request->isGet()) { $this->view->form = $form; $this->renderScript('product/share.phtml'); return; } if (false === $form->isValid($_POST)) { // form not valid $this->view->form = $form; $dummy = $this->view->render('product/share.phtml'); $this->_helper->json(array('status' => 'ok', 'message' => $dummy)); return; } $values = $form->getValues(); if (empty($memberInfo->firstname) and empty($memberInfo->lastname)) { $username = $memberInfo->username; } else { $username = $memberInfo->firstname . ' ' . $memberInfo->lastname; } $shareMail = new Default_Plugin_SendMail('tpl_social_mail_user'); $shareMail->setTemplateVar('sender', $values['sender_mail']); $shareMail->setTemplateVar('username', $username); $shareMail->setTemplateVar('permalink', $this->view->permaLink); $shareMail->setTemplateVar('permalinktext', 'View user\'s page'); $shareMail->setReceiverMail($values['mail']); $shareMail->send(); $this->_helper->json(array('status' => 'ok', 'redirect' => $this->view->permaLink)); } public function plingsAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } } public function plingsoldAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } } public function plingsajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $year = null; if ($this->hasParam('year')) { $year = $this->getParam('year'); } $this->view->year = $year; $this->_helper->viewRenderer('/plingsajax'); } public function plingsmonthajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $section_id = null; if ($this->hasParam('section_id')) { $section_id = $this->getParam('section_id'); } $this->view->yearmonth = $yearmonth; $this->view->section_id = $section_id; $this->_helper->viewRenderer('/plingsmonthajax'); } public function plingsajax3Action() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $year = null; if ($this->hasParam('year')) { $year = $this->getParam('year'); } $this->view->year = $year; $this->_helper->viewRenderer('/plingsajax3'); } public function plingsmonthajax3Action() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $section_id = null; if ($this->hasParam('section_id')) { $section_id = $this->getParam('section_id'); } $this->view->yearmonth = $yearmonth; $this->view->section_id = $section_id; $this->_helper->viewRenderer('/plingsmonthajax3'); } public function sectionplingsmonthajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $section_id = null; if ($this->hasParam('section_id')) { $section_id = $this->getParam('section_id'); } $this->view->yearmonth = $yearmonth; $this->view->section_id = $section_id; $this->_helper->viewRenderer('/sectionplingsmonthajax'); } public function sectioncreditsmonthajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $section_id = null; if ($this->hasParam('section_id')) { $section_id = $this->getParam('section_id'); } $project_id = null; if ($this->hasParam('project_id')) { $project_id = $this->getParam('project_id'); } $this->view->yearmonth = $yearmonth; $this->view->section_id = $section_id; $this->view->project_id = $project_id; $this->_helper->viewRenderer('/sectioncreditsmonthajax'); } public function sectionaffiliatesmonthajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $section_id = null; if ($this->hasParam('section_id')) { $section_id = $this->getParam('section_id'); } $this->view->yearmonth = $yearmonth; $this->view->section_id = $section_id; $this->_helper->viewRenderer('/sectionaffiliatesmonthajax'); } public function sectionaffiliatesmonthdetailajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $section_id = null; if ($this->hasParam('section_id')) { $section_id = $this->getParam('section_id'); } $this->view->yearmonth = $yearmonth; $this->view->section_id = $section_id; $this->_helper->viewRenderer('/sectionaffiliatesmonthdetailajax'); } public function sectionsajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $year = null; if ($this->hasParam('year')) { $year = $this->getParam('year'); } $this->view->year = $year; $this->_helper->viewRenderer('/sectionsajax'); } public function affiliatesajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $year = null; if ($this->hasParam('year')) { $year = $this->getParam('year'); } $this->view->year = $year; $this->_helper->viewRenderer('/affiliatesajax'); } public function sectionsmonthajaxAction() { $this->_helper->layout->disableLayout(); $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $yearmonth = null; if ($this->hasParam('yearmonth')) { $yearmonth = $this->getParam('yearmonth'); } $this->view->yearmonth = $yearmonth; $this->_helper->viewRenderer('/sectionsmonthajax'); } public function downloadhistoryAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); //backdore for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } if ($this->view->member) { $this->view->paramPageId = (int)$this->getParam('page'); //TODO do really sql paging instead of Zend_Paginator $dhistory = new Default_Model_DbTable_MemberDownloadHistory(); $offset = $this->view->paramPageId; $list = $dhistory->getDownloadhistory($this->view->member->member_id); $list->setItemCountPerPage(250); $list->setCurrentPageNumber($offset); $this->view->downloadhistory = $list; } else { $this->view->downloadhistory = array(); } } public function likesAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); //backdore for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } if ($this->view->member) { $this->view->paramPageId = (int)$this->getParam('page'); $model = new Default_Model_DbTable_ProjectFollower(); $offset = $this->view->paramPageId; $list = $model->fetchLikesForMember($this->view->member->member_id); $list->setItemCountPerPage(250); $list->setCurrentPageNumber($offset); $this->view->likes = $list; } else { $this->view->likes = array(); } } public function supportAction() { $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $model = new Default_Model_DbTable_Support(); $this->view->supporterlist = $model->getSupporterDonationList($this->view->member->member_id); } public function fundingAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } $model = new Default_Model_DbTable_Support(); $this->view->supporterlist = $model->getSupporterDonationList($this->view->member->member_id); } public function payoutoldAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } } public function payoutAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } } public function affiliatesAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } } public function payout3Action() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); $paypalValidStatusTable = new Default_Model_DbTable_PaypalValidStatus(); $paypalValidStatus = $paypalValidStatusTable->find($this->view->view_member->paypal_valid_status)->current(); $this->view->paypal_valid_status = $paypalValidStatus; //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; } } public function payouthistoryoldAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; if ($this->_memberId != $this->_authMember->member_id) { throw new Zend_Controller_Action_Exception('no authorization found'); } } $model = new Default_Model_StatDownload(); $resultSet = $model->getPayoutHistory($this->view->member->member_id); $this->view->payouthistory = $resultSet; } public function payouthistoryAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; if ($this->_memberId != $this->_authMember->member_id) { throw new Zend_Controller_Action_Exception('no authorization found'); } } $model = new Default_Model_StatDownload(); $resultSet = $model->getPayoutHistory2($this->view->member->member_id); $this->view->payouthistory2 = $resultSet; } public function _payouthistoryAction() { $tableMember = new Default_Model_Member(); $this->view->view_member = $tableMember->fetchMemberData($this->_memberId); //backdoor for admins $helperUserRole = new Backend_View_Helper_UserRole(); $userRoleName = $helperUserRole->userRole(); if (Default_Model_DbTable_MemberRole::ROLE_NAME_ADMIN == $userRoleName) { $this->view->member = $this->view->view_member; } else { $this->view->member = $this->_authMember; if ($this->_memberId != $this->_authMember->member_id) { throw new Zend_Controller_Action_Exception('no authorization found'); } } // these are already payed $sql = "SELECT `yearmonth`, `amount` FROM `member_payout` WHERE `member_id` = :member_id ORDER BY `yearmonth` ASC"; $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql, array('member_id' => $this->view->member->member_id)); // there are probably payed last 2 months // current month $date = new DateTime(); $ym = $date->format('Ym'); $is_in = false; foreach ($resultSet as $value) { if ($ym == $value['yearmonth']) { $is_in = true; break; } } if (!$is_in) { $model = new Default_Model_StatDownload(); $result = $model->getUserDownloadsForMonth($this->view->member->member_id, $ym); $amount = 0; foreach ($result as $value) { if ($value['is_license_missing_now'] == 1 || $value['is_source_missing_now'] == 1 || $value['is_pling_excluded_now'] == 1 ) { continue; } $amount = $amount + $value['probably_payout_amount']; } $currentMonth = array('yearmonth' => $ym, 'amount' => $amount); // test last month too $interval = new DateInterval('P1M');//2 months $lastmonthdate = $date->sub($interval); $ym = $lastmonthdate->format('Ym'); $is_in = false; foreach ($resultSet as $value) { if ($ym == $value['yearmonth']) { $is_in = true; break; } } if (!$is_in) { $model = new Default_Model_StatDownload(); $result = $model->getUserDownloadsForMonth($this->view->member->member_id, $ym); $amount = 0; foreach ($result as $value) { if ($value['is_license_missing'] == 1 || $value['is_source_missing'] == 1 || $value['is_pling_excluded'] == 1 ) { continue; } $amount = $amount + $value['probably_payout_amount']; } $lastMonth = array('yearmonth' => $ym, 'amount' => $amount); array_push($resultSet, $lastMonth); } array_push($resultSet, $currentMonth); } $this->view->payouthistory = $resultSet; } /** * @return Default_Form_Settings * @throws Zend_Form_Exception */ private function formPassword() { $form = new Default_Form_Settings(); $form->setMethod("POST")->setAttrib("id", "settingsPasswordForm")->setAction('/member/' . $this->_memberId . '/changepass'); $passOld = $form->createElement('password', 'passwordOld')->setLabel('Enter old Password:')->setRequired(true) ->removeDecorator('HtmlTag')->addValidator(new Local_Validate_OldPasswordConfirm())->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )); $pass1 = $form->createElement('password', 'password1')->setLabel('Enter new Password:')->setRequired(true) ->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING))->removeDecorator('HtmlTag') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )); $pass2 = $form->createElement('password', 'password2')->setLabel('Re-enter new Password:')->setRequired(true) ->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING))->removeDecorator('HtmlTag') ->setDecorators(array( 'ViewHelper', 'Label', 'Errors', array( 'ViewScript', array( 'viewScript' => 'settings/viewscripts/flatui_input.phtml', 'placement' => false ) ) )); $passValid = new Local_Validate_PasswordConfirm($pass2->getValue()); $pass1->addValidator($passValid); $form->addElement($passOld)->addElement($pass1)->addElement($pass2); return $form; } private function fetchMemberId() { if (false === Zend_Auth::getInstance()->hasIdentity()) { return null; } $auth = Zend_Auth::getInstance()->getIdentity(); if ($this->_userName == $auth->username) { return $auth->member_id; } if (Default_Model_DbTable_Member::ROLE_ID_ADMIN == $auth->roleId) { return $this->_memberId; } } } \ No newline at end of file diff --git a/application/modules/default/models/Info.php b/application/modules/default/models/Info.php index 4da1e336d..5e12cd524 100644 --- a/application/modules/default/models/Info.php +++ b/application/modules/default/models/Info.php @@ -1,2134 +1,2174 @@ . **/ class Default_Model_Info { const WALLPAPERCATEGORYID = '295'; const TAG_ISORIGINAL = 'original-product'; public function getLast200ImgsProductsForAllStores($limit = 200) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . md5('getLast200ImgsProductsForAllStores' . $limit); if ($resultSet = $cache->load($cacheName)) { return $resultSet; } else { $activeCategories = $this->getActiveCategoriesForAllStores(); $sql = ' SELECT `image_small` ,`project_id` ,`title` FROM `project` WHERE `project`.`image_small` IS NOT NULL AND `project`.`status` = 100 AND `project`.`project_category_id` IN (' . implode(',', $activeCategories) . ') ORDER BY ifnull(`project`.`changed_at`, `project`.`created_at`) DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); if (count($resultSet) > 0) { $cache->save($resultSet, $cacheName, array(), 14400); return $resultSet; } else { return array(); } } } public function getActiveCategoriesForAllStores($limit = null) { $sql = ' SELECT DISTINCT `config_store_category`.`project_category_id` FROM `config_store` JOIN `config_store_category` ON `config_store`.`store_id` = `config_store_category`.`store_id` JOIN `project_category` ON `config_store_category`.`project_category_id` = `project_category`.`project_category_id` WHERE `project_category`.`is_active` = 1 ORDER BY `config_store_category`.`order`; '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); if (count($resultSet) > 0) { $values = array_map(function ($row) { return $row['project_category_id']; }, $resultSet); return $values; } else { return array(); } } public function getActiveStoresForCrossDomainLogin($limit = null) { $sql = ' SELECT DISTINCT `config_store`.`host` FROM `config_store` WHERE `config_store`.`cross_domain_login` = 1 ORDER BY `config_store`.`order`; '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); if (count($resultSet) > 0) { $values = array_map(function ($row) { return $row['host']; }, $resultSet); return $values; } else { return array(); } } public function countTotalActiveMembers() { $cacheName = __FUNCTION__ . md5('countTotalActiveMembers'); $cache = Zend_Registry::get('cache'); $result = $cache->load($cacheName); if ($result) { return (int)$result['count_active_members']; } $sql = "SELECT count(1) AS `count_active_members` FROM ( SELECT count(1) AS `count_active_projects` FROM `project` `p` WHERE `p`.`status` = 100 AND `p`.`type_id` = 1 GROUP BY `p`.`member_id` ) AS `A`;"; $result = $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql); $cache->save($result, $cacheName); return (int)$result['count_active_members']; } /** * if category id not set the latest comments for all categories on the current host wil be returned. * * @param int $limit * @param int|null $project_category_id * @param array $tags * * @return array * @throws Zend_Cache_Exception * @throws Zend_Exception */ public function getLatestComments($limit = 5, $project_category_id = null, $tags = null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheNameTags = is_array($tags) ? implode('_', $tags) : ''; $cacheName = __FUNCTION__ . '_new_' . md5(Zend_Registry::get('store_host') . (int)$limit . (int)$project_category_id . $cacheNameTags); if (($latestComments = $cache->load($cacheName))) { return $latestComments; } if (empty($project_category_id)) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); } else { $activeCategories = $this->getActiveCategoriesForCatId($project_category_id); } if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `comment_id` ,`comment_text` ,`member`.`member_id` ,`member`.`profile_image_url` ,`comment_created_at` ,`member`.`username` ,`comment_target_id` ,`title` ,`stat_projects`.`project_id` ,`cat_title` AS `catTitle` FROM `comments` STRAIGHT_JOIN `member` ON `comments`.`comment_member_id` = `member`.`member_id` INNER JOIN `stat_projects` ON `comments`.`comment_target_id` = `stat_projects`.`project_id` '; /* if (isset($tags)) { $sql .= ' JOIN (SELECT DISTINCT project_id FROM stat_project_tagids WHERE tag_id in (' . implode(',', $tags) . ')) AS store_tags ON stat_projects.project_id = store_tags.project_id'; } */ $sql .= ' WHERE comments.comment_active = 1 AND stat_projects.status = 100 AND stat_projects.type_id in (1,3) AND comments.comment_type = 0 AND stat_projects.project_category_id IN (' . implode(',', $activeCategories) . ') '; //Store Tag Filter if (isset($tags)) { $tagList = $tags; //build where statement für projects $sql .= " AND ("; if(!is_array($tagList)) { $tagList = array($tagList); } foreach($tagList as $item) { #and $sql .= ' find_in_set('.$item.', tag_ids) AND '; } $sql .= ' 1=1)';; } $sql .= ' ORDER BY comments.comment_created_at DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); if (count($resultSet) > 0) { $cache->save($resultSet, $cacheName, array(), 300); return $resultSet; } else { $cache->save(array(), $cacheName, array(), 300); return array(); } } /** * @param int $omitCategoryId * * @return array * @TODO: check all occurrences of this function */ public function getActiveCategoriesForCurrentHost($omitCategoryId = null) { $currentHostMainCategories = Zend_Registry::get('store_category_list'); $modelCategory = new Default_Model_DbTable_ProjectCategory(); $activeChildren = $modelCategory->fetchChildIds($currentHostMainCategories); $activeCategories = array_unique(array_merge($currentHostMainCategories, $activeChildren)); if (empty($omitCategoryId)) { return $activeCategories; } $omitChildren = $modelCategory->fetchChildIds($omitCategoryId); return array_diff($activeCategories, $omitChildren); } /** * @param int $project_category_id * @param int|null $omitCategoryId * * @return array */ public function getActiveCategoriesForCatId($project_category_id, $omitCategoryId = null) { $modelCategory = new Default_Model_DbTable_ProjectCategory(); $activeChildren = $modelCategory->fetchChildIds($project_category_id); $activeCategories = array_unique(array_merge(array($project_category_id), $activeChildren)); if (empty($omitCategoryId)) { return $activeCategories; } $omitChildren = $modelCategory->fetchChildIds($omitCategoryId); return array_diff($activeCategories, $omitChildren); } /** * if category id not set the most downloaded products for all categories on the current host wil be returned. * * @param int $limit * @param null $project_category_id * @param array $tags * * @return array|false|mixed * @throws Zend_Cache_Exception * @throws Zend_Exception */ public function getMostDownloaded($limit = 100, $project_category_id = null, $tags = null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheNameTags = is_array($tags) ? implode('_', $tags) : ''; $cacheName = __FUNCTION__ . '_new_' . md5(Zend_Registry::get('store_host') . (int)$limit . (int)$project_category_id . $cacheNameTags); if (($mostDownloaded = $cache->load($cacheName))) { return $mostDownloaded; } if (empty($project_category_id)) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); } else { $activeCategories = $this->getActiveCategoriesForCatId($project_category_id); } if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `p`.`project_id` ,`p`.`title` ,`p`.`image_small` ,`s`.`amount` ,`s`.`category_title` ,`p`.`package_types` ,`p`.`tag_ids` FROM `stat_downloads_quarter_year` `s` INNER JOIN `stat_projects` `p` ON `s`.`project_id` = `p`.`project_id`'; /* if (isset($tags)) { $sql .= ' JOIN (SELECT DISTINCT project_id FROM stat_project_tagids WHERE tag_id in (' . implode(',', $tags) . ')) AS store_tags ON p.project_id = store_tags.project_id'; } * */ $sql .= ' WHERE p.status=100 and p.project_category_id IN (' . implode(',', $activeCategories) . ') '; //Store Tag Filter if (isset($tags)) { $tagList = $tags; //build where statement für projects $sql .= " AND ("; if(!is_array($tagList)) { $tagList = array($tagList); } foreach($tagList as $item) { #and $sql .= ' find_in_set('.$item.', tag_ids) AND '; } $sql .= ' 1=1)';; } $sql .= ' ORDER BY s.amount DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); if (count($resultSet) > 0) { $cache->save($resultSet, $cacheName, array(), 300); return $resultSet; } else { $cache->save($resultSet, $cacheName, array(), 300); return array(); } } /** * @param int $limit * @param int|null $project_category_id * @param array|null $tags * @param string|null $tag_isoriginal * * @return array|false * @throws Zend_Cache_Exception * @throws Zend_Exception */ public function getLastProductsForHostStores($limit = 10, $project_category_id = null, $tags = null, $tag_isoriginal = null) { $catids = ""; if ($project_category_id) { $catids = str_replace(',', '', (string)$project_category_id); } /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheNameTags = is_array($tags) ? implode('_', $tags) : ''; $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit . $catids . $cacheNameTags . $tag_isoriginal); if (($resultSet = $cache->load($cacheName))) { return $resultSet; } $activeCategories = array(); if (empty($project_category_id)) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); } else { $cats = explode(",", $project_category_id); if (count($cats) == 1) { $activeCategories = $this->getActiveCategoriesForCatId($project_category_id); } else { foreach ($cats as $cat) { $tmp = $this->getActiveCategoriesForCatId($cat); $activeCategories = array_merge($tmp, $activeCategories); } } } if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `p`.* FROM `stat_projects` AS `p` '; /* if (isset($tags)) { $sql .= ' JOIN (SELECT DISTINCT project_id FROM stat_project_tagids WHERE tag_id in (' . implode(',', $tags) . ')) AS store_tags ON p.project_id = store_tags.project_id '; } * */ $sql .= ' WHERE `p`.`status` = 100 AND `p`.`project_category_id` IN (' . implode(',', $activeCategories) . ') AND `p`.`amount_reports` IS NULL'; //Store Tag Filter if (isset($tags)) { $tagList = $tags; //build where statement für projects $sql .= " AND ("; if(!is_array($tagList)) { $tagList = array($tagList); } foreach($tagList as $item) { #and $sql .= ' find_in_set('.$item.', tag_ids) AND '; } $sql .= ' 1=1)';; } if (isset($tag_isoriginal)) { if ($tag_isoriginal) { $sql .= ' AND find_in_set("' . self::TAG_ISORIGINAL . '", tags)'; } else { $sql .= ' AND NOT find_in_set("' . self::TAG_ISORIGINAL . '", tags)'; } } //$sql .= ' ORDER BY IFNULL(p.changed_at,p.created_at) DESC'; $sql .= ' ORDER BY p.major_updated_at DESC'; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $cache->save($resultSet, $cacheName, array(), 300); if (count($resultSet) > 0) { return $resultSet; } return array(); } /** * @param int $limit * @param string|null $project_category_id * @param array|null $tags * @param string|null $tag_isoriginal * @param int $offset * * @return string * @throws Zend_Cache_Exception * @throws Zend_Exception */ public function getJsonLastProductsForHostStores( $limit = 10, $project_category_id = null, $tags = null, $tag_isoriginal = null, $offset = 0 ) { $store_id = null; if (empty($store_id)) { $store_config = Zend_Registry::get('store_config'); $store_id = $store_config->store_id; $store_tags = Zend_Registry::isRegistered('config_store_tags') ? Zend_Registry::get('config_store_tags') : array(); if(empty($tags)) { $tags = $store_tags; } else { $tags = array_merge($tags, $store_tags); } } $cat_ids = ""; if ($project_category_id) { $cat_ids = str_replace(',', '_', (string)$project_category_id); } /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheNameTags = is_array($tags) ? implode('_', $tags) : ''; $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit . $cat_ids . $cacheNameTags . $tag_isoriginal . $offset); if (($resultSet = $cache->load($cacheName))) { return $resultSet; } $activeCategories = array(); if (empty($project_category_id)) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); } else { $cats = explode(",", $project_category_id); if (count($cats) == 1) { $activeCategories = $this->getActiveCategoriesForCatId($project_category_id); } else { foreach ($cats as $cat) { $tmp = $this->getActiveCategoriesForCatId($cat); $activeCategories = array_merge($tmp, $activeCategories); } } } if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `project_id`, `member_id`, `image_small`, `title`, `version`, `cat_title`, `count_comments`, `package_names`, `tag_ids`, `laplace_score`, `count_likes`, `count_dislikes`, `changed_at`, `created_at` FROM `stat_projects` AS `p`'; /* if (isset($tags)) { $sql .= ' JOIN (SELECT DISTINCT project_id FROM stat_project_tagids WHERE tag_id in (' . implode(',', $tags) . ')) AS store_tags ON p.project_id = store_tags.project_id'; } * */ $sql .= ' WHERE `p`.`status` = 100 AND `p`.`project_category_id` IN (' . implode(',', $activeCategories) . ') AND `p`.`amount_reports` IS NULL'; //Store Tag Filter if (isset($tags)) { $tagList = $tags; //build where statement für projects $sql .= " AND ("; if(!is_array($tagList)) { $tagList = array($tagList); } foreach($tagList as $item) { #and $sql .= ' find_in_set('.$item.', tag_ids) AND '; } $sql .= ' 1=1)';; } if (isset($tag_isoriginal)) { if ($tag_isoriginal) { $sql .= ' AND find_in_set("' . self::TAG_ISORIGINAL . '", tags)'; } else { $sql .= ' AND NOT find_in_set("' . self::TAG_ISORIGINAL . '", tags)'; } } $sql .= ' ORDER BY IFNULL(p.changed_at,p.created_at) DESC'; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } if (isset($offset)) { $sql .= ' offset ' . (int)$offset; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $imagehelper = new Default_View_Helper_Image(); foreach ($resultSet as &$value) { $value['image_small'] = $imagehelper->Image($value['image_small'], array('width' => 200, 'height' => 200)); } if (count($resultSet) > 0) { $result = Zend_Json::encode($resultSet); $cache->save($result, $cacheName, array(), 300); return $result; } return Zend_Json::encode(''); } /** * @param int $limit * @param string|null $project_category_id * @param array|null $tags * * @return array|false * @throws Zend_Cache_Exception * @throws Zend_Exception */ public function getTopProductsForHostStores($limit = 10, $project_category_id = null, $tags = null) { $catids = ""; if ($project_category_id) { $catids = str_replace(',', '', (string)$project_category_id); } /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheNameTags = is_array($tags) ? implode('_', $tags) : ''; $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit . $catids . $cacheNameTags); if (($resultSet = $cache->load($cacheName))) { return $resultSet; } $activeCategories = array(); if (empty($project_category_id)) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); } else { $cats = explode(",", $project_category_id); if (count($cats) == 1) { $activeCategories = $this->getActiveCategoriesForCatId($project_category_id); } else { foreach ($cats as $cat) { $tmp = $this->getActiveCategoriesForCatId($cat); $activeCategories = array_merge($tmp, $activeCategories); } } } if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `p`.* FROM `stat_projects` AS `p`'; /* if (isset($tags)) { $sql .= ' JOIN (SELECT DISTINCT project_id FROM stat_project_tagids WHERE tag_id in (' . implode(',', $tags) . ')) AS store_tags ON p.project_id = store_tags.project_id'; } * */ $sql .= ' WHERE `p`.`status` = 100 AND `p`.`project_category_id` IN (' . implode(',', $activeCategories) . ') AND `p`.`amount_reports` IS NULL'; //Store Tag Filter if (isset($tags)) { $tagList = $tags; //build where statement für projects $sql .= " AND ("; if(!is_array($tagList)) { $tagList = array($tagList); } foreach($tagList as $item) { #and $sql .= ' find_in_set('.$item.', tag_ids) AND '; } $sql .= ' 1=1)';; } /*$sql .= ' ORDER BY (round(((count_likes + 6) / ((count_likes + count_dislikes) + 12)),2) * 100) DESC, created_at DESC ';*/ $sql .= ' ORDER BY laplace_score DESC, created_at DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $cache->save($resultSet, $cacheName, array(), 300); if (count($resultSet) > 0) { return $resultSet; } return array(); } public function getRandProduct() { $pid = $this->getRandomStoreProjectIds(); $project_id = $pid['project_id']; $sql="SELECT p.project_id ,p.title ,p.description ,p.image_small ,p.count_comments ,p.changed_at ,pr.likes as count_likes ,pr.dislikes as count_dislikes ,IFNULL(pr.score_with_pling, 500) AS laplace_score ,m.profile_image_url ,m.username FROM project as p JOIN member AS m ON m.member_id = p.member_id LEFT join stat_rating_project AS pr ON p.project_id = pr.project_id WHERE p.project_id = :project_id"; /*$sql = ' SELECT `p`.* ,laplace_score(`p`.`count_likes`, `p`.`count_dislikes`) AS `laplace_score` ,`m`.`profile_image_url` ,`m`.`username` FROM `project` AS `p` JOIN `member` AS `m` ON `m`.`member_id` = `p`.`member_id` WHERE `p`.`project_id` = :project_id ';*/ $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql, array('project_id' => $project_id)); return $resultSet; } public function getRandPlingedProduct() { $pid = $this->getRandomPlingedProjectIds(); $project_id = $pid['project_id']; $sql = "SELECT p.project_id ,p.title ,p.description ,p.image_small ,p.count_comments ,p.changed_at ,pr.likes as count_likes ,pr.dislikes as count_dislikes ,IFNULL(pr.score_with_pling, 500) AS laplace_score ,m.profile_image_url ,m.username ,(select count(1) from project_plings pp where pp.project_id = p.project_id and pp.is_deleted = 0) as sum_plings FROM project as p JOIN member AS m ON m.member_id = p.member_id LEFT join stat_rating_project AS pr ON p.project_id = pr.project_id WHERE p.project_id = :project_id"; /*$sql = ' SELECT `p`.* ,laplace_score(`p`.`count_likes`, `p`.`count_dislikes`) AS `laplace_score` ,`m`.`profile_image_url` ,`m`.`username` ,(select count(1) from project_plings pp where pp.project_id = p.project_id and pp.is_deleted = 0) as sum_plings FROM `project` AS `p` JOIN `member` AS `m` ON `m`.`member_id` = `p`.`member_id` WHERE `p`.`project_id` = :project_id ';*/ $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql, array('project_id' => $project_id)); return $resultSet; /*$resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql, array('project_id' => $project_id)); if (count($resultSet) > 0) { return new Zend_Paginator(new Zend_Paginator_Adapter_Array($resultSet)); } return new Zend_Paginator(new Zend_Paginator_Adapter_Array(array()));*/ } public function getRandFeaturedProduct() { $pid = $this->getRandomFeaturedProjectIds(); $project_id = $pid['project_id']; $sql="SELECT p.project_id ,p.title ,p.description ,p.image_small ,p.count_comments ,p.changed_at ,pr.likes as count_likes ,pr.dislikes as count_dislikes ,IFNULL(pr.score_with_pling, 500) AS laplace_score ,m.profile_image_url ,m.username FROM project as p JOIN member AS m ON m.member_id = p.member_id LEFT join stat_rating_project AS pr ON p.project_id = pr.project_id WHERE p.project_id = :project_id"; /*$sql = ' SELECT `p`.project_id ,IFNULL(`pr`.`score_with_pling`, 500) AS `laplace_score` ,`m`.`profile_image_url` ,`m`.`username` FROM `project` AS `p` JOIN `member` AS `m` ON `m`.`member_id` = `p`.`member_id` LEFT join `stat_rating_project` AS `pr` ON `p`.`project_id` = `pr`.`project_id` WHERE `p`.`project_id` = :project_id ';*/ $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql, array('project_id' => $project_id)); return $resultSet; } public function getRandomStoreProjectIds() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host')); $resultSet = $cache->load($cacheName); if (false == $resultSet) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `p`.`project_id` FROM `project` AS `p` WHERE `p`.`status` = 100 AND `p`.`type_id` = 1 AND `p`.`project_category_id` IN (' . implode(',', $activeCategories) . ') '; $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $cache->save($resultSet, $cacheName, array(), 3600 * 24); } $irandom = rand(0, sizeof($resultSet)-1); return $resultSet[$irandom]; } public function getRandomPlingedProjectIds() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ ; $resultSet = $cache->load($cacheName); if (false == $resultSet) { $sql=" select p.project_id from project_plings pl inner join stat_projects p on pl.project_id = p.project_id where pl.is_deleted = 0 and pl.is_active = 1 "; $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $cache->save($resultSet, $cacheName, array(), 3600 * 24); //cache is cleaned once a day } $irandom = rand(0, sizeof($resultSet)-1); return $resultSet[$irandom]; } public function getRandomFeaturedProjectIds() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ ; $resultSet = $cache->load($cacheName); if (false == $resultSet) { $sql="select project_id from project p where p.status = 100 and p.featured = 1 "; $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $cache->save($resultSet, $cacheName, array(), 3600 * 24); //cache is cleaned once a day } $irandom = rand(0, sizeof($resultSet)-1); return $resultSet[$irandom]; } /** * @param int $limit * @param null $project_category_id * * @return array|Zend_Paginator */ public function getFeaturedProductsForHostStores($limit = 10, $project_category_id = null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit . (int)$project_category_id); if (false !== ($resultSet = $cache->load($cacheName))) { return new Zend_Paginator(new Zend_Paginator_Adapter_Array($resultSet)); } if (empty($project_category_id)) { $activeCategories = $this->getActiveCategoriesForCurrentHost(); } else { $activeCategories = $this->getActiveCategoriesForCatId($project_category_id); } if (count($activeCategories) == 0) { return array(); } $sql = ' SELECT `p`.* ,`m`.`profile_image_url` ,`m`.`username` FROM `stat_projects` AS `p` JOIN `member` AS `m` ON `m`.`member_id` = `p`.`member_id` WHERE `p`.`status` = 100 AND `p`.`type_id` = 1 AND `p`.`featured` = 1 AND `p`.`project_category_id` IN (' . implode(',', $activeCategories) . ') '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql); $cache->save($resultSet, $cacheName, array(), 60); if (count($resultSet) > 0) { return new Zend_Paginator(new Zend_Paginator_Adapter_Array($resultSet)); } else { return new Zend_Paginator(new Zend_Paginator_Adapter_Array(array())); } } public function getLastCommentsForUsersProjects($member_id, $limit = 10, $comment_type=0) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$member_id . (int)$limit).$comment_type; if (false !== ($resultSet = $cache->load($cacheName))) { return $resultSet; } $sql = ' SELECT comment_id ,comment_text , member.member_id ,member.profile_image_url ,comment_created_at ,username ,title ,project_id ,comments.comment_target_id FROM comments JOIN project ON comments.comment_target_id = project.project_id STRAIGHT_JOIN member ON comments.comment_member_id = member.member_id WHERE comments.comment_active = 1 AND project.status = 100 and comments.comment_type=:comment_type AND project.member_id =:member_id and comments.comment_member_id <>:member_id ORDER BY comments.comment_created_at DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql, array('member_id' => $member_id, 'comment_type'=>$comment_type)); if (count($resultSet) > 0) { $cache->save($resultSet, $cacheName, array(), 300); return $resultSet; } else { $cache->save(array(), $cacheName, array(), 300); return array(); } } + public function getFeaturedProductsForUser($member_id,$limit = 10) + { + /** @var Zend_Cache_Core $cache */ + $cache = Zend_Registry::get('cache'); + $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$member_id . (int)$limit); + + if (false !== ($resultSet = $cache->load($cacheName))) { + return $resultSet; + } + + $sql="SELECT + p.project_id + ,p.title + ,p.description + ,p.image_small + ,p.count_comments + ,p.changed_at + ,p.laplace_score + ,p.profile_image_url + ,p.username + FROM + stat_projects as p + WHERE + p.status = 100 and p.featured = 1 and p.member_id = 24 + "; + + if (isset($limit)) { + $sql .= ' limit ' . (int)$limit; + } + + $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('threshold' => Default_Model_Spam::SPAM_THRESHOLD, 'member_id' => $member_id)); + + if ($result->rowCount() > 0) { + $resultSet = $result->fetchAll(); + } else { + $resultSet = array(); + } + $cache->save($resultSet, $cacheName, array(), 300); + return $resultSet; + } public function getLastVotesForUsersProjects($member_id, $limit = 10) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$member_id . (int)$limit); if (false !== ($resultSet = $cache->load($cacheName))) { return $resultSet; } $sql = ' SELECT `rating_id` ,`member`.`member_id` ,`member`.`profile_image_url` ,`username` ,`user_like` ,`user_dislike` ,`score` ,`project_rating`.`project_id` ,`project_rating`.`created_at` ,`project`.`title` ,`comments`.`comment_text` ,`comments`.`comment_id` FROM `project_rating` JOIN `project` ON `project_rating`.`project_id` = `project`.`project_id` join `comments` on `project_rating`.`comment_id` = `comments`.`comment_id` STRAIGHT_JOIN `member` ON `project_rating`.`member_id` = `member`.`member_id` WHERE `project`.`status` = 100 and `project_rating`.`rating_active`=1 AND `project`.`member_id` = :member_id ORDER BY `rating_id` DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql, array('member_id' => $member_id)); if (count($resultSet) > 0) { $cache->save($resultSet, $cacheName, array(), 300); return $resultSet; } else { $cache->save(array(), $cacheName, array(), 300); return array(); } } public function getLastSpamProjects($member_id, $limit = 10) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$member_id . (int)$limit); if (false !== ($resultSet = $cache->load($cacheName))) { return $resultSet; } $sql = " SELECT * FROM `stat_projects` WHERE `stat_projects`.`amount_reports` >= :threshold AND `stat_projects`.`status` = 100 AND `stat_projects`.`member_id` = :member_id ORDER BY `stat_projects`.`changed_at` DESC, `stat_projects`.`created_at` DESC, `stat_projects`.`amount_reports` DESC "; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('threshold' => Default_Model_Spam::SPAM_THRESHOLD, 'member_id' => $member_id)); if ($result->rowCount() > 0) { $resultSet = $result->fetchAll(); } else { $resultSet = array(); } $cache->save($resultSet, $cacheName, array(), 300); return $resultSet; } public function getLastDonationsForUsersProjects($member_id, $limit = 10) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$member_id . (int)$limit); if (false !== ($resultSet = $cache->load($cacheName))) { return $resultSet; } $sql = ' SELECT plings.project_id, plings.id ,member.member_id ,profile_image_url ,plings.create_time ,username ,plings.amount ,comment ,project.title FROM plings JOIN project ON project.project_id = plings.project_id STRAIGHT_JOIN member ON plings.member_id = member.member_id WHERE plings.status_id = 2 AND project.status=100 AND project.member_id = :member_id ORDER BY create_time DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql, array('member_id' => $member_id)); if (count($resultSet) > 0) { $cache->save($resultSet, $cacheName, array(), 300); return $resultSet; } else { $cache->save(array(), $cacheName, array(), 300); return array(); } } /** * @param int $limit * * @return array|false|mixed */ public function getNewActiveMembers($limit = 20) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit); if (false !== ($newMembers = $cache->load($cacheName))) { return $newMembers; } $sql = ' SELECT member_id, profile_image_url, username, created_at FROM member WHERE `is_active` = :activeVal AND `type` = :typeVal ORDER BY created_at DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultMembers = Zend_Db_Table::getDefaultAdapter()->query($sql, array( 'activeVal' => Default_Model_Member::MEMBER_ACTIVE, 'typeVal' => Default_Model_Member::MEMBER_TYPE_PERSON ))->fetchAll() ; $cache->save($resultMembers, $cacheName, array(), 300); return $resultMembers; } public function getSupporters($limit = 20) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' select s.member_id as supporter_id ,s.member_id ,(select username from member m where m.member_id = s.member_id) as username ,(select profile_image_url from member m where m.member_id = s.member_id) as profile_image_url ,max(s.active_time_max) as created_at from v_support s group by member_id order by active_time_max desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getNewActiveSupporters($limit = 20) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } /*$sql = ' SELECT s.member_id as supporter_id ,s.member_id ,(select username from member m where m.member_id = s.member_id) as username ,(select profile_image_url from member m where m.member_id = s.member_id) as profile_image_url ,min(s.active_time) as created_at from support s where s.status_id = 2 and (DATE_ADD((s.active_time), INTERVAL 1 YEAR) > now()) group by member_id order by s.active_time desc ';*/ $sql = ' select s.member_id as supporter_id ,s.member_id ,(select username from member m where m.member_id = s.member_id) as username ,(select profile_image_url from member m where m.member_id = s.member_id) as profile_image_url ,max(s.active_time_max) as created_at from v_support s group by member_id order by active_time_max desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getNewActiveSupportersForSectionAll($limit = 20) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' SELECT s.*, s.member_id as supporter_id ,s.member_id ,(select username from member m where m.member_id = s.member_id) as username ,(select profile_image_url from member m where m.member_id = s.member_id) as profile_image_url ,MAX(s.active_time) AS active_time_max ,ss.tier AS section_support_tier from section_support_paypements ss JOIN support s ON s.id = ss.support_id WHERE ss.yearmonth = DATE_FORMAT(NOW(), "%Y%m") GROUP BY s.member_id,ss.tier order BY active_time_max desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql)->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getSectionSupportersActiveMonths($section_id) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . $section_id ; $sql = "SELECT COUNT(1) AS active_months, member_id,sum(tier) sum_support FROM ( SELECT s.member_id, p.yearmonth , sum(p.tier) tier FROM section_support_paypements p JOIN support s ON s.id = p.support_id WHERE p.section_id = :section_id GROUP BY s.member_id, p.yearmonth ) A GROUP BY member_id "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' => $section_id))->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getNewActiveSupportersForSectionUnique($section_id, $limit = 1000) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . $section_id . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' SELECT s.member_id ,m.username ,m.profile_image_url ,sum(ss.tier) AS sum_support from section_support_paypements ss JOIN support s ON s.id = ss.support_id join member m on m.member_id = s.member_id WHERE ss.section_id = :section_id AND ss.yearmonth = DATE_FORMAT(NOW(), "%Y%m") GROUP BY s.member_id order BY ss.tier DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' => $section_id))->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getRandomSupporterForSection($section_id) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . $section_id; $supporters = $cache->load($cacheName); if (!$supporters) { $sql = ' select section_id, member_id, weight from v_supporter_view_queue where section_id = :section_id order by weight desc '; $supporters = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' => $section_id))->fetchAll(); //If there is no real supporter, show pling user if(!$supporters || count($supporters) == 0) { $sql = ' select section_id, member_id, weight from v_supporter_view_queue_all where section_id = :section_id order by weight desc '; $supporters = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' => $section_id))->fetchAll(); } $cache->save($supporters, $cacheName, array(), 300); } $sumWeight =0; foreach ($supporters as $s) { $sumWeight=$sumWeight+$s['weight']; } // select Random [1.. sumWeight]; $randomWeight = rand(1,$sumWeight); $sumWeight =0; $member_id=null; foreach ($supporters as $s) { $sumWeight=$sumWeight+$s['weight']; if($sumWeight >= $randomWeight) { $member_id = $s['member_id']; break; } } if($member_id) { $sql = "select member_id,username,profile_image_url from member where member_id=:member_id"; $result = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql,array('member_id' => $member_id)); return $result; } return null; } public function getNewActiveSupportersForSection($section_id, $limit = 20) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . $section_id . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' SELECT s.*, s.member_id as supporter_id ,s.member_id ,(select username from member m where m.member_id = s.member_id) as username ,(select profile_image_url from member m where m.member_id = s.member_id) as profile_image_url ,MAX(s.active_time) AS active_time_max ,ss.tier AS section_support_tier from section_support_paypements ss JOIN support s ON s.id = ss.support_id WHERE ss.section_id = :section_id AND ss.yearmonth = DATE_FORMAT(NOW(), "%Y%m") GROUP BY s.member_id,ss.tier order BY active_time_max desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' => $section_id))->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getNewActiveSupportersForSectionAndMonth($section_id, $yearmonth, $limit = 100) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . $section_id . '_' . $yearmonth . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' SELECT s.*, s.member_id as supporter_id ,s.member_id ,(select username from member m where m.member_id = s.member_id) as username ,(select profile_image_url from member m where m.member_id = s.member_id) as profile_image_url ,MAX(s.active_time) AS active_time_max ,SUM(ss.tier) AS sum_tier from section_support_paypements ss JOIN support s ON s.id = ss.support_id WHERE ss.section_id = :section_id AND ss.yearmonth = :yearmonth GROUP BY s.member_id order BY SUM(ss.tier) DESC, active_time_max desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' => $section_id, 'yearmonth' => $yearmonth))->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getNewActivePlingProduct($limit = 20) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' select pl.member_id as pling_member_id ,pl.project_id ,p.title ,p.image_small ,p.laplace_score ,p.count_likes ,p.count_dislikes ,p.member_id ,p.profile_image_url ,p.username ,p.cat_title as catTitle ,( select max(created_at) from project_plings pt where pt.member_id = pl.member_id and pt.project_id=pl.project_id ) as created_at ,(select count(1) from project_plings pl2 where pl2.project_id = p.project_id and pl2.is_active = 1 and pl2.is_deleted = 0 ) as sum_plings from project_plings pl inner join stat_projects p on pl.project_id = p.project_id and p.status=100 where pl.is_deleted = 0 and pl.is_active = 1 order by created_at desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getJsonNewActivePlingProduct($limit = 20,$offset=null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit).md5((int)$offset);; if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' select pl.member_id as pling_member_id ,pl.project_id ,p.title ,p.image_small ,p.laplace_score ,p.count_likes ,p.count_dislikes ,p.member_id ,p.description ,p.profile_image_url ,p.username ,p.cat_title ,p.count_comments ,( select max(created_at) from project_plings pt where pt.member_id = pl.member_id and pt.project_id=pl.project_id ) as pling_created_at ,(select count(1) from project_plings pl2 where pl2.project_id = p.project_id and pl2.is_active = 1 and pl2.is_deleted = 0 ) as sum_plings ,p.project_changed_at as changed_at ,p.project_created_at as created_at from project_plings pl inner join stat_projects p on pl.project_id = p.project_id and p.status > 30 where pl.is_deleted = 0 and pl.is_active = 1 order by pling_created_at desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } if (isset($offset)) { $sql .= ' offset ' . (int)$offset; } $resultSet = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $imagehelper = new Default_View_Helper_Image(); foreach ($resultSet as &$value) { $value['image_small'] = $imagehelper->Image($value['image_small'], array('width' => 200, 'height' => 200)); } $result = Zend_Json::encode($resultSet); $cache->save($result, $cacheName, array(), 300); return $result; } /** * @param int $limit * * @return array|false|mixed */ public function getTopScoreUsers($limit = 120,$offset=null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit).md5((int)$offset);; if (false !== ($resultMembers = $cache->load($cacheName))) { return $resultMembers; } $sql = ' select s.* ,m.profile_image_url ,m.username from member_score s inner join member m on s.member_id = m.member_id order by s.score desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } if (isset($offset)) { $sql .= ' offset ' . (int)$offset; } $resultMembers = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $cache->save($resultMembers, $cacheName, array(), 300); return $resultMembers; } public function getMostPlingedProductsTotalCnt(){ $sql = ' select count(1) as total_count from ( select distinct pl.project_id from project_plings pl inner join stat_projects p on pl.project_id = p.project_id and p.status = 100 where pl.is_deleted = 0 and pl.is_active = 1 ) t '; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $totalcnt = $result[0]['total_count']; return $totalcnt; } public function getMostPlingedProducts($limit = 20,$offset = null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit).md5((int)$offset); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' select pl.project_id ,count(1) as sum_plings ,p.title ,p.image_small ,p.laplace_score ,p.count_likes ,p.count_dislikes ,p.member_id ,p.profile_image_url ,p.username ,p.cat_title as catTitle ,p.project_changed_at ,p.version ,p.description ,p.package_names ,p.count_comments from project_plings pl inner join stat_projects p on pl.project_id = p.project_id and p.status = 100 where pl.is_deleted = 0 and pl.is_active = 1 group by pl.project_id order by sum_plings desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } if (isset($offset)) { $sql .= ' offset ' . (int)$offset; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getMostPlingedProductsForUser($member_id, $limit = 20,$offset = null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' .md5($member_id).md5((int)$limit).md5((int)$offset); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' select pl.project_id ,count(1) as sum_plings ,p.title ,p.image_small ,p.cat_title as catTitle ,p.project_changed_at from project_plings pl inner join stat_projects p on pl.project_id = p.project_id and p.status = 100 where pl.is_deleted = 0 and pl.is_active = 1 and p.member_id = :member_id group by pl.project_id order by sum_plings desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } if (isset($offset)) { $sql .= ' offset ' . (int)$offset; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('member_id' => $member_id))->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getMostPlingedCreatorsTotalCnt(){ $sql = ' select count(1) as total_count from ( select distinct p.member_id from stat_projects p join project_plings pl on p.project_id = pl.project_id where p.status = 100 and pl.is_deleted = 0 and pl.is_active = 1 ) t '; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $totalcnt = $result[0]['total_count']; return $totalcnt; } public function getMostPlingedCreators($limit = 20,$offset = null) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5((int)$limit).md5((int)$offset); if (false !== ($newSupporters = $cache->load($cacheName))) { return $newSupporters; } $sql = ' select p.member_id, count(1) as cnt, m.username, m.profile_image_url, m.created_at from stat_projects p join project_plings pl on p.project_id = pl.project_id join member m on p.member_id = m.member_id where p.status = 100 and pl.is_deleted = 0 and pl.is_active = 1 group by p.member_id order by cnt desc '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } if (isset($offset)) { $sql .= ' offset ' . (int)$offset; } $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $cache->save($result, $cacheName, array(), 300); return $result; } public function getCountActiveSupporters() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__; if (false !== ($totalcnt = $cache->load($cacheName))) { return $totalcnt; } /*$sql = ' SELECT count( distinct s.member_id) as total_count from support s where s.status_id = 2 and (DATE_ADD((s.active_time), INTERVAL 1 YEAR) > now()) ';*/ $sql = ' SELECT count( distinct s.member_id) as total_count from v_support s where is_valid = 1 '; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $totalcnt = $result[0]['total_count']; $cache->save($totalcnt, $cacheName, array(), 300); return $totalcnt; } public function getCountAllSupporters() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__; if (false !== ($totalcnt = $cache->load($cacheName))) { return $totalcnt; } $sql = ' SELECT count( distinct s.member_id) as total_count from v_support s '; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $totalcnt = $result[0]['total_count']; $cache->save($totalcnt, $cacheName, array(), 300); return $totalcnt; } public function getCountTierSupporters($tier) { $sql = " select count(1) as cnt from ( select member_id, max(amount), tier from support where status_id = 2 group by member_id ) t where tier = :tier "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('tier' =>$tier))->fetchAll(); return $result[0]['cnt']; } public function getCountSectionSupporters($section_id) { $sql = " select count(1) as cnt FROM section_support JOIN support ON support.id = section_support.support_id where support.status_id = 2 AND support.type_id = 1 AND section_support.section_id = :section_id "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('section_id' =>$section_id))->fetchAll(); return $result[0]['cnt']; } public function getCountSupportedMonthsForSectionAndMember($section_id, $member_id) { $sql = " SELECT COUNT(1) AS num_months FROM ( SELECT s.member_id, p.yearmonth FROM section_support_paypements p JOIN support s ON s.id = p.support_id WHERE member_id = :member_id AND p.section_id = :section_id GROUP BY s.member_id, p.yearmonth ) A "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('member_id' => $member_id, 'section_id' =>$section_id))->fetchRow(); return $result['num_months']; } public function getSumSupporting() { $sql = " SELECT SUM(s.tier) as sum_tier FROM v_support v JOIN support s ON s.member_id = v.member_id AND s.active_time = v.active_time_max WHERE v.is_valid = 1 "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql)->fetchAll(); return $result[0]['sum_tier']; } public function getSumPayoutForMonth($yearmonth) { $sql = " SELECT SUM(p.probably_payout_amount) AS sum_payout FROM member_dl_plings p WHERE p.yearmonth = :yearmonth AND p.paypal_mail IS NOT null "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('yearmonth' => $yearmonth))->fetchAll(); return $result[0]['sum_tier']; } public function getModeratorsList() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__; if (false !== ($newMembers = $cache->load($cacheName))) { return $newMembers; } $sql = ' SELECT member_id, profile_image_url, username, created_at FROM member WHERE `is_active` = :activeVal AND `type` = :typeVal and `roleid` = :roleid ORDER BY created_at DESC '; if (isset($limit)) { $sql .= ' limit ' . (int)$limit; } $resultMembers = Zend_Db_Table::getDefaultAdapter()->query($sql, array( 'activeVal' => Default_Model_Member::MEMBER_ACTIVE, 'typeVal' => Default_Model_Member::MEMBER_TYPE_PERSON, 'roleid' => Default_Model_DbTable_Member::ROLE_ID_MODERATOR ))->fetchAll() ; $cache->save($resultMembers, $cacheName, array(), 300); return $resultMembers; } public function getCountMembers() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__; if (false !== ($totalcnt = $cache->load($cacheName))) { return $totalcnt; } $sql = " SELECT count(1) AS total_count FROM member WHERE is_active=1 AND is_deleted=0 "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll(); $totalcnt = $result[0]['total_count']; $cache->save($totalcnt, $cacheName, array(), 300); return $totalcnt; } public function getTooptipForMember($member_id) { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__ . '_' . md5($member_id); if (false !== ($tooptip = $cache->load($cacheName))) { return $tooptip; } $modelMember = new Default_Model_Member(); $tblFollower = new Default_Model_DbTable_ProjectFollower(); $modelProject = new Default_Model_Project(); $printDate = new Default_View_Helper_PrintDate(); $printDateSince = new Default_View_Helper_PrintDateSince(); $cnt = $modelMember->fetchCommentsCount($member_id); $cntLikesGave = $tblFollower->countLikesHeGave($member_id); $cntLikesGot = $tblFollower->countLikesHeGot($member_id); $donationinfo = $modelMember->fetchSupporterDonationInfo($member_id); $lastactive = $modelMember->fetchLastActiveTime($member_id); $cntprojects = $modelProject->countAllProjectsForMember($member_id, true); $member = $modelMember->find($member_id)->current(); $textCountryCity = $member->city; $textCountryCity .= $member->country ? ', ' . $member->country : ''; $data = array( 'totalComments' => $cnt, 'created_at' => $printDateSince->printDateSince($member->created_at), 'username' => $member->username, 'countrycity' => $textCountryCity, 'lastactive_at' => $printDateSince->printDateSince($lastactive), 'cntProjects' => $cntprojects, 'issupporter' => $donationinfo['issupporter'], 'supportMax' => $donationinfo['active_time_max'], 'supportMin' => $donationinfo['active_time_min'], 'supportCnt' => $donationinfo['cnt'], 'cntLikesGave' => $cntLikesGave, 'cntLikesGot' => $cntLikesGot ); $cache->save($data, $cacheName, array(), 3600); return $data; } public function getProbablyPayoutPlingsCurrentmonth($project_id) { $sql = " select FORMAT(probably_payout_amount, 2) as amount from member_dl_plings where project_id = :project_id and yearmonth=(DATE_FORMAT(NOW(),'%Y%m'))"; $result = Zend_Db_Table::getDefaultAdapter()->fetchRow($sql, array('project_id' => $project_id)); return $result['amount']; } public function getOCSInstallInstruction() { /** @var Zend_Cache_Core $cache */ $cache = Zend_Registry::get('cache'); $cacheName = __FUNCTION__; if (false !== ($instruction = $cache->load($cacheName))) { return $instruction; } $config = Zend_Registry::get('config')->settings->server->opencode; $readme = 'https://opencode.net/OCS/ocs-url/raw/master/docs/How-to-install.md?inline=false'; $httpClient = new Zend_Http_Client($readme, array('keepalive' => true, 'strictredirects' => true)); $httpClient->resetParameters(); $httpClient->setUri($readme); $httpClient->setHeaders('Private-Token', $config->private_token); $httpClient->setHeaders('Sudo', $config->user_sudo); $httpClient->setHeaders('User-Agent', $config->user_agent); $httpClient->setMethod(Zend_Http_Client::GET); $response = $httpClient->request(); $body = $response->getRawBody(); if (count($body) == 0) { return array(); } include_once('Parsedown.php'); $Parsedown = new Parsedown(); $readmetext = $Parsedown->text($body); $cache->save($readmetext, $cacheName, array(), 3600); return $readmetext; } public function getDiscussionOpendeskop($member_id) { $sql = " select c.comment_id ,c.comment_text ,c.comment_member_id ,c.comment_created_at ,m.username ,p.project_id ,p.title ,cp.comment_member_id p_comment_member_id ,(select username from member m where m.member_id = cp.comment_member_id) p_username from comments c inner join project p on c.comment_target_id = p.project_id and p.status = 100 inner join member m ON c.comment_member_id = m.member_id left join comments cp on c.comment_parent_id = cp.comment_id where c.comment_type = 0 and c.comment_active = 1 and c.comment_member_id = :member_id ORDER BY c.comment_created_at DESC limit 10 "; $result = Zend_Db_Table::getDefaultAdapter()->query($sql, array('member_id' => $member_id))->fetchAll(); return $result; } } \ No newline at end of file diff --git a/application/modules/default/views/scripts/user/activities.phtml b/application/modules/default/views/scripts/user/activities.phtml index a6152974c..974d6f657 100644 --- a/application/modules/default/views/scripts/user/activities.phtml +++ b/application/modules/default/views/scripts/user/activities.phtml @@ -1,122 +1,140 @@ . **/ $this->tab = 'activities'; $helpProductUrl = new Default_View_Helper_BuildProductUrl(); $helpDate = new Default_View_Helper_PrintDate(); ?>
render('user/partials/userHeader_top.phtml'); ?>
render('user/partials/userHeader.phtml'); ?> comments)==0 and count($this->votes)==0 and count($this->donations)==0){ + if((count($this->comments)+count($this->votes)+count($this->donations)+count($this->featured))==0){ ?>

translate('no activities yet') ?>

translate('Activities') ?>

+
+
featured)>0) { echo count($this->featured). ' featured product'.(count($this->featured)>1?'s':'');}?>
+
+ featured as $f) { ?> +
+
+ + + +
+
+ + +
comments)>0) { echo count($this->comments). ' Comment'.(count($this->comments)>1?'s':'');}?>
comments as $comment) { ?>
'. $comment_title . ' : '.$comment_text.' '.$helpDate->printDate($comment['comment_created_at']).''; ?>
votes)>0) { echo count($this->votes). ' vote'.(count($this->votes)>1?'s':'');}?>
votes as $vote) { ?>
'. $vote['title'] . ' '.$helpDate->printDate($vote['created_at']).''; ?>
donations)>0) { echo count($this->donations). ' donation'.(count($this->donations)>1?'s':'');}?>
donations as $donation) { ?>
'. $donation['title'] . ' : '.$donation['comment'].' '.$helpDate->printDate($donation['create_time']).''; ?>