/** * Establish if there is a day * witch matches for all people * @param caldates * @return Day */ public function compareCommonDates(CalendarDateRepository $calDates) { $dates = $calDates->getDates(); //get the number of peope $numberOfPeople = count($dates); $dateArr = array(); $dayNameArr = array(); //flatten the array... foreach ($dates as $date) { foreach ($date as $value) { $dateArr[] = $value; $dayNameArr[] = $value->getName(); } } //check if there is a value with the same amount of matches as people $countArr = array_count_values($dayNameArr); if (in_array($numberOfPeople, $countArr)) { //get the value of the index $day = array_search($numberOfPeople, $countArr); foreach ($dateArr as $date) { if ($date->getName() == $day) { //TODO how handle multiple days matching? new calendarDateRepo? return $date; } } } return null; }
/** * Get info from each persons calendar * @return CalendarDates $calendarDates */ public function getCalendarInfo() { //get URL to calendar page $url = $this->calendarLink; //Get the sourcecode $data = $this->curl->curlGetReq($url); //find all links to each person $query = "//a"; $aTagNodes = $this->curl->getDOMData($data, $query); $calendarDates = new CalendarDateRepository(); //loop through each link, representing a person foreach ($aTagNodes as $at) { //get the href to that persons calendar $calURL = $at->getAttribute("href"); //get the sourcecode of that page $data = $this->curl->curlGetReq($url . $calURL); //get the table header containing name of the days $query = "//th"; $days = $this->curl->getDOMData($data, $query); //get the table data containing availability $query = "//td"; $availibility = $this->curl->getDOMData($data, $query); $dates = array(); /* * loop table data, if the availability of that day is ok * save that data. */ for ($i = 0; $i < $days->length; $i++) { $availibilityStr = $availibility[$i]->nodeValue; if (strtolower($availibilityStr) === "ok") { //$calendarDates->add($days[$i]->nodeValue); $dates[] = new Day($days[$i]->nodeValue); } } $calendarDates->add($dates); } return $calendarDates; }