wikipoints/models/Trips.php

45 lines
817 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class Trips extends Model
{
const STATUS_PRIVATE = 'PRIVATE';
const STATUS_PUBLIC = 'PUBLIC';
const STATUS_DELETED = 'DELETED';
function __construct($fromArray = array())
{
$this->_tableName_ = 'trips';
parent::__construct($fromArray);
$this->setRelation('tracks', 'id', 'Tracks', 'tripId', self::TO_MANY, '`id` ASC');
}
static function model()
{
return new self();
}
function distance()
{
return Geo::formatedDistance($this->distance);
}
/**
* Считает/пересчитывает длину трека и всех его фрагментов
*/
function calculateDist()
{
$tracks = $this->tracks;
$distance = 0;
foreach ($tracks as $track) {
$distance += $track->calculateDist();
}
$this->distance = $distance;
$this->save();
return $distance;
}
}