示例#1
0
 /**
  * Get a Project Object by ID
  * 
  * @param mixed $project_id
  * @return Application_Model_Project
  */
 public static function GetProjectInfo($project_id)
 {
     $db = Zend_Db_Table::getDefaultAdapter();
     $sql = "SELECT \n        sp.value as status_progress_value, sp.display_static as status_value_display,\n        p.*, \n        c.name as done_for_corporation_display, c.po_required,\n        dfw.name as done_for_workgroup_display, dfw.access_pct_completed,\n        dbw.name as done_by_workgroup_display,\n        loi.industry AS location_owner_industry_display,\n        s.title as stage_title, \n        cu.firstname cu_firstname, cu.lastname cu_lastname, cu.middlename cu_middlename, \n        mu.firstname mu_firstname, mu.lastname mu_lastname, mu.middlename mu_middlename, \n        su.firstname su_firstname, su.lastname su_lastname, su.middlename su_middlename,\n        acq_mu.firstname acq_mu_firstname, acq_mu.lastname acq_mu_lastname, acq_mu.middlename acq_mu_middlename,\n        le.firstname acq_le_firstname, le.lastname acq_le_lastname, le.middlename acq_le_middlename,\n        pm.firstname pm_firstname, pm.lastname pm_lastname, pm.middlename pm_middlename,\n        pe.firstname pe_firstname, pe.lastname pe_lastname, pe.middlename pe_middlename,\n        fsl.firstname fsl_firstname, fsl.lastname fsl_lastname, fsl.middlename fsl_middlename,\n        bt.title bill_type_display, bt.internal bill_type_internal, \n        pp.display_static probability_display,\n        sched.firstname sched_firstname, sched.lastname sched_lastname, sched.middlename sched_middlename,\n        acct.firstname acct_firstname, acct.lastname acct_lastname, acct.middlename acct_middlename,\n        pit.name acct_invoice_type_name, \n        pbt.building_type as building_type_display,\n        poc.firstname as poc_firstname, poc.middlename as poc_middlename, poc.lastname as poc_lastname,\n        epc.display acq_estimating_percent_complete_display,\n        CASE WHEN pu.project_id IS NULL THEN 0 ELSE 1 END `on_project_team`,\n        IFNULL(pu.favorite, 0) favorite,\n        bts.state AS acct_billing_state_state, bts.state_abbr AS acct_billing_state_abbr,\n        pt.display AS acct_project_type_display\n        FROM projects p \n        INNER JOIN project_stages s ON p.stage_id=s.stage_id\n        INNER JOIN corporations c ON c.corporation_id = p.done_for_corporation\n        INNER JOIN locations l ON l.location_id = p.done_at_location\n        INNER JOIN corporations lo ON lo.corporation_id = l.corporation_id\n        INNER JOIN corporation_industry loi ON loi.corporation_industry_id = lo.industry\n        INNER JOIN workgroups dfw ON dfw.workgroup_id = p.done_for_workgroup\n        INNER JOIN workgroups dbw ON dbw.workgroup_id = p.done_by_workgroup\n        LEFT JOIN users cu ON p.created_by=cu.user_id \n        LEFT JOIN users mu ON p.modified_by=mu.user_id \n        LEFT JOIN users su ON p.acq_sales_person = su.user_id\n        LEFT JOIN users acq_mu ON acq_mu.user_id = p.acq_modified_by\n        LEFT JOIN users sched ON p.schedule_modified_by = sched.user_id\n        LEFT JOIN users acct ON p.acct_modified_by = acct.user_id\n        LEFT JOIN users le ON le.user_id = p.acq_estimator\n        LEFT JOIN users pm ON pm.user_id = p.acct_project_manager \n        LEFT JOIN users pe ON pe.user_id = p.acct_project_engineer \n        LEFT JOIN users fsl ON fsl.user_id = p.acct_field_staff_leader \n        LEFT JOIN project_bill_types bt ON bt.bill_type = p.bill_type\n        LEFT JOIN project_percentages_probabilities pp ON pp.project_probability_id = p.acq_probability \n        LEFT JOIN project_invoice_types pit ON pit.project_invoice_type_id = p.acct_invoice_type\n        LEFT JOIN project_building_types pbt ON pbt.building_type_id = p.acq_building_type\n        LEFT JOIN users poc ON poc.user_id = p.point_of_contact\n        LEFT JOIN project_percentages_estimating epc ON p.acq_estimating_percent_complete = epc.project_estimating_id\n        LEFT JOIN project_users pu ON p.project_id = pu.project_id AND pu.user_id = ?\n        LEFT JOIN states bts ON bts.state_id = p.acct_billing_state\n        LEFT JOIN project_types pt ON pt.id = p.acct_project_type\n        \n        -- Project Tasks and the last history entry for the overall \n        LEFT JOIN project_tasks ptasks ON ptasks.project_id = p.project_id AND ptasks.is_overall = 1\n        LEFT JOIN (select MAX(project_task_history_id) project_task_history_id, project_task_id FROM project_task_history GROUP BY project_task_id) ptaskhist_max ON ptasks.project_task_id = ptaskhist_max.project_task_id\n        LEFT JOIN project_task_history ptaskhist ON ptaskhist_max.project_task_history_id = ptaskhist.project_task_history_id\n        LEFT JOIN project_percentages_task sp ON sp.project_percentage_id = IFNULL(ptaskhist.project_percentage_id, ?)\n        -- End Project Tasks\n        \n        WHERE p.project_id = ?";
     $object = $db->fetchRow($sql, array(ProNav_Auth::getUserID(), Application_Model_ProgressOption::STATUS_TASK_NOT_STARTED, $project_id));
     $project = new Application_Model_Project();
     if ($object) {
         foreach ($object as $property => $value) {
             $project->{$property} = $value;
         }
     }
     $project->DoneAtLocation = Application_Model_Locations::getLocation($object->done_at_location);
     $project->DoneForCorporation = new Application_Model_Corporation($object->done_for_corporation, $object->done_for_corporation_display);
     $project->DoneForCorporation->po_required = $object->po_required;
     $project->DoneForWorkgroup = new Application_Model_Workgroup($object->done_for_workgroup, $object->done_for_workgroup_display);
     $project->DoneByWorkgroup = new Application_Model_Workgroup($object->done_by_workgroup, $object->done_by_workgroup_display);
     $project->CreatedBy = new Application_Model_User($object->created_by, $object->cu_firstname, $object->cu_lastname);
     $project->PointContact = new Application_Model_User($object->point_of_contact, $object->poc_firstname, $object->poc_lastname);
     $project->Salesman = new Application_Model_User($object->acq_sales_person, $object->su_firstname, $object->su_lastname);
     $project->ModifiedBy = new Application_Model_User($object->modified_by, $object->mu_firstname, $object->mu_lastname);
     $project->AcqModifiedBy = new Application_Model_User($object->acq_modified_by, $object->acq_mu_firstname, $object->acq_mu_lastname);
     $project->ScheduledBy = new Application_Model_User($object->schedule_modified_by, $object->sched_firstname, $object->sched_lastname);
     $project->AccountingBy = new Application_Model_User($object->acct_modified_by, $object->acct_firstname, $object->acct_lastname);
     $project->Estimator = new Application_Model_User($object->acq_estimator, $object->acq_le_firstname, $object->acq_le_lastname);
     $project->ProjectManager = new Application_Model_User($object->acct_project_manager, $object->pm_firstname, $object->pm_lastname);
     $project->ProjectEngineer = new Application_Model_User($object->acct_project_engineer, $object->pe_firstname, $object->pe_lastname);
     $project->FieldStaffLeader = new Application_Model_User($object->acct_field_staff_leader, $object->fsl_firstname, $object->fsl_lastname);
     $project->BookingProbability = new Application_Model_ProgressOption($object->acq_probability, 0, $object->probability_display);
     $project->BillType = new stdClass();
     $project->BillType->bill_type = $object->bill_type;
     $project->BillType->display = $object->bill_type_display;
     $project->BillType->internal = $object->bill_type_internal;
     if (property_exists($object, 'acct_invoice_state')) {
         $project->InvoiceState = new stdClass();
         $project->InvoiceState->invoice_state = $object->acct_invoice_state;
         $project->InvoiceState->name = $object->acct_invoice_state_name;
     }
     if (property_exists($object, 'acct_invoice_type')) {
         $project->InvoiceType = new stdClass();
         $project->InvoiceType->invoice_type = $object->acct_invoice_type;
         $project->InvoiceType->name = $object->acct_invoice_type_name;
     }
     return $project;
 }
 private function getLocationsForCorp($corporation_id)
 {
     $locations = Application_Model_Locations::getCorporationLocations($corporation_id);
     return ProNav_Utils::getSelectOptions($locations, 'location_id', 'name');
 }