コード例 #1
0
ファイル: Deal.php プロジェクト: houzhenggang/cobalt
 /**
  * Prepare HTML field templates for each dataTable column.
  *
  * @param   string column name
  * @param   object of item
  * @return  string HTML template for propper field
  */
 public function getDataTableFieldTemplate($column, $item)
 {
     switch ($column) {
         case 'id':
             $template = '<input type="checkbox" class="export" name="ids[]" value="' . $item->id . '" />';
             break;
         case 'name':
             $template = '<a href="' . RouteHelper::_('index.php?view=deals&layout=deal&id=' . $item->id) . '">' . $item->name . '</a>';
             break;
         case 'company_name':
             $template = '<a href="' . RouteHelper::_('index.php?view=companies&layout=company&id=' . $item->company_id) . '">' . $item->company_name . '</a>';
             break;
         case 'amount':
             $template = ConfigHelper::getCurrency() . $item->amount;
             break;
         case 'status_name':
             if (!isset($item->status_id) || !$item->status_id) {
                 $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $statuses = DealHelper::getStatuses(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_status_' . $item->id . '_link">';
             $template .= '  <span class="deal-status-' . $item->status_name . '">' . $item->status_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_status_' . $item->id . '" role="menu">';
             if (isset($statuses) && count($statuses)) {
                 foreach ($statuses as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="status_select dropdown_item" data-field="status_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="deal-status-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'stage_name':
             if (!isset($item->stage_id) || !$item->stage_id) {
                 $item->stage_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $stages = DealHelper::getStages(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_stage_' . $item->id . '_link">';
             $template .= '  <span class="deal-stage-' . $item->stage_name . '">' . $item->stage_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_stage_' . $item->id . '" role="menu">';
             if (isset($stages) && count($stages)) {
                 foreach ($stages as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="stage_select dropdown_item" data-field="stage_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="deal-stage-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'source_name':
             if (!isset($item->source_id) || !$item->source_id) {
                 $item->source_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $sources = DealHelper::getSources(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_source_' . $item->id . '_link">';
             $template .= '  <span class="deal-source-' . $item->source_name . '">' . $item->source_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_source_' . $item->id . '" role="menu">';
             if (isset($sources) && count($sources)) {
                 foreach ($sources as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="source_select dropdown_item" data-field="source_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="deal-source-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'expected_close':
             if ($item->expected_close == "0000-00-00 00:00:00") {
                 $template = TextHelper::_('COBALT_NOT_SET');
             } else {
                 $template = DateHelper::formatDate($item->expected_close);
             }
             break;
         case 'actual_close':
             if ($item->actual_close == "0000-00-00 00:00:00") {
                 $template = TextHelper::_('COBALT_ACTIVE_DEAL');
             } else {
                 $template = DateHelper::formatDate($item->actual_close);
             }
             break;
         case 'action':
             $template = '<div class="btn-group">';
             // @TODO: make these 2 buttons work
             // $template .= ' <a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_CONTACTS').'" data-placement="bottom" class="btn" href="javascript:void(0);" onclick="Cobalt.showDealContactsDialogModal('.$item->id.');"><i class="glyphicon glyphicon-user"></i></a>';
             // $template .= ' <a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_NOTES').'" data-placement="bottom" class="btn" href="javascript:void(0);" onclick="openNoteModal(\'.deal->id.\',\'deal\');"><i class="glyphicon glyphicon-file"></i></a>';
             $template .= ' <a data-toggle="popover" title="' . TextHelper::_('COBALT_VIEW_DETAILS') . '" data-placement="top" data-html="true" data-content-class="extras-' . $item->id . '" class="btn btn-xs btn-default" href="#" tabindex="0"><i class="glyphicon glyphicon-info-sign"></i></a>';
             $template .= '</div>';
             $template .= '<div class="extras-' . $item->id . ' hide">';
             $template .= ' <b>' . TextHelper::_('COBALT_PRIMARY_CONTACT') . '</b>';
             $template .= ' <a href="' . RouteHelper::_('index.php?view=people&layout=person&id=' . $item->primary_contact_id) . '">' . $item->primary_contact_first_name . '</a><br>';
             $template .= ' <b>' . TextHelper::_('COBALT_NEXT_ACTION') . '</b><br>';
             $template .= '</div>';
             break;
         default:
             if (isset($column) && isset($item->{$column})) {
                 $template = $item->{$column};
             } else {
                 $template = '';
             }
             break;
     }
     return $template;
 }
コード例 #2
0
 /**
  * Get custom field values from picklists // forecasts // otherwise return the value as it was an input field
  */
 public static function getCustomValue($customType, $customNameOrId, $customValue, $itemId)
 {
     $db = \Cobalt\Container::fetch('db');
     $query = $db->getQuery(true);
     $id = str_replace("custom_", "", $customNameOrId);
     $query->select("c.type,c.values")->from("#__" . $customType . "_custom AS c")->where("c.id=" . $id);
     $db->setQuery($query);
     $custom = $db->loadObject();
     switch ($custom->type) {
         case "forecast":
             $query->clear();
             $query->select("(d.amount * ( d.probability / 100 )) AS amount")->from("#__deals AS d")->where("d.id=" . $itemId);
             $db->setQuery($query);
             $result = $db->loadResult();
             return ConfigHelper::getCurrency() . $result;
             break;
         case "currency":
             return ConfigHelper::getCurrency() . $customValue;
             break;
         case "picklist":
             $values = json_decode($custom->values);
             return array_key_exists($customValue, $values) ? $values[$customValue] : TextHelper::_('COBALT_NONE');
             break;
         case "date":
             return DateHelper::formatDate($customValue);
             break;
         default:
             return $customValue;
             break;
     }
     return $customValue;
 }