protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $total = CustomerTable::rebuildSlugs();
     $this->logSection('siwapp', "{$total} Customer slugs rebuilt.");
 }
Exemple #2
0
 public function getTaxesPercent($tax_names = null)
 {
     $tax_names = $tax_names ? is_array($tax_names) ? array_map(array('CustomerTable', 'slugify'), $tax_names) : array(CustomerTable::slugify($tax_names)) : null;
     $total = 0;
     foreach ($this->Taxes as $tax) {
         if (!$tax_names || in_array(CustomerTable::slugify($tax->name), $tax_names)) {
             $total += $tax->getValue();
         }
     }
     return $total;
 }
 public function preup()
 {
     $customers = Doctrine_Query::create()->select('c.name, c.name_slug')->from('Customer c')->execute();
     $used_names = array();
     $used_slugs = array();
     foreach ($customers as $c) {
         if (!in_array($c->name, $used_names) && !in_array(CustomerTable::slugify($c->name), $used_slugs)) {
             $used_names[] = $c->name;
             $used_slugs[] = CustomerTable::slugify($c->name);
         } else {
             $counter = 1;
             while (in_array($c->name . '--' . $counter, $used_names) || in_array(CustomerTable::slugify($c->name . '--' . $counter), $used_slugs)) {
                 $counter++;
             }
             $c->name = $c->name . '--' . $counter;
             $c->name_slug = CustomerTable::slugify($c->name);
             $c->save();
         }
     }
 }
Exemple #4
0
$invoice->setSeriesId('1');
$invoice->save();
$t->is($invoice->number, 9, 'When changing number series, the inv number changes');
$invoice->setSeriesId('2');
$invoice->save();
$t->is($invoice->number, 5, 'When changing back it gets the next maximun number available');
// checks savings with modified customer data
$t->diag('customers mod available: checking that moddified cust data does not alter customer object itself');
$invoice = Doctrine::getTable('Invoice')->findOneBy('CustomerName', 'Smith and Co.');
$invoice->customer_email = '*****@*****.**';
$invoice->save();
$t->is($invoice->customer_id, $customer_id, "customer id not changed");
$c = Doctrine::getTable('Customer')->findOneById($customer_id);
$t->is($c->name . $c->email, 'Smith and Co.jody_nichols@example.com', 'Customer object is not modified');
$t->diag('customers mod not available: checking that moddified cust data in the invoice alter customer object itself');
PropertyTable::set('siwapp_modules', array('products', 'estimates'));
$invoice->customer_email = '*****@*****.**';
$invoice->save();
$c = Doctrine::getTable('Customer')->findOneById($customer_id);
$t->is($c->name . $c->email, 'Smith and Co.test2@testmail.com', 'Customer object is modified');
PropertyTable::set('siwapp_modules', array('customers', 'products', 'estimates'));
$t->diag('checking that changing customer name changes customer');
$invoice->customer_name = 'Rouster and Sideways';
$invoice->save();
$c = Doctrine::getTable('Customer')->findOneById($invoice->customer_id);
$t->is($c->name_slug, CustomerTable::slugify($invoice->customer_name), 'A different customer object is associated');
$t->diag('checking that db-new customer name creates a new customer');
$invoice->customer_name = 'New Rouster and Sideways';
$invoice->save();
$c = Doctrine::getTable('Customer')->findOneByNameSlug(CustomerTable::slugify($invoice->customer_name));
$t->is($c->name, $invoice->customer_name, 'New Customer created');
 /** 
  * takes care of sluggifying fields before saving
  */
 public function preSave($event)
 {
     if (!$this->name_slug) {
         $this->name_slug = CustomerTable::slugify($this->name);
     }
     parent::preSave($event);
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     $taintedValues['name_slug'] = CustomerTable::slugify($taintedValues['name']);
     parent::bind($taintedValues, $taintedFiles);
 }
 /**
  * Rebuild the name slug for each Customer in database.
  */
 public static function rebuildSlugs()
 {
     $total = 0;
     $customers = Doctrine::getTable('Customer')->createQuery()->execute();
     foreach ($customers as $customer) {
         $customer->setNameSlug(CustomerTable::slugify($customer->getName()));
         $customer->save();
         $total++;
     }
     return $total;
 }
Exemple #8
0
<?php

include dirname(__FILE__) . '/../../bootstrap/Doctrine.php';
$t = new lime_test(8, new lime_output_color());
$t->diag("CustomerTable class tests");
$slugged = CustomerTable::slugify('Some Text with 5 SpACes');
$t->is($slugged, 'sometextwith5spaces', '->slugify(\'Some Text with 5 SpACes\')');
$slugged = CustomerTable::slugify('  Text with -ç-€-®-ñ-©- and , and_ & chars');
$t->is($slugged, 'textwithceurrncandand_chars', '->slugify(\'  Text with -ç-€-®-ñ-©- and , and_ & chars\')');
$t->diag("Checking with test data.");
$test = Doctrine::getTable('Customer')->matchName('  spring -- shi eld');
$t->is($test->getNameSlug(), 'springshield', '->matchName()');
$invoice = new Invoice();
$invoice->setCustomerName(' Sonky !rubber Goods');
$test = Doctrine::getTable('Customer')->getCustomerMatch($invoice);
$t->is($test->getIdentification(), '40487600161', '->getCustomerMatch() with name');
$invoice->setCustomerName(' Sonky !rubberaa Goods');
$invoice->setCustomerIdentification('40487600161');
$test = Doctrine::getTable('Customer')->getCustomerMatch($invoice);
$t->is($test->state(), Doctrine_Record::STATE_TCLEAN, '->getCustomerMatch() return new object if name doesn\'t match and identification matchs');
$invoice->setCustomerName(' Sonky !rubber Goods');
$invoice->setCustomerIdentification('GGD');
$test = Doctrine::getTable('Customer')->getCustomerMatch($invoice);
$t->is($test->state(), Doctrine_Record::STATE_CLEAN, '->getCustomerMatch() matchs if identification doesn\'t match and name matchs');
$t->is($test->getEmail(), '*****@*****.**', 'and gets the right customer');
$test = Doctrine::getTable('Customer')->simpleRetrieveForSelect('Rouster and Sideways', 2);
$t->is(count($test), 1, '::simpleRetrieveForSelect');