Hallo,
da ich demnächst eine Komponente für Joomla für einen Bekannten programmieren soll, habe ich jetzt mal kurz meine Kenntnisse aufgefrischt. Natürlich kann man seine eigenen Leistungen nicht objektiv bewerten. Deswegen wollte ich fragen, wie “sauber” mein PHP ist.
Also was kann ich am Stil verbessern (Algorithmus eher unwichtig)?
Was kann man für die Entwicklung auf meinem aktuellen Level ca. als Stundenlohn verlangen?
Danke schon mal
PS: Bitte nicht meckern, ich weiß, dass ich kein Profi bin!
Hier mal mein Auffrischungsprojekt:
class_calendar.php (Edit: mit BnWs Tipps)
[code]<?
class cCalendar{
private $month;
private $year;
private $monthnames=array("Januar","Februar","Maerz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
function __construct() {
$this->year = date("Y");
$this->month = date("n");
}
public function setmonth($month){ //month uebergeben
if (is_integer($month) && ($month>0) && ($month<13)){
$this->month = $month;
return true;
}else{
return false;
}
}
public function addmonth($month){ //month uebergeben
if (is_integer($month) && ($month < 241) && ($month > -241) ){
$this->year += floor(($this->month+$month-1)/12);
if($month > (-$this->month) ){
$this->month = ($this->month+$month-1)%12+1;
}else{
$this->month = 12-abs($this->month+$month)%12;
}
return true;
}else{
return false;
}
}
public function setyear($year){ //year uebergeben
if (is_integer($year) && ($year>1969)){
$this->year = $year;
return true;
}else{
return false;
}
}
public function getcode($mark = false){ //Kalenderquellcode (Mark = aktuellen Tag markieren)
$today = date("njY");
$dummyday = $this->mdummydays();
$maxmday = $this->mdays();
$code='<div class="calendar"><table><tr><td colspan="7" class="monthheader">'.$this->monthnames[$this->month-1].' '.$this->year.'</td></tr><tr class="weekhead"><td>Mo</td><td>Di</td><td>Mi</td><td>Do</td><td>Fr</td><td class="saturday">Sa</td><td class="sunday">So</td></tr>';
for ($i = 0; $i < $this->rows(); $i++){
$code .= '<tr class="weeks">';
for ($j = 1; $j < 8 ; $j++){
$classcode = '';
$day = $i*7+$j-$dummyday;
if (($day < 1) || ($day > $maxmday)){
$day = '';
}else if (($today == $this->month.$day.$this->year) && $mark){
$classcode = ' class="today"';
}
$code .= "<td".$classcode.">".$day."</td>";
}
$code .= "</tr>";
}
$code .= '</table></div>';
return $code;
}
private function mdays(){ //Anzahl der tage des months ermitteln
return date("t",mktime(0, 0, 0, $this->month, 1, $this->year));
}
private function mdummydays(){ //Anzahl der Tage vor erster Tag des months
$days = date("w",mktime(0, 0, 0, $this->month, 1, $this->year)) - 1;
if ($days == -1){
$days = 6;
}
return $days;
}
private function rows(){ //Zeilen des Kalenders berechnen
$days = $this->mdummydays() + $this->mdays();
if ($days < 29){
return 4;
}else if ($days > 35){
return 6;
}else{
return 5;
}
}
}
?>[/code]
index.php (Edit: mit BnWs Tipps)
[code]
Kalender .today{ color: #F00; } .weekhead{ color: #03C; font-weight: bold; } .weeks{ text-align: right; } .weeks td:hover { background-color: #999; font-weight: bold; color: #03C; } .weeks:hover { background-color: #CCC; } .monthheader{ text-align: center; background-color: #03C; color: #FFF; } #cnavl{ margin-right: 70px; } .sunday{ color: #F00; } .saturday{ color: #000; } [/code]