addAscendingOrderByColumn(CoursePeer::SLUG); $this->courses = CoursePeer::doSelect($c); foreach($this->courses as $c) $c->setCulture($this->getUser()->getCulture()); } /** * List page * * @return void * @author Benjamin Ramey **/ public function executeList() { //$this->Transform(); $this->forward('courses', 'index'); } /** * Prices actions * * @return void * @author Benjamin Ramey **/ public function executePrices() { } /** * Shows a course description * * @return void * @author Benjamin Ramey **/ public function executeCourse() { $slug = $this->getRequestParameter("courseNameSlug"); $course = CoursePeer::getBySlug($slug); if(!$course) { $this->forward404(); } $course = $course[0]; $course->setCulture($this->getUser()->getCulture()); $this->course = $course; } /** * Public courses page * * @return void * @author Benjamin Ramey **/ public function executePubliccourses() { } /** * Schedule page * * @return void * @author Benjamin Ramey **/ public function executeSchedule() { } private function Transform() { $path = sfConfig::get('sf_data_dir')."/xml/courses"; $allFiles = scandir($path); $files = array(); for($c = 0; $c < count($allFiles); $c++) { if(substr($allFiles[$c], -3) == "xml") array_push($files, $allFiles[$c]); } foreach($files as $file) { $data = xml_parse_file($path."/".$file); $en = html_print_xml_page($data['page']['en']); $de = html_print_xml_page($data['page']['de']); $en = str_replace("

For more information and reservations:","", $en); $en = str_replace("contact information

", "", $en); $de = str_replace("

Weitere Informationen und Reservierungen unter:", "", $de); $de = str_replace("Kontaktinformation

", "", $de); $course = new Course(); $course->setSlug(str_replace(" ", "", strtolower($data['page']['en']['name']))); //$xml = simplexml_load_file(sfConfig::get('sf_data_dir')."/xml/courses/".$file); $course->setCulture('en'); $course->setTitle($data['page']['en']['name']); $course->setDescription($en); $course->setCulture('de'); $course->setTitle($data['page']['de']['name']); $course->setDescription($de); $course->save(); } } } function html_print_xml_page($data) { $page_name = $data['name']; $page_content = ''; $sections = 0; $paras = 0; isset($data['content']['section']) ? $sections = 1 : $paras = 1; if($sections ) { $contents = xml_force_array($data['content']['section']); $page_content = html_print_sections($contents); } else if($paras) { $contents = xml_force_array($data['content']['para']); $page_content = html_print_paragraphs($contents); } //print "
$page_name
\n"; //print "
\n"; return $page_content; //print "
\n"; } ###################################################################################################### print sections of an xml page # parameters: 1) array of sections to print # returns: the html for the sections function html_print_sections(&$sections) { $page_content = ''; foreach($sections as $sec) { $page_content .= "
\n"; $page_content .= "
{$sec['name']}
\n"; $page_content .= "
\n"; $paras = xml_force_array($sec['text']['para']); $page_content .= html_print_paragraphs($paras); $page_content .= "
\n"; $page_content .= "
\n"; } return $page_content; } ###################################################################################################### print paragraphs of an xml page # parameters: 1) array of paragraphs to print # returns: the html for the paragraphs function html_print_paragraphs(&$paragraphs) { $page_content = ''; foreach($paragraphs as $para) { $page_content .= '

'; if(is_array($para)) { foreach($para as $key => $value) { switch($key) { case 'line': if(is_array($value)) { foreach($value as $line) { $page_content .= '
'.$line; } } else { $page_content .= '
'.$value; } break; case 'paracontent': $page_content .= $value; break; case 'list': $page_content .= "

    \n"; foreach($para['list']['listitem'] as $item) { $page_content .= "
  • $item
  • \n"; } $page_content .= "
\n"; break; case 'heading': $page_content .= "$value\n"; break; case 'link': if(is_array($value)) { $page_content .= " {$value['linktext']}"; } else { $page_content .= " $value"; } break; case 'image': $images = xml_force_array($para['image']); $page_content .= html_print_images($images); break; default: break; } } } else { $page_content .= $para; } $page_content .= "

\n"; } return $page_content; } ###################################################################################################### print images of an xml page # parameters: 1) array of images to print # returns: the html for the images function html_print_images(&$images) { $page_content = ''; foreach($images as $image) { if(is_array($image)) { foreach($image as $key => $value) { switch($key) { case 'link': $page_content .= "[0],[1]...[x]; $element = biography # endsup: [biography]=>[0],[1]...[x+1] if(isset($tmp_refs[$last_index][$element][0])) { array_push($tmp_refs[$last_index][$element],''); $tmp_index = count($tmp_refs[$last_index][$element]) - 1; $tmp_refs[] =& $tmp_refs[$last_index][$element][$tmp_index]; } # case example: [biography]=>[paragraph]; $element = biography # endsup: [biography]=>[0]=>[paragraph] # [1]=>'' else { $tmp_ary = $tmp_refs[$last_index][$element]; $tmp_refs[$last_index][$element] = array($tmp_ary,''); $tmp_refs[] =& $tmp_refs[$last_index][$element][1]; } } # case example: [biography]=>"string"; $element = biography # endsup: [biography]=>[0]=>"string" # [1]=>'' else { $tmp_refs[$last_index][$element] = array($tmp_refs[$last_index][$element],''); $tmp_refs[] =& $tmp_refs[$last_index][$element][1]; } } # case example: [biography]=> NULL; $element = biography # endsup: [biography]=>"" else { $tmp_refs[$last_index][$element] = ''; $tmp_refs[] =& $tmp_refs[$last_index][$element]; } # if there are parameters, add them as if they were imbedded elements if(!empty($parameters)) { $pairs = explode(' ',$parameters); $last_index = count($tmp_refs) - 1; # we can do this, because we know the last element added # is always fresh and new $tmp_refs[$last_index] = array(); foreach($pairs as $pair) { # if a parameter is empty, just continue to next one if(empty($pair)) { continue; } list($name,$value) = explode('=',$pair); $value = str_replace("'",'',$value); $value = str_replace('"','',$value); $tmp_refs[$last_index][$name] = $value; } } # we've already found an opening tag, now find the closing tag $end_tag = strpos($to_process,""); # if there is not closing tag--oops! badly formatted xml doc if($end_tag === FALSE) { return("XML document improperly formed. No closing tag found for element: $element"); } # get the string length of the opening tag and all the paramters # inside, plus the opening and closing brackets $element_len = strlen($matches[0]); # then, the contents of this xml tag start after the above # measured length to the end of the $to_process string, minus # the length of the closing tag $contents = substr($to_process,$element_len,$end_tag - $element_len); # if there is text in the $to_process string past this closing # tag that we just found, put it on top of the $xml_left tag # it's a sister element of the current one if($extra = substr($to_process,$end_tag + strlen(""))) { array_push($xml_left,$extra); } # if not sister elements are found, we are at the end of this # generation of elements, so place an END indicator in the # $xml_left array else { array_push($xml_left,'!~~END~~!'); } array_push($xml_left,$contents); } # we place the identifier END to indicate the end of an xml tag that # has nested tags and no content itself, if this is NOT the case # we have content to assign the current xml tag else if($to_process != '!~~END~~!') { $tmp_refs[$last_index] = $to_process; array_pop($tmp_refs); } # if we miss the above two ifs, we are at the end of an element # but don't have content to assign, so step back one generation # in the xml document else { $tmp = array_pop($tmp_refs); } } # if all went well, we return an associative array with all the xml # data in it, properly nested return($data); } ##################################################### FUNCTION: xml_force_array # # parameters: path to file to parse # returns: associative array of xml file data function xml_force_array($element) { $array = array(); if(is_array($element)) { if(isset($element[0])) { $array = $element; } else { array_push($array,$element); } } else { array_push($array,$element); } return($array); }