예제 #1
0
 public function __construct()
 {
     $this->previousDay = DateHelper::formatDBDate(date('Y-m-d') . " - 1 day");
     $this->today = DateHelper::formatDBDate(date('Y-m-d'));
     $this->access = UsersHelper::getRole($this->person_id);
     $this->users = $this->getUsers($this->person_id, $this->access);
 }
예제 #2
0
 public static function getTotalDocuments()
 {
     //db
     $db = \Cobalt\Container::fetch('db');
     $query = $db->getQuery(true);
     //select
     $query->select("count(*)");
     $query->from("#__documents AS d");
     //filter depending on user access
     $role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     if ($role != 'exec') {
         if ($role == 'manager') {
             $query->join('inner', '#__users AS u ON d.owner_id = u.id');
             $query->where('u.team_id=' . $team_id);
         } else {
             $query->where(array("d.owner_id=" . $user_id, 'd.shared=1'), 'OR');
         }
     }
     //return count
     $db->setQuery($query);
     $result = $db->loadResult();
     return $result;
 }
예제 #3
0
 public function render($tpl = null)
 {
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     //event model
     $model = new EventModel();
     $view = $app->input->get('view');
     $layout = $this->getLayout();
     switch ($layout) {
         case 'event_dock':
             break;
         case 'edit_event':
         case 'edit_task':
             break;
         case 'default':
         default:
             $event_id = $app->input->get('id');
             if ($app->input->get('loc')) {
                 $events = $model->getEvents($app->input->get('loc'), null, $app->input->get($app->input->get('loc') . '_id'));
             } else {
                 $events = $model->getEvents();
             }
             $state = $model->getState();
             $this->event_statuses = EventHelper::getEventStatuses();
             $this->event_types = EventHelper::getEventTypes();
             $this->event_categories = EventHelper::getCategories(TRUE);
             $this->event_due_dates = EventHelper::getEventDueDates();
             $this->event_associations = EventHelper::getEventAssociations();
             $this->event_users = UsersHelper::getUsers(NULL, TRUE);
             $this->event_teams = UsersHelper::getTeams();
             $this->dataTableColumns = $model->getDataTableColumns();
             $document->addScriptDeclaration("\n            loc = 'events';\n            order_url = 'index.php?view=events&layout=list&format=raw&tmpl=component';\n            order_dir = '" . $state->get('Event.' . $view . '_' . $layout . '_' . 'filter_order_Dir') . "';\n            order_col = '" . $state->get('Event.' . $view . '_' . $layout . '_' . 'filter_order') . "';\n            var dataTableColumns = " . json_encode($this->dataTableColumns) . ";");
             $this->state = $state;
             break;
     }
     if ($layout != 'edit_task' || $layout != "edit_event") {
         if (TemplateHelper::isMobile()) {
             $model->set('current_events', true);
             $document->addScriptDeclaration('loc="events";');
         }
     }
     if (TemplateHelper::isMobile() && isset($event_id)) {
         $person_model = new PeopleModel();
         $person_model->set('event_id', $event_id);
         $person_model->set('recent', false);
         $person_model->set('_id', null);
         $this->people = $person_model->getPeople();
     }
     $document->addScriptDeclaration('var layout="' . $layout . '"');
     //assign results to view
     $this->events = $events;
     $this->member_role = UsersHelper::getRole();
     $this->user_id = UsersHelper::getUserId();
     $this->team_id = UsersHelper::getTeamId();
     //display
     return parent::render();
 }
예제 #4
0
 public function execute()
 {
     $loc = $this->makeSingular($this->getInput()->getString('loc'));
     $modelPath = "Cobalt\\Model\\" . ucwords($loc);
     $model = new $modelPath();
     $start = $this->getInput()->getInt('start', 0);
     $length = $this->getInput()->getInt('length', 0);
     $orderArr = $this->getInput()->get('order', array(array('column' => 1, 'dir' => 'asc')), 'ARRAY');
     $searchArr = $this->getInput()->get('search', array('value' => '', 'regex' => false), 'ARRAY');
     $columns = $model->getDataTableColumns();
     $user = $this->getApplication()->getUser();
     $teamId = UsersHelper::getTeamId();
     $memberRole = UsersHelper::getRole();
     $countFunc = 'get' . ucwords($loc) . 'Count';
     // Set request variables which models will understand
     if (isset($columns[$orderArr[0]['column']]['ordering'])) {
         $order = $columns[$orderArr[0]['column']]['ordering'];
         $this->getInput()->set('filter_order', $order);
     }
     if (isset($orderArr[0]['dir'])) {
         $dir = $orderArr[0]['dir'];
         $this->getInput()->set('filter_order_Dir', $dir);
     }
     if (isset($searchArr['value'])) {
         $value = $this->setFilters($searchArr['value']);
     }
     $this->getInput()->set('limit', $length);
     $this->getInput()->set('limitstart', $start);
     // Prepare response
     $response = new \stdClass();
     $response->data = $model->getDataTableItems();
     $response->draw = $this->getInput()->getInt('draw');
     $response->recordsTotal = UsersHelper::$countFunc($user->get('id'), $teamId, $memberRole);
     $response->recordsFiltered = $model->getTotal();
     $alerts = $this->getApplication()->getMessageQueue();
     if (isset($alerts[0])) {
         $response->alert = new \stdClass();
         $response->alert->message = $alerts[0];
         $response->alert->type = 'alert';
         $this->getApplication()->clearMessageQueue();
     }
     $this->getApplication()->close(json_encode($response));
 }
예제 #5
0
 /**
  * Get sources for return on investment reports
  * @param none
  * @return mixed $results
  */
 public function getRoiSources()
 {
     //get DBO
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     //construct query string
     $query->select("s.id,s.name,count(d.id) as number_of_deals,sum(d.amount) as revenue,s.type,s.cost");
     $query->select("IF ( s.type <> 'per', ( ( ( ( sum(d.amount) - s.cost ) / s.cost ) * 100 ) ), ( ( sum(d.amount) - ( s.cost * count(d.id) ) ) / ( s.cost * count(d.id) ) * 100 ) ) AS roi");
     $query->from("#__sources AS s");
     //left join data
     $won_stage_ids = DealHelper::getWonStages();
     $query->leftJoin("#__deals AS d ON d.source_id = s.id AND d.stage_id IN (" . implode(',', $won_stage_ids) . ") AND d.published=1 AND d.archived=0");
     $query->leftJoin("#__users AS u ON u.id = d.owner_id");
     //set our sorting direction if set via post
     $query->order($this->getState('Source.filter_order') . ' ' . $this->getState('Source.filter_order_Dir'));
     //group data
     $query->group("s.id");
     if ($this->_id) {
         if (is_array($this->_id)) {
             $query->where("s.id IN (" . implode(',', $this->_id) . ")");
         } else {
             $query->where("s.id={$this->_id}");
         }
     }
     //filter based on member access roles
     $user_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     if ($member_role != 'exec') {
         if ($member_role == 'manager') {
             $query->where("u.team_id={$team_id}");
         } else {
             $query->where("(d.owner_id={$user_id})");
         }
     }
     //set query and load results
     $db->setQuery($query);
     $results = $db->loadAssocList();
     return $results;
 }
예제 #6
0
 public function render()
 {
     //app
     $this->app = JFactory::getApplication();
     //load reports menu bar
     $this->menu = TemplateHelper::loadReportMenu();
     //get document
     $this->document = JFactory::getDocument();
     //determine view layout
     $this->layout = $this->getLayout();
     $func = "_display_" . $this->layout;
     if (method_exists($this, $func)) {
         $this->{$func}();
     }
     //assign user filter priviliges
     $this->member_role = UsersHelper::getRole();
     $this->user_id = UsersHelper::getUserId();
     $this->team_id = UsersHelper::getTeamId();
     //if the user is not basic then they are able to filter through company/team/user data
     if ($this->member_role != 'basic') {
         //exec can see teams
         if ($this->member_role == 'exec') {
             $this->teams = UsersHelper::getTeams();
         }
         //manager and exec users
         $this->users = UsersHelper::getUsers();
     }
     //assign team names for drop downs
     $this->team_names = DropdownHelper::getTeamNames();
     //assign user names for drop downs
     $this->user_names = DropdownHelper::getUserNames();
     //assign categories for drop downs
     $this->categories = NoteHelper::getCategories();
     //display
     return parent::render();
 }
