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() { //get post data $data = $this->getInput()->getArray(array('association_id' => 'int', 'association_type' => 'string', 'person_id' => 'int')); //get db Object $db = $this->container->fetch('db'); $query = $db->getQuery(true); $table = $this->getInput()->getCmd('table'); $loc = $this->getInput()->getCmd('loc'); unset($data['table']); unset($data['loc']); if (empty($data['person_id'])) { unset($data['person_id']); } //write to tables if there is no association already in cf tables $query->select('* FROM #__' . $table . '_cf'); //loop to see if we have matches in database $overrides = array('tmpl'); foreach ($data as $key => $value) { if (!in_array($key, $overrides)) { $query->where($key . " = '" . $value . "'"); } } $db->setQuery($query); $results = $db->loadAssocList(); $response = new \stdClass(); //determine if we found any results if (count($results) == 0) { $query->insert('#__' . $table . '_cf'); //timestamp $data['created'] = date('Y-m-d H:i:s'); $date = DateHelper::formatDBDate(date('Y-m-d H:i:s')); //loop through data to get query string foreach ($data as $key => $value) { if (!in_array($key, $overrides)) { // determine key and key values $query->set($key . " = '" . $value . "'"); } } $db->setQuery($query)->execute(); //if return data requested if ($table == 'people') { //determine which page we want are wanting to send information back to if ($loc == 'deal') { $model = new PeopleModel(); $return = $model->getPerson($data['person_id']); $response->alert = new \stdClass(); $response->alert->message = \JText::_('DEAL_CONTACT_ADDED_SUCCESS'); $response->alert->type = 'success'; $response->item = $return; $response->reload = 2000; } if ($loc == 'person') { $model = new DealModel(); $return = $model->getDeals(array_key_exists('deal_id', $data) ? $data['deal_id'] : ""); $return = $return[0]; $response->alert = new \stdClass(); $response->alert->message = $return; $response->alert->type = 'success'; } } } else { $response->alert = new \stdClass(); $response->alert->message = \JText::_('DEAL_CONTACT_ERROR_FAILURE_ADD_PERSON'); $response->alert->type = 'error'; } //return json data echo json_encode($response); }
/** * Generate vcards for people * @return [type] [description] */ public function getVcard() { $app = \Cobalt\Container::fetch('app'); $person_id = $app->input->get('person_id'); $model = new People(); $person = $model->getPerson($person_id); $person = $person[0]; $str = ""; $str .= "BEGIN:VCARD\r\n"; $str .= "VERSION:4.0\r\n"; $str .= "N:" . $person['last_name'] . ";" . $person['first_name'] . ";;;\r\n"; $str .= "FN: " . $person['first_name'] . " " . $person['last_name'] . "\r\n"; $str .= "ORG:" . $person['company_name'] . "\r\n"; $str .= "TITLE:" . $person['position'] . "\r\n"; $str .= 'TEL;TYPE="work,voice";VALUE=uri:tel:+' . $person['phone'] . "\r\n"; $str .= 'TEL;TYPE="mobile,voice";VALUE=uri:tel:+' . $person['mobile_phone'] . "\r\n"; $str .= 'ADR;TYPE=work:;;' . $person['work_address_1'] . " " . $person['work_address_2'] . ';' . $person['work_city'] . ';' . $person['work_state'] . ';' . $person['work_zip'] . ';' . $person['work_country'] . "\r\n"; $str .= "EMAIL:" . $person['email'] . "\r\n"; $str .= "END:VCARD\r\n"; return $str; }
/** * Add Cobalt People to Acymailing Lists */ public static function addMailingList($data) { $person_id = $data['person_id']; $listid = $data['listid']; $db = \Cobalt\Container::fetch('db'); $query = $db->getQuery(true); $peopleModel = new PeopleModel(); $person = $peopleModel->getPerson($person_id); $person = $person[0]; $time = time(); $query->select("subid")->from("#__acymailing_subscriber")->where("email='" . $person['email'] . "'"); $db->setQuery($query); $subid = $db->loadResult(); if ($subid) { $query->clear(); $query->update("#__acymailing_listsub")->set(array("subdate={$time}", "status=1"))->where("subid=" . $subid)->where("listid=" . $listid); $db->setQuery($query); $db->query(); } else { $query->insert("#__acymailing_subscriber")->columns("email,name,created,confirmed,enabled,accept,html")->values($db->Quote($person['email']) . ',' . $db->Quote($person['first_name'] . ' ' . $person['last_name']) . ',' . $time . ',' . '1,1,1,1'); $db->setQuery($query); $db->query(); $subid = $db->insertid(); $query->clear(); $query->insert("#__acymailing_listsub")->columns("listid,subid,subdate,status")->values($listid . ',' . $subid . ',' . $time . ',1'); $db->setQuery($query); $db->query(); } return true; }