public function render($tpl = null) { //get model and retrieve info $model = new EventModel(); if (TemplateHelper::isMobile()) { $model->set('current_events', true); } $events = $model->getEvents(); $eventDock = ViewHelper::getView('events', 'dashboard_event_dock', 'phtml', array('events' => $events)); $dealModel = new DealModel(); $dealModel->set('_view', 'dashboard'); $dealModel->set('recent', true); $dealModel->set('archived', 0); $recentDeals = $dealModel->getDeals(); $doc = JFactory::getDocument(); //get data for sales graphs $model = new GraphsModel(); $graph_data = $model->getGraphData(); $activityHelper = new ActivityHelper(); $activity = $activityHelper->getActivity(); //assign results to view $this->eventDock = $eventDock; $this->graph_data = $graph_data; $this->recentDeals = $recentDeals; $this->activity = $activity; $json = TRUE; $peopleModel = new PeopleModel(); if (TemplateHelper::isMobile()) { $dealModel->set('recent', false); $totalDeals = $dealModel->getTotal(); $peopleModel->set('type', 'leads'); $totalLeads = $peopleModel->getTotal(); $peopleModel->set('type', 'not_leads'); $totalContacts = $peopleModel->getTotal(); $companyModel = new CompanyModel(); $totalCompanies = $companyModel->getTotal(); $user = UsersHelper::getLoggedInUser(); $this->first_name = $user->first_name; $this->numEvents = count($events); $this->numDeals = $totalDeals; $this->numLeads = $totalLeads; $this->numContacts = $totalContacts; $this->numCompanies = $totalCompanies; } $peopleNames = $peopleModel->getPeopleNames($json); $doc->addScriptDeclaration("var people_names=" . $peopleNames . ";"); $dealModel = new DealModel(); $dealNames = $dealModel->getDealNames($json); $doc->addScriptDeclaration("var deal_names=" . $dealNames . ";"); /** get latest activities **/ $this->latest_activities = ViewHelper::getView('dashboard', 'latest_activities', 'phtml'); $this->latest_activities->activity = $activity; $activityHelper = new ActivityHelper(); $activity = $activityHelper->getActivity(); //display return parent::render(); }
public function execute() { $company_name = $this->getInput()->getString('company_name'); $companyModel = new CompanyModel(); $existingCompany = $companyModel->checkCompanyName($company_name); if ($existingCompany != "") { echo json_encode(array('success' => true, 'company_id' => $existingCompany, 'message' => "")); } else { echo json_encode(array('success' => true, 'message' => ucwords(TextHelper::_('COBALT_COMPANY_WILL_BE_CREATED')))); } }
public function execute() { //set view $view = ViewHelper::getView('companies', 'raw', 'html'); $view->setLayout('list'); //get filters $type = $this->getInput()->get('type'); $user = $this->getInput()->get('user'); $team = $this->getInput()->get('team_id'); //get deals $model = new CompanyModel(); $companies = $model->getCompanies(null, $type, $user, $team); //assign references $view->companies = $companies; //display echo $view->render(); }
public function render() { //japplication $app = JFactory::getApplication(); $id = $app->input->get('id') ? $app->input->get('id') : null; $layout = $this->getLayout(); //get model $model = new CompanyModel(); //layout switch ($layout) { case "add": case "edit": $this->company = $model->getCompany(); $edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'html'); $edit_custom_fields_view->type = "company"; $edit_custom_fields_view->item = $this->company; $this->edit_custom_fields_view = $edit_custom_fields_view; break; case "entry": $this->company = $model->getCompany(); $this->k = 0; break; case "list": $this->companies = $model->getCompanies($id); $this->total = $model->getTotal(); $this->pagination = $model->getPagination(); $this->state = $model->getState(); break; } //display view echo parent::render(); }
/** * Get CSV data * @param [type] $data_type [description] * @return [type] [description] */ public function getCsvData($data_type) { $app = \Cobalt\Container::fetch('app'); $data = array(); $export_ids = $app->input->get('ids'); switch ($data_type) { case "deals": $model = new Deal(); $data = $model->getDeals($export_ids); break; case "companies": $model = new Company(); $data = $model->getCompanies($export_ids); break; case "people": $model = new People(); $data = $model->getPeople($export_ids); break; case "sales_pipeline": $model = new Deal(); $data = $model->getReportDeals($export_ids); break; case "source_report": $model = new Deal(); $data = $model->getDeals($export_ids); break; case "roi_report": $model = new Source(); $data = $model->getRoiSources($export_ids); break; case "notes": $model = new Note(); $data = $model->getNotes(NULL, NULL, FALSE); break; case "custom_report": $model = new Report(); $data = $model->getCustomReportData($app->input->get('report_id')); break; } if (count($data)) { $header = array_keys((array) $data[0]); } return array('header' => $header, 'rows' => $data); }
public function render() { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $id = $app->input->get('id') ? $app->input->get('id') : null; $company_id = $app->input->get('company_id'); //retrieve people from model $model = new PeopleModel(); $model->set('company_id', $company_id); $layout = $this->getLayout(); $this->total = $model->getTotal(); $this->pagination = $model->getPagination(); //assign refs switch ($layout) { case "entry": $this->k = 0; $this->person = $model->getPerson(); break; case "add": case "edit": $this->person = $model->getPerson(); $this->edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'phtml', array('type' => 'people', 'item' => $this->person)); $companyModel = new CompanyModel(); $json = TRUE; $companyNames = $companyModel->getCompanyNames($json); $document->addScriptDeclaration("var company_names=" . $companyNames . ";"); break; case "people_dock_list": $people = $model->getPeople($id); $this->people = $people; break; default: $people = $model->getPeople($id); $this->people = $people; $this->state = $model->getState(); break; } //display view echo parent::render(); }
public function execute() { //open model $model = new PeopleModel(); //retrieve all people $people = $model->getPeopleList(); if (count($people)) { foreach ($people as $index => $row) { $people[$index]['type'] = "person"; $people[$index]['association_link'] = RouteHelper::_('index.php?view=people&layout=person&id=' . $row['id']); } } //open model $model = new DealModel(); //retrieve all people $deals = $model->getDealList(); if (count($deals)) { foreach ($deals as $index => $row) { $deals[$index]['type'] = 'deal'; $deals[$index]['association_link'] = RouteHelper::_('index.php?view=deals&layout=deal&id=' . $row['id']); } } //open model $model = new CompanyModel(); //retrieve all people $companies = $model->getCompanyList(); if (count($companies)) { foreach ($companies as $index => $row) { $companies[$index]['type'] = 'company'; $companies[$index]['association_link'] = RouteHelper::_('index.php?view=companies&layout=company&id=' . $row['id']); } } //merge our results to a grand object $results = array_merge($people, $deals, $companies); //return results as json object echo json_encode($results); }
/** * Method to store a record * * @return boolean True on success */ public function store($data = null, $returnRow = false) { //Load Tables $row = new DealTable(); $oldRow = new DealTable(); if ($data == null) { $data = $this->app->input->post->getArray(); } //date generation $date = DateHelper::formatDBDate(date('Y-m-d H:i:s')); //assign the creation date if (!array_key_exists('id', $data) || array_key_exists('id', $data) && $data['id'] <= 0) { $data['created'] = $date; $status = "created"; //assign the owner id $data['owner_id'] = array_key_exists('owner_id', $data) ? $data['owner_id'] : $this->app->getUser()->get('id'); } else { $row->load($data['id']); $oldRow->load($data['id']); $status = "updated"; } //update our modified date $data['modified'] = $date; //generate custom field string $customArray = array(); foreach ($data as $name => $value) { if (strstr($name, 'custom_') && !strstr($name, '_input') && !strstr($name, "_hidden")) { $id = str_replace('custom_', '', $name); $customArray[] = array('custom_field_id' => $id, 'custom_field_value' => $value); unset($data[$name]); } } if (array_key_exists('expected_close', $data)) { if (strpos($data['expected_close'], '/')) { $dateParts = explode('/', $data['expected_close']); $expected_close = new \JDate(sprintf('%s-%s-%s 00:00:00', $dateParts[1], $dateParts[0], '20' . $dateParts[2])); } else { $expected_close = new \JDate($data['expected_close']); } $data['expected_close'] = $expected_close->toSql(); } if (array_key_exists('company_name', $data) && $data['company_name'] != "" || array_key_exists('company', $data) && $data['company'] != "") { $company_name = array_key_exists('company_name', $data) ? $data['company_name'] : $data['company']; $companyModel = new Company(); $existingCompany = $companyModel->checkCompanyName($company_name); if ($existingCompany == "") { $cdata = array(); $cdata['name'] = $company_name; $data['company_id'] = $companyModel->store($cdata); } else { $data['company_id'] = $existingCompany; } } if (array_key_exists('company_id', $data) && is_array($data['company_id'])) { $company_name = $data['company_id']['value']; $companyModel = new Company(); $existingCompany = $companyModel->checkCompanyName($company_name); if ($existingCompany == "") { $cdata = array(); $cdata['name'] = $company_name; $data['company_id'] = $companyModel->store($cdata)->id; } else { $data['company_id'] = $existingCompany; } } //deal was closed $closedStages = $this->getClosedStages(); if (array_key_exists('stage_id', $data) && in_array($data['stage_id'], $closedStages)) { $data['actual_close'] = $date; } /** check for and automatically associate and create primary contacts or people **/ if (array_key_exists('person_name', $data) && $data['person_name'] != "") { $peopleModel = new People(); $existingPerson = $peopleModel->checkPersonName($data['person_name']); if ($existingPerson == "") { $pdata = array(); $name = explode(" ", $data['person_name']); $pdata['first_name'] = $name[0]; $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : ""; if (array_key_exists('company_id', $data)) { $pdata['company_id'] = $data['company_id']; } $data['person_id'] = $peopleModel->store($pdata); } else { $data['person_id'] = $existingPerson; } } if (array_key_exists('primary_contact_name', $data) && $data['primary_contact_name'] != "") { $peopleModel = new People(); $existingPerson = $peopleModel->checkPersonName($data['primary_contact_name']); if ($existingPerson == "") { $pdata = array(); $name = explode(" ", $data['primary_contact_name']); $pdata['first_name'] = $name[0]; $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : ""; if (array_key_exists('company_id', $data)) { $pdata['company_id'] = $data['company_id']; } $data['primary_contact_id'] = $peopleModel->store($pdata); } else { $data['primary_contact_id'] = $existingPerson; } } // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->db->getErrorMsg()); return false; } //$this->app->triggerEvent('onBeforeDealSave', array(&$row)); // Make sure the record is valid if (!$row->check()) { $this->setError($this->db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->db->getErrorMsg()); return false; } $deal_id = array_key_exists('id', $data) && $data['id'] > 0 ? $data['id'] : $row->id; ActivityHelper::saveActivity($oldRow, $row, 'deal', $status); //if we receive no custom post data do not modify the custom fields if (count($customArray) > 0) { CobaltHelper::storeCustomCf($deal_id, $customArray, 'deal'); } if (!empty($data['primary_contact_id']) || !empty($data['person_id'])) { $contactId = array_key_exists('primary_contact_id', $data) ? $data['primary_contact_id'] : $data['person_id']; $this->storeContact($deal_id, $contactId); } $closed_stages = DealHelper::getClosedStages(); $row->closed = in_array($row->stage_id, $closed_stages) ? TRUE : FALSE; $row->actual_close_formatted = isset($row->actual_close) ? DateHelper::formatDate($row->actual_close) : DateHelper::formatDate(date("Y-m-d")); $row->expected_close_formatted = isset($row->expected_close) ? DateHelper::formatDate($row->expected_close) : DateHelper::formatDate(date("Y-m-d")); //$this->app->triggerEvent('onAfterDealSave', array(&$row)); //return success if ($returnRow) { return $row; } else { return $deal_id; } }
/** * Read a CSV File * @param [String] $file * @return [Mixed] $data */ public function readCSVFile($file, $table = null) { $app = \Cobalt\Container::fetch('app'); ini_set("auto_detect_line_endings", "1"); $data = array(); $line = 1; $headers = array(); $i = -2; $db = JFactory::getDBO(); $table = $db->getTableColumns("#__" . $app->input->get('import_type', $table)); $special_headers = array('company_id', 'company_name', 'stage_name', 'source_name', 'status_name', 'primary_contact_name', 'assignee_name', 'type'); if (($handle = fopen($file, "r")) !== false) { while (($read = fgetcsv($handle, 1000, ",")) !== false) { $i++; $num = count($read); if ($line == 1) { $headers = $read; $data['headers'] = $headers; } else { $line_data = array(); for ($c = 0; $c < $num; $c++) { $header_name = array_key_exists($c, $headers) ? $headers[$c] : false; if ($header_name) { if (in_array($header_name, $special_headers)) { $read[$c] = utf8_encode($read[$c]); switch ($header_name) { case "company_id": $model = new Company(); $new_header = "company_id"; $company_name = $model->getCompanyName($read[$c]); $name = "name=\"import_id[" . $i . "][" . $new_header . "]\""; if ($company_name != "") { $name = $company_name; } else { $name = ""; } $special_data = array('label' => $read[$c], 'value' => $name); break; case "company_name": $model = new Company(); $new_header = "company_id"; $company_id = $model->getCompanyList($read[$c]); $name = "name=\"import_id[" . $i . "][" . $new_header . "]\""; if (count($company_id) > 0) { $name = $company_id[0]['name']; } else { $name = $read[$c]; } $special_data = array('label' => $read[$c], 'value' => utf8_encode($name)); break; case "stage_name": $new_header = "stage_id"; $stage_id = DealHelper::getStages($read[$c]); $name = "name=\"import_id[" . $i . "][" . $new_header . "]\""; if (count($stage_id)) { $keys = array_keys($stage_id); $stage_id = $keys[0]; } $special_data = array('dropdown' => DropdownHelper::generateDropdown('stage', $stage_id, $name)); break; case "source_name": $new_header = "source_id"; $source_id = DealHelper::getSources($read[$c]); $name = "name=\"import_id[" . $i . "][" . $new_header . "]\""; if (count($source_id)) { $keys = array_keys($source_id); $source_id = $keys[0]; } $special_data = array('dropdown' => DropdownHelper::generateDropdown('source', $source_id, $name)); break; case "status_name": $new_header = "status_id"; $status_id = DealHelper::getStatuses($read[$c]); $name = "name=\"import_id[" . $i . "][" . $new_header . "]\""; if (count($status_id)) { $keys = array_keys($status_id); $status_id = $keys[0]; } $special_data = array('dropdown' => DropdownHelper::generateDropdown('deal_status', $status_id, $name)); break; case "primary_contact_name": $new_header = "primary_contact_id"; $model = new People(); $contact = $model->searchForContact($read[$c]); if ($contact) { $special_data = array('label' => $contact[0]->label, 'value' => $contact[0]->value); } else { $special_data = array(); } break; case "assignee_name": $new_header = "assignee_id"; $model = new People(); $contact = $model->searchForContact($read[$c]); break; case "type": $new_header = "type"; $special_data = array('dropdown' => ucwords(DropdownHelper::getContactTypes($read[$c]))); break; } $line_data[$new_header] = $special_data; } else { if (array_key_exists($header_name, $table)) { $line_data[$header_name] = utf8_encode($read[$c]); } } } } if (count($line_data) > 0) { $data[] = $line_data; } } $line++; } fclose($handle); } return $data; }
public function render() { $app = \Cobalt\Container::fetch('app'); //retrieve deal list from model $model = new DealModel(); $state = $model->getState(); $dealList = array(); $deal = array(); $doc = JFactory::getDocument(); //session info $session = JFactory::getSession(); $member_role = UsersHelper::getRole(); $user_id = UsersHelper::getUserId(); $team_id = UsersHelper::getTeamId(); //determine if we are requesting a specific deal or all deals //if id requested if ($app->input->get('id')) { $model->set('_id', $app->input->get('id')); $dealList = $model->getDeals(); if (is_null($dealList[0]->id)) { $app->redirect(RouteHelper::_('index.php?view=deals'), TextHelper::_('COBALT_NOT_AUTHORIZED')); } //display remove and assign primary contact to deal $app->input->set('loc', 'deal'); } else { //else load all deals if ($app->input->get('layout') != 'edit') { if (TemplateHelper::isMobile()) { $model->set('ordering', 'd.name ASC'); } $dealList = $model->getDeals(); } } //determine if we are editing an existing deal entry if (count($dealList) == 1) { //grab deal object $deal = $dealList[0]; $deal->header = ucwords(TextHelper::_('COBALT_DEAL_EDIT')); } else { //else we are creating a new entry $deal = new \stdClass(); $deal->name = ""; $deal->summary = ""; $deal->company_id = $app->input->get('company_id') ? $app->input->get('company_id') : null; $deal->person_id = $app->input->get('person_id') ? $app->input->get('person_id') : null; //get company name to prefill data and hidden fields if ($deal->company_id) { $company = CompanyHelper::getCompany($deal->company_id); $deal->company_name = $company[0]['name']; $deal->company_id = $company[0]['id']; } //if a person is specified prefill data if ($deal->person_id) { $person = PeopleHelper::getPerson($deal->person_id); $deal->person_name = $person[0]['last_name'] . ', ' . $person[0]['first_name']; $deal->person_id = $person[0]['id']; //assign company if person is associated with company if ($person[0]['company_id']) { $deal->company_id = $person[0]['company_id']; $deal->company_name = $person[0]['company_name']; } } //assign rest of null data $deal->amount = ""; $deal->stage_id = 0; $deal->source_id = 0; $deal->probability = 0; $deal->status_id = 0; $deal->expected_close = ""; $deal->header = ucwords(TextHelper::_('COBALT_DEAL_HEADER')); } //load javalibs if (!TemplateHelper::isMobile()) { $doc->addScript(JURI::base() . 'src/Cobalt/media/js/deal_manager.js'); } //dropdown info //get deal type filters $deal_types = DealHelper::getDealTypes(); $deal_type_name = $session->get('deal_type_filter'); $deal_type_name = array_key_exists($deal_type_name, $deal_types) ? $deal_types[$deal_type_name] : $deal_types['']; //get column filters $column_filters = DealHelper::getColumnFilters(); $selected_columns = DealHelper::getSelectedColumnFilters(); //get member access info $teams = UsersHelper::getTeams(); $users = UsersHelper::getUsers(); $stages = DealHelper::getStages(); //get deal stage filters $stage_name = $session->get('deal_stage_filter'); $stage_name = $stage_name ? $stages[$stage_name] : $stages['all']; //get session data to prefill filters $user_filter = $session->get('deal_user_filter'); $team_filter = $session->get('deal_team_filter'); if ($user_filter == "all" && $user_filter != $user_id) { $user_name = TextHelper::_('COBALT_ALL_USERS'); } elseif ($user_filter == "all") { $user_name = TextHelper::_('COBALT_ME'); } elseif ($user_filter and $user_filter != $user_id and $user_filter != 'all') { $user_info = UsersHelper::getUsers($user_filter); $user_info = $user_info[0]; $user_name = $user_info['first_name'] . " " . $user_info['last_name']; } elseif ($team_filter) { $team_info = UsersHelper::getTeams($team_filter); $team = $team_info[0]; $user_name = $team['team_name'] . TextHelper::_('COBALT_TEAM_APPEND'); } else { $user_name = TextHelper::_('COBALT_ME'); } //get closing time filters $closing_names = DealHelper::getClosing(); $closing_name = $session->get('deal_close_filter'); $closing_name = $closing_name ? $closing_names[$closing_name] : $closing_names['all']; //get total deals associated with user $total_deals = UsersHelper::getDealCount($user_id, $team_id, $member_role); //Load Events & Tasks for person $layout = $this->getLayout(); if ($layout == "deal") { $model = new EventModel(); $events = $model->getEvents("deal", null, $app->input->get('id')); $this->event_dock = ViewHelper::getView('events', 'event_dock', 'phtml', array('events' => $events)); $primary_contact_id = DealHelper::getPrimaryContact($dealList[0]->id); $this->contact_info = ViewHelper::getView('contacts', 'default', 'phtml', array('contacts' => $dealList[0]->people, 'primary_contact_id' => $primary_contact_id)); $this->document_list = ViewHelper::getView('documents', 'list', 'phtml', array('documents' => $deal->documents, 'total' => $total, 'pagination' => $pagination)); //$this->document_list = ViewHelper::getView('documents','document_row','phtml',array('documents'=>$deal->documents)); $this->custom_fields_view = ViewHelper::getView('custom', 'default', 'phtml', array('type' => 'deal', 'item' => $dealList[0])); } if ($layout == "default") { $this->dataTableColumns = $model->getDataTableColumns(); $pagination = $model->getPagination(); $total = $model->getTotal(); $this->deal_list = ViewHelper::getView('deals', 'list', 'phtml', array('dealList' => $dealList, 'total' => $total, 'pagination' => $pagination)); $this->state = $state; $doc->addScriptDeclaration("\n loc = 'deals';\n order_url = 'index.php?view=deals&layout=list&format=raw&tmpl=component';\n order_dir = '" . $state->get('Deal.filter_order_Dir') . "';\n order_col = '" . $state->get('Deal.filter_order') . "';\n var dataTableColumns = " . json_encode($this->dataTableColumns) . ";"); $deal_name = $state->get('Deal.deals_name'); $this->deal_filter = $deal_name; } if (TemplateHelper::isMobile()) { $this->add_note = ViewHelper::getView('note', 'edit', 'phtml'); $this->add_task = ViewHelper::getView('events', 'edit_task', 'phtml', array('association_type' => 'deal', 'assocation_id' => $app->input->get('id'))); } if ($layout == "edit") { $item = $app->input->get('id') && array_key_exists(0, $dealList) ? $dealList[0] : array('id' => ''); $this->edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'phtml', array('type' => 'deal', 'item' => $item)); $json = TRUE; $companyModel = new CompanyModel(); $companyNames = $companyModel->getCompanyNames($json); $doc->addScriptDeclaration("var company_names=" . $companyNames . ";"); $peopleModel = new PeopleModel(); $peopleNames = $peopleModel->getPeopleNames($json); $doc->addScriptDeclaration("var people_names=" . $peopleNames . ";"); } $closed_stages = DealHelper::getClosedStages(); //assign results to view $this->closed_stages = $closed_stages; $this->dealList = $dealList; $this->totalDeals = $total_deals; $this->deal = $deal; $this->deal_types = $deal_types; $this->deal_type_name = $deal_type_name; $this->user_id = $user_id; $this->member_role = $member_role; $this->teams = $teams; $this->users = $users; $this->stages = $stages; $this->stage_name = $stage_name; $this->user_name = $user_name; $this->closing_names = $closing_names; $this->closing_name = $closing_name; $this->state = $state; $this->column_filters = $column_filters; $this->selected_columns = $selected_columns; //display return parent::render(); }
/** * Method to store a record * * @return boolean True on success */ public function store($data = null) { //Load Tables $row = new PeopleTable(); $oldRow = new PeopleTable(); if ($data == null) { $data = $this->app->input->getArray(array('id' => 'int', 'first_name' => 'string', 'last_name' => 'string', 'company' => 'string', 'company_id' => 'int', 'position' => 'string', 'phone' => 'string', 'email' => 'email', 'source_id' => 'int', 'status_id' => 'int', 'deal_id' => 'int', 'type' => 'string', 'home_address_1' => 'string', 'home_address_2' => 'string', 'home_city' => 'string', 'home_state' => 'string', 'home_zip' => 'string', 'home_country' => 'string', 'work_address_1' => 'string', 'work_address_2' => 'string', 'work_city' => 'string', 'work_country' => 'string', 'work_state' => 'string', 'work_zip' => 'string', 'assignee_name' => 'string', 'assignee_id' => 'int', 'assignment_note' => 'string', 'mobile_phone' => 'string', 'home_email' => 'email', 'other_email' => 'email', 'home_phone' => 'string', 'fax' => 'string', 'website' => 'string', 'facebook_url' => 'string', 'twitter_user' => 'string', 'linkedin_url' => 'string', 'aim' => 'string')); } //date generation $date = DateHelper::formatDBDate(date('Y-m-d H:i:s')); if (!array_key_exists('id', $data) || array_key_exists('id', $data) && $data['id'] <= 0) { $data['created'] = $date; $data['owner_id'] = array_key_exists('owner_id', $data) ? $data['owner_id'] : UsersHelper::getUserId(); $status = "created"; } else { $row->load($data['id']); $oldRow->load($data['id']); $status = "updated"; } $data['modified'] = $date; //generate custom field string $customArray = array(); foreach ($data as $name => $value) { if (strstr($name, 'custom_') && !strstr($name, '_input') && !strstr($name, "_hidden")) { $id = str_replace('custom_', '', $name); $customArray[] = array('custom_field_id' => $id, 'custom_field_value' => $value); unset($data[$name]); } } if (array_key_exists('company_name', $data) && $data['company_name'] != "" || array_key_exists('company', $data) && $data['company'] != "") { $company_name = array_key_exists('company_name', $data) ? $data['company_name'] : $data['company']; $companyModel = new Company(); $existingCompany = $companyModel->checkCompanyName($company_name); if ($existingCompany == "") { $cdata = array(); $cdata['name'] = $company_name; $data['company_id'] = $companyModel->store($cdata); } else { $data['company_id'] = $existingCompany; } } if (array_key_exists('company_id', $data) && is_array($data['company_id'])) { $company_name = $data['company_id']['value']; $companyModel = new Company(); $existingCompany = $companyModel->checkCompanyName($company_name); if ($existingCompany == "") { $cdata = array(); $cdata['name'] = $company_name; $data['company_id'] = $companyModel->store($cdata)->id; } else { $data['company_id'] = $existingCompany; } } /** retrieving joomla user id **/ if (array_key_exists('email', $data)) { $data['id'] = self::associateJoomlaUser($data['email']); } // Bind the form fields to the table if (!$row->bind($data)) { $this->setError($this->db->getErrorMsg()); return false; } $app = \Cobalt\Container::fetch('app'); //$app->triggerEvent('onBeforePersonSave', array(&$row)); // Make sure the record is valid if (!$row->check()) { $this->setError($this->db->getErrorMsg()); return false; } // Store the web link table to the database if (!$row->store()) { $this->setError($this->db->getErrorMsg()); return false; } $person_id = isset($data['id']) ? $data['id'] : $this->db->insertId(); /** Updating the joomla user **/ if (array_key_exists('id', $data) && intval($data['id']) && array_key_exists('email', $data) && array_key_exists('first_name', $data) && array_key_exists('last_name', $data)) { self::updateJoomlaUser($data); } ActivityHelper::saveActivity($oldRow, $row, 'person', $status); //if we receive no custom post data do not modify the custom fields if (count($customArray) > 0) { CobaltHelper::storeCustomCf($person_id, $customArray, 'people'); } //bind to cf tables for deal & person association if (isset($data['deal_id']) && $data['deal_id']) { $deal = array('association_id = ' . $data['deal_id'], 'association_type="deal"', 'person_id = ' . $row->id, "created = '{$date}'"); if (!$this->dealsPeople($deal)) { return false; } } //Pass Status to plugin & form ID if available $row->status = $status; if (isset($data) && is_array($data) && array_key_exists('form_id', $data)) { $row->form_id = $data['form_id']; } else { $row->form_id = ''; } //$app->triggerEvent('onAfterPersonSave', array(&$row)); return $person_id; }
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(); }
public function render() { $app = JFactory::getApplication(); $app->input->set('view', 'companies'); $app->input->set('layout', $app->input->get('layout', 'default')); //get model $model = new CompanyModel(); $state = $model->getState(); //session data $session = JFactory::getSession(); $member_role = UsersHelper::getRole(); $user_id = UsersHelper::getUserId(); $team_id = UsersHelper::getTeamId(); $company = $session->get('company_type_filter'); $user = $session->get('company_user_filter'); $team = $session->get('company_team_filter'); //load java libs $doc = JFactory::getDocument(); $doc->addScript(JURI::base() . 'src/Cobalt/media/js/company_manager.js'); //determine if we are requesting a specific company or all companies //if id requested if ($app->input->get('id')) { $companies = $model->getCompanies($app->input->get('id')); if (is_null($companies[0]['id'])) { $app = JFactory::getApplication(); $app->redirect(RouteHelper::_('index.php?view=companies'), TextHelper::_('COBALT_NOT_AUTHORIZED')); } } else { //else load all companies if ($app->input->get('layout') != 'edit') { $companies = $model->getCompanies(); } } //assign pagination $pagination = $model->getPagination(); $this->pagination = $pagination; //get company type filters $company_types = CompanyHelper::getTypes(); $company_type = $company ? $company_types[$company] : $company_types['all']; //get user filter 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 == "") { $user_name = TextHelper::_('COBALT_ALL_USERS'); } else { $user_name = TextHelper::_('COBALT_ME'); } //get associated members and teams $teams = UsersHelper::getTeams(); $users = UsersHelper::getUsers(); //get total associated companies for count display $company_count = UsersHelper::getCompanyCount($user_id, $team_id, $member_role); //Load Events & Tasks for person $layout = $app->input->get('layout'); switch ($layout) { case 'company': $model = new EventModel(); $events = $model->getEvents("company", 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' => $companies[0]['deals'])); $this->document_list = ViewHelper::getView('documents', 'document_row', 'phtml', array('documents' => $companies[0]['documents'])); $this->people_dock = ViewHelper::getView('people', 'people_dock', 'html', array('people' => $companies[0]['people'])); $custom_fields_view = ViewHelper::getView('custom', 'default', 'html'); $type = "company"; $custom_fields_view->type = $type; $custom_fields_view->item = $companies[0]; $this->custom_fields_view = $custom_fields_view; if (TemplateHelper::isMobile()) { $add_note = ViewHelper::getView('note', 'edit', 'html'); $this->add_note = $add_note; } break; case 'default': default: //get column filters $this->column_filters = CompanyHelper::getColumnFilters(); $this->selected_columns = CompanyHelper::getSelectedColumnFilters(); $company_list = ViewHelper::getView('companies', 'list', 'html', array('companies' => $companies)); $total = $model->getTotal(); $pagination = $model->getPagination(); $company_list->total = $total; $company_list->pagination = $pagination; $this->company_list = $company_list; $company_name = $state->get('Company.companies_name'); $this->company_filter = $company_name; $this->dataTableColumns = $model->getDataTableColumns(); $doc->addScriptDeclaration("\n var loc = 'companies';\n var order_dir = '" . $state->get('Company.filter_order_Dir') . "';\n var order_col = '" . $state->get('Company.filter_order') . "';\n var dataTableColumns = " . json_encode($this->dataTableColumns) . ";"); break; case 'edit': $item = $app->input->get('id') && array_key_exists(0, $companies) ? $companies[0] : array('id' => ''); $edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'html'); $type = "company"; $edit_custom_fields_view->type = $type; $edit_custom_fields_view->item = $item; $this->edit_custom_fields_view = $edit_custom_fields_view; break; } //ref assignments $this->companies = $companies; $this->user_id = $user_id; $this->member_role = $member_role; $this->teams = $teams; $this->users = $users; $this->company_types = $company_types; $this->company_type = $company_type; $this->user_name = $user_name; $this->company_count = $company_count; $this->state = $state; //display return parent::render(); }