예제 #7
0
 public function getNotes($object_id = NULL, $type = NULL, $display = true)
 {
     $app = \Cobalt\Container::fetch('app');
     //grab db
     $db = JFactory::getDBO();
     //initialize query
     $query = $db->getQuery(true);
     //gen query string
     $query->select("n.*,cat.name as category_name,comp.name as company_name,\n                        comp.id as company_id,deal.name as deal_name,deal.id as deal_id,\n                        person.id as person_id,person.first_name as person_first_name,\n                        person.last_name as person_last_name, owner.first_name as owner_first_name,\n                        event.name as event_name, event.id as event_id,\n                        owner.last_name as owner_last_name, author.email");
     $query->from("#__notes as n");
     $query->leftJoin("#__notes_categories AS cat ON cat.id = n.category_id");
     $query->leftJoin("#__companies AS comp ON comp.id = n.company_id AND comp.published>0");
     $query->leftJoin("#__events AS event ON event.id = n.event_id AND event.published>0");
     $query->leftJoin("#__deals AS deal ON deal.id = n.deal_id AND deal.published>0");
     $query->leftJoin("#__people AS person on n.person_id = person.id AND person.published>0");
     $query->leftJoin("#__users AS owner ON n.owner_id = owner.id");
     $query->leftJoin("#__users AS author ON author.id = owner.id");
     $company_filter = $this->getState('Note.company_name');
     if ($company_filter != null) {
         $query->where("comp.name LIKE '%" . $company_filter . "%'");
     }
     //deal
     $deal_filter = $this->getState('Note.deal_name');
     if ($deal_filter != null) {
         $query->where("deal.name LIKE '%" . $deal_filter . "%'");
     }
     //person
     $person_filter = $this->getState('Note.person_name');
     if ($person_filter != null) {
     }
     if ($object_id) {
         switch ($type) {
             case 'person':
             case 'people':
                 $query->where('n.person_id =' . $object_id);
                 break;
             case 'company':
                 $query->where('(n.company_id =' . $object_id . ' OR deal.company_id = ' . $object_id . ' OR person.company_id = ' . $object_id . ")");
                 break;
             case 'deal':
                 $query->where('n.deal_id=' . $object_id);
                 break;
             case "event":
                 $query->where("n.event_id={$object_id}");
                 break;
         }
     }
     //owner
     $owner_filter = $this->getState('Note.owner_id');
     if ($owner_filter != null && $owner_filter != "all") {
         $owner_type = $this->getState('Note.owner_type');
         switch ($owner_type) {
             case "team":
                 $team_member_ids = UsersHelper::getTeamUsers($owner_filter, TRUE);
                 $query->where("n.owner_id IN (" . implode(',', $team_member_ids) . ")");
                 break;
             case "member":
                 $query->where("n.owner_id=" . $owner_filter);
                 break;
         }
     }
     //created
     $created_filter = $this->getState('Note.created');
     if ($company_filter != null) {
     }
     //category
     $category_filter = $this->getState('Note.category_id');
     if ($category_filter != null) {
         $query->where("n.category_id=" . $category_filter);
     }
     if ($this->_id) {
         if (is_array($this->_id)) {
             $query->where("n.id IN (" . implode(',', $this->_id) . ")");
         } else {
             $query->where("n.id={$this->_id}");
         }
     }
     /** ---------------------------------------------------------------
      * Filter data using member role permissions
      */
     $member_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     if ($this->public_notes != true) {
         if ($member_role != 'exec') {
             //manager filter
             if ($member_role == 'manager') {
                 $query->where('owner.team_id = ' . $team_id);
             } else {
                 //basic user filter
                 $query->where(array('n.owner_id = ' . $member_id));
             }
         }
     }
     $query->where("n.published=" . $this->published);
     $query->order("n.modified DESC");
     //load results
     $db->setQuery($query);
     $results = $db->loadAssocList();
     //clean results
     if (count($results) > 0) {
         foreach ($results as $key => $note) {
             $results[$key]['created_formatted'] = DateHelper::formatDate($note['created']);
             $results[$key]['owner_avatar'] = CobaltHelper::getGravatar($note['email']);
         }
     }
     //$app->triggerEvent('onNoteLoad', array(&$results));
     if (!$display) {
         //return results
         return $results;
     } else {
         $notesView = ViewHelper::getView('note', 'default', 'phtml', array('notes' => $results));
         return $notesView;
     }
 }
예제 #8
0
 public function buildWhere()
 {
     if ($this->deal_id) {
         $this->query->where("(cf.association_id = " . $this->deal_id . " OR d2.id = " . $this->deal_id . ")");
     }
     if ($this->event_id) {
         $event_model = new Event();
         $event = $event_model->getEvent($this->event_id);
         if (array_key_exists('association_type', $event) && $event['association_type'] != null) {
             switch ($event['association_type']) {
                 case "person":
                     $this->query->where("p.id=" . $event['association_id']);
                     break;
                 case "deal":
                     $this->query->where("cf.association_id=" . $event['association_id']);
                     $this->query->where("cf.association_type='deal'");
                     break;
                 case "company":
                     $this->query->where("p.company_id=" . $event['association_id']);
                     break;
             }
         } else {
             return false;
         }
     }
     if ($this->company_id) {
         $this->query->where("p.company_id=" . $this->company_id);
     }
     //filter based on member access roles
     $user_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     if ($member_role != 'exec') {
         if ($member_role == 'manager') {
             $this->query->where("u.team_id={$team_id}");
         } else {
             $this->query->where("p.owner_id={$user_id}");
         }
     }
     $this->query->where("p.published>0");
     return true;
 }
예제 #9
0
 public function render()
 {
     $app = JFactory::getApplication();
     //determine the type of goal we are creating//editing
     $type = $app->input->get('type');
     //edit layout
     if ($this->getLayout() == 'edit') {
         switch ($type) {
             case "win_cash":
                 $header = ucwords(TextHelper::_('COBALT_WIN_MORE_CASH'));
                 break;
             case "win_deals":
                 $header = ucwords(TextHelper::_('COBALT_WIN_MORE_DEALS'));
                 break;
             case "move_deals":
                 $header = ucwords(TextHelper::_('COBALT_MOVE_DEALS_FORWARD'));
                 break;
             case "complete_tasks":
                 $header = ucwords(TextHelper::_('COBALT_COMPLETE_TASKS'));
                 break;
             case "write_notes":
                 $header = ucwords(TextHelper::_('COBALT_WRITE_NOTES'));
                 break;
             case "create_deals":
                 $header = ucwords(TextHelper::_('COBALT_CREATE_DEALS'));
                 break;
             default:
                 $app->redirect('index.php?view=goals');
                 break;
         }
         $this->header = $header;
     } elseif ($this->getLayout() != 'add') {
         //load model
         $model = new GoalModel();
         //get all goals from model depending on user type
         $member_role = UsersHelper::getRole();
         //basic members
         if ($member_role == 'basic') {
             $individual_goals = $model->getIndividualGoals();
             $team_goals = $model->getTeamGoals();
             $company_goals = $model->getCompanyGoals();
             $leaderboards = $model->getLeaderBoards();
         }
         //managers
         if ($member_role == 'manager') {
             // $individual_goals = $model->getManagerIndividualGoals();
             $individual_goals = $model->getIndividualGoals();
             $team_goals = $model->getTeamGoals();
             $company_goals = $model->getCompanyGoals();
             $leaderboards = $model->getLeaderBoards();
         }
         //executives
         if ($member_role == 'exec') {
             // $individual_goals = $model->getExecIndividualGoals();
             $individual_goals = $model->getIndividualGoals();
             // $team_goals = $model->getExecTeamGoals();
             $team_goals = $model->getTeamGoals();
             $company_goals = $model->getCompanyGoals();
             $leaderboards = $model->getLeaderBoards();
         }
         //assign goals to global goal object to pass through to view
         $goals = new \stdClass();
         $goals->individual_goals = $individual_goals;
         $goals->team_goals = $team_goals;
         $goals->company_goals = $company_goals;
         $goals->leaderboards = $leaderboards;
         //if we get results then load the default goals page else show the add goals page
         $goal_count = false;
         foreach ($goals as $goal_list) {
             if (count($goal_list) > 0) {
                 $goal_count = true;
             }
         }
         if ($goal_count) {
             //set layout
             $this->setLayout('default');
             //assign view refs
             $this->goals = $goals;
         } else {
             //add goal layout
             $this->setLayout('add');
         }
     }
     //load java libs
     $doc = JFactory::getDocument();
     $doc->addScript(JURI::base() . 'src/Cobalt/media/js/goal_manager.js');
     //get associated members and teams
     $teams = UsersHelper::getTeams();
     $users = UsersHelper::getUsers();
     $member_role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     //assign view refs
     $this->type = $type;
     $this->teams = $teams;
     $this->users = $users;
     $this->user_id = $user_id;
     $this->team_id = $team_id;
     $this->member_role = $member_role;
     $this->leaderboard_list = DropdownHelper::getLeaderBoards();
     //display
     return parent::render();
 }
