SourPHPTest | ||||
|
||||
Coverage | ||||||||||||
Classes | Functions / Methods | Lines | ||||||||||
Total |
|
100.00% | 1 / 1 |
|
100.00% | 4 / 4 |
|
100.00% | 28 / 28 | |||
SourPHP |
|
100.00% | 1 / 1 |
|
100.00% | 4 / 4 |
|
100.00% | 28 / 28 | |||
public function getEntryById($entryId) |
|
100.00% | 1 / 1 |
|
100.00% | 5 / 5 | ||||||
public function getEntryByTitle($entryTitle, $page=1) |
|
100.00% | 1 / 1 |
|
100.00% | 4 / 4 | ||||||
public function getAllEntriesByTitle($entryTitle) |
|
100.00% | 1 / 1 |
|
100.00% | 9 / 9 | ||||||
public function getEntriesByTitleAfterGivenTime($entryTitle, $timestamp) |
|
100.00% | 1 / 1 |
|
100.00% | 10 / 10 |
1 : <? 2 : /** 3 : * SourPHP 4 : * 5 : * LICENSE 6 : * 7 : * This file can be distributed under terms of LGPL 8 : * 9 : * @package SourPHP 10 : * @copyright Osman Yuksel 11 : * @LICENSE http://www.gnu.org/licenses/lgpl-3.0.txt 12 : * @version 0.1 13 : */ 14 : 15 : require_once("SourPHPInterface.php"); 16 : require_once("SourPHPCore.php"); 17 : 18 : /** 19 : * SourPHP 20 : * 21 : * @implements SourPHPInterface 22 : * @author Osman Yuksel <yuxel |AT| sonsuzdongu |DOT| com> 23 : */ 24 : class SourPHP extends SourPHPCore implements SourPHPInterface{ 25 : 26 : 27 : /** 28 : * fetches entry details by id 29 : * 30 : * @param int $entryId 31 : * @return mixed array(entryId,title, content, order, author, dateCreated, dateEdited) 32 : */ 33 : public function getEntryById($entryId){ 34 2 : $data = $this->fetchId($entryId); 35 2 : $doc = $this->createDomDocumentFromData($data); 36 2 : $details = $this->getContentOfEntriesFromDoc($doc); 37 : 38 2 : $entryDetail = $details[0]; 39 2 : return $entryDetail; 40 : } 41 : 42 : /** 43 : * fetches entry details by entry title 44 : * 45 : * @param string $entryTitle 46 : * @return mixed array(entryId,title, content, order, author, dateCreated, dateEdited) 47 : */ 48 : public function getEntryByTitle($entryTitle, $page=1){ 49 5 : $data = $this->fetchEntry($entryTitle, $page); 50 5 : $doc = $this->createDomDocumentFromData($data); 51 5 : $details = $this->getContentOfEntriesFromDoc($doc); 52 : 53 5 : return $details; 54 : } 55 : 56 : 57 : /** 58 : * fetches all entries by entry title 59 : * 60 : * @param string $entryTitle 61 : * @return mixed array(entryId,title, content, order, author, dateCreated, dateEdited) 62 : */ 63 : public function getAllEntriesByTitle($entryTitle){ 64 4 : $data = $this->fetchEntry($entryTitle, $page); 65 4 : $doc = $this->createDomDocumentFromData($data); 66 4 : $numOfPages = $this->getNumberOfPages($doc); 67 4 : $details = array(); 68 : 69 4 : for($i=1;$i<=$numOfPages;$i++){ 70 4 : $detailsOfPage = $this->getEntryByTitle($entryTitle, $i); 71 4 : $details = array_merge($details, $detailsOfPage); 72 4 : } 73 : 74 4 : return $details; 75 : } 76 : 77 : 78 : /** 79 : * fetch entries, which are created after $timestamp 80 : * this could be useful on such thing like feed aggregator 81 : * 82 : * @param string $entryTitle 83 : * @param int $timestamp entries created after this time 84 : * @return mixed array(entryId,title, content, order, author, dateCreated, dateEdited) 85 : */ 86 : public function getEntriesByTitleAfterGivenTime($entryTitle, $timestamp){ 87 : 88 3 : $details = $this->getAllEntriesByTitle($entryTitle); 89 : 90 3 : $foundKey = count($details); 91 : 92 3 : foreach($details as $key=>$value){ 93 3 : if($value['dateCreated'] > $timestamp) { 94 2 : $foundKey = $key; 95 2 : break; 96 : } 97 3 : } 98 : 99 3 : $foundEntries = array_slice($details, $foundKey); 100 : 101 : 102 3 : $return = empty($foundEntries)?false:$foundEntries; 103 : 104 3 : return $return; 105 : } 106 : 107 : 108 : 109 : 110 : 111 : 112 : } |
Generated by PHPUnit 3.4.1 and Xdebug 2.0.5 at Sat Dec 19 12:27:11 EET 2009. |