예제 #1
0
 /**
  * 
  * @param array $args
  *	project
  *	message
  * @return array
  */
 function getList($args = array())
 {
     if (isset($args['project'])) {
         $this->db->join('project_document', "project_document.document = document.id AND project_document.project = {$args['project']}", 'inner');
     }
     if (isset($args['message'])) {
         $this->db->join('message_document', "message_document.document = document.id AND message_document.message = {$args['message']}", 'inner');
     }
     return parent::getList($args);
 }
예제 #2
0
 function __construct()
 {
     parent::__construct();
     $this->table = 'company';
     $this->recognize($this->input->server('SERVER_NAME'));
     //获取存在数据库中的公司配置项
     $this->db->from('company_config')->where('company', $this->id);
     $config = array_sub($this->db->get()->result_array(), 'value', 'name');
     array_walk($config, function (&$value) {
         $decoded = json_decode($value, true);
         if (!is_null($decoded)) {
             $value = $decoded;
         }
     });
     $this->config->company = $config;
 }
예제 #3
0
 function getList(array $args = array())
 {
     $args['company'] = $args['display'] = false;
     return parent::getList($args);
 }
예제 #4
0
    /**
     * 继承自SS_Model::getList(),具有基本的type,label,orderby和limit配置功能
     * @param array $args:
     * name string 匹配部分people.name, people.abbreviation, people.name_en
     * 
     * is_team=>bool
     * 
     * in_project int 只获得指定事务中的人员列表
     * 	project_people_type 指定事务,特定关联类型
     * 	project_people_role 指定事务,特定角色
     * 
     * in_same_project_with, int or array, people.id 有相同的相关案件的人员
     * 
     * is_staff
     * 
     * 人员 - 人员关系查找
     * 直接关系
     * is_relative_of =>user_id people_relationship 人员关联,根据本人获得相关人
     * has_relative_like => user_id people_relationship 人员关联,根据相关人获得本人
     * 间接关系
     * is_secondary_relative_of 右侧相关人的右侧相关人
     *	~_team bool 中间相关人是团队,下同
     * is_both_relative_with 右侧相关人的左侧相关人
     *	~_team
     * has_common_relative_with 左侧相关人的右侧相关人
     *	~_team
     * has_secondary_relative_like 左侧相关人的左侧相关人
     *	~_team
     * 
     * 团队 - 人员关系查找
     * in_team => array or int, is_relative_of的别名
     * team_leader_of => array or int team(s)
     * 
     */
    function getList($args = array())
    {
        $this->db->select('
			people.id,people.type,people.name,people.phone,people.email,
			IF(people.abbreviation IS NULL,people.name,people.abbreviation) AS abbreviation,
			people.uid,people.time,people.time_insert
		', false);
        if (isset($args['name'])) {
            $args['name'] = $this->db->escape_like_str($args['name']);
            $this->db->where("(people.name LIKE '%{$args['name']}%' \tOR people.abbreviation LIKE '%{$args['name']}%' OR people.name_en LIKE '%{$args['name']}%')", NULL, false);
            unset($args['name']);
        }
        if (isset($args['is_team'])) {
            if ($args['is_team']) {
                $this->db->where("people.id IN (SELECT id FROM people INNER JOIN team USING (id) WHERE people.company = {$this->company->id})", NULL, false);
            } else {
                $this->db->where("people.id NOT IN (SELECT id FROM people INNER JOIN team USING (id) WHERE people.company = {$this->company->id})", NULL, false);
            }
        }
        if (isset($args['in_project'])) {
            $this->db->select('project_people.id AS relationship_id,GROUP_CONCAT(project_people.role) AS role, project_people.weight', false)->join('project_people', "project_people.people = people.id AND project_people.project{$this->db->escape_int_array($args['in_project'])}", 'inner')->group_by('project_people.people');
            if (isset($args['project_people_type'])) {
                $this->db->where('project_people.type', $args['project_people_type']);
            }
            if (isset($args['project_people_role'])) {
                $this->db->where('project_people.role', $args['project_people_role']);
            }
        }
        if (isset($args['in_same_project_with'])) {
            $this->db->where("\n\t\t\t\tpeople.id IN (\n\t\t\t\t\tSELECT people FROM project_people WHERE `project` IN (\n\t\t\t\t\t\tSELECT `project` FROM project_people WHERE people{$this->db->escape_int_array($args['in_same_project_with'])}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t", NULL, false);
        }
        if (isset($args['in_team'])) {
            $args['is_relative_of'] = $args['in_team'];
            unset($args['in_team']);
        }
        if (isset($args['is_staff'])) {
            if ($args['is_staff']) {
                $this->db->join('staff', 'staff.id = people.id', 'inner');
            } else {
                $this->db->where('people.id NOT IN (SELECT id FROM staff)');
            }
        }
        if (isset($args['team_leader_of'])) {
            $this->db->where("people.id IN (SELECT leader FROM team WHERE id " . $this->db->escape_int_array($args['team_leader_of']) . ")", NULL, false);
        }
        if (isset($args['is_relative_of'])) {
            $this->db->join("people_relationship", "people.id = people_relationship.relative AND people_relationship.people{$this->db->escape_int_array($args['is_relative_of'])}", 'inner')->select('people_relationship.relation, people_relationship.accepted, people_relationship.time relationship_time');
            if (isset($args['accepted'])) {
                $this->db->where('people_relationship.accepted', $args['accepted']);
            }
            if (isset($args['is_on'])) {
                $this->db->where('people_relationship.is_on', $args['is_on']);
            }
        }
        if (isset($args['has_relative_like'])) {
            $this->db->join('people_relationship', "people.id = people_relationship.people AND people_relationship.relative{$this->db->escape_int_array($args['has_relative_like'])}", 'inner')->select('people_relationship.relation, people_relationship.accepted, people_relationship.time relationship_time');
            if (isset($args['accepted'])) {
                $this->db->where('people_relationship.accepted', $args['accepted']);
            }
            if (isset($args['is_on'])) {
                $this->db->where('people_relationship.is_on', $args['is_on']);
            }
        }
        if (isset($args['is_secondary_relative_of'])) {
            $this->db->where("people.id IN (SELECT relative FROM people_relationship WHERE people IN (SELECT relative FROM people_relationship" . (empty($args['is_secondary_relative_of_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.relative') . " WHERE people{$this->db->escape_int_array($args['is_secondary_relative_of'])}))");
        }
        if (isset($args['is_both_relative_with'])) {
            $this->db->where("people.id IN (SELECT relative FROM people_relationship WHERE people IN (SELECT people FROM people_relationship" . (empty($args['is_both_relative_with_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.people') . " WHERE relative{$this->db->escape_int_array($args['is_both_relative_with'])}))");
        }
        if (isset($args['has_common_relative_with'])) {
            $this->db->where("people.id IN (SELECT people FROM people_relationship WHERE relative IN (SELECT relative FROM people_relationship" . (empty($args['has_common_relative_with_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.relative') . " WHERE people{$this->db->escape_int_array($args['has_common_relative_with'])}))");
        }
        if (isset($args['has_secondary_relative_like'])) {
            $this->db->where("people.id IN (SELECT people FROM people_relationship WHERE relative IN (SELECT people FROM people_relationship" . (empty($args['has_secondary_relative_like_team']) ? '' : ' INNER JOIN team ON team.id = people_relationship.people') . " WHERE relative{$this->db->escape_int_array($args['has_secondary_relative_like'])}))");
        }
        return parent::getList($args);
    }
예제 #5
0
 function add(array $data = array())
 {
     foreach (array('account', 'received', 'people') as $field) {
         if (empty($data[$field])) {
             unset($data[$field]);
         }
     }
     $insert_id = parent::add($data);
     if (!isset($data['account'])) {
         $this->db->update('account', array('account' => $insert_id), array('id' => $insert_id));
     } else {
         $account = $this->db->select('project, team, subject')->from('account')->where('id', intval($data['account']))->limit(1)->get()->row();
         $this->db->update('account', $account, array('id' => $insert_id));
     }
     if (isset($data['received']) && $data['received']) {
     }
     return $insert_id;
 }
예제 #6
0
 /**
  * @param array $args
  * people
  *	role
  * num
  * active
  * is_relative_of
  * before
  * time_contract
  *	from
  *	to
  * first_contact
  *	from
  *	to
  * count
  * group
  *	team
  *	people
  *		role
  * 
  */
 function getList(array $args = array())
 {
     if (isset($args['people'])) {
         $where = "project.id IN (SELECT project FROM project_people WHERE people{$this->db->escape_int_array($args['people'])}";
         if (isset($args['role'])) {
             $where .= " AND role = '{$args['role']}'";
         }
         $where .= ')';
         $this->db->where($where, NULL, FALSE);
     }
     if (isset($args['people_is_relative_of'])) {
         $where = "project.id IN (SELECT project FROM project_people WHERE people IN (SELECT relative FROM people_relationship WHERE people{$this->db->escape_int_array($args['people_is_relative_of'])})";
         if (isset($args['role'])) {
             $where .= " AND role = '{$args['role']}'";
         }
         $where .= ')';
         $this->db->where($where, NULL, FALSE);
     }
     if (isset($args['people_has_relative_like'])) {
         $where = "project.id IN (SELECT project FROM project_people WHERE people IN (SELECT people FROM people_relationship WHERE relative{$this->db->escape_int_array($args['people_has_relative_like'])})";
         if (isset($args['role'])) {
             $where .= " AND role = '{$args['role']}'";
         }
         $where .= ')';
         $this->db->where($where, NULL, FALSE);
     }
     if (isset($args['num'])) {
         $this->db->like('project.num', $args['num']);
     }
     if (isset($args['active'])) {
         $this->db->where('project.active', (bool) $args['active']);
     }
     if (isset($args['is_relative_of'])) {
         $this->db->select('project.*')->select('relationship.relation')->join('project_relationship relationship', "relationship.relative = project.id", 'inner')->where('relationship.project', intval($args['is_relative_of']));
     }
     if (isset($args['before'])) {
         $this->db->where('project.id <', $args['before']);
     }
     foreach (array('first_contact', 'time_contract', 'end') as $date_field) {
         if (isset($args[$date_field]['from']) && $args[$date_field]['from']) {
             $this->db->where("TO_DAYS(project.{$date_field}) >= TO_DAYS('{$args[$date_field]['from']}')", NULL, FALSE);
         }
         if (isset($args[$date_field . '/from']) && $args[$date_field . '/from']) {
             $this->db->where("TO_DAYS(project.{$date_field}) >= TO_DAYS('{$args[$date_field . '/from']}')", NULL, FALSE);
         }
         if (isset($args[$date_field]['to']) && $args[$date_field]['to']) {
             $this->db->where("TO_DAYS(project.{$date_field}) <= TO_DAYS('{$args[$date_field]['to']}')", NULL, FALSE);
         }
         if (isset($args[$date_field . '/to']) && $args[$date_field . '/to']) {
             $this->db->where("TO_DAYS(project.{$date_field}) <= TO_DAYS('{$args[$date_field . '/to']}')", NULL, FALSE);
         }
     }
     if (isset($args['group_by'])) {
         if ($args['group_by'] === 'team') {
             $this->db->join('team', 'team.id = project.team', 'inner')->group_by('project.team')->select('team.id `team`, team.name `team_name`');
         }
         if ($args['group_by'] === 'people') {
             $this->db->join('project_people', 'project_people.project = project.id', 'inner')->join('people', 'people.id = project_people.people', 'inner')->group_by('project_people.people')->select('people.name AS people_name, people.id AS people');
             if (isset($args['role'])) {
                 $this->db->where('project_people.role', $args['role']);
             }
         }
     }
     return parent::getList($args);
 }
예제 #7
0
 function update($schedule_id, $data)
 {
     $schedule_id = intval($schedule_id);
     //attemp to convert date string to timestamp
     foreach (array('start', 'end', 'deadline') as $timepoint) {
         if (isset($data[$timepoint])) {
             if (strtotime($data[$timepoint])) {
                 $data[$timepoint] = strtotime($data[$timepoint]);
             }
         }
     }
     foreach (array('start', 'end', 'deadline', 'hours_own') as $var) {
         if (isset($data[$var])) {
             if ($data[$var] === '') {
                 $data[$var] = NULL;
             }
         }
     }
     //generate hours by start timestamp and end timestamp
     if (isset($data['start']) && isset($data['end'])) {
         $data['hours_own'] = round(($data['end'] - $data['start']) / 3600, 2);
     }
     if (array_key_exists('hours_own', $data) && is_null($data['hours_own'])) {
         $data['hours_own'] = $data['end'] = NULL;
     }
     $return = parent::update($schedule_id, $data);
     //generate end timestamp by start timestamp end hours
     if (isset($data['hours_own']) && is_numeric($data['hours_own'])) {
         $this->db->where('id', $schedule_id)->set('end', "start + 3600 * {$data['hours_own']}", false)->update('schedule');
     }
     return $return;
 }
예제 #8
0
 function __construct()
 {
     parent::__construct();
 }