예제 #10
0
 /**
  * Get data for custom reports
  * @param  int   $id custom id data to retrieve
  * @return mixed $results
  */
 public function getCustomReportData($id = null)
 {
     //get db
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $app = \Cobalt\Container::fetch('app');
     //get the custom report so we know what data to filter and select
     $custom_report = $this->getCustomReports($id);
     $custom_report = $custom_report[0];
     $custom_report_fields = unserialize($custom_report['fields']);
     //gen query
     //construct query string
     $queryString = 'd.*,SUM(d.amount) AS filtered_total,';
     $queryString .= 'c.name as company_name,';
     $queryString .= 'stat.name as status_name,';
     $queryString .= 'source.name as source_name,';
     $queryString .= 'stage.name as stage_name,stage.percent,';
     $queryString .= 'user.first_name, user.last_name,';
     $queryString .= 'p.first_name as primary_contact_first_name,p.last_name as primary_contact_last_name,';
     $queryString .= "p.email as primary_contact_email,p.phone as primary_contact_phone,";
     $queryString .= "pc.name as primary_contact_company_name";
     //select
     $query->select($queryString);
     $query->from("#__deals AS d");
     //left join
     $query->leftJoin('#__companies AS c ON c.id = d.company_id AND c.published>0');
     $query->leftJoin('#__deal_status AS stat ON stat.id = d.status_id');
     $query->leftJoin('#__sources AS source ON source.id = d.source_id');
     $query->leftJoin('#__stages AS stage on stage.id = d.stage_id');
     $query->leftJoin('#__users AS user ON user.id = d.owner_id');
     $query->leftJoin("#__people AS p ON p.id = d.primary_contact_id AND p.published>0");
     $query->leftJoin("#__companies AS pc ON pc.id = p.company_id AND pc.published>0");
     //group results
     $query->group("d.id");
     //filter data with user state requests
     $layout = str_replace("_filter", "", $app->input->get('layout'));
     $view = $app->input->get('view');
     if ($view == "print") {
         $layout = "custom_report";
         $id = $app->input->get('custom_report');
     }
     $filter_order = $this->getState('Report.' . $id . '_' . $layout . '_filter_order');
     $filter_order_Dir = $this->getState('Report.' . $id . '_' . $layout . '_filter_order_Dir');
     $filter_order = strstr($filter_order, "custom_") ? str_replace("d.", "", $filter_order) : $filter_order;
     $query->order($filter_order . ' ' . $filter_order_Dir);
     //assign defaults
     $close = null;
     $modified = null;
     $created = null;
     $status = null;
     $source = null;
     $stage = null;
     //filter by deal names
     $deal_filter = $this->getState('Report.' . $id . '_' . $layout . '_name');
     if ($deal_filter != null) {
         $query->where("d.name LIKE '%" . $deal_filter . "%'");
     }
     //owner
     $owner_filter = $this->getState('Report.' . $id . '_' . $layout . '_owner_id');
     if ($owner_filter != null and $owner_filter != 'all') {
         $owner_type = $this->getState('Report.' . $id . '_' . $layout . '_owner_type');
         if ($owner_type == 'member') {
             $query->where("d.owner_id=" . $owner_filter);
         }
         if ($owner_type == 'team') {
             //get team members
             $team_members = UsersHelper::getTeamUsers($owner_filter);
             //filter by results having team ids
             $ids = "";
             for ($i = 0; $i < count($team_members); $i++) {
                 $member = $team_members[$i];
                 $ids .= $member['id'] . ",";
             }
             $ids = substr($ids, 0, -1);
             $query->where("d.owner_id IN(" . $ids . ")");
         }
     }
     //amount
     $amount_filter = $this->getState('Report.' . $id . '_' . $layout . '_amount');
     if ($amount_filter != null and $amount_filter != 'all') {
         if ($amount_filter == 'small') {
             $query->where("d.amount <= 50");
         }
         if ($amount_filter == 'medium') {
             $query->where("d.amount > 50 AND d.amount <= 400");
         }
         if ($amount_filter == 'large') {
             $query->where("d.amount > 400");
         }
     }
     //source
     $source_filter = $this->getState('Report.' . $id . '_' . $layout . '_source_id');
     if ($source_filter != null and $source_filter != 'all') {
         $source = $source_filter;
     }
     //stage
     $stage_filter = $this->getState('Report.' . $id . '_' . $layout . '_stage_id');
     if ($stage_filter != null and $stage_filter != 'all') {
         $stage = $stage_filter;
     }
     //status
     $status_filter = $this->getState('Report.' . $id . '_' . $layout . '_status_id');
     if ($status_filter != null and $status_filter != 'all') {
         $status = $status_filter;
     }
     //expected close
     $expected_close_filter = $this->getState('Report.' . $id . '_' . $layout . '_expected_close');
     if ($expected_close_filter != null and $expected_close_filter != 'all') {
         $close = $expected_close_filter;
     }
     //modified
     $modified_filter = $this->getState('Report.' . $id . '_' . $layout . '_modified');
     if ($modified_filter != null and $modified_filter != 'all') {
         $modified = $modified_filter;
     }
     //created
     $created_filter = $this->getState('Report.' . $id . '_' . $layout . '_created');
     if ($created_filter != null and $created_filter != 'all') {
         $created = $created_filter;
     }
     //filter by primary contact name
     $primary_contact_name = $this->getState('Report.' . $id . '_' . $layout . '_primary_contact_name');
     if ($primary_contact_name != null) {
         $query->where("(p.first_name LIKE '%" . $primary_contact_name . "%' OR p.last_name LIKE '%" . $primary_contact_name . "%')");
     }
     //filter by primary contact email
     $primary_contact_email = $this->getState('Report.' . $id . '_' . $layout . '_primary_contact_email');
     if ($primary_contact_email != null) {
         $query->where("p.email LIKE '%" . $primary_contact_email . "%'");
     }
     //filter by primary contact phone
     $primary_contact_phone = $this->getState('Report.' . $id . '_' . $layout . '_primary_contact_phone');
     if ($primary_contact_phone != null) {
         $query->where("p.phone LIKE '%" . $primary_contact_phone . "%'");
     }
     //get current date to use for all date filtering
     $date = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
     /** --------------------------------------------
      * Search for closing deal filters
      */
     if ($close != null && $close != "any") {
         if ($close == "this_week") {
             $this_week = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
             $next_week = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+7 days"));
             $query->where("d.expected_close >= '{$this_week}'");
             $query->where("d.expected_close < '{$next_week}'");
         }
         if ($close == "next_week") {
             $next_week = date('Y-m-d 00:00:00', strtotime(DateHelper::formatDBDate(date("Y-m-d", strtotime($date))) . "+7 days"));
             $week_after_next = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+14 days"));
             $query->where("d.expected_close >= '{$next_week}'");
             $query->where("d.expected_close < '{$week_after_next}'");
         }
         if ($close == "this_month") {
             $this_month = DateHelper::formatDBDate(date('Y-m-0 00:00:00'));
             $next_month = date('Y-m-0 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+1 month"));
             $query->where("d.expected_close >= '{$this_month}'");
             $query->where("d.expected_close < '{$next_month}'");
         }
         if ($close == "next_month") {
             $next_month = date("Y-m-0 00:00:00", strtotime(date("Y-m-d 00:00:00", strtotime($date)) . "+1 month"));
             $next_next_month = date("Y-m-0 00:00:00", strtotime(date("Y-m-d 00:00:00", strtotime($date)) . "+2 months"));
             $query->where("d.expected_close >= '{$next_month}'");
             $query->where("d.expected_close < '{$next_next_month}'");
         }
     }
     /** --------------------------------------------
      * Search for modified deal filters
      */
     if ($modified != null && $modified != "any") {
         if ($modified == "this_week") {
             $this_week = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
             $last_week = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "-7 days"));
             $query->where("d.modified >= '{$last_week}'");
             $query->where("d.modified < '{$this_week}'");
         }
         if ($modified == "last_week") {
             $last_week = DateHelper::formatDBDate(date("Y-m-d", strtotime("-7 days")));
             $week_before_last = DateHelper::formatDBDate(date("Y-m-d", strtotime("-14 days")));
             $query->where("d.modified >= '{$week_before_last}'");
             $query->where("d.modified < '{$last_week}'");
         }
         if ($modified == "this_month") {
             $this_month = DateHelper::formatDBDate(date('Y-m-1 00:00:00'));
             $next_month = date('Y-m-1 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+1 month"));
             $query->where("d.modified >= '{$this_month}'");
             $query->where("d.modified < '{$next_month}'");
         }
         if ($modified == "last_month") {
             $this_month = DateHelper::formatDBDate(date('Y-m-1 00:00:00'));
             $last_month = date('Y-m-1 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "-1 month"));
             $query->where("d.modified >= '{$last_month}'");
             $query->where("d.modified < '{$this_month}'");
         }
     }
     /** --------------------------------------------
      * Search for created deal filters
      */
     if ($created != null && $created != "any") {
         if ($created == "this_week") {
             $this_week = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
             $last_week = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date) . "-7 days")));
             $query->where("d.created >= '{$last_week}'");
             $query->where("d.created < '{$this_week}'");
         }
         if ($created == "last_week") {
             $last_week = DateHelper::formatDBDate(date("Y-m-d", strtotime("-7 days")));
             $week_before_last = DateHelper::formatDBDate(date("Y-m-d", strtotime("-14 days")));
             $query->where("d.created >= '{$week_before_last}'");
             $query->where("d.created < '{$last_week}'");
         }
         if ($created == "this_month") {
             $this_month = DateHelper::formatDBDate(date('Y-m-1 00:00:00'));
             $next_month = date('Y-m-1 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+1 month"));
             $query->where("d.created >= '{$this_month}'");
             $query->where("d.created < '{$next_month}'");
         }
         if ($created == "last_month") {
             $this_month = DateHelper::formatDBDate(date('Y-m-1 00:00:00'));
             $last_month = date('Y-m-1 00:00:00', strtotime(date("Y-m-d", strtotime($date) . "-1 month")));
             $query->where("d.created >= '{$last_month}'");
             $query->where("d.created < '{$this_month}'");
         }
         if ($created == "today") {
             $today = DateHelper::formatDBDate(date("Y-m-d 00:00:00"));
             $tomorrow = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+1 day"));
             $query->where("d.created >= '{$today}'");
             $query->where("d.created < '{$tomorrow}'");
         }
         if ($created == "yesterday") {
             $today = DateHelper::formatDBDate(date("Y-m-d 00:00:00"));
             $yesterday = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "-1 day"));
             $query->where("d.created >= '{$yesterday}'");
             $query->where("d.created < '{$today}'");
         }
     }
     /** ------------------------------------------
      * Search for status
      */
     if ($status != null and $status != 'all') {
         $query->where("d.status_id=" . $status);
     }
     /** -------------------------
      * Search for sources
      */
     if ($source != null and $source != 'all') {
         $query->where('d.source_id=' . $source);
     }
     /** ----------------------------------------------------------------
      * Filter for stage id associations
      */
     if ($stage != null && $stage != 'all') {
         //if we want active deals we must retrieve the active stage ids to filter by
         if ($stage == 'active') {
             //get stage ids
             $stage_ids = DealHelper::getActiveStages();
             //filter by results having team ids
             $stages = "";
             for ($i = 0; $i < count($stage_ids); $i++) {
                 $stage = $stage_ids[$i];
                 $stages .= $stage['id'] . ",";
             }
             $stages = substr($stages, 0, -1);
             $query->where("d.stage_id IN(" . $stages . ")");
         } else {
             // else filter by the stage id
             $query->where("d.stage_id='" . $stage . "'");
         }
     }
     /** ---------------------------------------------------------------------------------------------------------------
      * Field for custom field user states
      */
     //Get custom filters
     $custom_fields = DealHelper::getUserCustomFields();
     //If the user has defined any custom fields we will left join the associated data here
     if (count($custom_fields) > 0) {
         foreach ($custom_fields as $row) {
             //Join different data based on type
             switch ($row['type']) {
                 //If the type is forecast we want to calculate the amount
                 case "forecast":
                     $query->select("( d.amount * ( d.probability / 100 )) as custom_" . $row['id']);
                     break;
                     //Else join the associated value from the database
                 //Else join the associated value from the database
                 default:
                     $query->select("custom_" . $row['id'] . ".value as custom_" . $row['id']);
                     $query->leftJoin("#__deal_custom_cf as custom_" . $row['id'] . " on " . "custom_" . $row['id'] . ".deal_id = d.id AND " . "custom_" . $row['id'] . ".custom_field_id = " . $row['id']);
                     break;
             }
             //If the user has any associated user state requests set in the model we set the filters here
             $custom_field_filter = $this->getState('Report.' . $id . '_' . $layout . '_' . $row['id']);
             if ($custom_field_filter != null and $custom_field_filter != 'all') {
                 switch ($row['type']) {
                     case "forecast":
                         $query->where("( d.amount * ( d.probability / 100 )) LIKE '%" . $custom_field_filter . "%'");
                         break;
                     case "date":
                         if ($custom_field_filter == "this_week") {
                             $this_week = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
                             $next_week = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+7 days"));
                             $query->where("custom_" . $row['id'] . ".value >= '{$this_week}'");
                             $query->where("custom_" . $row['id'] . ".value < '{$next_week}'");
                         }
                         if ($custom_field_filter == "next_week") {
                             $next_week = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+7 days"));
                             $week_after_next = date('Y-m-d 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+14 days"));
                             $query->where("custom_" . $row['id'] . ".value >= '{$next_week}'");
                             $query->where("custom_" . $row['id'] . ".value < '{$week_after_next}'");
                         }
                         if ($custom_field_filter == "this_month") {
                             $this_month = DateHelper::formatDBDate(date('Y-m-0 00:00:00'));
                             $next_month = date('Y-m-0 00:00:00', strtotime(date("Y-m-d", strtotime($date)) . "+1 month"));
                             $query->where("custom_" . $row['id'] . ".value >= '{$this_month}'");
                             $query->where("custom_" . $row['id'] . ".value < '{$next_month}'");
                         }
                         if ($custom_field_filter == "next_month") {
                             $next_month = date("Y-m-0 00:00:00", strtotime(date("Y-m-d 00:00:00", strtotime($date)) . "+1 month"));
                             $next_next_month = date("Y-m-0 00:00:00", strtotime(date("Y-m-d 00:00:00", strtotime($date)) . "+2 months"));
                             $query->where("custom_" . $row['id'] . ".value >= '{$next_month}'");
                             $query->where("custom_" . $row['id'] . ".value < '{$next_next_month}'");
                         }
                         break;
                     default:
                         $query->where("custom_" . $row['id'] . ".value LIKE '%" . $custom_field_filter . "%'");
                         break;
                 }
             }
         }
     }
     //filter based on member access roles
     $user_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     if ($member_role != 'exec') {
         if ($member_role == 'manager') {
             $query->where("user.team_id={$team_id}");
         } else {
             $query->where("(d.owner_id={$user_id})");
         }
     }
     $query->where("d.published=" . $this->published);
     $query->where("d.archived=0");
     //return results
     $db->setQuery($query);
     $results = $db->loadAssocList();
     return $results;
 }
