3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 743 Views |
-
Help with Conditional logic

4 March 2011 at 7:24am
HI Everyone:
I have a notice page and notice holder which I pull data from and place on the home page.
I have them display based on the type of notice and if they are expired. I am trying to simply just place a line of text that states "no notices" if the notice type does not have any non expired pages.
Everything is successful except, because I am using a control to show the data, if I use an If Else statement, the message appears the total amount of times i have notices. so since I am allowing 3 notices max to appear, the "no notices" message will appear three times. Anyone have suggestions where I can prevent this. here is my code:
homepage.ss
<div id="campusNotices">
<ul>
<% control SafetyNotices %>
<% if InFuture(HomePageExpiration) %>
<% if NoticeType==Safety %>
<li><a href="$Link"><span>$NoticeDate: $Title</span></a></li>
<% end_if %>
<% end_if %>
<% end_control %>
</ul>
</div>homepage.php
public function GetCampusNoticePage(){
return DataObject::get("CampusNoticePage");}
function SafetyNotices($num=5) {
$Notices = DataObject::get_one("CampusNoticeHolder");
return ($Notices) ? DataObject::get("CampusNoticePage", "ParentID = $Notices->ID", "NoticeDate DESC", "", $num) : false;
}page.php < this is in the class section to allow this function to be used sitewide
public function InPast($fieldname) {
return $this->$fieldname < date('Y-m-d H:i:s');
}public function InFuture($fieldname) {
return $this->$fieldname > date('Y-m-d H:i:s');
}campusnoticepage.php
class CampusNoticePage extends Page {
public static $db = array(
'NoticeDate' => 'Date',
'NoticeType' => "Enum('Traffic, Safety','Traffic')",
'HomePageExpiration' => 'Date',
);public static $has_one = array(
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DatePickerField('NoticeDate'), 'Content');
$fields->addFieldToTab("Root.Content.Main", new DropdownField( 'NoticeType' , 'Notice Type', array(
'Traffic' => 'Traffic',
'Safety' => 'Safety'
),$this->NoticeType), 'Content');
$fields->addFieldToTab("Root.Content.Main", new DatePickerField('HomePageExpiration'), 'Content');
$fields->removeFieldFromTab("Root.Content.Main","NavigationOrder");
$fields->removeFieldFromTab("Root.Content.Main","ThirdLevelTitle");
$fields->removeFieldFromTab("Root.Content.Main","ThirdLevelDesc");
return $fields;
}I know I am using the hell out of the IF?else statements so any suggestions would be great!
| 743 Views | ||
|
Page:
1
|
Go to Top |

