Beispiel #1
0
     }
 }
 if ($df->hasFixedValues()) {
     $values = array();
     $max_length = 1;
     foreach (explode("\n", $fixed_values) as $val) {
         $val = trim($val);
         $len = strlen($val);
         if ($len > 0) {
             $values[] = $val;
             if ($len > $max_length) {
                 $max_length = $len;
             }
         }
     }
     $contents_table = DynamicFields::getFixedValuesTableName($field_id, true);
     try {
         $zdb->connection->beginTransaction();
         $zdb->db->query('DROP TABLE IF EXISTS ' . $contents_table, Adapter::QUERY_MODE_EXECUTE);
         $zdb->db->query('CREATE TABLE ' . $contents_table . ' (id INTEGER NOT NULL,val varchar(' . $max_length . ') NOT NULL)', Adapter::QUERY_MODE_EXECUTE);
         $zdb->connection->commit();
     } catch (Exception $e) {
         $zdb->connection->rollBack();
         Analog::log('Unable to manage fields values table ' . $contents_table . ' | ' . $e->getMessage(), Analog::ERROR);
         $error_detected[] = _T("An error occured storing managing fields values table");
     }
     if (count($error_detected) == 0) {
         try {
             $zdb->connection->beginTransaction();
             $insert = $zdb->insert(str_replace(PREFIX_DB, '', $contents_table));
             $insert->values(array('id' => ':id', 'val' => ':val'));
Beispiel #2
0
 /**
  * Returns an array of fixed valued for a field of type 'choice'.
  *
  * @return void
  */
 private function _loadFixedValues()
 {
     global $zdb;
     try {
         $val_select = $zdb->select(DynamicFields::getFixedValuesTableName($this->id));
         $val_select->columns(array('val'))->order('id');
         $results = $zdb->execute($val_select);
         $this->values = array();
         if ($results) {
             foreach ($results as $val) {
                 $this->values[] = $val->val;
             }
         }
     } catch (\Exception $e) {
         Analog::log(__METHOD__ . ' | ' . $e->getMessage(), Analog::WARNING);
     }
 }
Beispiel #3
0
 /**
  * Builds the SELECT statement
  *
  * @param int   $mode   the current mode (see self::SHOW_*)
  * @param array $fields fields list to retrieve
  * @param bool  $photos true if we want to get only members with photos
  *                      Default to false, only relevant for SHOW_PUBLIC_LIST
  * @param bool  $count  true if we want to count members, defaults to false
  *
  * @return Select SELECT statement
  */
 private function _buildSelect($mode, $fields, $photos, $count = false)
 {
     global $zdb, $login;
     try {
         $fieldsList = $fields != null ? !is_array($fields) || count($fields) < 1 ? (array) '*' : $fields : (array) '*';
         $select = $zdb->select(self::TABLE, 'a');
         $select->columns($fieldsList);
         $select->quantifier('DISTINCT');
         switch ($mode) {
             case self::SHOW_STAFF:
             case self::SHOW_LIST:
             case self::SHOW_ARRAY_LIST:
                 $select->join(array('p' => PREFIX_DB . Status::TABLE), 'a.' . Status::PK . '=p.' . Status::PK, array());
                 break;
             case self::SHOW_EXPORT:
                 //basically the same as above, but without any fields
                 $select->join(array('p' => PREFIX_DB . Status::TABLE), 'a.' . Status::PK . '=p.' . Status::PK, array());
                 break;
             case self::SHOW_MANAGED:
                 $select->join(array('p' => PREFIX_DB . Status::TABLE), 'a.' . Status::PK . '=p.' . Status::PK)->join(array('gr' => PREFIX_DB . Group::GROUPSUSERS_TABLE), 'a.' . Adherent::PK . '=gr.' . Adherent::PK, array())->join(array('m' => PREFIX_DB . Group::GROUPSMANAGERS_TABLE), 'gr.' . Group::PK . '=m.' . Group::PK, array())->where('m.' . Adherent::PK . ' = ' . $login->id);
             case self::SHOW_PUBLIC_LIST:
                 if ($photos) {
                     $select->join(array('p' => PREFIX_DB . Picture::TABLE), 'a.' . self::PK . '= p.' . self::PK);
                 }
                 break;
         }
         //check for contributions filtering
         if ($this->_filters instanceof AdvancedMembersList && $this->_filters->withinContributions()) {
             $select->join(array('ct' => PREFIX_DB . Contribution::TABLE), 'ct.' . self::PK . '=a.' . self::PK, array(), $select::JOIN_LEFT);
         }
         //check if there are dynamic fields in the filter
         $hasDf = false;
         $hasCdf = false;
         $cdfs = array();
         $cdfcs = array();
         if ($this->_filters instanceof AdvancedMembersList && $this->_filters->free_search && count($this->_filters->free_search) > 0 && !isset($this->_filters->free_search['empty'])) {
             $free_searches = $this->_filters->free_search;
             foreach ($free_searches as $fs) {
                 if (strpos($fs['field'], 'dyn_') === 0) {
                     $hasDf = true;
                 }
                 if (strpos($fs['field'], 'dync_') === 0) {
                     $hasCdf = true;
                     $cdfs[] = str_replace('dync_', '', $fs['field']);
                 }
             }
         }
         //check if there are dynamic fields for contributions in filter
         $hasDfc = false;
         $hasCdfc = false;
         if ($this->_filters instanceof AdvancedMembersList && $this->_filters->withinContributions()) {
             if ($this->_filters->contrib_dynamic && count($this->_filters->contrib_dynamic) > 0 && !isset($this->_filters->contrib_dynamic['empty'])) {
                 $hasDfc = true;
                 //check if there are dynamic fields in the filter
                 foreach ($this->_filters->contrib_dynamic as $k => $cd) {
                     if (is_array($cd)) {
                         $hasCdfc = true;
                         $cdfcs[] = $k;
                     }
                 }
             }
         }
         if ($hasDf === true || $hasCdf === true) {
             $select->join(array('df' => PREFIX_DB . DynamicFields::TABLE), 'df.item_id=a.' . self::PK, array(), $select::JOIN_LEFT);
         }
         if ($hasDfc === true || $hasCdfc === true) {
             $select->join(array('dfc' => PREFIX_DB . DynamicFields::TABLE), 'dfc.item_id=ct.' . Contribution::PK, array(), $select::JOIN_LEFT);
         }
         if ($hasCdf === true || $hasCdfc === true) {
             $cdf_field = 'cdf.id';
             if (TYPE_DB === 'pgsql') {
                 $cdf_field .= '::text';
             }
             foreach ($cdfs as $cdf) {
                 $rcdf_field = str_replace('cdf.', 'cdf' . $cdf . '.', $cdf_field);
                 $select->join(array('cdf' . $cdf => DynamicFields::getFixedValuesTableName($cdf, true)), $rcdf_field . '=df.field_val', array(), $select::JOIN_LEFT);
             }
             $cdf_field = 'cdfc.id';
             if (TYPE_DB === 'pgsql') {
                 $cdf_field .= '::text';
             }
             foreach ($cdfcs as $cdf) {
                 $rcdf_field = str_replace('cdfc.', 'cdfc' . $cdf . '.', $cdf_field);
                 $select->join(array('cdfc' . $cdf => DynamicFields::getFixedValuesTableName($cdf, true)), $rcdf_field . '=dfc.field_val', array(), $select::JOIN_LEFT);
             }
         }
         if ($mode == self::SHOW_LIST || $mode == self::SHOW_MANAGED) {
             if ($this->_filters !== false) {
                 $this->_buildWhereClause($select);
             }
             $select->order($this->_buildOrderClause($fields));
         } else {
             if ($mode == self::SHOW_PUBLIC_LIST) {
                 $select->where('activite_adh = true')->where('bool_display_info = true');
                 $select->where->greaterThan('date_echeance', date('Y-m-d'))->or->equalTo('bool_exempt_adh', true);
             }
         }
         if ($mode === self::SHOW_STAFF) {
             $select->where->lessThan('p.priorite_statut', self::NON_STAFF_MEMBERS);
         }
         if ($count) {
             $this->_proceedCount($select);
         }
         //Fix for #687, but only for MySQL (break on PostgreSQL)
         //$select->group('a.' . Adherent::PK);
         return $select;
     } catch (\Exception $e) {
         Analog::log('Cannot build SELECT clause for members | ' . $e->getMessage(), Analog::WARNING);
         return false;
     }
 }