diff --git a/application/modules/default/models/Info.php b/application/modules/default/models/Info.php
index 2b2d93f0b..88e29f801 100644
--- a/application/modules/default/models/Info.php
+++ b/application/modules/default/models/Info.php
@@ -1,1153 +1,1250 @@
.
**/
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 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 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();
}
}
/**
* 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
*
* @return array
* @throws Zend_Cache_Exception
* @throws Zend_Exception
*/
public function getLatestComments($limit = 5, $project_category_id = null,$package_type = null)
{
/** @var Zend_Cache_Core $cache */
$cache = Zend_Registry::get('cache');
$cacheName =
__FUNCTION__ . '_new_' . md5(Zend_Registry::get('store_host') . (int)$limit . (int)$project_category_id.$package_type);
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 ';
$sql .= ' WHERE comments.comment_active = 1
AND stat_projects.status = 100
AND stat_projects.type_id = 1
AND comments.comment_type = 0
AND stat_projects.project_category_id IN (' . implode(',', $activeCategories) . ')
';
if(isset($package_type)) {
$sql .= ' AND find_in_set('.$package_type.', stat_projects.package_types)';
}
$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 latest plings for all categories on the current host wil be returned.
*
* @param int $limit
* @param null $project_category_id
*
* @return array|false|mixed
*/
/*/* public function getLatestPlings($limit = 5, $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 (($latestPlings = $cache->load($cacheName))) {
return $latestPlings;
}
if (empty($project_category_id)) {
$activeCategories = $this->getActiveCategoriesForCurrentHost();
} else {
$activeCategories = $this->getActiveCategoriesForCatId($project_category_id);
}
if (count($activeCategories) == 0) {
return array();
}
$storeConfig = Zend_Registry::isRegistered('store_config') ? Zend_Registry::get('store_config') : null;
$storePackageTypeIds = null;
if ($storeConfig) {
$storePackageTypeIds = $storeConfig['package_type'];
}
$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';
if ($storePackageTypeIds) {
$sql .= ' JOIN (SELECT DISTINCT project_id FROM project_package_type WHERE package_type_id in ('
. $storePackageTypeIds . ')) package_type ON project.project_id = package_type.project_id';
}
$sql .= ' WHERE
plings.status_id = 2
AND project.status <> 30
AND project.project_category_id IN (' . implode(',', $activeCategories) . ')
ORDER BY plings.create_time 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();
}
}*/
/**
* 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
*
* @return array|false|mixed
*/
public function getMostDownloaded($limit = 100, $project_category_id = null, $package_type=null)
{
/** @var Zend_Cache_Core $cache */
$cache = Zend_Registry::get('cache');
$cacheName =
__FUNCTION__ . '_new_' . md5(Zend_Registry::get('store_host') . (int)$limit . (int)$project_category_id.$package_type);
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
FROM stat_downloads_quarter_year s
INNER JOIN stat_projects p ON s.project_id = p.project_id';
$sql .= ' WHERE
p.status=100
and
p.project_category_id IN (' . implode(',', $activeCategories) . ')
';
if(isset($package_type)) {
$sql .= ' AND find_in_set('.$package_type.', p.package_types)';
}
$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();
}
}
public function getLastProductsForHostStores($limit = 10, $project_category_id = null, $package_type = null,$tag_isoriginal = null)
{
/** @var Zend_Cache_Core $cache */
if($project_category_id) {
$catids = str_replace(',', '', (string)$project_category_id);
}else
{
$catids="";
}
$cache = Zend_Registry::get('cache');
$cacheName =
__FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit .$catids.$package_type.$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
WHERE
p.status = 100
AND p.project_category_id IN (' . implode(',', $activeCategories) . ')
AND p.amount_reports is null';
if(isset($package_type)) {
$sql .= ' AND find_in_set('.$package_type.', package_types)';
}
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;
}
$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();
}
}
+
+
+ public function getJsonLastProductsForHostStores($limit = 10, $project_category_id = null, $package_type = null,$tag_isoriginal = null, $offset = 0)
+ {
+ /** @var Zend_Cache_Core $cache */
+
+ if($project_category_id) {
+ $catids = str_replace(',', '_', (string)$project_category_id);
+ }else
+ {
+ $catids="";
+ }
+ $cache = Zend_Registry::get('cache');
+ $cacheName =
+ __FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit .$catids.$package_type.$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,
+ laplace_score,
+ count_likes,
+ count_dislikes,
+ changed_at,
+ created_at
+ FROM
+ stat_projects AS p
+ WHERE
+ p.status = 100
+ AND p.project_category_id IN (' . implode(',', $activeCategories) . ')
+ AND p.amount_reports is null';
+
+ if(isset($package_type)) {
+ $sql .= ' AND find_in_set('.$package_type.', package_types)';
+ }
+
+ 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['project_image_small_uri'] = $imagehelper->Image($value['image_small'], array('width' => 80, 'height' => 80));
+ }
+ if (count($resultSet) > 0) {
+ $result = Zend_Json::encode($resultSet);
+ $cache->save($result, $cacheName, array(), 300);
+ return $result;
+ } else {
+ return Zend_Json::encode('');
+ }
+ }
public function getTopProductsForHostStores($limit = 10, $project_category_id = null, $package_type = null)
{
/** @var Zend_Cache_Core $cache */
if($project_category_id) {
$catids = str_replace(',', '', (string)$project_category_id);
}else
{
$catids="";
}
$cache = Zend_Registry::get('cache');
$cacheName =
__FUNCTION__ . '_' . md5(Zend_Registry::get('store_host') . (int)$limit .$catids.$package_type);
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
WHERE
p.status = 100
AND p.project_category_id IN (' . implode(',', $activeCategories) . ')
AND p.amount_reports is null';
if(isset($package_type)) {
$sql .= ' AND find_in_set('.$package_type.', package_types)';
}
$sql .= ' ORDER BY (round(((count_likes + 6) / ((count_likes + count_dislikes) + 12)),2) * 100) DESC, 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($resultSet, $cacheName, array(), 300);
return array();
}
}
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));
return $resultSet[$irandom];
}
public function getRandProduct(){
$pid = $this->getRandomStoreProjectIds();
$project_id = $pid['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()->fetchAll($sql, array('project_id' => $project_id));
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 getRandProduct_(){
// $activeCategories = $this->getActiveCategoriesForCurrentHost();
// if (count($activeCategories) == 0) {
// return array();
// }
// $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.status = 100
// AND p.type_id = 1
// AND p.project_category_id IN ('. implode(',', $activeCategories).')
// ORDER BY RAND() LIMIT 1
// ';
// $resultSet = Zend_Db_Table::getDefaultAdapter()->fetchAll($sql);
// 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()));
// }
// }
/**
* @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)
{
/** @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
comment_id
,comment_text
, member.member_id
,comment_created_at
,username
,title
,project_id
FROM comments
JOIN project ON comments.comment_target_id = project.project_id AND comments.comment_type = 0
STRAIGHT_JOIN member ON comments.comment_member_id = member.member_id
WHERE comments.comment_active = 1
AND project.status = 100
AND project.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));
if (count($resultSet) > 0) {
$cache->save($resultSet, $cacheName, array(), 300);
return $resultSet;
} else {
$cache->save(array(), $cacheName, array(), 300);
return array();
}
}
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
,username
,user_like
,user_dislike
,project_rating.project_id
,project_rating.created_at
,project.title
FROM project_rating
JOIN project ON project_rating.project_id = project.project_id
STRAIGHT_JOIN member ON project_rating.member_id = member.member_id
WHERE project.status = 100
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 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;
}
/**
* @param int $limit
*
* @return array|false|mixed
*/
public function getTopScoreUsers($limit = 120)
{
/** @var Zend_Cache_Core $cache */
$cache = Zend_Registry::get('cache');
$cacheName = __FUNCTION__ . '_' . md5((int)$limit);
if (false !== ($resultMembers = $cache->load($cacheName))) {
return $resultMembers;
}
$model = new Default_Model_DbTable_MemberScore();
$resultMembers = $model->fetchTopUsers($limit);
$cache->save($resultMembers, $cacheName, array(), 300);
return $resultMembers;
}
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
';
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 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 min(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 > 30
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 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())
';
$result = Zend_Db_Table::getDefaultAdapter()->query($sql, array())->fetchAll();
$totalcnt = $result[0]['total_count'];
$cache->save($totalcnt, $cacheName,array() , 300);
return $totalcnt;
}
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://git.opendesktop.org/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;
}
}
\ No newline at end of file
diff --git a/application/modules/default/views/scripts/home/index-opendesktop-test.phtml b/application/modules/default/views/scripts/home/index-opendesktop-test.phtml
index 45c974301..8ca9b00e5 100755
--- a/application/modules/default/views/scripts/home/index-opendesktop-test.phtml
+++ b/application/modules/default/views/scripts/home/index-opendesktop-test.phtml
@@ -1,143 +1,138 @@
.
**/
$this->headTitle($_SERVER['HTTP_HOST'], 'SET');
$this->doctype(Zend_View_Helper_Doctype::XHTML1_RDFA);
$this->headMeta()->appendProperty('og:url', 'www.opendesktop.org');
$this->headMeta()->appendProperty('og:type', 'website');
$this->headMeta()->appendProperty('og:title', 'opendesktop.org');
$this->headMeta()->appendProperty('og:site_name','www.opendesktop.org');
$this->headMeta()->appendProperty('og:description','A community where developers and artists share applications, themes and other content');
$this->headMeta()->appendProperty('og:image','https://www.opendesktop.org/images/system/opendesktop-logo.png');
$modelInfo = new Default_Model_Info();
-$this->comments = $modelInfo->getLatestComments(10);
-//$this->users = $modelInfo->getNewActiveMembers(18);
-//$this->supporters = $modelInfo->getNewActiveSupporters(9);
-//$this->plingproducts = $modelInfo->getNewActivePlingProduct(9);
-$this->productsThemesGTK = $modelInfo->getLastProductsForHostStores(5,"366,363,273,267,138,125,131,153,154,414,133");
-$this->productsThemesPlasma = $modelInfo->getLastProductsForHostStores(5,"365,119,123,266,114,118,349,417,101,100,111,422,423,446,417");
-$this->productsWindowmanager = $modelInfo->getLastProductsForHostStores(5,"117,267,139,143,142,140,141,144");
-$this->productsIconsCursors= $modelInfo->getLastProductsForHostStores(5,"386,107");
-$this->productsScreenshots= $modelInfo->getLastProductsForHostStores(5,"225,445");
-$this->productsApps = $modelInfo->getLastProductsForHostStores(5,233);
-$this->productsAddons = $modelInfo->getLastProductsForHostStores(5,"152");
-$this->productsWallpapersOriginal = $modelInfo->getLastProductsForHostStores(5,"295,158",null,true);
-$this->productsWallpapers = $modelInfo->getLastProductsForHostStores(5,"295,158",null,false);
-$this->countSupporters = $modelInfo->getCountActiveSupporters();
+
+$productsThemesGTK = $modelInfo->getJsonLastProductsForHostStores(5,"366,363,273,267,138,125,131,153,154,414,133");
+$productsThemesPlasma = $modelInfo->getJsonLastProductsForHostStores(5,"365,119,123,266,114,118,349,417,101,100,111,422,423,446,417");
+$productsWindowmanager = $modelInfo->getJsonLastProductsForHostStores(5,"117,267,139,143,142,140,141,144");
+$productsIconsCursors= $modelInfo->getJsonLastProductsForHostStores(5,"386,107");
+$productsScreenshots= $modelInfo->getJsonLastProductsForHostStores(5,"225,445");
+$productsApps = $modelInfo->getJsonLastProductsForHostStores(5,233);
+$productsAddons = $modelInfo->getJsonLastProductsForHostStores(5,"152");
+$productsWallpapersOriginal = $modelInfo->getJsonLastProductsForHostStores(5,"295,158",null,true);
+$productsWallpapers = $modelInfo->getJsonLastProductsForHostStores(5,"295,158",null,false);
$featuredProducts = $modelInfo->getFeaturedProductsForHostStores(100);
if ($featuredProducts->getTotalItemCount()) {
$request = Zend_Controller_Front::getInstance()->getRequest();
$offset = (int)$request->getParam('page');
$irandom = rand(1,$featuredProducts->getTotalItemCount());
$featuredProducts->setItemCountPerPage(1);
$featuredProducts->setCurrentPageNumber($irandom);
$this->featureProducts = $featuredProducts;
}
$helperBuildMemberUrl = new Default_View_Helper_BuildMemberUrl();
$helperImage = new Default_View_Helper_Image();
$helpPrintDate = new Default_View_Helper_PrintDate();
$item;
foreach ($this->featureProducts as $i) {
$item = $i;
break;
}
$helpCategories = new Default_View_Helper_FetchCategoriesForProductAsString();
-
+$imagehelper = new Default_View_Helper_Image();
$feature = array(
'project_id' => $item['project_id'],
'member_id' => $item['member_id'],
'username' => $item['username'],
- 'profile_image_url' => $item['profile_image_url'],
+ 'profile_image_url' => $imagehelper->Image($item['profile_image_url'],array('width' => 300, 'height' => 230, 'crop' => 1)),
'featured' => $item['featured'],
'description' => $item['description'],
'title' => $item['title'],
'category' => $helpCategories->fetchCategoriesForProductAsString($item['project_id']),
'image_small' => $item['image_small'],
'laplace_score' => $item['laplace_score'],
'count_likes' => $item['count_likes'],
'count_dislikes' => $item['count_dislikes'],
'changed_at' => $item['changed_at'],
'created_at' => $item['created_at'],
'count_comments' => $item['count_comments']
);
$response = array(
- "productsThemesGTK" => Zend_Json::encode($this->productsThemesGTK),
- "productsThemesPlasma" => Zend_Json::encode($this->productsThemesPlasma),
- "productsWindowmanager" => Zend_Json::encode($this->productsWindowmanager),
- "productsIconsCursors" => Zend_Json::encode($this->productsIconsCursors),
- "productsScreenshots" => Zend_Json::encode($this->productsScreenshots),
- "productsApps" => Zend_Json::encode($this->productsApps),
- "productsAddons" => Zend_Json::encode($this->productsAddons),
- "productsWallpapersOriginal" => Zend_Json::encode($this->productsWallpapersOriginal),
- "productsWallpapers" => Zend_Json::encode($this->productsWallpapers),
+ "productsThemesGTK" => $productsThemesGTK,
+ "productsThemesPlasma" => $productsThemesPlasma,
+ "productsWindowmanager" => $productsWindowmanager,
+ "productsIconsCursors" => $productsIconsCursors,
+ "productsScreenshots" => $productsScreenshots,
+ "productsApps" => $productsApps,
+ "productsAddons" => $productsAddons,
+ "productsWallpapersOriginal" => $productsWallpapersOriginal,
+ "productsWallpapers" => $productsWallpapers,
"featureProducts" => Zend_Json::encode($feature)
);
-
?>
-