TASK.PHP :
<?php
/**
* This is the model class for table "task".
*
* The followings are the available columns in table 'task':
* @property integer $id
* @property string $content
* @property string $deadline
* @property string $created
* @property string $finished
* @property integer $author_id
* @property integer $user_id
* @property integer $project_id
*
* The followings are the available model relations:
* @property Message[] $messages
* @property Project $project
* @property User $user
*/
class Task extends CActiveRecord {
public $user_name;
public $image;
public $file;
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Task the static model class
*/
public static function model($className = __CLASS__) {
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName() {
return 'task';
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
// array('created, finished, author_id, user_id, project_id', 'required'),
array('priorytet, author_id, deadline, user_id, project_id', 'required'),
array('author_id, project_id', 'numerical', 'integerOnly' => true),
array('content', 'length', 'max' => 400),
array('deadline, created, finished', 'length', 'max' => 45),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('[b]user_name[/b], id, content, deadline, created, finished, author_id, user_id, project_id', 'safe', 'on' => 'search'),
array('image', 'file', 'types' => 'jpg, gif, png, jpeg', 'allowEmpty' => TRUE),
array('file', 'file', 'types' => 'zip, rar', 'allowEmpty' => true),
);
}
/**
* @return array relational rules.
*/
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'messages' => array(self::HAS_MANY, 'Message', 'task_id'),
'project' => array(self::BELONGS_TO, 'Project', 'project_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
'author' => array(self::BELONGS_TO, 'User', 'author_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'id' => 'ID',
'content' => 'Nazwa',
'deadline' => 'Czas realizacji',
'created' => 'Stworzony',
'finished' => 'Zakończony',
'author_id' => 'Autor',
'user_id' => 'Użytkownik',
'project_id' => 'Projekt',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('content', $this->content, true);
$criteria->compare('deadline', $this->deadline, true);
$criteria->compare('created', $this->created, true);
$criteria->compare('finished', $this->finished, true);
$criteria->compare('author_id', $this->author_id);
$criteria->compare('user_id', $this->user_id);
$criteria->compare('project_id', $this->project_id);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
// public function getProjectTasks() {
//
// $select = Yii::app()->db->createCommand()
// ->select(array('task.*', 'u.name as user_name', 'a.name as author_name'))
// ->from('task')
// ->join('user u', 'u.id=task.user_id')
// ->join('user a', 'a.id=task.author_id');
//
//
//
// return $select->queryAll();
// }
public function searchWithUser() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->with = 'user'; //dla jednej tabeli
$criteria->with = array('user', 'author', 'project'); //dla kilku tabel
$criteria->compare('id', $this->id);
$criteria->compare('content', $this->content, true);
$criteria->compare('deadline', $this->deadline, true);
$criteria->compare('created', $this->created, true);
$criteria->compare('finished', $this->finished, true);
$criteria->compare('author_id', $this->author_id);
$criteria->compare('user_id', $this->user_id);
$criteria->compare('project_id', $this->project_id);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
public function getPriorytet() {
if ($this->priorytet == 2)
echo '<div id="priorytet" style="background-position:-50px 0;"></div>';
if ($this->priorytet == 3)
echo '<div id="priorytet" style="background-position:-25px 0;"></div>';
if ($this->priorytet == 4)
echo '<div id="priorytet" style="background-position:1px 0;"></div>';
return $this;
}
}