56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 21/12/2017
|
|
* Time: 18:05
|
|
*/
|
|
|
|
|
|
class Project extends BaseModel {
|
|
|
|
protected $table = "projects";
|
|
|
|
public function offers()
|
|
{
|
|
return $this->hasMany( 'Offer' );
|
|
}
|
|
|
|
public function projectleader()
|
|
{
|
|
return $this->belongsTo( 'User', 'projectleader_id' );
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo( 'Customer' );
|
|
}
|
|
|
|
public static function getAllProjects( $archive = 'F' )
|
|
{
|
|
$projects = Project::with( [
|
|
'projectleader' => function ( $q ) {
|
|
$q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" );
|
|
}] )
|
|
->with( [
|
|
'offers' => function ( $q ) {
|
|
$q->whereArchive( 'F' )
|
|
->with( [
|
|
'payment' => function ( $q ) {
|
|
$q->selectRaw( '*' );
|
|
}] );
|
|
}] )
|
|
->with( 'customer' );
|
|
|
|
if ( $archive == 'F' ) $projects = $projects->whereArchive( 'F' );
|
|
|
|
$projects = $projects->get();
|
|
|
|
return $projects;
|
|
}
|
|
|
|
public static function removeProject( $projectID )
|
|
{
|
|
Project::whereId($projectID)->delete();
|
|
}
|
|
} |