本文整理汇总了PHP中Report::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Report::toArray方法的具体用法?PHP Report::toArray怎么用?PHP Report::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Report
的用法示例。
在下文中一共展示了Report::toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getReports
function getReports($filter)
{
$reports = array();
if (!is_null($filter)) {
$db = new Database();
$sql = "SELECT `id` FROM reports WHERE statusID=?";
$sql = $db->prepareQuery($sql, $filter);
} else {
//not filtered. all reports
$db = new Database();
$sql = "SELECT `id` FROM reports";
}
$results = $db->select($sql);
if (is_array($results)) {
foreach ($results as $result) {
$newReport = new Report();
$newReport->fetch($result['id']);
$reports[] = $newReport->toArray();
}
}
return $reports;
}
示例2: toArray
public function toArray()
{
return ['timestamp' => $this->timestamp->format(\DateTime::ATOM)] + $this->report->toArray();
}
示例3: reportPhotoPost
private function reportPhotoPost()
{
if (!$this->validatePhoto()) {
return 'error: photo upload failed';
}
$report = new Report();
//fetch and check for valid report
$report->fetch($this->args[0]);
if ($report->getID() == null) {
$this->response['message'] = 'error: failed to load report with id ' . $this->args[0];
$this->response['code'] = 405;
}
//report id
$reportID = $this->args[0];
$photo = $this->files['photo'];
$upload_dir = Path::uploads() . $reportID . '/';
//make the directory if it doesn't already exist
if (!file_exists($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
//make sure there wasnt an error with the upload
if ($photo['error'] !== UPLOAD_ERR_OK) {
$this->response['message'] = 'error: photo upload error';
$this->response['code'] = 400;
}
//make sure filename is safe
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $photo['name']);
//different dir for each report
$i = 0;
$parts = pathinfo($name);
while (file_exists($upload_dir . $name)) {
//myfile-1.png
$name = $parts['filename'] . '-' . $i . '.' . $parts['extension'];
}
//move file from temp directory
$success = move_uploaded_file($photo['tmp_name'], $upload_dir . $name);
if (!$success) {
$this->response['message'] = 'error: unable to save file';
$this->response['code'] = 500;
}
//set proper file permissions on new file
chmod($upload_dir . $name, 0644);
//update the report in DB with file location
$report->setPhotoPath($upload_dir . $name);
$report->save();
return $report->toArray();
}