35 lines
594 B
PHP
35 lines
594 B
PHP
<?php
|
|
|
|
class Article extends Model
|
|
{
|
|
|
|
function __construct($fromArray = array())
|
|
{
|
|
$this->_tableName_ = 'articles';
|
|
parent::__construct($fromArray);
|
|
$this->setRelation('authorUser', 'author', 'User', 'id', self::TO_ONE);
|
|
}
|
|
|
|
static function model()
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
public function getImg($size = 'small')
|
|
{
|
|
$imgId = (int)$this->photoId;
|
|
if ($imgId) {
|
|
|
|
$img = ArticlePhotos::model()->getByPK($imgId);
|
|
|
|
if ($img) {
|
|
return '/photos/articles/' . $size . '/' . $img->name;
|
|
}
|
|
|
|
}
|
|
|
|
return $size == 'small' ? '/img/noPhoto200150.png' : '/img/logo.png';
|
|
}
|
|
|
|
}
|