/** * Prepare HTML field templates for each dataTable column. * * @param string column name * @param object of item * @return string HTML template for propper field */ public function getDataTableFieldTemplate($column, $item) { switch ($column) { case 'id': $template = '<input type="checkbox" class="export" name="ids[]" value="' . $item->id . '" />'; break; case 'avatar': if (isset($item->avatar) && $item->avatar) { $template = '<img id="avatar_img_' . $item->id . '" data-item-type="people" data-item-id="' . $item->id . '" class="avatar" src="' . JURI::base() . 'src/Cobalt/media/avatars/' . $item->avatar . '"/>'; } else { $template = '<img id="avatar_img_' . $item->id . '" data-item-type="people" data-item-id="' . $item->id . '" class="avatar" src="' . JURI::base() . 'src/Cobalt/media/images/person.png' . '"/>'; } break; case 'name': $template = '<a href="' . RouteHelper::_('index.php?view=people&layout=person&id=' . $item->id) . '">' . $item->first_name . ' ' . $item->last_name . '</a>'; break; case 'company_name': $template = '<a href="' . RouteHelper::_('index.php?view=companies&layout=company&id=' . $item->company_id) . '">' . $item->company_name . '</a>'; break; case 'owner': if (!isset($item->owner_last_name) || !$item->owner_last_name) { $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $me = array(array('label' => TextHelper::_('COBALT_ME'), 'value' => UsersHelper::getLoggedInUser()->id)); $users = UsersHelper::getUsers(null, true); $users = array_merge($me, $users); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="oerson_owner_' . $item->id . '_link">'; $template .= $item->owner_first_name . ' ' . $item->owner_last_name; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_status_' . $item->id . '" role="menu">'; if (isset($users) && count($users)) { foreach ($users as $id => $user) { $template .= ' <li>'; $template .= ' <a href="#" class="owner_select dropdown_item" data-field="owner_id" data-item="person" data-item-id="' . $item->id . '" data-value="' . $user['value'] . '">'; $template .= ' <span class="person-owner-' . OutputFilter::stringURLUnicodeSlug($user['value']) . '">' . $user['label'] . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'status_name': if (!isset($item->status_id) || !$item->status_id) { $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $statuses = PeopleHelper::getStatusList(); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_stage_' . $item->id . '_link">'; $template .= ' <span class="person-status-' . $item->status_name . '">' . $item->status_name . '</span>'; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_stage_' . $item->id . '" role="menu">'; if (isset($statuses) && count($statuses)) { foreach ($statuses as $id => $status) { $template .= ' <li>'; $template .= ' <a href="#" class="status_select dropdown_item" data-field="status_id" data-item="people" data-item-id="' . $item->id . '" data-value="' . $status['id'] . '">'; $template .= ' <span class="person-status-' . OutputFilter::stringURLUnicodeSlug($status['id']) . '">' . $status['name'] . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'source_name': if (!isset($item->source_id) || !$item->source_id) { $item->source_name = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $sources = DealHelper::getSources(null, true); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="person_source_' . $item->id . '_link">'; $template .= ' <span class="person-source-' . $item->source_name . '">' . $item->source_name . '</span>'; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="person_source_' . $item->id . '" role="menu">'; if (isset($sources) && count($sources)) { foreach ($sources as $id => $name) { $template .= ' <li>'; $template .= ' <a href="#" class="source_select dropdown_item" data-field="source_id" data-item="people" data-item-id="' . $item->id . '" data-value="' . $id . '">'; $template .= ' <span class="person-source-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'type': if (!isset($item->type) || !$item->type) { $item->type = TextHelper::_('COBALT_CLICK_TO_EDIT'); } $types = PeopleHelper::getPeopleTypes(false); $template = '<div class="dropdown">'; $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="person_type_' . $item->id . '_link">'; $template .= $item->type; $template .= ' </a>'; $template .= ' <ul class="dropdown-menu" aria-labelledby="person_type_' . $item->id . '" role="menu">'; if (isset($types) && count($types)) { foreach ($types as $id => $name) { $template .= ' <li>'; $template .= ' <a href="#" class="type_select dropdown_item" data-field="type" data-item="people" data-item-id="' . $item->id . '" data-value="' . $id . '">'; $template .= ' <span class="person-type-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>'; $template .= ' </a>'; $template .= ' </li>'; } } $template .= ' </ul>'; $template .= ' </div>'; break; case 'notes': // $template = '<a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_NOTES').'" data-placement="bottom" class="btn" href="#" onclick="Cobalt.openNoteModal('.$item->id.', \'people\');"><i class="glyphicon glyphicon-file"></i></a>'; $template = ''; // @TODO: Implement notes modal break; case 'address': $template = $item->work_city . '<br>' . $item->work_state . '<br>' . $item->work_zip . '<br>' . $item->work_country; break; case 'created': $template = DateHelper::formatDate($item->created); break; case 'modified': $template = DateHelper::formatDate($item->modified); break; default: if (isset($column) && isset($item->{$column})) { $template = $item->{$column}; } else { $template = ''; } break; } return $template; }
public function render() { $app = JFactory::getApplication(); ///retrieve task list from model $model = new PeopleModel(); $state = $model->getState(); //session data $session = JFactory::getSession(); $user_id = UsersHelper::getUserId(); $team_id = UsersHelper::getTeamId(); $member_role = UsersHelper::getRole(); $people_type_name = $session->get('people_type_filter'); $user = $session->get('people_user_filter'); $team = $session->get('people_team_filter'); $stage = $session->get('people_stage_filter'); $tag = $session->get('people_tag_filter'); $status = $session->get('people_status_filter'); //load java $document = JFactory::getDocument(); $document->addScript(JURI::base() . 'src/Cobalt/media/js/people_manager.js'); //get list of people $people = $model->getPeople(); $person = array(); //Pagination $this->pagination = $model->getPagination(); //determine if we are editing an existing person entry if ($app->input->get('id')) { //grab deal object $person = $people[0]; if (is_null($person['id'])) { $app->redirect(RouteHelper::_('index.php?view=people'), TextHelper::_('COBALT_NOT_AUTHORIZED')); } $person['header'] = TextHelper::_('COBALT_EDIT') . ' ' . $person['first_name'] . ' ' . $person['last_name']; } else { //else we are creating a new entry $person = array(); $person['id'] = ''; $person['first_name'] = ""; $person['last_name'] = ""; $person['company_id'] = $app->input->get('company_id') ? $app->input->get('company_id') : null; $person['deal_id'] = $app->input->get('deal_id') ? $app->input->get('deal_id') : null; //get company name to prefill data on page and hidden fields if ($person['company_id']) { $company = CompanyHelper::getCompany($person['company_id']); $person['company_name'] = $company[0]['name']; $person['company_id'] = $company[0]['id']; } //get deal name to prefill data on page and hidden fields if ($person['deal_id']) { $deal = DealHelper::getDeal($person['deal_id']); $person['deal_name'] = $deal[0]['name']; $person['deal_id'] = $deal[0]['id']; } $person['position'] = ""; $person['phone'] = ""; $person['email'] = ""; $person['type'] = ''; $person['source_id'] = null; $person['status_id'] = null; $person['header'] = TextHelper::_('COBALT_PERSON_ADD'); } //get total people associated with users account $total_people = UsersHelper::getPeopleCount($user_id, $team_id, $member_role); //get filter types $people_types = PeopleHelper::getPeopleTypes(); $people_type_name = $people_type_name && array_key_exists($people_type_name, $people_types) ? $people_types[$people_type_name] : $people_types['all']; //get column filters $column_filters = PeopleHelper::getColumnFilters(); $selected_columns = PeopleHelper::getSelectedColumnFilters(); //get user filter //get associated users//teams $teams = UsersHelper::getTeams(); $users = UsersHelper::getUsers(); if ($user and $user != $user_id and $user != 'all') { $user_info = UsersHelper::getUsers($user); $user_info = $user_info[0]; $user_name = $user_info['first_name'] . " " . $user_info['last_name']; } elseif ($team) { $team_info = UsersHelper::getTeams($team); $team_info = $team_info[0]; $user_name = $team_info['team_name'] . TextHelper::_('COBALT_TEAM_APPEND'); } elseif ($user == 'all') { $user_name = TextHelper::_('COBALT_ALL_USERS'); } else { $user_name = TextHelper::_('COBALT_ME'); } //get stage filter $stages = PeopleHelper::getStages(); $stages_name = $stage ? $stages[$stage] : $stages['past_thirty']; //get tag filter $tag_list = PeopleHelper::getTagList(); for ($i = 0; $i < count($tag_list); $i++) { if ($tag_list[$i]['id'] == $tag and $tag != 'any') { $tag_name = $tag_list[$i]['name']; break; } } $tag_name = ($tag and $tag != 'any') ? $tag_name : 'all tags'; //get status filter $status_list = PeopleHelper::getStatusList(); for ($i = 0; $i < count($status_list); $i++) { if ($status_list[$i]['id'] == $status and $status != 'any') { $status_name = $status_list[$i]['name']; break; } } $status_name = ($status and $status != 'any') ? $status_name : 'any status'; $dropdowns = $model->getDropdowns(); //Load Events & Tasks for person $layout = $this->getLayout(); if ($layout == "person") { $model = new EventModel(); $events = $model->getEvents("person", null, $app->input->get('id')); $this->event_dock = ViewHelper::getView('events', 'event_dock', 'phtml', array('events' => $events)); $this->deal_dock = ViewHelper::getView('deals', 'deal_dock', 'phtml', array('deals' => $person['deals'])); $this->document_list = ViewHelper::getView('documents', 'document_row', 'phtml', array('documents' => $person['documents'])); $this->custom_fields_view = ViewHelper::getView('custom', 'default', 'phtml', array('type' => 'people', 'item' => $person)); } if ($layout == "default") { $total = $model->getTotal(); $pagination = $model->getPagination(); $this->people_list = ViewHelper::getView('people', 'list', 'phtml', array('people' => $people, 'total' => $total, 'pagination' => $pagination)); $this->people_filter = $state->get('Deal.people_name'); $this->dataTableColumns = $model->getDataTableColumns(); JFactory::getDocument()->addScriptDeclaration("\n var loc = 'people';\n var order_dir = '" . $state->get('People.filter_order_Dir') . "';\n var order_col = '" . $state->get('People.filter_order') . "';\n var dataTableColumns = " . json_encode($this->dataTableColumns) . ";"); } if ($layout == "edit") { $item = $app->input->get('id') && array_key_exists(0, $people) ? $people[0] : array('id' => ''); $this->edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'phtml', array('type' => 'people', 'item' => $item)); $companyModel = new CompanyModel(); $json = TRUE; $companyNames = $companyModel->getCompanyNames($json); $document->addScriptDeclaration("var company_names=" . $companyNames . ";"); } if (TemplateHelper::isMobile() && $app->input->get('id')) { $this->add_note = ViewHelper::getView('note', 'edit', 'phtml', array('add_note' => $add_note)); $this->add_task = ViewHelper::getView('events', 'edit_task', 'phtml', array('association_type' => 'person', 'assocation_id' => $app->input->get('id'))); } //assign results to view $this->people = $people; $this->person = $person; $this->totalPeople = $total_people; $this->people_type_name = $people_type_name; $this->people_types = $people_types; $this->user_id = $user_id; $this->team_id = $team_id; $this->member_role = $member_role; $this->user_name = $user_name; $this->teams = $teams; $this->users = $users; $this->stages = $stages; $this->stages_name = $stages_name; $this->tag_list = $tag_list; $this->tag_name = $tag_name; $this->status_list = $status_list; $this->status_name = $status_name; $this->state = $state; $this->column_filters = $column_filters; $this->selected_columns = $selected_columns; $this->dropdown = $dropdowns; //display return parent::render(); }