'accounts', 'contact_id'=>'contacts', 'opportunity_id'=>'opportunities', 'email_id' => 'emails', ); ////////////////////////////////////////////////////////////////// // METHODS ////////////////////////////////////////////////////////////////// /** * */ function Project() { parent::SugarBean(); } /** * overriding the base class function to do a join with users table */ /** * */ function fill_in_additional_detail_fields() { parent::fill_in_additional_detail_fields(); $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id); //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id); //$this->total_actual_effort = $this->_get_total_actual_effort($this->id); } /** * */ function fill_in_additional_list_fields() { parent::fill_in_additional_list_fields(); $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id); //$this->total_estimated_effort = $this->_get_total_estimated_effort($this->id); //$this->total_actual_effort = $this->_get_total_actual_effort($this->id); } /** * Save changes that have been made to a relationship. * * @param $is_update true if this save is an update. */ function save_relationship_changes($is_update, $exclude=array()) { parent::save_relationship_changes($is_update, $exclude); $new_rel_id = false; $new_rel_link = false; //this allows us to dynamically relate modules without adding it to the relationship_fields array if(!empty($_REQUEST['relate_id']) && !in_array($_REQUEST['relate_to'], $exclude) && $_REQUEST['relate_id'] != $this->id){ $new_rel_id = $_REQUEST['relate_id']; $new_rel_relname = $_REQUEST['relate_to']; if(!empty($this->in_workflow) && !empty($this->not_use_rel_in_req)) { $new_rel_id = $this->new_rel_id; $new_rel_relname = $this->new_rel_relname; } $new_rel_link = $new_rel_relname; //Try to find the link in this bean based on the relationship foreach ( $this->field_defs as $key => $def ) { if (isset($def['type']) && $def['type'] == 'link' && isset($def['relationship']) && $def['relationship'] == $new_rel_relname) { $new_rel_link = $key; } } if ($new_rel_link == 'contacts') { $accountId = $this->db->getOne('SELECT account_id FROM accounts_contacts WHERE contact_id=' . $this->db->quoted($new_rel_id)); if ($accountId !== false) { if($this->load_relationship('accounts')){ $this->accounts->add($accountId); } } } } } /** * */ function _get_total_estimated_effort($project_id) { $return_value = ''; $query = 'SELECT SUM('.$this->db->convert('estimated_effort', "IFNULL", 0).') total_estimated_effort'; $query.= ' FROM project_task'; $query.= " WHERE parent_id='{$project_id}' AND deleted=0"; $result = $this->db->query($query,true," Error filling in additional detail fields: "); $row = $this->db->fetchByAssoc($result); if($row != null) { $return_value = $row['total_estimated_effort']; } return $return_value; } /** * */ function _get_total_actual_effort($project_id) { $return_value = ''; $query = 'SELECT SUM('.$this->db->convert('actual_effort', "IFNULL", 0).') total_actual_effort'; $query.= ' FROM project_task'; $query.= " WHERE parent_id='{$project_id}' AND deleted=0"; $result = $this->db->query($query,true," Error filling in additional detail fields: "); $row = $this->db->fetchByAssoc($result); if($row != null) { $return_value = $row['total_actual_effort']; } return $return_value; } /** * */ function get_summary_text() { return $this->name; } /** * */ function build_generic_where_clause ($the_query_string) { $where_clauses = array(); $the_query_string = $GLOBALS['db']->quote($the_query_string); array_push($where_clauses, "project.name LIKE '%$the_query_string%'"); $the_where = ''; foreach($where_clauses as $clause) { if($the_where != '') $the_where .= " OR "; $the_where .= $clause; } return $the_where; } function get_list_view_data() { $field_list = $this->get_list_view_array(); $field_list['USER_NAME'] = empty($this->user_name) ? '' : $this->user_name; $field_list['ASSIGNED_USER_NAME'] = $this->assigned_user_name; return $field_list; } function bean_implements($interface){ switch($interface){ case 'ACL':return true; } return false; } function create_export_query(&$order_by, &$where, $relate_link_join='') { $custom_join = $this->custom_fields->getJOIN(true, true,$where); if($custom_join) $custom_join['join'] .= $relate_link_join; $query = "SELECT project.*, users.user_name as assigned_user_name "; if($custom_join){ $query .= $custom_join['select']; } $query .= " FROM project "; if($custom_join){ $query .= $custom_join['join']; } $query .= " LEFT JOIN users ON project.assigned_user_id=users.id "; $where_auto = " project.deleted=0 "; if($where != "") $query .= "where ($where) AND ".$where_auto; else $query .= "where ".$where_auto; if(!empty($order_by)){ //check to see if order by variable already has table name by looking for dot "." $table_defined_already = strpos($order_by, "."); if($table_defined_already === false){ //table not defined yet, define accounts to avoid "ambigous column" SQL error $query .= " ORDER BY $order_by"; }else{ //table already defined, just add it to end of query $query .= " ORDER BY $order_by"; } } return $query; } function getAllProjectTasks(){ $projectTasks = array(); $query = "SELECT * FROM project_task WHERE project_id = '" . $this->id. "' AND deleted = 0 ORDER BY project_task_id"; $result = $this->db->query($query,true,"Error retrieving project tasks"); $row = $this->db->fetchByAssoc($result); while ($row != null){ $projectTaskBean = new ProjectTask(); $projectTaskBean->id = $row['id']; $projectTaskBean->retrieve(); array_push($projectTasks, $projectTaskBean); $row = $this->db->fetchByAssoc($result); } return $projectTasks; } } ?>