예제 #11
0
 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();
 }
예제 #12
0
 /**
  * Build our db query object
  */
 public function _buildQuery()
 {
     $app = \Cobalt\Container::fetch('app');
     if ($this->db->name == 'mysqli') {
         $this->db->setQuery("SET SQL_BIG_SELECTS=1")->execute();
     }
     $user = $this->_user;
     $team = $this->_team;
     $id = $this->_id;
     $type = $this->_type;
     $view = $app->input->get('view');
     if (!$id) {
         $session = $app->getSession();
         //determine whether we are searching for a team or user
         if ($user) {
             $session->set('company_team_filter', null);
         }
         if ($team) {
             $session->set('company_user_filter', null);
         }
         //set user session data
         if ($type != null) {
             $session->set('company_type_filter', $type);
         } else {
             $sess_type = $session->get('company_type_filter');
             $type = $sess_type;
         }
         if ($user != null) {
             $session->set('company_user_filter', $user);
         } else {
             $sess_user = $session->get('company_user_filter');
             $user = $sess_user;
         }
         if ($team != null) {
             $session->set('company_team_filter', $team);
         } else {
             $sess_team = $session->get('company_team_filter');
             $team = $sess_team;
         }
     }
     //generate query for base companies
     $query = $this->db->getQuery(true);
     $export = $app->input->get('export');
     if ($export) {
         $select_string = 'c.name,c.description,c.address_1,c.address_2,c.address_city,';
         $select_string .= 'c.address_state,c.address_zip,c.address_country,c.website,c.created,c.modified';
         $query->select($select_string)->from("#__companies as c")->leftJoin("#__users AS u on u.id = c.owner_id");
     } else {
         $query->select('c.*')->from("#__companies as c")->leftJoin("#__users AS u on u.id = c.owner_id");
     }
     if (!$id) {
         //get current date
         $date = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
         $type = $this->getState('Company.item_filter', $type);
         //filter for type
         if ($type != null && $type != "all") {
             //filter for companies with tasks due today
             if ($type == 'today') {
                 $query->leftJoin("#__events_cf as event_company_cf on event_company_cf.association_id = c.id AND event_company_cf.association_type='company'");
                 $query->join('INNER', "#__events as event on event.id = event_company_cf.event_id");
                 $query->where("event.due_date='{$date}'");
                 $query->where("event.published>0");
             }
             //filter for companies and deals//tasks due tomorrow
             if ($type == "tomorrow") {
                 $tomorrow = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() + 1 * 24 * 60 * 60));
                 $query->leftJoin("#__events_cf as event_company_cf on event_company_cf.association_id = c.id AND event_company_cf.association_type='company'");
                 $query->join('INNER', "#__events as event on event.id = event_company_cf.event_id");
                 $query->where("event.due_date='{$tomorrow}'");
                 $query->where("event.published>0");
             }
             //filter for companies updated in the last 30 days
             if ($type == "updated_thirty") {
                 $last_thirty_days = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() - 30 * 24 * 60 * 60));
                 $query->where("c.modified >'{$last_thirty_days}'");
             }
             //filter for past companies// last contacted 30 days ago or longer
             if ($type == "past") {
                 $last_thirty_days = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() - 30 * 24 * 60 * 60));
                 $query->where("c.modified <'{$last_thirty_days}'");
             }
             //filter for recent companies
             if ($type == "recent") {
                 $last_thirty_days = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() - 30 * 24 * 60 * 60));
                 $query->where("c.modified >'{$last_thirty_days}'");
             }
             $query->group("c.id");
         }
         /** company name filter **/
         $company_name = $this->getState('Company.' . $view . '_name');
         if ($company_name != null) {
             $query->where("( c.name LIKE '%" . $company_name . "%' )");
         }
     }
     //search for specific companies
     if ($id != null) {
         if (is_array($id)) {
             $query->where("c.id IN (" . implode(',', $id) . ")");
         } else {
             $query->where("c.id={$id}");
         }
     }
     //filter based on member access roles
     $user_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     //filter based on specified user
     if ($user && $user != 'all') {
         $query->where("c.owner_id = " . $user);
     }
     //filter based on team
     if ($team) {
         $team_members = UsersHelper::getTeamUsers($team, true);
         $query->where("c.owner_id IN (" . implode(',', $team_members) . ")");
     }
     //set user state requests
     $query->order($this->getState('Company.filter_order') . ' ' . $this->getState('Company.filter_order_Dir'))->where("c.published=" . $this->published);
     return $query;
 }
