]> git.agnieray.net Git - galette.git/commitdiff
Reaplce all Zend_Db_Select and Zend_Db_Expr with their ZF2 equivalents
authorJohan Cwiklinski <johan@x-tnd.be>
Sat, 23 Nov 2013 17:13:46 +0000 (18:13 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 22 Dec 2013 09:14:24 +0000 (10:14 +0100)
23 files changed:
galette/configurer_fiches.php
galette/editer_champ.php
galette/includes/i18n.inc.php
galette/lib/Galette/Core/Db.php
galette/lib/Galette/Core/MailingHistory.php
galette/lib/Galette/Core/Picture.php
galette/lib/Galette/DynamicFieldsTypes/DynamicFieldType.php
galette/lib/Galette/Entity/Contribution.php
galette/lib/Galette/Entity/DynamicFields.php
galette/lib/Galette/Entity/FieldsCategories.php
galette/lib/Galette/Entity/FieldsConfig.php
galette/lib/Galette/Entity/PdfModel.php
galette/lib/Galette/Entity/Reminder.php
galette/lib/Galette/Entity/Texts.php
galette/lib/Galette/Filters/MembersList.php
galette/lib/Galette/IO/Charts.php
galette/lib/Galette/Repository/Contributions.php
galette/lib/Galette/Repository/Groups.php
galette/lib/Galette/Repository/Members.php
galette/lib/Galette/Repository/PdfModels.php
galette/lib/Galette/Repository/Reminders.php
galette/lib/Galette/Repository/Titles.php
galette/traduire_libelles.php

index 3f0ba8befad687680542d2f33f05039d95fbae39..48f8d9e6d091978fe0f8bd57aff58e1ca1611654 100644 (file)
@@ -39,6 +39,7 @@
 use Galette\Entity\DynamicFields as DynamicFields;
 use Galette\DynamicFieldsTypes\DynamicFieldType as DynamicFieldType;
 use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
 
 
 /** @ignore */
@@ -93,15 +94,17 @@ if ( $form_name == '' ) {
 
             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;
                 }
 
@@ -161,85 +164,100 @@ if ( $form_name == '' ) {
         }
         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(),
@@ -249,12 +267,12 @@ if ( $form_name == '' ) {
         }
     }
 
