/**
  * Call when click on Export to csv (client info)
  * @param  sfWebRequest $request
  */
 public function executeExport($request)
 {
     $sf_user = $this->getUser();
     $sf_guard_user = $sf_user->getGuardUser();
     $sf_guard_userid = $sf_guard_user->getId();
     $branch_id = $sf_user->getUserBranch()->getId();
     // retrieve value of form post
     $form_data = $request->getParameter('field_name');
     $search = $request->getParameter('search');
     $search_type = $search['type'];
     $search_value = $search[$search_type];
     if ($search_value == '') {
         $search_value = $search['keyword'];
     }
     $csv_output = '';
     $header = array();
     $data_row = array();
     $column_names = sfConfig::get('mod_client_csvcolumns_options');
     // set client criteria
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addJoin(sfGuardUserPeer::ID, sfGuardUserGroupPeer::USER_ID);
     $c->addJoin(sfGuardGroupPeer::ID, sfGuardUserGroupPeer::GROUP_ID);
     $c->addJoin(sfGuardUserPeer::ID, ProfilePeer::USER_ID);
     $c->addJoin(sfGuardUserPeer::ID, BranchUsersPeer::USER_ID);
     $c->add(sfGuardGroupPeer::NAME, sfGuardGroupPeer::CLIENT);
     $c->add(BranchUsersPeer::BRANCH_ID, $branch_id);
     $c->addJoin(ProfilePeer::RANK, clientRankPeer::RANK_ID, Criteria::LEFT_JOIN);
     $c->add(clientRankPeer::BRANCH_ID, $branch_id, Criteria::EQUAL);
     //In case of opportunity is selected, also check user is selected all or any particular opportunity client, 0 is for all
     if ($search_type == 'krank' && $search_value != 0) {
         $c->add(ProfilePeer::RANK, $search_value, Criteria::EQUAL);
     }
     if ($search_type == 'ksales') {
         $c->add(ProfilePeer::SALES_ID, $search_value, Criteria::EQUAL);
     }
     foreach ($form_data as $key => $value) {
         if ($value != "") {
             $header[$value] = $column_names[$value];
             if ($value == 'sales_id') {
                 $c->addAlias('p1', ProfilePeer::TABLE_NAME);
                 $c->addJoin(ProfilePeer::SALES_ID, 'p1.user_id', Criteria::LEFT_JOIN);
                 $c->addSelectColumn('concat(p1.fname," ", p1.lname) as salesperson');
             } elseif ($value == 'rank') {
                 $c->addSelectColumn('if(length(RANK_DETAILS)>0, concat(RANK_NAME,"-",RANK_DETAILS), RANK_NAME)');
             } else {
                 $c->addSelectColumn('replace(' . ProfilePeer::translateFieldName($value, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME) . ',",","#")');
             }
         }
     }
     $rs = ProfilePeer::doSelectRs($c);
     if ($rs) {
         $csv_output = implode(',', $header) . "\n";
         while ($rs->next()) {
             $data_row = array_values($rs->getRow());
             $csv_output .= implode(',', $data_row) . "\n";
         }
     }
     $this->downloadCSV($csv_output);
 }
Exemplo n.º 2
0
 /**
  * Sets a field from the object by name passed in as a string.
  *
  * @param      string $name peer name
  * @param      mixed $value field value
  * @param      string $type The type of fieldname the $name is of:
  *                     one of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
  *                     BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
  * @return     void
  */
 public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
 {
     $pos = ProfilePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
     return $this->setByPosition($pos, $value);
 }