Sistema di banner per categorie
This commit is contained in:
@@ -281,7 +281,7 @@ class AnalyticsHelper {
|
||||
* @param int $position
|
||||
* @param string $replaced id del banner rimpiazzato
|
||||
*/
|
||||
public static function getBannerToShow($position, $replaced = null){
|
||||
public static function getBannerToShow($position, $replaced = null, $category = BannerModel::GENERAL_CATEGORY){
|
||||
// Rimuovi il replaced dalla lista
|
||||
$shown = array();
|
||||
$rval = null;
|
||||
@@ -306,7 +306,7 @@ class AnalyticsHelper {
|
||||
}
|
||||
}
|
||||
|
||||
$baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDate(strtotime("tomorrow"))));
|
||||
$baseSearchArray = array("position"=>$position,"end"=>array('$gte'=>new MongoDate(strtotime("tomorrow"))),"category"=>$category);
|
||||
// Prendi il primo dei "mai mostrati oggi" tra quelli non presenti nella pagina
|
||||
$todayPlusShown = array_merge($idList,$shown);
|
||||
if (sizeof($todayPlusShown)>0){
|
||||
|
||||
@@ -7,10 +7,14 @@ Creation Date: 11/mar/2016
|
||||
class BannerHelper{
|
||||
private static $INTERNAL_COUNT = 1;
|
||||
|
||||
public static function printBanner($position = BannerModel::POSITION_HEAD){
|
||||
public static function printBanner($position = BannerModel::POSITION_HEAD, $category = null){
|
||||
if (is_null($category)){
|
||||
$category = BannerModel::GENERAL_CATEGORY;
|
||||
}
|
||||
|
||||
$cur = self::getPlaceholderId();
|
||||
?>
|
||||
<div id="<?php echo $cur;?>"><script type="text/javascript">$(document).ready(function () {bannerRoll('<?php echo $cur;?>',<?php echo $position;?>);});</script></div>
|
||||
<div id="<?php echo $cur;?>"><script type="text/javascript">$(document).ready(function () {bannerRoll('<?php echo $cur;?>',<?php echo $position;?>,<?php echo $category;?>);});</script></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,22 @@ class BannerModel extends HasMediaModel{
|
||||
const POSITION_HEAD = 1;
|
||||
const POSITION_BODY = 2;
|
||||
|
||||
const GENERAL_CATEGORY = 0;
|
||||
|
||||
public static $BANNER_POSITIONS = array(
|
||||
self::POSITION_HEAD=>array("label"=>"Testata"),
|
||||
self::POSITION_BODY=>array("label"=>"Corpo")
|
||||
);
|
||||
|
||||
public function __construct($saveableObject = null){
|
||||
parent::__construct($saveableObject);
|
||||
|
||||
if (!$this->hasProperty("categories")){
|
||||
$this->categories = array(self::GENERAL_CATEGORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function __set($attr,$value){
|
||||
if (strcmp("type", $attr)==0 || strcmp("position", $attr)==0){
|
||||
$value = intval($value);
|
||||
|
||||
@@ -169,7 +169,7 @@ class GUIHandler {
|
||||
self::$onLoadEvents[] = $script;
|
||||
}
|
||||
|
||||
public static function generateHeadPublic(){
|
||||
public static function generateHeadPublic($bannerCategory = BannerModel::GENERAL_CATEGORY){
|
||||
$mesi = array(1=>'Gennaio', 'Febbraio', 'Marzo', 'Aprile',
|
||||
'Maggio', 'Giugno', 'Luglio', 'Agosto',
|
||||
'Settembre', 'Ottobre', 'Novembre','Dicembre');
|
||||
@@ -218,12 +218,12 @@ class GUIHandler {
|
||||
</div>
|
||||
<div class="middleBar">
|
||||
<div class="leftBanner topBanner mediaContent">
|
||||
<?php BannerHelper::printBanner(BannerModel::POSITION_HEAD);?>
|
||||
<?php BannerHelper::printBanner(BannerModel::POSITION_HEAD,$bannerCategory);?>
|
||||
<!-- <div id="topLeftBan"><script type="text/javascript">$(document).ready(function () {bannerRoll('topLeftBan');});</script></div> -->
|
||||
</div>
|
||||
<div class="logo"><a href="http://ifattidinapoli.com/index.php"><img src="images/logo_uff.png"></a></div>
|
||||
<div class="rightBanner topBanner mediaContent">
|
||||
<?php BannerHelper::printBanner(BannerModel::POSITION_HEAD);?>
|
||||
<?php BannerHelper::printBanner(BannerModel::POSITION_HEAD,$bannerCategory);?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bottomBar" style="height:40px;width:1000px;"></div>
|
||||
@@ -372,7 +372,7 @@ class GUIHandler {
|
||||
}
|
||||
|
||||
|
||||
public static function generateRightBannerBlock(){
|
||||
public static function generateRightBannerBlock($category = BannerModel::GENERAL_CATEGORY){
|
||||
$stats = GlobalVariables::get("dao")->aggregate("StatisticModel",PipelineHelper::getMostViewedOfLastDays(strtotime("-7 days"),5));
|
||||
$idArray = array_map(function ($ele){ return new MongoId($ele["_id"]["notizia"]);}, $stats);
|
||||
|
||||
@@ -405,8 +405,8 @@ class GUIHandler {
|
||||
?>
|
||||
<div id="rightBarContainer" class="">
|
||||
<div class="rotoBanner">
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY);?></div>
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY);?></div>
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
||||
</div>
|
||||
<div class="reader">
|
||||
<div class="lastNews">
|
||||
@@ -436,8 +436,8 @@ class GUIHandler {
|
||||
</div>
|
||||
</div>
|
||||
<div class="rotoBanner not">
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY);?></div>
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY);?></div>
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
||||
<div class="bannerContainer mediaContent"><?php BannerHelper::printBanner(BannerModel::POSITION_BODY,$category);?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
@@ -42,7 +42,20 @@ try{
|
||||
throw new GUIException("Selezionare una posizione per il banner");
|
||||
}
|
||||
$banner->position = PostHandler::get("position");
|
||||
|
||||
|
||||
$banner->categories = array();
|
||||
|
||||
$general = PostHandler::get("categories_".BannerModel::GENERAL_CATEGORY);
|
||||
if (!is_null($general) && strcasecmp($general, BannerModel::GENERAL_CATEGORY)==0){
|
||||
$banner->categories[] = BannerModel::GENERAL_CATEGORY;
|
||||
}
|
||||
foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
||||
$val = PostHandler::get("categories_".$category);
|
||||
if (!is_null($val) && strcasecmp($val, $category)==0){
|
||||
$banner->categories[] = $category;
|
||||
}
|
||||
}
|
||||
|
||||
GlobalVariables::get("dao")->save($banner);
|
||||
GUIHandler::redirectPost("admin/homeBanner.php",array("id"=>$banner->id));
|
||||
}
|
||||
@@ -95,6 +108,13 @@ try{
|
||||
<span class="label">Data fine:</span>
|
||||
<input type="text" id="datepickerEnd" name="dateEnd" value="<?php echo date("d-m-Y",$banner->end->sec);?>">
|
||||
</div>
|
||||
<div><span class="label"> </span><b>Categorie</b></div>
|
||||
<?php
|
||||
echo '<div><span class="label">Generale</span><input type="checkbox" name="categories_'.BannerModel::GENERAL_CATEGORY.'" value="'.BannerModel::GENERAL_CATEGORY.'" '.(in_array(BannerModel::GENERAL_CATEGORY, $banner->categories)?'checked="checked"':"").' /><br/>';
|
||||
foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
||||
echo '<div><span class="label">'.$data["label"].'</span><input type="checkbox" name="categories_'.$category.'" value="'.$category.'" '.(in_array($category, $banner->categories)?'checked="checked"':"").' /><br/>';
|
||||
}
|
||||
?>
|
||||
|
||||
</form>
|
||||
<div class="formBtns">
|
||||
|
||||
+2
-2
@@ -120,7 +120,7 @@ GUIHandler::generateHtmlHeaders(array("additionalHeaders"=>$additionalHeaders,"a
|
||||
<div style="width:1000px;margin-left:auto;margin-right:auto;" itemscope itemtype="http://schema.org/Article">
|
||||
<?php
|
||||
|
||||
GUIHandler::generateHeadPublic();
|
||||
GUIHandler::generateHeadPublic($articolo->category);
|
||||
GUIHandler::generateMenu();
|
||||
?>
|
||||
<div class="articoloCategory">
|
||||
@@ -300,7 +300,7 @@ GUIHandler::generateHtmlHeaders(array("additionalHeaders"=>$additionalHeaders,"a
|
||||
</div>
|
||||
</div>
|
||||
<div class="articoloRightBar" style="width:280px;display:inline-block;">
|
||||
<?php GUIHandler::generateRightBannerBlock();?>
|
||||
<?php GUIHandler::generateRightBannerBlock($articolo->category);?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
@@ -46,7 +46,7 @@ try{
|
||||
?>
|
||||
<div style="width:1000px;margin-left:auto;margin-right:auto;">
|
||||
<?php
|
||||
GUIHandler::generateHeadPublic();
|
||||
GUIHandler::generateHeadPublic($category);
|
||||
GUIHandler::generateMenu();?>
|
||||
<div class="categorySummaryContainer">
|
||||
<?php $i=0;
|
||||
@@ -77,7 +77,7 @@ try{
|
||||
?>
|
||||
</div>
|
||||
<div class="summaryRightBar">
|
||||
<?php GUIHandler::generateRightBannerBlock();?>
|
||||
<?php GUIHandler::generateRightBannerBlock($category);?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
+12
-2
@@ -20,10 +20,20 @@ Creation Date: 02/mar/2016
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists("cat",$_GET)) {
|
||||
$category = intval($_GET["cat"]);
|
||||
if ($category!= BannerModel::GENERAL_CATEGORY && !array_key_exists($category,NotiziaModel::$NOTIZIE_CATEGORY)){
|
||||
$category = BannerModel::GENERAL_CATEGORY;
|
||||
}
|
||||
}
|
||||
|
||||
// $banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$_GET['id']));
|
||||
|
||||
// ASDSessionHandler::setSessionValue("bannerActive",array());
|
||||
$banner = AnalyticsHelper::getBannerToShow($position,$replaced);
|
||||
$banner = AnalyticsHelper::getBannerToShow($position,$replaced,$category);
|
||||
if (is_null($banner) && $category!=BannerModel::GENERAL_CATEGORY){
|
||||
$banner = AnalyticsHelper::getBannerToShow($position,$replaced,BannerModel::GENERAL_CATEGORY);
|
||||
}
|
||||
// var_dump($replaced);
|
||||
|
||||
if (!is_null($banner)){
|
||||
@@ -37,7 +47,7 @@ Creation Date: 02/mar/2016
|
||||
<script type="text/javascript">
|
||||
var rand = Math.floor((Math.random() * 100) + 1);
|
||||
setTimeout(function () {
|
||||
bannerRoll('<?php echo $banner->id;?>',<?php echo $position; ?>);
|
||||
bannerRoll('<?php echo $banner->id;?>',<?php echo $position; ?>,<?php echo $category?>);
|
||||
},60000+rand);
|
||||
</script>
|
||||
<?php
|
||||
|
||||
@@ -53,10 +53,10 @@ function logout(){
|
||||
});
|
||||
}
|
||||
|
||||
function bannerRoll(prev,pos){
|
||||
function bannerRoll(prev,pos,category){
|
||||
$.ajax({
|
||||
method:"POST",
|
||||
url:'getBanner.php?replaced='+prev+'&pos='+pos,
|
||||
url:'getBanner.php?replaced='+prev+'&pos='+pos+'&cat='+category,
|
||||
dataType:'html',
|
||||
success: function(data){
|
||||
$('#'+prev).parent().html(data);
|
||||
|
||||
Reference in New Issue
Block a user