예제 #13
0
 /**
  * Method to retrieve documents
  * @param $id specific id to retrieve, if null all are returned
  */
 public function getDocuments($id = null)
 {
     $app = \Cobalt\Container::fetch('app');
     //get DBO
     $db = JFactory::getDBO();
     //gen query
     $query = $db->getQuery(true);
     $query->select("d.*," . "c.name as company_name," . "deal.name as deal_name," . "p.first_name as owner_first_name, p.last_name as owner_last_name," . "CONCAT(u.first_name,' ',u.last_name) AS owner_name");
     $query->from("#__documents AS d");
     $query->leftJoin("#__companies AS c ON d.association_type = 'company' AND d.association_id = c.id");
     $query->leftJoin("#__deals AS deal ON d.association_type = 'deal' AND d.association_id = deal.id");
     $query->leftJoin("#__people AS p ON d.association_type ='person' AND d.association_id = p.id");
     $query->leftJoin("#__users AS u ON u.id = d.owner_id");
     //get user data
     $member_type = UsersHelper::getRole();
     $member_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     //get session data
     $session = JFactory::getSession();
     //get post data
     $assoc = $app->input->get('assoc');
     $user = $app->input->get('user');
     $type = $app->input->get('type');
     $team = $app->input->get('team_id');
     $document_name = $app->input->getString('document_name');
     //determine if we are searching for a team or a user
     if ($team) {
         $session->set('document_user_filter', null);
     }
     if ($user) {
         $session->set('document_team_filter', null);
     }
     //set user session data
     if ($assoc != null) {
         $session->set('document_assoc_filter', $assoc);
     } else {
         $sess_assoc = $session->get('document_assoc_filter');
         $assoc = $sess_assoc;
     }
     if ($user != null) {
         $session->set('document_user_filter', $user);
         $session->set('document_team_filter', null);
     } else {
         $sess_user = $session->get('document_user_filter');
         $user = $sess_user;
     }
     if ($type != null) {
         $session->set('document_type_filter', $type);
     } else {
         $sess_type = $session->get('document_type_filter');
         $type = $sess_type;
     }
     if ($team != null) {
         $session->set('document_team_filter', $team);
         $session->set('document_user_filter', null);
     } else {
         $sess_team = $session->get('document_team_filter');
         $team = $sess_team;
     }
     //filter for team
     if ($team) {
         $query->where("u.team_id={$team}");
     }
     //filter for user
     if ($user && $user != "all") {
         $query->where('d.owner_id=' . $user);
     }
     //filter data
     if ($assoc and $assoc != 'all') {
         switch ($assoc) {
             case "deals":
                 $query->where("d.association_type='deal'");
                 break;
             case "people":
                 $query->where("d.association_type='person'");
                 break;
             case "companies":
                 $query->where("d.association_type='company'");
                 break;
             case "emails":
                 $query->where("d.email=1");
                 break;
             case "shared":
                 $query->where("d.shared=1");
                 break;
         }
     }
     //set user filter states
     $query->order($this->getState('Document.filter_order') . ' ' . $this->getState('Document.filter_order_Dir'));
     //filter for types
     if ($type and $type != 'all') {
         $doc_types = array();
         switch ($type) {
             case "spreadsheets":
                 $doc_types = array('xlr', 'xls', 'xlsx');
                 break;
             case "images":
                 $doc_types = array('bmp', 'gif', 'jpg', 'jpeg', 'png', 'psd', 'pspimage', 'thm', 'tif', 'yuv');
                 break;
             case "documents":
                 $doc_types = array();
                 break;
             case "pdfs":
                 $doc_types = array('pdf');
                 break;
             case "presentations":
                 $doc_types = array('pps', 'ppt', 'pptx', 'key', 'odp');
                 break;
             case "others":
                 $doc_types = array();
                 break;
         }
         if (count($doc_types)) {
             $queryString = '';
             foreach ($doc_types as $key => $type) {
                 if ($key) {
                     $queryString .= " OR d.filetype='" . $type . "'";
                 } else {
                     $queryString .= " d.filetype='" . $type . "'";
                 }
             }
             $query->where('(' . $queryString . ')');
         }
     }
     //sort depending on member role
     if ($member_type != 'exec') {
         if ($assoc != 'shared') {
             $shared = $assoc == "all" ? "OR d.shared=1" : "";
             if ($member_type == 'manager') {
                 $query->where('(u.team_id=' . $team_id . " {$shared})");
             } else {
                 $query->where('(d.owner_id=' . $member_id . " {$shared})");
             }
         }
     }
     if ($id) {
         $query->where("d.id=" . $id);
     }
     if ($this->company_id) {
         $query->where("(d.association_type='company' AND d.association_id=" . $this->company_id . ')');
     }
     if ($this->deal_id) {
         $query->where("(d.association_type='deal' AND d.association_id=" . $this->deal_id . ')');
     }
     if ($this->person_id) {
         $query->where("(d.association_type='person' AND d.association_id=" . $this->person_id . ')');
     }
     if (!empty($document_name)) {
         $query->where("( d.name LIKE '%" . $document_name . "%' OR deal.name LIKE '%" . $document_name . "%' OR c.name LIKE '%" . $document_name . "%')");
     }
     //get results
     $offset = $app->input->getInt('start', 0);
     $limit = $app->input->getInt('length', 0);
     $db->setQuery($query, $offset, $limit);
     $results = $db->loadAssocList();
     //$app->triggerEvent('onDocumentLoad', array(&$results));
     //return results
     return $results;
 }
예제 #14
0
 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();
 }
예제 #15
0
 /**
  * Get a leaderboard entry
  * @param  int   $id id of leaderboard to get
  * @return mixed $results db results of leaderboard info
  */
 public function getLeaderBoards($id = null)
 {
     //load database
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     //load goals and associate with user depending on team//role that have a leaderboard flag in the database
     $query->select("g.*")->from("#__goals AS g")->where("g.leaderboard=1");
     $query->leftJoin("#__users AS u ON u.id = g.assigned_id");
     //search for specific leaderboards and join essential data
     if ($id) {
         //search for id
         $query->where("g.id={$id}");
     } else {
         //filter based on member access roles
         $user_id = UsersHelper::getUserId();
         $member_role = UsersHelper::getRole();
         $team_id = UsersHelper::getTeamId();
         if ($member_role != 'exec') {
             if ($member_role == 'manager') {
                 $query->where("u.team_id={$team_id}");
             } else {
                 $query->where("(g.owner_id={$user_id})");
             }
         }
     }
     $query->where("g.published=" . $this->published);
     //get results
     $db->setQuery($query);
     $results = $db->loadAssocList();
     //get data for leaderboard
     for ($i = 0; $i < count($results); $i++) {
         $results[$i]['members'] = $this->leaderboardInfo($results[$i]);
     }
     //return goals
     return $results;
 }
예제 #16
0
 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();
 }