-    $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 ) {
index cece57c44b803fe13f2ea364dcc3655b5106ee20..d433669b2708105d67938e7341ae98cb17e2cbd7 100644 (file)
@@ -37,6 +37,7 @@
  */
 
 use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
 use Galette\Entity\DynamicFields as DynamicFields;
 use Galette\DynamicFieldsTypes\DynamicFieldType as DynamicFieldType;
 
@@ -86,7 +87,7 @@ if ( isset($_POST['valid']) ) {
     $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', '');
 
@@ -101,12 +102,15 @@ if ( isset($_POST['valid']) ) {
         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);
@@ -130,7 +134,6 @@ if ( isset($_POST['valid']) ) {
                     'field_id = ' . $field_id
                 );
             } catch (Exception $e) {
-                /** FIXME */
                 Analog::log(
                     'An error occured storing field | ' . $e->getMessage(),
                     Analog::ERROR
@@ -155,17 +158,20 @@ if ( isset($_POST['valid']) ) {
             $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(),
@@ -177,23 +183,30 @@ if ( isset($_POST['valid']) ) {
             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
index d561a2aac2c508f5bca0718a04e8e04e9218d067..ea30bbde6b8d3f2bb2e3e224d0c7bb4b62623ef0 100644 (file)
@@ -42,7 +42,8 @@ if (!defined('GALETTE_ROOT')) {
 }
 
 use Analog\Analog as Analog;
-use Zend\Db\Sql\Sql;
+use Zend\Db\Sql\Expression;
+use Galette\Core\L10n;
 
 $disable_gettext=true;
 
@@ -83,16 +84,23 @@ function addDynamicTranslation($text_orig, $error_detected)
     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 .
@@ -101,7 +109,7 @@ function addDynamicTranslation($text_orig, $error_detected)
                 );
 
                 $where = array();
-                $owhere = $select->getPart(Zend_Db_Select::WHERE);
+                $owhere = $select->getPart($select::WHERE);
                 foreach ( $owhere as $c ) {
                     $where[] = preg_replace('/^AND /', '', $c);
                 }
@@ -125,7 +133,6 @@ function addDynamicTranslation($text_orig, $error_detected)
             }
         }
     } catch (Exception $e) {
-        /** FIXME */
         Analog::log(
             'An error occured adding dynamic translation for `' .
             $text_orig . '` | ' . $e->getMessage(),
@@ -192,11 +199,17 @@ function updateDynamicTranslation(
 
     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);
 
@@ -207,7 +220,7 @@ function updateDynamicTranslation(
         $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);
             }
@@ -249,7 +262,7 @@ function getDynamicTranslation($text_orig, $text_locale)
 {
     global $zdb;
     try {
-        $select = $zdb->select(Galette\Core\L10n::TABLE);
+        $select = $zdb->select(L10n::TABLE);
         $select->limit(1)->columns(
             array('text_trans')
         )->where(
index 24050af5bf3944b11cd5a62bcd612e3df02aa2dc..6b422ae3220c5dda54ba2db9633ffe13cba6fc36 100644 (file)
@@ -170,13 +170,13 @@ class Db
             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(
@@ -443,11 +443,10 @@ class Db
 
                 //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!');
@@ -608,11 +607,6 @@ class Db
         }
 
         try {
-            $select = new \Zend_Db_Select($this->_db);
-            $select->from($table);
-
-            $result = $select->query();
-
             $descr = $this->_db->describeTable($table);
 
             $pkeys = array();
@@ -650,8 +644,10 @@ class Db
                 }
             }
 
-            $r = $result->fetchAll();
-            foreach ( $r as $row ) {
+            $select = $this->_sql->select($table);
+            $results = $this->execute($select);
+
+            foreach ( $results as $row ) {
                 $data = array();
                 $where = array();
 
@@ -666,11 +662,9 @@ class Db
                 }
 
                 //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(
@@ -757,7 +751,7 @@ class Db
     }
 
     /**
-     * Execture query string
+     * Execute query string
      *
      * @param SqlInterface $sql SQL object
      *
@@ -786,12 +780,12 @@ class Db
     }
 
     /**
-    * 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 ) {
index 8851056bedbbf5c7f45bbf41e993c61ab9051c03..5940e449af8fb035895907ec135a622f5f3416b2 100644 (file)
@@ -309,8 +309,16 @@ class MailingHistory extends History
                     $_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,
index df4d176280c07c6eefbed17a6fbe7aca76a2119d..dd32c47a6954180a0fcf82a2447c48252b485942 100644 (file)
@@ -514,14 +514,22 @@ class Picture
 
         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(
index b6770255f09bcebe237b81c11f2a19582f9f2303..a89602a15ecd7fd469e1ec77674243572c0942c5 100644 (file)
@@ -97,12 +97,11 @@ abstract class DynamicFieldType
         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;
@@ -136,14 +135,17 @@ abstract class DynamicFieldType
         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 ) {
@@ -155,10 +157,6 @@ abstract class DynamicFieldType
                 __METHOD__ . ' | ' . $e->getMessage(),
                 Analog::WARNING
             );
-            Analog::log(
-                'Query was: ' . $val_select->__toString() . ' ' . $e->__toString(),
-                Analog::INFO
-            );
         }
     }
 
index a313c816826dcfe35e68683c0d3ca686ce8f4c75..155c10f77b2a8e4ed7560e8062cc0924721f7929 100644 (file)
@@ -233,14 +233,15 @@ class Contribution
         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;
@@ -250,7 +251,6 @@ class Contribution
                 );
             }
         } catch (\Exception $e) {
-            /** FIXME */
             Analog::log(
                 'An error occured attempting to load contribution #' . $id .
                 $e->getMessage(),
@@ -472,28 +472,28 @@ class Contribution
         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);
 
@@ -502,15 +502,10 @@ class Contribution
             }
             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;
         }
     }
@@ -528,7 +523,6 @@ class Contribution
             $zdb->db->beginTransaction();
             $values = array();
             $fields = self::getDbFields();
-            /** FIXME: quote? */
             foreach ( $fields as $field ) {
                 $prop = '_' . $this->_fields[$field]['propname'];
                 switch ( $field ) {
@@ -627,14 +621,16 @@ class Contribution
             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(
@@ -674,7 +670,6 @@ class Contribution
             }
             return true;
         } catch (\Exception $e) {
-            /** FIXME */
             if ( $transaction ) {
                 $zdb->db->rollBack();
             }
index 61d1f31f057eed87d59cdb19ad2945838f3d659a..f8f54715e1cd0e898bd1b6cbd6027d12f57cdf98 100644 (file)
@@ -501,7 +501,7 @@ class DynamicFields
                     }
                 }
 
-                $owhere = $select->getPart(\Zend_Db_Select::WHERE);
+                $owhere = $select->getPart($select::WHERE);
                 foreach ( $owhere as $c ) {
                     $where[] = preg_replace('/^AND /', '', $c);
                 }
@@ -638,12 +638,14 @@ class DynamicFields
         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 {
@@ -674,17 +676,25 @@ class DynamicFields
         //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;
             }
index 4068f8c3b4b7e57301f5714f20d4ab8847937453..787ebe8e14a511e6eccd2e8ca6125f7ac5b19582 100644 (file)
@@ -101,21 +101,15 @@ class FieldsCategories
         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;
         }
     }
