use Galette\Entity\DynamicFields as DynamicFields;
use Galette\DynamicFieldsTypes\DynamicFieldType as DynamicFieldType;
use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
/** @ignore */
if ( !$duplicated ) {
try {
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . DynamicFieldType::TABLE,
- 'COUNT(*) + 1 AS idx'
- )->where('field_form = ?', $form_name);
- $str = $select->__toString();
- $idx = $select->query()->fetchColumn();
+ $select = $zdb->select(DynamicFieldType::TABLE);
+ $select->columns(
+ array(
+ 'idx' => new Expression('COUNT(*) + 1')
+ )
+ );
+ $select->where(array('field_form' => $form_name));
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $idx = $result->idx;
} catch (Exception $e) {
- /** FIXME */
throw $e;
}
}
if ( $action !== '' ) {
try {
- $zdb->db->beginTransaction();
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . DynamicFieldType::TABLE,
+ $zdb->connection->beginTransaction();
+ $select = $zdb->select(DynamicFieldType::TABLE);
+ $select->columns(
array('field_type', 'field_index', 'field_name')
- )->where(DynamicFieldType::PK . ' = ?', $field_id)
- ->where('field_form = ?', $form_name);
- $res = $select->query()->fetch();
- if ( $res !== false ) {
- $old_rank = $res->field_index;
+ )->where(
+ array(
+ DynamicFieldType::PK => $field_id,
+ 'field_form' => $form_name
+ )
+ );
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+
+ if ( $result !== false ) {
+ $old_rank = $result->field_index;
$query_list = array();
if ( $action == 'del' ) {
- $up = $zdb->db->update(
- PREFIX_DB . DynamicFieldType::TABLE,
+ $update = $zdb->update(DynamicFieldType::TABLE);
+ $update->set(
array(
- 'field_index' => new Zend_Db_Expr('field_index-1')
- ),
- array(
- 'field_index > ?' => $old_rank,
- 'field_form = ?' => $form_name
+ 'field_index' => new Expression('field_index-1')
)
- );
+ )->where
+ ->greaterThan('field_index', $old_rank)
+ ->equalTo('field_form', $form_name);
+ $zdb->execute($update);
- $del1 = $zdb->db->delete(
- PREFIX_DB . DynamicFields::TABLE,
+ $delete = $zdb->delete(DynamicFields::TABLE);
+ $delete->where(
array(
- 'field_id = ?' => $field_id,
- 'field_form = ?' => $form_name
+ 'field_id' => $field_id,
+ 'field_form' => $form_name
)
);
+ $zdb->execute($delete);
- $del2 = $zdb->db->delete(
- PREFIX_DB . DynamicFieldType::TABLE,
+ $delete = $zdb->delete(DynamicFieldType::TABLE);
+ $delete->where(
array(
- 'field_id = ?' => $field_id,
- 'field_form = ?' => $form_name
+ 'field_id' => $field_id,
+ 'field_form' => $form_name
)
);
+ $zdb->execute($delete);
- $df = $dyn_fields->getFieldType($res->field_type);
+ $df = $dyn_fields->getFieldType($result->field_type);
if ( $df->hasFixedValues() ) {
- $contents_table = DynamicFields::getFixedValuesTableName($field_id);
- $zdb->db->getConnection()->exec(
- 'DROP TABLE IF EXISTS ' . $contents_table
+ $contents_table = DynamicFields::getFixedValuesTableName(
+ $field_id
+ );
+ $zdb->db->query(
+ 'DROP TABLE IF EXISTS ' . $contents_table,
+ Adapter::QUERY_MODE_EXECUTE
);
}
- deleteDynamicTranslation($res->field_name, $error_detected);
+ deleteDynamicTranslation(
+ $result->field_name,
+ $error_detected
+ );
} else {
$direction = $action == "up" ? -1: 1;
$new_rank = $old_rank + $direction;
- $zdb->db->update(
- PREFIX_DB . DynamicFieldType::TABLE,
+ $update = $zdb->update(DynamicFieldType::TABLE);
+ $update->set(
array(
'field_index' => $old_rank
- ),
+ )
+ )->where(
array(
- 'field_index = ?' => $new_rank,
- 'field_form = ?' => $form_name
+ 'field_index' => $new_rank,
+ 'field_form' => $form_name
)
);
+ $zdb->execute($update);
- $zdb->db->update(
- PREFIX_DB . DynamicFieldType::TABLE,
+ $update = $zdb->update(DynamicFieldType::TABLE);
+ $update->set(
array(
'field_index' => $new_rank
- ),
+ )
+ )->where(
array(
- 'field_id = ?' => $field_id,
- 'field_form = ?' => $form_name
+ 'field_id' => $field_id,
+ 'field_form' => $form_name
)
);
+ $zdb->execute($update);
}
}
- $zdb->db->commit();
+ $zdb->connection->commit();
} catch(Exception $e) {
- /** FIXME */
- //this one does not seem to work :'(
- $zdb->db->rollBack();
+ $zdb->connection->rollBack();
Analog::log(
'Unable to change field ' . $field_id . ' rank | ' .
$e->getMessage(),
}
}
- $select = new Zend_Db_Select($zdb->db);
- $select->from(PREFIX_DB . DynamicFieldType::TABLE)
- ->where('field_form = ?', $form_name)
+ $select = $zdb->select(DynamicFieldType::TABLE);
+ $select
+ ->where(array('field_form' => $form_name))
->order('field_index');
- $results = $select->query()->fetchAll();
+ $results = $zdb->execute($select);
$dfields = array();
if ( $results ) {
*/
use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
use Galette\Entity\DynamicFields as DynamicFields;
use Galette\DynamicFieldsTypes\DynamicFieldType as DynamicFieldType;
$field_size = get_numeric_posted_value('field_size', null);
$field_repeat = get_numeric_posted_value(
'field_repeat',
- new Zend_Db_Expr('NULL')
+ new Expression('NULL')
);
$fixed_values = get_form_value('fixed_values', '');
if ( $duplicated ) {
$error_detected[] = _T("- Field name already used.");
} else {
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . DynamicFieldType::TABLE,
- 'field_name'
- )->where('field_id = ?', $field_id);
- $old_field_name = $select->query()->fetchColumn();
+ $select = $zdb->select(DynamicFieldType::TABLE);
+ $select->columns(
+ array('field_name')
+ )->where(array('field_id' => $field_id));
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $old_field_name = $current->field_name;
+
if ( $old_field_name && $field_name != $old_field_name ) {
addDynamicTranslation($field_name, $error_detected);
deleteDynamicTranslation($old_field_name, $error_detected);
'field_id = ' . $field_id
);
} catch (Exception $e) {
- /** FIXME */
Analog::log(
'An error occured storing field | ' . $e->getMessage(),
Analog::ERROR
$contents_table = DynamicFields::getFixedValuesTableName($field_id);
try {
- $zdb->db->beginTransaction();
- $zdb->db->getConnection()->exec('DROP TABLE IF EXISTS ' . $contents_table);
+ $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)'
+ ') NOT NULL)',
+ Adapter::QUERY_MODE_EXECUTE
);
- $zdb->db->commit();
+ $zdb->connection->commit();
} catch (Exception $e) {
- /** FIXME */
- $zdb->db->rollBack();
+ $zdb->connection->rollBack();
Analog::log(
'Unable to manage fields values table ' .
$contents_table . ' | ' . $e->getMessage(),
if (count($error_detected) == 0) {
try {
- $zdb->db->beginTransaction();
- $stmt = $zdb->db->prepare(
- 'INSERT INTO ' . $contents_table .
- ' (' . $zdb->db->quoteIdentifier('id') . ', ' .
- $zdb->db->quoteIdentifier('val') . ')' .
- ' VALUES(:id, :val)'
+ $zdb->connection->beginTransaction();
+
+ $insert = $zdb->insert(
+ str_replace(PREFIX_DB, '', $contents_table)
+ );
+ $insert->values(
+ array(
+ 'id' => ':id',
+ 'val' => ':val'
+ )
);
+ $stmt = $sql->prepareStatementForSqlObject($insert);
for ( $i = 0; $i < count($values); $i++ ) {
- $stmt->bindValue(':id', $i, PDO::PARAM_INT);
- $stmt->bindValue(':val', $values[$i], PDO::PARAM_STR);
- $stmt->execute();
+ $stmt->execute(
+ array(
+ 'id' => $i,
+ 'val' => $values[$i]
+ )
+ );
}
- $zdb->db->commit();
+ $zdb->connection->commit();
}catch (Exception $e) {
- /** FIXME */
- $zdb->db->rollBack();
+ $zdb->connection->rollBack();
Analog::log(
'Unable to store field ' . $field_id . ' values',
Analog::ERROR
}
use Analog\Analog as Analog;
-use Zend\Db\Sql\Sql;
+use Zend\Db\Sql\Expression;
+use Galette\Core\L10n;
$disable_gettext=true;
try {
foreach ( $i18n->getList() as $lang ) {
//check if translation already exists
- $select = new Zend_Db_Select($zdb->db);
- $select->from($l10n_table, 'text_nref')
- ->where('text_orig = ?', $text_orig)
- ->where('text_locale = ?', $lang->getLongID());
- $nref = $select->query()->fetch()->text_nref;
+ $select = $zdb->select(L10n::TABLE);
+ $select->columns(array('text_nref'))
+ ->where(
+ array(
+ 'text_orig', $text_orig,
+ 'text_locale', $lang->getLongID()
+ )
+ );
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $nref = $result->text_nref;
if ( is_numeric($nref) && $nref > 0 ) {
//already existing, update
$values = array(
- 'text_nref' => new Zend_Db_Expr('text_nref+1')
+ 'text_nref' => new Expression('text_nref+1')
);
Analog::log(
'Entry for `' . $text_orig .
);
$where = array();
- $owhere = $select->getPart(Zend_Db_Select::WHERE);
+ $owhere = $select->getPart($select::WHERE);
foreach ( $owhere as $c ) {
$where[] = preg_replace('/^AND /', '', $c);
}
}
}
} catch (Exception $e) {
- /** FIXME */
Analog::log(
'An error occured adding dynamic translation for `' .
$text_orig . '` | ' . $e->getMessage(),
try {
//check if translation already exists
- $select = new Zend_Db_Select($zdb->db);
- $select->from($l10n_table, 'text_nref')
- ->where('text_orig = ?', $text_orig)
- ->where('text_locale = ?', $text_locale);
- $nref = $select->query()->fetch()->text_nref;
+ $select = $zdb->select(L10n::TABLE);
+ $select->columns(array('text_nref'))->where(
+ array(
+ 'text_orig' => $text_orig,
+ 'text_locale' => $text_locale
+ )
+ );
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $nref = $result->text_nref;
$exists = (is_numeric($nref) && $nref > 0);
$res = false;
if ( $exists ) {
$where = array();
- $owhere = $select->getPart(Zend_Db_Select::WHERE);
+ $owhere = $select->getPart($select::WHERE);
foreach ( $owhere as $c ) {
$where[] = preg_replace('/^AND /', '', $c);
}
{
global $zdb;
try {
- $select = $zdb->select(Galette\Core\L10n::TABLE);
+ $select = $zdb->select(L10n::TABLE);
$select->limit(1)->columns(
array('text_trans')
)->where(
return true;
}
try {
- $select = new \Zend_Db_Select($this->db);
- $select->from(
- PREFIX_DB . 'database',
+ $select = $this->select('database');
+ $select->columns(
array('version')
)->limit(1);
- $sql = $select->__toString();
- $res = $select->query()->fetch();
+
+ $results = $this->execute($select);
+ $result = $results->current();
return $res->version === GALETTE_DB_VERSION;
} catch ( \Exception $e ) {
Analog::log(
//can Galette SELECT records ?
try {
- $select = new \Zend_Db_Select($this->_db);
- $select->from('galette_test')
- ->where('test_id = ?', 1);
- $res = $select->query()->fetchAll();
- if ( count($res) === 1 ) {
+ $select = $this->select('test');
+ $select->where('test_id = 1');
+ $results = $zdb->execute($select);
+ if ( $results->count() === 1 ) {
$results['select'] = true;
} else {
throw new \Exception('Select is empty!');
}
try {
- $select = new \Zend_Db_Select($this->_db);
- $select->from($table);
-
- $result = $select->query();
-
$descr = $this->_db->describeTable($table);
$pkeys = array();
}
}
- $r = $result->fetchAll();
- foreach ( $r as $row ) {
+ $select = $this->_sql->select($table);
+ $results = $this->execute($select);
+
+ foreach ( $results as $row ) {
$data = array();
$where = array();
}
//finally, update data!
- $this->_db->update(
- $table,
- $data,
- $where
- );
+ $update = $this->_sql->update($table);
+ $update->set($data)->where($where);
+ $this->execute($update);
}
} catch (\Exception $e) {
Analog::log(
}
/**
- * Execture query string
+ * Execute query string
*
* @param SqlInterface $sql SQL object
*
}
/**
- * Global getter method
- *
- * @param string $name name of the variable we want to retrieve
- *
- * @return mixed
- */
+ * Global getter method
+ *
+ * @param string $name name of the variable we want to retrieve
+ *
+ * @return mixed
+ */
public function __get($name)
{
switch ( $name ) {
$_recipients[$_r->id] = $_r->sname . ' <' . $_r->email . '>';
}
}
+
+ $sender = null;
+ if ( $this->_sender === 0 ) {
+ $sender = new Expression('NULL');
+ } else {
+ $sender = $this->_sender;
+ }
+
$values = array(
- 'mailing_sender' => ($this->_sender === 0) ? new \Zend_Db_Expr('NULL') : $this->_sender,
+ 'mailing_sender' => $sender,
'mailing_subject' => $this->_subject,
'mailing_body' => $this->_message,
'mailing_date' => $this->_date,
try {
$insert = $zdb->insert($this->tbl_prefix . $class::TABLE);
- $insert->values(
- array(
- $class::PK => ':id',
- 'picture' => ':picture',
- 'format' => ':format'
- )
- );
$stmt = $sql->prepareStatementForSqlObject($insert);
+ $container = $stmt->getParameterContainer();
+ $container->offsetSet(
+ $class::PK,
+ ':id'
+ );
+ $container->offsetSet(
+ 'picture',
+ ':picture',
+ $container::TYPE_LOB
+ );
+ $container->offsetSet(
+ 'format',
+ ':format'
+ );
+ $stmt->setParameterContainer($container);
$stmt->execute(
array(
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . self::TABLE
- )->where('field_id = ?', $this->id);
- $sql = $select->__toString();
- $result = $select->query()->fetch();
+ $select = $zdb->select(self::TABLE);
+ $select->where('field_id = ' . $this->id);
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
if ($result !== false) {
$this->name = $result->field_name;
global $zdb;
try {
- $val_select = new \Zend_Db_Select($zdb->db);
+ $val_select = $zdb->select(
+ DynamicFields::getFixedValuesTableName($this->id)
+ );
- $val_select->from(
- DynamicFields::getFixedValuesTableName($this->id),
- 'val'
+ $val_select->columns(
+ array(
+ 'val'
+ )
)->order('id');
- $results = $val_select->query()->fetchAll();
+ $results = $zdb->execute($val_select);
$this->values = array();
if ( $results ) {
foreach ( $results as $val ) {
__METHOD__ . ' | ' . $e->getMessage(),
Analog::WARNING
);
- Analog::log(
- 'Query was: ' . $val_select->__toString() . ' ' . $e->__toString(),
- Analog::INFO
- );
}
}
global $zdb, $login;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' = ?', $id);
+ $select = $zdb->select(self::TABLE);
+ $select->where(self::PK . ' = ' . $id);
//restrict query on current member id if he's not admin nor staff member
if ( !$login->isAdmin() && !$login->isStaff() ) {
- $select->where(Adherent::PK . ' = ?', $login->id);
+ $select->where(Adherent::PK . ' = ' . $login->id);
}
- $row = $select->query()->fetch();
+
+ $results = $zdb->execute($select);
+ $row = $results->current();
if ( $row !== false ) {
$this->_loadFromRS($row);
return true;
);
}
} catch (\Exception $e) {
- /** FIXME */
Analog::log(
'An error occured attempting to load contribution #' . $id .
$e->getMessage(),
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- array('c' => PREFIX_DB . self::TABLE),
+ $select = $zdb->seelct(self::TABLE, 'c');
+ $select->columns(
array('date_debut_cotis', 'date_fin_cotis')
)->join(
array('ct' => PREFIX_DB . ContributionsTypes::TABLE),
'c.' . ContributionsTypes::PK . '=ct.' . ContributionsTypes::PK,
array()
- )->where(Adherent::PK . ' = ?', $this->_member)
- ->where('cotis_extension = ?', (string)1)
- ->where(
- '((' . $zdb->db->quoteInto('date_debut_cotis >= ?', $this->_begin_date) .
- ' AND '. $zdb->db->quoteInto('date_debut_cotis < ?', $this->_end_date) .
- ') OR (' . $zdb->db->quoteInto('date_fin_cotis > ?', $this->_begin_date) .
- ' AND ' . $zdb->db->quoteInto('date_fin_cotis <= ?', $this->_end_date) . '))'
- );
+ )->where(Adherent::PK . ' = ' . $this->_member)
+ ->where(array('cotis_extension' => (string)1))
+ ->where
+ ->greaterThanOrEqualTo('date_debut_cotis', $this->_begin_date)
+ ->lessThan('date_debut_cotis', $this->_end_date)
+ ->or
+ ->greaterThan('date_fin_cotis', $this->_begin_date)
+ ->lessThanOrEqualTo('date_fin_cotis <= ?', $this->_end_date);
if ( $this->id != '' ) {
- $select->where(self::PK . ' != ?', $this->id);
+ $select->where(self::PK . ' != ' . $this->id);
}
- $result = $select->query()->fetch();
+ $results = $zdb->execute($query);
+ $result = $results->current();
if ( $result !== false ) {
$d = new \DateTime($result->date_debut_cotis);
}
return true;
} catch (\Exception $e) {
- /** FIXME */
Analog::log(
'An error occured checking overlaping fee. ' . $e->getMessage(),
Analog::ERROR
);
- Analog::log(
- 'Query was: ' . $select->__toString(),
- Analog::DEBUG
- );
return false;
}
}
$zdb->db->beginTransaction();
$values = array();
$fields = self::getDbFields();
- /** FIXME: quote? */
foreach ( $fields as $field ) {
$prop = '_' . $this->_fields[$field]['propname'];
switch ( $field ) {
if ( $due_date != '' ) {
$date_fin_update = $due_date;
} else {
- $date_fin_update = new \Zend_Db_Expr('NULL');
+ $date_fin_update = new Expression('NULL');
}
- $edit = $zdb->db->update(
- PREFIX_DB . Adherent::TABLE,
- array('date_echeance' => $date_fin_update),
+ $update = $zdb->update(Adherent::TABLE);
+ $update->set(
+ array('date_echeance' => $date_fin_update)
+ )->where(
Adherent::PK . '=' . $this->_member
);
+ $zdb->execute($update);
return true;
} catch (\Exception $e) {
Analog::log(
}
return true;
} catch (\Exception $e) {
- /** FIXME */
if ( $transaction ) {
$zdb->db->rollBack();
}
}
}
- $owhere = $select->getPart(\Zend_Db_Select::WHERE);
+ $owhere = $select->getPart($select::WHERE);
foreach ( $owhere as $c ) {
$where[] = preg_replace('/^AND /', '', $c);
}
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . DynamicFieldType::TABLE,
- 'field_type'
- )->where('field_id = ?', $id);
- $field_type = $select->query()->fetchColumn();
+ $select = $zdb->select(DynamicFieldType::TABLE);
+ $select->columns(
+ array('field_type')
+ )->where('field_id = ' . $id);
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $field_type = $result->field_type;
if ( $field_type !== false ) {
return $this->getFieldType($field_type, $id);
} else {
//let's consider field is duplicated, in case of future errors
$duplicated = true;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . DynamicFieldType::TABLE,
- 'COUNT(field_id)'
- )->where('field_form = ?', $form_name)
- ->where('field_name = ?', $field_name);
+ $select = $zdb->select(DynamicFieldType::TABLE);
+ $select->columns(
+ array(
+ 'cnt' => new Expression('COUNT(field_id)')
+ )
+ )->where(
+ array(
+ 'field_form' => $form_name,
+ 'field_name' => $field_name
+ )
+ );
if ( $field_id !== null ) {
- $select->where('NOT field_id = ?', $field_id);
+ $select->where->notIn('NOT field_id', $field_id);
}
- $dup = $select->query()->fetchColumn();
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $dup = $result->cnt;
if ( !$dup > 0 ) {
$duplicated = false;
}
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(PREFIX_DB . self::TABLE)
- ->order('position');
- return $select->query()->fetchAll();
+ $select = $zdb->select(self::TABLE);
+ $select->order('position');
+ return $zdb->execute($select);
} catch (\Exception $e) {
- /** TODO */
Analog::log(
'[' . get_class($this) . '] Cannot get fields categories list | ' .
$e->getMessage(),
Analog::WARNING
);
- Analog::log(
- 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
- Analog::ERROR
- );
return false;
}
}
return $e;
}
}
-
- /**
- * GETTERS
- */
-
- /**
- * SETTERS
- */
}
$old_required = null;
try {
- $select = new \Zend_Db_Select($zdb->db);
+ $select = $zdb->select('required');
$select->from(PREFIX_DB . 'required');
- $old_required = $select->query()->fetchAll();
+ $old_required = $zdb->execute($select);
} catch ( \Exception $pe ) {
Analog::log(
'Unable to retrieve required fields_config. Maybe ' .
return true;
}
- $zdb->db->beginTransaction();
+ $zdb->Connection->beginTransaction();
try {
- $sql = 'UPDATE ' . PREFIX_DB . self::TABLE .
- ' SET required=:required WHERE table_name=\'' .
- $this->_table .'\' AND field_id=:field_id';
- $stmt = $zdb->db->prepare($sql);
+ $update = $this->_zdb->update(self::TABLE);
+ $update->set(
+ array(
+ 'required' => ':required'
+ )
+ )->where(
+ array(
+ 'field_id' => ':field_id',
+ 'table_name' => $this->_table
+ )
+ );
+
+ $stmt = $this->_zdb->sql->prepareStatementForSqlObject($update);
foreach ( $old_required as $or ) {
- $params = array(
- 'field_id' => $or->field_id,
- 'required' => ($or->required === false) ? 'false' : true
+ /** Why where parameter is named where1 ?? */
+ $stmt->execute(
+ array(
+ 'required' => ($or->required === false) ? 'false' : true,
+ 'where1' => $or->field_id
+ )
);
- $stmt->execute($params);
}
$class = get_class($this);
Analog::INFO
);
- $zdb->db->query('DROP TABLE ' . PREFIX_DB . 'required;');
+ $zdb->db->query(
+ 'DROP TABLE ' . PREFIX_DB . 'required',
+ Adapter::QUERY_MODE_EXECUTE
+ );
- $zdb->db->commit();
+ $zdb->Connection->commit();
return true;
} catch ( \Exception $e ) {
- $zdb->db->rollBack();
+ $zdb->connection->rollBack();
Analog::log(
'An error occured migrating old required fields. | ' .
$e->getMessage(),
namespace Galette\Entity;
use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
/**
* PDF Model
protected function load($id, $preferences)
{
try {
- $select = new \Zend_Db_Select($this->_zdb->db);
- $select->limit(1)->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' = ?', $id);
+ $select = $zdb->select(self::TABLE);
+ $select->limit(1)
+ ->where(self::PK . ' = ' . $id);
- $res = $select->query()->fetchAll();
- $this->loadFromRs($res[0], $preferences);
+ $results = $zdb->execute($select);
+ $this->loadFromRs($results->current(), $preferences);
} catch ( \Exception $e ) {
Analog::log(
'An error occured loading model #' . $id . "Message:\n" .
{
$title = $this->_title;
if ( trim($title === '') ) {
- $title = new \Zend_Db_Expr('NULL');
+ $title = new Expression('NULL');
}
$subtitle = $this->_subtitle;
if ( trim($subtitle === '') ) {
- $subtitle = new \Zend_Db_Expr('NULL');
+ $subtitle = new Expression('NULL');
}
$data = array(
try {
if ( $this->_id !== null ) {
- $up = $this->_zdb->db->update(
- PREFIX_DB . self::TABLE,
- $data,
+ $update = $this->_zdb->update(self::TABLE);
+ $update->set($data)->where(
self::PK . '=' . $this->_id
);
+ $this->_zdb->execute($update);
} else {
$data['model_name'] = $this->_name;
- $add = $this->_zdb->db->insert(
- PREFIX_DB . self::TABLE,
- $data
- );
- if ( !$add > 0 ) {
+ $insert = $this->_zdb->insert(self::TABLE);
+ $insert->values($data);
+ $add = $this->_zdb->execute($insert);
+ if ( !$add->count() > 0 ) {
Analog::log('Not stored!', Analog::ERROR);
return false;
}
namespace Galette\Entity;
use Analog\Analog;
+use Zend\Db\Sql\Expression;
use \Galette\Core\GaletteMail;
/**
{
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->limit(1)->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' = ?', $id);
+ $select = $zdb->select(self::TABLE);
+ $select->limit(1)
+ ->where(self::PK . ' = ' . $id);
- $res = $select->query()->fetchAll();
- $this->_loadFromRs($res[0]);
+ $results = $zdb->execute($select);
+ $this->_loadFromRs($results->current());
} catch ( \Exception $e ) {
Analog::log(
'An error occured loading reminder #' . $id . "Message:\n" .
$data = array(
'reminder_type' => $this->_type,
'reminder_dest' => $this->_dest->id,
- 'reminder_date' => new \Zend_Db_Expr('NOW()'),
+ 'reminder_date' => new Expression('NOW()'),
'reminder_success' => ($this->_success) ? true : 'false',
'reminder_nomail' => ($this->_nomail) ? true : 'false'
);
namespace Galette\Entity;
use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
/**
* Texts class for galette
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . self::TABLE,
+ $select = $zdb->select(self::TABLE);
+ $select->columns(
array('tref', 'tcomment')
- )->where('tlang = ?', $lang);
+ )->where(array('tlang' => $lang));
- return $select->query(\Zend_Db::FETCH_ASSOC)->fetchAll();
+ return $zdb->execute($select);
} catch (\Exception $e) {
- /** TODO */
Analog::log(
'Cannot get refs for lang `' . $lang . '` | ' .
$e->getMessage(),
Analog::WARNING
);
- Analog::log(
- 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
- Analog::ERROR
- );
return false;
}
}
//been initialized
$proceed = false;
if ( $check_first === true ) {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . self::TABLE,
- 'COUNT(' . self::PK . ') as counter'
+ $select = $zdb->select(self::TABLE);
+ $select->columns(
+ array(
+ 'counter' => new Expression('COUNT(' . self::PK . ')')
+ )
);
- $count = $select->query()->fetchObject()->counter;
+
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $count = $result->counter;
if ( $count == 0 ) {
//if we got no values in texts table, let's proceed
$proceed = true;
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . self::TABLE
- );
- $list = $select->query()->fetchAll();
+ $select = $zdb->select(self::TABLE);
+ $list = $zdb->execute($select);
$missing = array();
foreach ( $this->_defaults as $default ) {
/**
* Add SQL limit
*
- * @param Zend_Db_Select $select Original select
+ * @param Select $select Original select
*
* @return <type>
*/
//companies
$select1->combine($select2);
- //$select->union(array($select1, $select2), \Zend_Db_Select::SQL_UNION_ALL);
$results = $zdb->execute($select1);
/**
* Count contributions from the query
*
- * @param Zend_Db_Select $select Original select
+ * @param Select $select Original select
*
* @return void
*/
/**
* Calculate sum of all selected contributions
*
- * @param Zend_Db_Select $select Original select
+ * @param Select $select Original select
*
* @return void
*/
/**
* Builds where clause, for filtering on simple list mode
*
- * @param Zend_Db_Select $select Original select
+ * @param Select $select Original select
*
* @return string SQL WHERE clause
*/
$res = true;
try {
if ( $transaction ) {
- $zdb->db->beginTransaction();
+ $zdb->connection->beginTransaction();
}
- $select = new \Zend_Db_Select($zdb->db);
+ $seelct = $zdb->select(self::TABLE);
$select->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' IN (?)', $list);
- $contributions = $select->query()->fetchAll();
+ ->where->in(self::PK, $list);
+ $contributions = $zdb->execute($select);
foreach ( $contributions as $contribution ) {
$c = new Contribution($contribution);
$res = $c->remove(false);
}
}
if ( $transaction ) {
- $zdb->db->commit();
+ $zdb->connection->commit();
}
$hist->add(
str_replace(
)
);
} catch (\Exception $e) {
- /** FIXME */
if ( $transaction ) {
- $zdb->db->rollBack();
+ $zdb->connection->rollBack();
}
Analog::log(
'An error occured trying to remove contributions | ' .
global $zdb;
try {
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . Group::TABLE,
+ $select = $zdb->select(Group::TABLE);
+ $select->columns(
array('group_name')
- )->where('group_name = ?', $name);
- $res = $select->query()->fetchAll();
- return !(count($res) > 0);
+ )->where(array('group_name' => $name));
+ $results = $zdb->execute($select);
+ return !($results->count() > 0);
} catch (\Exception $e) {
Analog::log(
'Cannot list groups (simple) | ' . $e->getMessage(),
Analog::WARNING
);
- Analog::log(
- 'Query was: ' . $select->__toString() . ' ' . $e->getTraceAsString(),
- Analog::ERROR
- );
}
}
}
use Analog\Analog as Analog;
use Zend\Db\Sql\Expression;
+use Zend\Db\Sql\Predicate\PredicateSet;
use Galette\Entity\Adherent as Adherent;
use Galette\Entity\Contribution as Contribution;
use Galette\Entity\Transaction as Transaction;
$this->_filters->setLimit($select);
- Analog::log(
- "The following query will be executed: \n" .
- $select->__toString(),
- Analog::DEBUG
- );
-
- $result = $select->query()->fetchAll();
+ $results = $zdb->execute($select);
$members = array();
- foreach ( $result as $row ) {
+ foreach ( $results as $row ) {
$deps = array(
'groups' => false,
'dues' => false,
* Default to false, only relevant for SHOW_PUBLIC_LIST
* @param bool $count true if we want to count members, defaults to false
*
- * @return Zend_Db_Select SELECT statement
+ * @return Select SELECT statement
*/
private function _buildSelect($mode, $fields, $photos, $count = false)
{
/**
* Count members from the query
*
- * @param Zend_Db_Select $select Original select
+ * @param Select $select Original select
*
* @return void
*/
/**
* Builds where clause, for filtering on simple list mode
*
- * @param Zend_Db_Select $select Original select
+ * @param Select $select Original select
*
* @return string SQL WHERE clause
*/
global $zdb;
try {
- $zdb->db->beginTransaction();
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . Adherent::TABLE,
+ $zdb->connection->beginTransaction();
+ $select = $zdb->select(Adherent::TABLE);
+ $select->columns(
array('id_adh', 'login_adh', 'mdp_adh')
)->where(
- 'login_adh = ?', new \Zend_Db_Expr('NULL')
- )->orWhere(
- 'login_adh = ?', ''
- )->orWhere(
- 'mdp_adh = ?', new \Zend_Db_Expr('NULL')
- )->orWhere(
- 'mdp_adh = ?', ''
+ array(
+ 'login_adh' => new Expression('NULL'),
+ 'login_adh' => '',
+ 'mdp_adh' => new Expression('NULL'),
+ 'mdp_adh' => ''
+ ),
+ PredicateSet::OP_OR
);
- $res = $select->query()->fetchAll();
+ $results = $zdb->execute($select);
$processed = 0;
- if ( count($res) > 0 ) {
- $sql = 'UPDATE ' . PREFIX_DB . Adherent::TABLE .
- ' SET login_adh = :login, mdp_adh = :pass WHERE ' .
- Adherent::PK . ' = :id';
- $stmt = $zdb->db->prepare($sql);
+ if ( $results->count() > 0 ) {
+ $update = $this->_zdb->update(Adherent::TABLE);
+ $update->set(
+ array(
+ 'login_adh' => ':login',
+ 'mdp_adh' => ':pass'
+ )
+ )->where->equalTo(Adherent::PK, ':id');
+
+ $stmt = $this->_zdb->sql->prepareStatementForSqlObject($update);
$p = new \Galette\Core\Password();
- foreach ($res as $m) {
+ foreach ($results as $m) {
$dirty = false;
if ($m->login_adh == ''
|| !isset($m->login_adh)
}
if ( $dirty === true ) {
+ /** Why where parameter is named where1 ?? */
$stmt->execute(
array(
- 'login' => $m->login_adh,
- 'pass' => $m->mdp_adh,
- 'id' => $m->id_adh
+ 'login' => $m->login_adh,
+ 'pass' => $m->mdp_adh,
+ 'where1' => $m->id_adh
)
);
$processed++;
}
}
}
- $zdb->db->commit();
+ $zdb->connection->commit();
$this->_count = $processed;
return true;
} catch ( \Exception $e ) {
- $zdb->db->rollBack();
+ $zdb->connection->rollBack();
Analog::log(
'An error occured trying to retrieve members with ' .
'empty logins/passwords (' . $e->getMessage(),
namespace Galette\Repository;
use Analog\Analog;
+use Zend\Db\Sql\Expression;
use Galette\Entity\PdfModel;
use Galette\Entity\PdfMain;
use Galette\Entity\PdfInvoice;
public function getList()
{
try {
- $select = new \Zend_Db_Select($this->zdb->db);
- $select->from(
- array('a' => PREFIX_DB . PdfModel::TABLE)
- )->order(PdfModel::PK);
+ $select = $this->zdb->select(PdfModel::TABLE, 'a');
+ $select->order(PdfModel::PK);
$models = array();
- $res = $select->query()->fetchAll();
- foreach ( $res as $row ) {
+ $results = $this->zdb->execute($select);
+ foreach ( $results as $row ) {
$class = PdfModel::getTypeClass($row->model_type);
$models[] = new $class($this->zdb, $this->preferences, $row);
}
//been initialized
$proceed = false;
if ( $check_first === true ) {
- $select = new \Zend_Db_Select($this->zdb->db);
- $select->from(
- PREFIX_DB . $ent::TABLE,
- 'COUNT(' . $ent::PK . ') as counter'
+ $select = $this->zdb->select(self::TABLE);
+ $select->columns(
+ array(
+ 'counter' => new Expression('COUNT(' . $ent::PK . ')')
+ )
);
- $count = $select->query()->fetchObject()->counter;
+
+ $results = $this->zdb->execute($select);
+ $result = $results->current();
+ $count = $result->counter;
if ( $count == 0 ) {
//if we got no values in texts table, let's proceed
$proceed = true;
private function _checkUpdate($defaults)
{
try {
- $select = new \Zend_Db_Select($this->zdb->db);
$ent = $this->entity;
- $select->from(
- PREFIX_DB . $ent::TABLE
- );
- $list = $select->query()->fetchAll();
+ $select = $this->zdb->select($ent::TABLE);
+ $list = $this->zdb->execute($select);
$missing = array();
foreach ( $defaults as $default ) {
use Galette\Entity\Reminder;
use Galette\Filters\MembersList;
use Analog\Analog;
+use Zend\Db\Sql\Expression;
/**
* Reminders
*/
private function _loadToRemind($zdb, $type)
{
- $select = new \Zend_Db_Select($zdb->db);
- $select->from(
- array('a' => PREFIX_DB . Members::TABLE)
- )->joinLeft(
+ $select = $zdb->select(Members::TABLE, 'a');
+ $select->join(
array('r' => PREFIX_DB . self::TABLE),
'a.' . Members::PK . '=r.reminder_dest',
array(
- 'last_reminder' => new \Zend_Db_Expr('MAX(r.reminder_date)'),
+ 'last_reminder' => new Expression('MAX(r.reminder_date)'),
'r.reminder_type'
- )
- )->where(
- 'a.email_adh != \'\''
- )->where('a.activite_adh=true')
+ ),
+ $select::JOIN_LEFT
+ )->where('a.email_adh != \'\'')
+ ->where('a.activite_adh=true')
->where('bool_exempt_adh=false');
if ( $type === Reminder::LATE ) {
- $select->where(
- 'date_echeance < ?',
+ $select->where->LessThan(
+ 'date_echeance',
date('Y-m-d', time())
);
} else {
$now = new \DateTime();
$duedate = new \DateTime();
$duedate->modify('+1 month');
- $select->where('date_echeance > ?', $now->format('Y-m-d'))
- ->where(
- 'date_echeance < ?',
- $duedate->format('Y-m-d')
- );
+ $select->where->greaterThan(
+ 'date_echeance',
+ $now->format('Y-m-d')
+ )->greaterThan(
+ 'date_echeance',
+ $duedate->format('Y-m-d')
+ );
}
$select->group('a.id_adh')->group('r.reminder_type');
- $res = $select->query()->fetchAll();
+ $results = $zdb->execute($select);
- foreach ( $res as $r ) {
+ foreach ( $results as $r ) {
if ( $r->reminder_type === null || (int)$r->reminder_type === $type ) {
$date_checked = false;
use Galette\Entity\Title as Title;
use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
/**
* Titles repository management
if ( $d['long_label'] !== null ) {
$long = _T($d['long_label']);
} else {
- $long = new \Zend_Db_Expr('NULL');
+ $long = new Expression('NULL');
}
$stmt->bindParam(':id', $d['id_title']);
$stmt->bindParam(':short', $short);
{
global $zdb;
- $select = new \Zend_Db_Select($zdb->db);
- $select->limit(1)->from(PREFIX_DB . self::TABLE)
- ->where(self::PK . ' = ?', $title);
+ $select = $zdb->select(self::TABLE);
+ $select->limit(1)
+ ->where(array(self::PK => $title));
- $res = $select->query()->fetchColumn(1);
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $res = $result->short_label;
return _T($res);
}
}
*/
use Analog\Analog as Analog;
+use Galette\Core\L10n;
+use Zend\Db\Sql\Expression;
/** @ignore */
require_once 'includes/galette.inc.php';
$nb_fields = 0;
try {
- $select = new Zend_Db_Select($zdb->db);
- $select->from(
- PREFIX_DB . Galette\Core\L10n::TABLE,
- array('nb' => 'COUNT(text_orig)')
+ $select = $zdb->select(L10n::TABLE);
+ $select->columns(
+ array('nb' => new Expression('COUNT(text_orig)'))
);
- $nb_fields = $select->query()->fetch()->nb;
+ $results = $zdb->execute($select);
+ $result = $results->current();
+ $nb_fields = $result->nb;
} catch (Exception $e) {
- /** TODO */
Analog::log(
'An error occured counting l10n entries | ' .
$e->getMessage(),
Analog::WARNING
);
- Analog::log(
- 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
- Analog::ERROR
- );
}
if ( is_numeric($nb_fields) && $nb_fields > 0 ) {
try {
- $select = new Zend_Db_Select($zdb->db);
- $select->distinct()->from(
- PREFIX_DB . Galette\Core\L10n::TABLE,
- 'text_orig'
+ $select = $zdb->select(L10n::TABLE);
+ $select->quantifier('DISTINCT')->columns(
+ array('text_orig')
)->order('text_orig');
- $all_texts = $select->query()->fetchAll();
+ $all_texts = $zdb->execute($select);
$orig = array();
foreach ( $all_texts as $idx => $row ) {
$tpl->assign('orig', $orig);
$tpl->assign('trans', $trans);
} catch (Exception $e) {
- /** TODO */
Analog::log(
'An error occured retrieving l10n entries | ' .
$e->getMessage(),
Analog::WARNING
);
- Analog::log(
- 'Query was: ' . $select->__toString() . ' ' . $e->__toString(),
- Analog::ERROR
- );
}
}
$tpl->assign('page_title', _T("Translate labels"));