コード例 #1
0
ファイル: People.php プロジェクト: houzhenggang/cobalt
 public function getPerson($id = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $id = $id ? $id : $app->input->get('id');
     if ($id > 0) {
         $db = JFactory::getDBO();
         //generate query
         //
         $query = $db->getQuery(true);
         $query->select('p.*,c.name as company_name,stat.name as status_name,
                         source.name as source_name, owner.name as owner_name, crmery_user.first_name AS owner_first_name, crmery_user.last_name AS owner_last_name');
         $query->from('#__people AS p');
         $query->leftJoin('#__companies AS c ON c.id = p.company_id AND c.published>0');
         $query->leftJoin('#__people_status AS stat ON stat.id = p.status_id');
         $query->leftJoin('#__sources AS source ON source.id = p.source_id');
         $query->leftJoin('#__users AS owner ON p.owner_id = owner.id');
         $query->leftJoin("#__users AS crmery_user ON crmery_user.id = p.owner_id");
         //searching for specific person
         $query->where("p.published=" . $this->published);
         $query->where("p.id='" . $id . "'");
         //run query and grab results
         $db->setQuery($query);
         $person = $db->loadAssoc();
         /* Deals */
         $dealModel = new Deal();
         $dealModel->set('person_id', $person['id']);
         $person['deals'] = $dealModel->getDeals();
         /* Notes */
         $notesModel = new Note();
         $person['notes'] = $notesModel->getNotes($person['id'], 'person');
         /* Docs */
         $docsModel = new Document();
         $docsModel->set('person_id', $person['id']);
         $person['documents'] = $docsModel->getDocuments();
         /* Tweets */
         if ($person['twitter_user'] != "" && $person['twitter_user'] != " ") {
             $person['tweets'] = TweetsHelper::getTweets($person['twitter_user']);
         }
         $this->person = $person;
     } else {
         //TODO update things to OBJECTS
         $person = (array) new PeopleTable();
         $this->person = $person;
     }
     //$app->triggerEvent('onPersonLoad', array(&$person));
     return $person;
 }
コード例 #2
0
ファイル: Company.php プロジェクト: houzhenggang/cobalt
 public function getCompanies($id = null, $type = null, $user = null, $team = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $this->_id = $id;
     $this->_type = $type;
     $this->_user = $user;
     $this->_team = $team;
     //get query string
     $query = $this->_buildQuery();
     /** ------------------------------------------
      * Set query limits and load results
      */
     if (!TemplateHelper::isMobile()) {
         $limit = $this->getState($this->_view . '_limit');
         $limitStart = $this->getState($this->_view . '_limitstart');
         if (!$this->_id && $limit != 0) {
             if ($limitStart >= $this->getTotal()) {
                 $limitStart = 0;
                 $limit = 10;
                 $limitStart = $limit != 0 ? floor($limitStart / $limit) * $limit : 0;
                 $this->state->set($this->_view . '_limit', $limit);
                 $this->state->set($this->_view . '_limitstart', $limitStart);
             }
             $query .= " LIMIT " . $limit . " OFFSET " . $limitStart;
         }
     }
     //run query and grab results of companies
     $companies = $this->db->setQuery($query)->loadAssocList();
     //generate query to join people
     if (count($companies)) {
         $export = $app->input->get('export');
         if (!$export) {
             foreach ($companies as $key => $company) {
                 /* Tweets */
                 if ($company['twitter_user'] != "" && $company['twitter_user'] != " ") {
                     $companies[$key]['tweets'] = TweetsHelper::getTweets($company['twitter_user']);
                 }
                 //generate people query
                 $peopleModel = new People();
                 $peopleModel->set('company_id', $company['id']);
                 $companies[$key]['people'] = $peopleModel->getContacts();
                 //generate deal query
                 $dealModel = new Deal();
                 $dealModel->set('company_id', $company['id']);
                 $deals = $dealModel->getDeals();
                 $companies[$key]['pipeline'] = 0;
                 $companies[$key]['won_deals'] = 0;
                 for ($i = 0; $i < count($deals); $i++) {
                     $deal = $deals[$i];
                     $companies[$key]['pipeline'] += $deal->amount;
                     if ($deal->percent == 100) {
                         $companies[$key]['won_deals'] += $deal->amount;
                     }
                 }
                 $companies[$key]['deals'] = $deals;
                 //Get Associated Notes
                 $notesModel = new Note();
                 $companies[$key]['notes'] = $notesModel->getNotes($company['id'], 'company');
                 // Get Associated Documents
                 $documentModel = new Document();
                 $documentModel->set('company_id', $company['id']);
                 $companies[$key]['documents'] = $documentModel->getDocuments();
                 $companies[$key]['address_formatted'] = strlen($company['address_1']) > 0 ? $company['address_1'] . $company['address_2'] . ", " . $company['address_city'] . ' ' . $company['address_state'] . ', ' . $company['address_zip'] . ' ' . $company['address_country'] : "";
             }
         }
     }
     //$app->triggerEvent('onCompanyLoad',array(&$companies));
     return $companies;
 }