@@ -161,12 +155,4 @@ class FieldsCategories
             return $e;
         }
     }
-
-    /**
-    * GETTERS
-    */
-
-    /**
-    * SETTERS
-    */
 }
index 147911c0752722aeab2615be8344be889fdf9400..3a2c3cbeda43bff78e91bc57dbeba3d4ac1a118e 100644 (file)
@@ -468,10 +468,10 @@ class FieldsConfig
         $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 ' .
@@ -482,19 +482,30 @@ class FieldsConfig
             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);
@@ -508,12 +519,15 @@ class FieldsConfig
                 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(),
index 12c6f7639253ba453c2b86c1f1b68337a9e8c8d3..bbf87c15e53bbc3b26cf2cd24987649742020ae4 100644 (file)
@@ -38,6 +38,7 @@
 namespace Galette\Entity;
 
 use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
 
 /**
  * PDF Model
@@ -136,12 +137,12 @@ abstract class PdfModel
     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" .
@@ -214,12 +215,12 @@ abstract class PdfModel
     {
         $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(
@@ -234,18 +235,17 @@ abstract class PdfModel
 
         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;
                 }
index bf2fbabd1d52c1b3e327229c9b3e8059841ca06a..5921da282ffa7a599e76d7561b57f7fb2817a799 100644 (file)
@@ -38,6 +38,7 @@
 namespace Galette\Entity;
 
 use Analog\Analog;
+use Zend\Db\Sql\Expression;
 use \Galette\Core\GaletteMail;
 
 /**
@@ -103,12 +104,12 @@ class Reminder
     {
         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" .
@@ -160,7 +161,7 @@ class Reminder
         $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'
         );
index 77f4c69e5b0ea1e0bec2adec9ae61bc81cc3da1f..3ccc3b7243bc0a7bb903c37327103102ec57e76b 100644 (file)
@@ -39,6 +39,7 @@
 namespace Galette\Entity;
 
 use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
 
 /**
  * Texts class for galette
@@ -294,24 +295,18 @@ class Texts
         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;
         }
     }
@@ -346,12 +341,16 @@ class Texts
             //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;
@@ -410,11 +409,8 @@ class Texts
         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 ) {
index 8eedb82267b6fee5189f826fb718afd78db2279c..5dafe073322eb0a05330beb88e632bb64924b04f 100644 (file)
@@ -257,7 +257,7 @@ class MembersList extends Pagination
     /**
      * Add SQL limit
      *
-     * @param Zend_Db_Select $select Original select
+     * @param Select $select Original select
      *
      * @return <type>
      */
index 9872ddb59d6da16674d4ed656cea0a3064243e35..5e8d48fe3453d8ba0d712445541593aa612a0dce 100644 (file)
@@ -281,7 +281,6 @@ class Charts
 
         //companies
         $select1->combine($select2);
-        //$select->union(array($select1, $select2), \Zend_Db_Select::SQL_UNION_ALL);
 
         $results = $zdb->execute($select1);
 
index 06df167ede0c0878e0ff1dfe1676936d1a64ac4c..a16a024ede35e28abc16f97f713751e58690c735 100644 (file)
@@ -228,7 +228,7 @@ class Contributions extends Pagination
     /**
     * Count contributions from the query
     *
-    * @param Zend_Db_Select $select Original select
+    * @param Select $select Original select
     *
     * @return void
     */
@@ -267,7 +267,7 @@ class Contributions extends Pagination
     /**
     * Calculate sum of all selected contributions
     *
-    * @param Zend_Db_Select $select Original select
+    * @param Select $select Original select
     *
     * @return void
     */