예제 #17
0
 public static function generateDropdown($type, $selection = null, $name = null, $raw = false)
 {
     //base html
     $html = '';
     //grab db
     $db = \Cobalt\Container::fetch('db');
     //generate query based on type
     $query = $db->getQuery(true);
     switch ($type) {
         case "company":
             $query->select('id,name FROM #__companies AS c where c.published > 0');
             break;
         case "stage":
             $query->select('id,name FROM #__stages');
             break;
         case "source":
             $query->select('id,name FROM #__sources');
             break;
         case "deal_status":
             $query->select('id,name FROM #__deal_status');
             break;
         case "people_status":
             $query->select('id,name FROM #__people_status');
             break;
         case "deal":
             $query->select('d.id,d.name');
             $query->from("#__deals AS d");
             $query->where("d.published > 0");
             $query->leftJoin('#__users AS users ON users.id = d.owner_id');
             /** ---------------------------------------------------------------
              * Filter data using member role permissions
              */
             $member_id = UsersHelper::getUserId();
             $member_role = UsersHelper::getRole();
             $team_id = UsersHelper::getTeamId();
             if ($member_role != 'exec') {
                 //manager filter
                 if ($member_role == 'manager') {
                     $query->where('users.team_id = ' . $team_id);
                 } else {
                     //basic user filter
                     $query->where(array('d.owner_id = ' . $member_id));
                 }
             }
             break;
     }
     //run query and grab results
     if ($query != "") {
         $db->setQuery($query);
         $row = $db->loadAssocList();
     }
     if ($type == 'owner') {
         $me = array(array('label' => TextHelper::_('COBALT_ME'), 'value' => UsersHelper::getLoggedInUser()->id));
         $users = UsersHelper::getUsers(null, true);
         $row = array_merge($me, $users);
     }
     if (!isset($row)) {
         $row = array();
     } elseif (!is_array($row) && !(count($row) > 0)) {
         $row = array();
     }
     if ($raw) {
         return $row;
     }
     //determine which kind of dropdown we are generating
     $selected = $selection == null ? "selected='selected'" : '';
     switch ($type) {
         case "company":
             $name = $name ? $name : "name=company_id";
             $html = '
                 <select class="inputbox form-control" ' . $name . ' id="company_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_COMPANY_SELECT_COMPANY_OPTION_LABEL');
             foreach ($row as $company => $info) {
                 $selected = $info['id'] == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $info['id'] . '" ' . $selected . ' >' . $info['name'] . '</option>';
             }
             $html .= '</select>';
             break;
         case "stage":
             $name = $name ? $name : "name=stage_id";
             $html = '
                  <select class="inputbox form-control" ' . $name . ' id="stage_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_STAGE_SELECT_STAGE_OPTION_LABEL');
             foreach ($row as $stage => $info) {
                 $selected = $info['id'] == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $info['id'] . '" ' . $selected . ' ' . $name . ' >' . $info['name'] . '</option>';
             }
             $html .= '</select>';
             break;
         case "source":
             $name = $name ? $name : "name=source_id";
             $html = '<select class="inputbox form-control" ' . $name . ' id="source_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_SOURCE_SELECT_SOURCE_OPTION_LABEL');
             if (count($row) > 0) {
                 foreach ($row as $source => $info) {
                     $selected = $info['id'] == $selection ? "selected='selected'" : '';
                     $html .= '<option value="' . $info['id'] . '" ' . $selected . ' ' . $name . ' >' . $info['name'] . '</option>';
                 }
             }
             $html .= '</select>';
             break;
         case "probability":
             $name = $name ? $name : "name=probability";
             $html = '
                 <select class="inputbox form-control" ' . $name . ' id="probability_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_PROBABILITY_SELECT_PROBABILITY_OPTION_LABEL');
             for ($i = 5; $i <= 95; $i += 5) {
                 $selected = $i == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $i . '" ' . $selected . ' ' . $name . ' >' . $i . '%</option>';
             }
             $html .= '</select>';
             break;
         case "deal_status":
             $name = $name ? $name : "name=status_id";
             $html = '
                 <select class="inputbox form-control" ' . $name . ' id="status_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_DEAL_STATUS_SELECT_STATUS_OPTION_LABEL');
             foreach ($row as $status => $info) {
                 $selected = $info['id'] == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $info['id'] . '" ' . $selected . ' ' . $name . ' >' . $info['name'] . '</option>';
             }
             $html .= '</select>';
             break;
         case "people_status":
             $name = $name ? $name : "name=status_id";
             $html = '
                 <select class="inputbox form-control" ' . $name . ' id="status_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_PEOPLE_STATUS_SELECT_STATUS_OPTION_LABEL');
             foreach ($row as $status => $info) {
                 $selected = $info['id'] == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $info['id'] . '" ' . $selected . ' ' . $name . ' >' . $info['name'] . '</option>';
             }
             $html .= '</select>';
             break;
         case "deal":
             $name = $name ? $name : "name=deal_id";
             $html = '
                 <select class="inputbox form-control" ' . $name . ' id="deal_id">';
             $html .= "<option value='0' " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_DEAL_SELECT_DEAL_OPTION_LABEL');
             foreach ($row as $deal => $info) {
                 $selected = $info['id'] == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $info['id'] . '" ' . $selected . ' ' . $name . ' >' . $info['name'] . '</option>';
             }
             $html .= '</select>';
             break;
         case "owner":
             $name = $name ? $name : "name=owner_id";
             $html = '
                 <select class="inputbox form-control" ' . $name . ' id="owner_id">';
             $html .= "<option value=\"0\" " . $selected . ">" . TextHelper::_('COBALT_DROPDOWN_OWNER_SELECT_OWNER_OPTION_LABEL');
             foreach ($row as $i => $info) {
                 $selected = $info['value'] == $selection ? "selected='selected'" : '';
                 $html .= '<option value="' . $info['value'] . '" ' . $selected . ' ' . $name . ' >' . $info['label'] . '</option>';
             }
             $html .= '</select>';
             break;
         default:
             $model = DropdownHelper::getModelFromType($type);
             $html = '<ul>';
             $html .= '<li><a href="javascript:void(0)" onclick="saveAjax(\'' . $type . '\',\'' . $model . '\',\'Lead\')">' . TextHelper::_('COBALT_PERSON_LEAD') . '</a></li>';
             $html .= '<li><a href="javascript:void(0)" onclick="saveAjax(\'' . $type . '\',\'' . $model . '\',\'Contact\')">' . TextHelper::_('COBALT_PEOPLE_CONTACT') . '</a></li>';
             $html .= "</ul>";
             break;
     }
     return $html;
 }
