silverstripe-externallinks/code/model/BrokenExternalLink.php

71 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2014-08-07 03:56:15 +02:00
/**
* Represents a single link checked for a single run that is broken
*
* @method BrokenExternalPageTrack Track()
* @method BrokenExternalPageTrackStatus Status()
*/
2014-07-28 02:39:19 +02:00
class BrokenExternalLink extends DataObject {
private static $db = array(
'Link' => 'Varchar(2083)', // 2083 is the maximum length of a URL in Internet Explorer.
'HTTPCode' =>'Int'
);
private static $has_one = array(
2014-08-07 03:56:15 +02:00
'Track' => 'BrokenExternalPageTrack',
'Status' => 'BrokenExternalPageTrackStatus'
);
2014-08-07 03:56:15 +02:00
/**
* @return SiteTree
*/
public function Page() {
return $this->Track()->Page();
}
public static $summary_fields = array(
'Page.Title' => 'Page',
'HTTPCodeDescription' => 'HTTP Code',
'Created' => 'Created'
);
public static $searchable_fields = array(
'HTTPCode' => array('title' => 'HTTP Code')
);
public function canEdit($member = false) {
return false;
}
public function canView($member = false) {
2014-07-28 02:39:19 +02:00
$member = $member ? $member : Member::currentUser();
$codes = array('content-authors', 'administrators');
return Permission::checkMember($member, $codes);
}
/**
* Retrieve a human readable description of a response code
*
* @return string
*/
public function getHTTPCodeDescription() {
$code = $this->HTTPCode;
if(empty($code)) {
// Assume that $code = 0 means there was no response
$description = _t(__CLASS__.'.NOTAVAILABLE', 'Server Not Available');
} elseif(
($descriptions = Config::inst()->get('SS_HTTPResponse', 'status_codes'))
&& isset($descriptions[$code])
) {
$description = $descriptions[$code];
} else {
$description = _t(__CLASS__.'.UNKNOWNRESPONSE', 'Unknown Response Code');
}
return sprintf("%d (%s)", $code, $description);
}
}