@@ -343,7 +343,7 @@ class Contributions extends Pagination
     /**
      * 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
      */
@@ -461,12 +461,12 @@ class Contributions extends Pagination
             $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);
@@ -475,7 +475,7 @@ class Contributions extends Pagination
                     }
                 }
                 if ( $transaction ) {
-                    $zdb->db->commit();
+                    $zdb->connection->commit();
                 }
                 $hist->add(
                     str_replace(
@@ -485,9 +485,8 @@ class Contributions extends Pagination
                     )
                 );
             } catch (\Exception $e) {
-                /** FIXME */
                 if ( $transaction ) {
-                    $zdb->db->rollBack();
+                    $zdb->connection->rollBack();
                 }
                 Analog::log(
                     'An error occured trying to remove contributions | ' .
index d118dc95aee45c3b7410a3ebfe14d2e07e756e9e..6f159059cdd7832a54f97a37c1d6a3e5ff5e5802 100644 (file)
@@ -376,22 +376,17 @@ class Groups
         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
-            );
         }
     }
 }
index b8571e85733e37cffe4e00d08761f4873a5b16e2..461c9e8910a9196b09d20513942bf967a74a3b3e 100644 (file)
@@ -41,6 +41,7 @@ use Galette\Entity\DynamicFields;
 
 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;
@@ -429,15 +430,9 @@ class Members
 
             $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,
@@ -537,7 +532,7 @@ class Members
      *                      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)
     {
@@ -753,7 +748,7 @@ class Members
     /**
      * Count members from the query
      *
-     * @param Zend_Db_Select $select Original select
+     * @param Select $select Original select
      *
      * @return void
      */
@@ -871,7 +866,7 @@ class Members
     /**
      * 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
      */
@@ -1351,33 +1346,37 @@ class Members
         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)
@@ -1400,22 +1399,23 @@ class Members
                     }
 
                     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(),
index b532d3757de74b3ba1b23924ffbdf7bac920f012..5ba0bdeafabf94083b0c01d6ad83259e9b714915 100644 (file)
@@ -38,6 +38,7 @@
 namespace Galette\Repository;
 
 use Analog\Analog;
+use Zend\Db\Sql\Expression;
 use Galette\Entity\PdfModel;
 use Galette\Entity\PdfMain;
 use Galette\Entity\PdfInvoice;
@@ -65,14 +66,12 @@ class PdfModels extends Repository
     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);
             }
@@ -105,12 +104,16 @@ class PdfModels extends Repository
             //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;
@@ -163,12 +166,9 @@ class PdfModels extends Repository
     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 ) {
index 46ba61b9dd82fa48415c3d34c83ed1dc9a6c4186..6354b81e3e5358e511ea8e83a59325f65b9e9489 100644 (file)
@@ -40,6 +40,7 @@ namespace Galette\Repository;
 use Galette\Entity\Reminder;
 use Galette\Filters\MembersList;
 use Analog\Analog;
+use Zend\Db\Sql\Expression;
 
 /**
  * Reminders
@@ -88,42 +89,42 @@ class 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;
 
index 027d70c4f6515a2914bceaa6b85e8b13dd5c0bb1..9160ebcd4bb130feb2b3ea319bfb7955ee8fcaa2 100644 (file)
@@ -39,6 +39,7 @@ namespace Galette\Repository;
 
 use Galette\Entity\Title as Title;
 use Analog\Analog as Analog;
+use Zend\Db\Sql\Expression;
 
 /**
  * Titles repository management
@@ -123,7 +124,7 @@ class Titles
                 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);
@@ -156,11 +157,13 @@ class Titles
     {
         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);
     }
 }
index f4651fdab156928653f4fa81b9a52f5230e7f25e..8d3d28a920f91ad82717f783acdaebcad6fa7678 100644 (file)
@@ -37,6 +37,8 @@
  */
 
 use Analog\Analog as Analog;
+use Galette\Core\L10n;
+use Zend\Db\Sql\Expression;
 
 /** @ignore */
 require_once 'includes/galette.inc.php';
@@ -102,34 +104,29 @@ $tpl->assign('all_forms', $all_forms);
 
 $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 ) {
@@ -166,16 +163,11 @@ if ( is_numeric($nb_fields) && $nb_fields > 0 ) {
         $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"));