예제 #18
0
 public function render()
 {
     $layout = $this->getLayout();
     //get model
     $model = new DocumentModel();
     $documents = $model->getDocuments();
     $state = $model->getState();
     //add js
     $document = JFactory::getDocument();
     $document->addScript(JURI::base() . 'src/Cobalt/media/js/document_manager.js');
     //session data
     $session = JFactory::getSession();
     $member_role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     //associations
     $assoc = $session->get('document_assoc_filter');
     $assoc_names = DocumentHelper::getAssocTypes();
     $assoc_name = $assoc ? $assoc_names[$assoc] : $assoc_names['all'];
     //users
     $user_id = UsersHelper::getUserId();
     $user = $session->get('document_user_filter');
     $team = $session->get('document_team_filter');
     if ($user == "all") {
         $user_name = TextHelper::_('COBALT_ALL_USERS');
     } elseif ($user && $user != $user_id) {
         $user_info = UsersHelper::getUser($user);
         $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');
     } else {
         $user_name = TextHelper::_('COBALT_ME');
     }
     if ($layout == 'default') {
         $total = $model->getTotal();
         $pagination = $model->getPagination();
         $this->dataTableColumns = $model->getDataTableColumns();
         JFactory::getDocument()->addScriptDeclaration("\n            var loc = 'documents';\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) . ";");
     }
     //type
     $type = $session->get('document_type_filter');
     $type_names = DocumentHelper::getDocTypes();
     $type_name = $type && array_key_exists($type, $type_names) ? $type_names[$type] : $type_names['all'];
     //teams
     $teams = UsersHelper::getTeams();
     //users
     $users = UsersHelper::getUsers();
     //list view
     $document_list = ViewHelper::getView('documents', 'list', 'phtml', array('documents' => $documents, 'state' => $state, 'total' => $total, 'pagination' => $pagination));
     if ($layout == "download") {
         DealHelper::downloadDocument();
     }
     //assign ref
     $this->state = $state;
     $this->document_list = $document_list;
     $this->assoc_names = $assoc_names;
     $this->assoc_name = $assoc_name;
     $this->user_name = $user_name;
     $this->type_names = $type_names;
     $this->type_name = $type_name;
     $this->member_role = $member_role;
     $this->user_id = $user_id;
     $this->teams = $teams;
     $this->users = $users;
     //display
     return parent::render();
 }
예제 #19
0
 public function getDealList()
 {
     //gen query
     $query = $this->db->getQuery(true)->select("DISTINCT(d.id),d.name,d.id")->from("#__deals AS d")->leftJoin('#__users AS users ON users.id = d.owner_id')->leftJoin("#__people_cf AS pcf ON pcf.association_id = d.id AND pcf.association_type='deal'");
     /** ---------------------------------------------------------------
      * Filter data using member role permissions
      */
     $member_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     if ($member_role != 'exec') {
         //manager filter
         if ($member_role == 'manager') {
             $query->where('users.team_id = ' . $team_id);
         } else {
             //basic user filter
             $query->where(array('d.owner_id = ' . $member_id));
         }
     }
     $query->where("d.published=" . $this->published);
     $associationType = $this->app->input->get('association');
     $associationId = $this->app->input->get('association_id');
     if ($associationType == "company") {
         $query->where("d.company_id=" . $associationId);
     }
     if ($associationType == "person") {
         $query->where("pcf.person_id=" . $associationId);
     }
     $row = $this->db->setQuery($query)->loadAssocList();
     if (count($row) == 0) {
         $row = array();
     }
     $blank = array(array('name' => TextHelper::_('COBALT_NONE'), 'id' => 0));
     $return = array_merge($blank, $row);
     return $return;
 }
예제 #20
0
파일: Raw.php 프로젝트: houzhenggang/cobalt
 public function render($tpl = null)
 {
     $app = JFactory::getApplication();
     //if we are deleting goals determine which goals the user is allowed to delete
     if ($this->getLayout() == 'delete') {
         //get type of goal we are requesting to delete
         $type = $app->input->get('goal_type');
         //get member role to determine what goals the user can see
         $member_role = UsersHelper::getRole();
         //get model
         $model = new GoalModel();
         //show individual goals
         if ($type == 'member') {
             $this->header = TextHelper::_("COBALT_INDIVIDUAL_GOALS");
             //show goals for exectuvies
             if ($member_role == 'exec') {
                 $goals = $model->getExecIndividualGoals();
             }
             //show goals for managers
             if ($member_role == 'manager') {
                 $goals = $model->getManagerIndividualGoals();
             }
             //show goals for basic users
             if ($member_role == 'basic') {
                 $goals = $model->getIndividualGoals();
             }
         }
         //show team goals
         if ($type == 'team') {
             $this->header = TextHelper::_("COBALT_TEAM_GOALS");
             //show all goals to exectuvies
             if ($member_role == 'exec') {
                 $goals = $model->getExecTeamGoals();
             } else {
                 $goals = $model->getTeamGoals();
             }
         }
         //show company goals
         if ($type == 'company') {
             $this->header = TextHelper::_("COBALT_COMPANY_GOALS");
             $goals = $model->getCompanyGoals();
         }
         //assign view references
         $this->goals = $goals;
     } elseif ($this->getLayout() == 'edit') {
         //get type of goal we are requesting to delete
         $type = $app->input->get('type');
         $id = $app->input->getInt('id');
         if ($id) {
             $model = new GoalModel();
             $goal = $model->getGoal($id);
             $this->goal = $goal;
         }
         switch ($type) {
             case "win_cash":
                 $header = ucwords(TextHelper::_('COBALT_WIN_MORE_CASH'));
                 $header_img = 'src/Cobalt/media/images/win_more_cash.png';
                 break;
             case "win_deals":
                 $header = ucwords(TextHelper::_('COBALT_WIN_MORE_DEALS'));
                 $header_img = 'src/Cobalt/media/images/win_more_deals.png';
                 break;
             case "move_deals":
                 $header = ucwords(TextHelper::_('COBALT_MOVE_DEALS_FORWARD'));
                 $header_img = 'src/Cobalt/media/images/move_deals_forward.png';
                 break;
             case "complete_tasks":
                 $header = ucwords(TextHelper::_('COBALT_COMPLETE_TASKS'));
                 $header_img = 'src/Cobalt/media/images/complete_more_tasks.png';
                 break;
             case "write_notes":
                 $header = ucwords(TextHelper::_('COBALT_WRITE_NOTES'));
                 $header_img = 'src/Cobalt/media/images/write_more_notes.png';
                 break;
             case "create_deals":
                 $header = ucwords(TextHelper::_('COBALT_CREATE_DEALS'));
                 $header_img = 'src/Cobalt/media/images/create_deals.png';
                 break;
             default:
                 $app->redirect('index.php?view=goals');
                 break;
         }
         $this->header = $header;
         $this->header_img = $header_img;
     } elseif ($this->getLayout() != 'add') {
         //load model
         $model = new GoalModel();
         //get all goals from model depending on user type
         $member_role = UsersHelper::getRole();
         //basic members
         if ($member_role == 'basic') {
             $individual_goals = $model->getIndividualGoals();
             $team_goals = $model->getTeamGoals();
             $company_goals = $model->getCompanyGoals();
             $leaderboards = $model->getLeaderBoards();
         }
         //managers
         if ($member_role == 'manager') {
             // $individual_goals = $model->getManagerIndividualGoals();
             $individual_goals = $model->getIndividualGoals();
             $team_goals = $model->getTeamGoals();
             $company_goals = $model->getCompanyGoals();
             $leaderboards = $model->getLeaderBoards();
         }
         //executives
         if ($member_role == 'exec') {
             // $individual_goals = $model->getExecIndividualGoals();
             $individual_goals = $model->getIndividualGoals();
             // $team_goals = $model->getExecTeamGoals();
             $team_goals = $model->getTeamGoals();
             $company_goals = $model->getCompanyGoals();
             $leaderboards = $model->getLeaderBoards();
         }
         //assign goals to global goal object to pass through to view
         $goals = new \stdClass();
         $goals->individual_goals = $individual_goals;
         $goals->team_goals = $team_goals;
         $goals->company_goals = $company_goals;
         $goals->leaderboards = $leaderboards;
         //if we get results then load the default goals page else show the add goals page
         $goal_count = false;
         foreach ($goals as $goal_list) {
             if (count($goal_list) > 0) {
                 $goal_count = true;
             }
         }
         if ($goal_count) {
             //set layout
             $this->setLayout('default');
             //assign view refs
             $this->goals = $goals;
         } else {
             //add goal layout
             $this->setLayout('add');
         }
     }
     //load java libs
     $doc = JFactory::getDocument();
     $doc->addScript(\JURI::base() . 'src/Cobalt/media/js/goal_manager.js');
     //get associated members and teams
     $teams = UsersHelper::getTeams();
     $users = UsersHelper::getUsers();
     $member_role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     //assign view refs
     $this->type = $type;
     $this->teams = $teams;
     $this->users = $users;
     $this->user_id = $user_id;
     $this->team_id = $team_id;
     $this->member_role = $member_role;
     $this->leaderboard_list = DropdownHelper::getLeaderBoards();
     //display
     echo parent::render();
 }
예제 #21
0
 public function _buildQuery()
 {
     $app = \Cobalt\Container::fetch('app');
     $loc = $app->input->getCmd('loc', $this->loc);
     $association = null;
     $user = null;
     if ($this->db->name == 'mysqli') {
         $this->db->setQuery("SET SQL_BIG_SELECTS=1")->execute();
     }
     $query = $this->db->getQuery(true);
     $db = $this->db;
     $query->select("e.*," . "a.*," . "ci.name AS category_name," . "c.name as company_name, c.id as company_id," . "d.name as deal_name,d.id as deal_id," . "p.first_name as person_first_name, p.last_name as person_last_name,p.id as person_id," . "assignee.color AS assignee_color," . 'assignee.first_name AS assignee_first_name,assignee.last_name AS assignee_last_name,' . "owner.first_name as owner_first_name, owner.last_name as owner_last_name " . "FROM #__events AS e");
     $query->leftJoin("#__events_categories AS ci ON ci.id = e.category_id");
     $query->leftJoin("#__events_cf AS a ON e.id = a.event_id");
     $query->leftJoin("#__companies AS c ON a.association_type = 'company' AND a.association_id = c.id AND c.published>0");
     $query->leftJoin("#__deals AS d ON a.association_type = 'deal' AND a.association_id = d.id AND d.published>0");
     $query->leftJoin("#__people AS p ON a.association_type = 'person' AND a.association_id = p.id AND p.published>0");
     $query->leftJoin('#__users AS assignee ON assignee.id = e.assignee_id');
     $query->leftJoin('#__users AS owner ON owner.id = e.owner_id');
     //gather info
     $user_role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     //filter based on user role
     if ($user_role != 'exec' && $this->view != "print") {
         //manager filter
         if ($user_role == 'manager') {
             $query->where('(assignee.team_id = ' . $team_id . ' OR owner.team_id = ' . $team_id . ")");
         } else {
             //basic user filter
             $query->where("(e.assignee_id = " . $user_id . " OR e.owner_id =" . $user_id . ")");
         }
     }
     //search for certain user events
     if ($user && $this->view != "print") {
         if ($user == $user_id) {
             $query->where("(e.assignee_id=" . $user_id . ' OR e.owner_id=' . $user_id . ')');
         } elseif ($user != 'all') {
             $query->where(array("e.assignee_id=" . $user));
         }
     }
     if (!$association) {
         $association = $app->input->get('association_id') ? $app->input->get('association_id') : $app->input->get('id');
     }
     $association_type = $app->input->get('association_type') ? $app->input->get('association_type') : $app->input->get('layout');
     $association_types = array("company", "deal", "person");
     if ($association) {
         $association_type = $association_type ? $association_type : $loc;
         if ($association_type == "company") {
             if (is_array($association)) {
                 $query->where("(p.company_id=" . $association . " OR d.company_id=" . $association . " OR ( a.association_type=" . $db->quote("company") . " AND a.association_id IN(" . implode(",", $association) . ") ))");
             } else {
                 $query->where("(p.company_id=" . $association . " OR d.company_id=" . $association . " OR ( a.association_type=" . $db->quote("company") . " AND a.association_id=" . $association . " ))");
             }
         } else {
             if (is_array($association)) {
                 $query->where("a.association_id IN(" . implode(",", $association) . ")");
             } else {
                 $query->where("a.association_id=" . $association);
             }
             $query->where("a.association_type=" . $db->quote($association_type));
         }
     } elseif ($association_type && in_array($association_type, $association_types)) {
         $query->where("a.association_type=" . $db->Quote($association_type));
     } else {
         /** hide events associated with archived deals **/
         $query->where("(d.archived=0 OR d.archived IS NULL)");
     }
     if ($this->_id != null) {
         if (is_array($this->_id)) {
             $query->where("e.id IN (" . implode(',', $this->_id) . ")");
         } else {
             $query->where("e.id={$this->_id}");
         }
     }
     if ($this->current_events) {
         $now = DateHelper::formatDBDate(date('Y-m-d'));
         $query->where('e.due_date != "0000-00-00 00:00:00" AND e.due_date >="' . $now . '"');
     }
     /** Filter by status **/
     $status_filter = $this->getState('Event.' . $this->view . '_' . $this->layout . '_status');
     if ($status_filter != null && $this->view != "print") {
         $query->where("e.completed={$status_filter}");
     } else {
         if ($this->completed != null) {
             if ($this->completed == 'true') {
                 $query->where("e.completed=1");
             } elseif ($this->completed != 'false') {
                 $query->where("e.completed=" . $this->completed);
             }
         } else {
             $query->where("e.completed=0");
         }
     }
     /** Filter by type **/
     $type_filter = $this->getState('Event.' . $this->view . '_' . $this->layout . '_type');
     if ($type_filter != null && $type_filter != "all" && $this->view != "print") {
         $query->where("e.type='{$type_filter}'");
     }
     /** Filter by category **/
     $category_filter = $this->getState('Event.' . $this->view . '_' . $this->layout . '_category');
     if ($category_filter != null && $category_filter != "any" && $this->view != "print") {
         $query->where("e.category_id={$category_filter}");
     }
     /** Filter by due date **/
     $due_date_filter = $this->getState('Event.' . $this->view . '_' . $this->layout . '_due_date');
     if ($due_date_filter != null && $due_date_filter != "any" && $this->view != "print") {
         $date = DateHelper::formatDBDate(date('Y-m-d 00:00:00'));
         switch ($due_date_filter) {
             case "today":
                 $tomorrow = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() + 1 * 24 * 60 * 60));
                 $query->where("((e.due_date >= '{$date}' AND e.due_date < '{$tomorrow}') OR (e.start_time >= '{$date}' AND e.start_time < '{$tomorrow}'))");
                 break;
             case "tomorrow":
                 $tomorrow = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() + 1 * 24 * 60 * 60));
                 $day_after_tomorrow = DateHelper::formatDBDate(date('Y-m-d 00:00:00', time() + 2 * 24 * 60 * 60));
                 $query->where("((e.due_date >= '{$tomorrow}' AND e.due_date < '{$day_after_tomorrow}') OR (e.start_time >= '{$tomorrow}' AND e.start_time < '{$day_after_tomorrow}'))");
                 break;
             case "this_week":
                 $date_info = getDate(strtotime($date));
                 $today = $date_info['wday'];
                 $days_to_remove = -1 + $today;
                 $days_to_add = 5 - $today;
                 $beginning_of_week = DateHelper::formatDBDate(date('Y-m-d 00:00:00', strtotime($date . " - {$days_to_remove} days")));
                 $end_of_week = DateHelper::formatDBDate(date('Y-m-d 00:00:00', strtotime($date . " + {$days_to_add} days")));
                 $query->where("((e.due_date >= '{$beginning_of_week}' AND e.due_date < '{$end_of_week}') OR (e.start_time >= '{$beginning_of_week}' AND e.start_time < '{$end_of_week}'))");
                 break;
             case "past_due":
                 $query->where("((e.due_date < '{$date}' AND e.due_date != '0000-00-00 00:00:00') OR (e.start_time < '{$date}' AND e.start_time != '0000-00-00 00:00:00'))");
                 break;
             case "not_past_due":
                 $query->where("((e.due_date >= '{$date}' AND e.due_date != '0000-00-00 00:00:00') OR (e.start_time >= '{$date}' AND e.start_time != '0000-00-00 00:00:00'))");
                 break;
         }
     }
     /** Filter by assignee id **/
     $assignee_id_filter = $this->getState('Event.' . $this->view . '_' . $this->layout . '_assignee_id');
     $assignee_filter_type = $this->getState('Event.' . $this->view . '_' . $this->layout . '_assignee_filter_type');
     if ($loc != "calendar" && $assignee_id_filter != null && $assignee_id_filter != 'all' && $this->view != "print") {
         if ($assignee_filter_type == "team") {
             $team_members = UsersHelper::getTeamUsers($assignee_id_filter, TRUE);
             $query->where("e.assignee_id IN(" . implode(',', $team_members) . ")");
         } else {
             $query->where("e.assignee_id={$assignee_id_filter}");
         }
     }
     /** Filter by association type **/
     $association_type_filter = $this->getState('Event.' . $this->view . '_' . $this->layout . '_association_type');
     if ($association_type_filter != null && $association_type_filter != "any" && !$association && $assignee_id_filter != 'all' && $this->view != "print") {
         $query->where("a.association_type='" . $association_type_filter . "'");
     }
     $query->where("e.published=" . $this->published);
     if ($this->start_date) {
         $query->where("(e.due_date >= '" . $this->start_date . "' OR e.start_time >= '" . $this->start_date . "' OR e.repeats != 'none' )");
     }
     if ($this->end_date) {
         $query->where("(e.due_date < '" . $this->end_date . "' OR e.end_time < '" . $this->end_date . "' OR e.repeats != 'none' )");
     }
     if ($this->deal_id > 0) {
         $query->where("(a.association_id=" . $this->deal_id . " AND a.association_type='deal')");
     }
     $this->filter_order = $this->getState('Event.' . $this->view . '_' . $this->layout . '_filter_order');
     $this->filter_order_Dir = $this->getState('Event.' . $this->view . '_' . $this->layout . '_filter_order_Dir');
     $query->order($this->filter_order . ' ' . $this->filter_order_Dir);
     /** ------------------------------------------
      * Set query limits and load results
      */
     if ($this->getState("Event." . $this->view . '_' . $this->layout . '_limit') != 0) {
         $query .= " LIMIT " . $this->getState("Event." . $this->view . '_' . $this->layout . '_limit') . " OFFSET " . $this->getState("Event." . $this->view . '_' . $this->layout . '_limitstart');
     }
     return $query;
 }
예제 #22
0
 /**
  * Get people count associated with users
  * @param $id int User Id to filter for
  * @param $team int Team Id associated to user
  * @param $role String User role to filter for
  * @return int Count of people returned from database
  */
 public static function getPeopleCount($id = null, $team = null, $role = null)
 {
     //get db
     $db = \Cobalt\Container::fetch('db');
     $query = $db->getQuery(true);
     if (!$id) {
         $id = UsersHelper::getUserId();
     }
     if (!$team) {
         $team = UsersHelper::getTeamId();
     }
     if (!$role) {
         $role = UsersHelper::getRole();
     }
     //query
     $query->select('count(*)');
     $query->from('#__people AS p');
     $query->leftJoin("#__users AS u ON ( u.id = p.owner_id OR u.id = p.assignee_id ) AND u.published=1");
     //filter based on id and role
     if ($role != 'exec') {
         if ($role == 'manager') {
             $query->where("u.team_id={$team}");
         } else {
             $query->where("( p.owner_id={$id} OR p.assignee_id={$id} )");
         }
     }
     $query->where("p.published=1");
     //return results
     $db->setQuery($query);
     return $db->loadResult();
 }