Ejemplo n.º 1
0
 /**
  * Simple function to return the $config array
  * @param array $config if set, merge with existing array
  * @return array $config
  */
 public function config($config = array())
 {
     $db =& ConnectionManager::getDataSource($this->useDbConfig);
     if (!empty($config) && is_array($config)) {
         $db->config = set::merge($db->config, $config);
     }
     return $db->config;
 }
 function setup(&$Model, $settings = array())
 {
     if (empty($settings['fieldsOpt'])) {
         $settings['fieldsOpt'] = array();
     }
     if (!empty($settings['fields'])) {
         $settings['fieldsOpt'] = set::merge($settings['fieldsOpt'], array_filter(Set::normalize($settings['fields'])));
         $settings['fields'] = array_keys(Set::normalize($settings['fields']));
     }
     if (empty($this->settings[$Model->alias])) {
         $this->settings[$Model->alias] = $this->defSettings;
     }
     $this->settings[$Model->alias] = set::merge($this->settings[$Model->alias], $settings);
 }
Ejemplo n.º 3
0
 function _subProductsFields($types, $prefix = 'ShopSubproduct.')
 {
     App::import('Lib', 'Shop.SetMulti');
     $config = ShopConfig::load();
     $typeFields = array();
     if (!empty($types)) {
         foreach ($types as $key => $type) {
             $fields = set::normalize(array('id', 'code', 'label_fre', 'label_eng', 'operator', 'price'));
             if (isset($type['price']) && $type['price'] === false) {
                 unset($fields['price']);
                 unset($fields['operator']);
             }
             if (array_key_exists('price', $fields) && !empty($config['currencies'])) {
                 //$fields['price']['label'] = __('Default Price',true);
                 unset($fields['price']);
                 foreach ($config['currencies'] as $currency) {
                     $fOpt = array('label' => str_replace('%currency%', $currency, __('Price %currency%', true)), 'type' => 'text');
                     $fields['currency_prices.' . $currency] = $fOpt;
                 }
             }
             if (array_key_exists('operator', $fields)) {
                 if (count($type['operators']) == 1) {
                     $fields = SetMulti::insertBeforeKey($fields, 'operator', array('operator_display' => array('type' => 'definition', 'value' => $type['operators'][0], 'label' => __('Operator', true))));
                     $fields['operator']['type'] = 'hidden';
                     $fields['operator']['value'] = $type['operators'][0];
                 } else {
                     $fields['operator']['options'] = $type['operators'];
                 }
                 if (isset($type['adminFields'])) {
                     $fields = set::merge($fields, $type['adminFields']);
                 }
             }
             $typeField = array('type' => 'multiple', 'fields' => $fields, 'div' => array('class' => 'type'));
             if (!empty($type['children'])) {
                 $typeField['subline'] = $this->_subProductsFields($type['children'], 'children.');
             }
             $typeFields[$prefix . $key] = $typeField;
         }
     }
     return $typeFields;
 }
Ejemplo n.º 4
0
 function alterEmailQuery($opt)
 {
     $Model = $this->EmailModel;
     $modelName = $Model->alias;
     if (!empty($opt)) {
         $NewsletterEmail = ClassRegistry::init('Newsletter.NewsletterEmail');
         App::import('Lib', 'Newsletter.SetMulti');
         $replace = array($NewsletterEmail->alias . '.email' => $this->realField('email'), $NewsletterEmail->alias => $modelName);
         $opt = SetMulti::replaceTree(array_keys($replace), array_values($replace), $opt);
     }
     $conditions = array();
     if (!empty($opt['active']) || !isset($opt['active']) && !$this->options['showInnactive']) {
         if ($opt['mode'] != 'count' && $this->options['checkUnsubscribe']) {
             $NewsletterEmail = ClassRegistry::init('Newsletter.NewsletterEmail');
             $opt['joins'][] = array('alias' => $NewsletterEmail->alias, 'table' => $NewsletterEmail->useTable, 'type' => 'LEFT', 'conditions' => array($this->realField('email') . ' = ' . $NewsletterEmail->alias . '.email'));
             $conditions[] = array('or' => array($NewsletterEmail->alias . '.active' => 1, $NewsletterEmail->alias . '.id IS NULL'));
         }
         if (!empty($this->options['fields']['active']) && $Model->hasField($this->options['fields']['active'])) {
             $conditions[$this->realField('active')] = 1;
         }
     }
     $conditions['NOT'][$this->realField('email')] = "";
     $conditions[] = $this->realField('email') . ' IS NOT NULL';
     if (!empty($this->options['conditions'])) {
         if (!array($this->options['conditions'])) {
             $this->options['conditions'] = array($this->options['conditions']);
         }
         $conditions = set::merge($conditions, $this->options['conditions']);
     }
     $opt['conditions'][] = $conditions;
     if ((empty($opt['mode']) || $opt['mode'] != 'count') && empty($opt['fields'])) {
         $opt['fields'] = $this->emailFields();
     }
     if (!empty($this->options['findOptions']) && is_array($this->options['findOptions'])) {
         $opt = set::merge($opt, $this->options['findOptions']);
     }
     return $opt;
 }
Ejemplo n.º 5
0
 /**
  * Reduces an array to a the JS nomenclature for an object, useful for passing into JS configurations
  */
 static function arrayFlatten($arrayNested)
 {
     $returnArray = array();
     foreach ($arrayNested as $key => $val) {
         if (is_array($val)) {
             $returnArray = set::merge($returnArray, $val);
         } else {
             $returnArray[$key] = $val;
         }
     }
     return $returnArray;
 }
 function tabledEmailGetFindOptions($tableSendlist, $active = true, $addfindOptions = null)
 {
     $tableSendlist = $this->getTableSendlistID($tableSendlist, true);
     if (!empty($tableSendlist)) {
         $Model = $tableSendlist['modelClass'];
         $modelName = $Model->alias;
         $conditions = array();
         if ($active && !is_null($tableSendlist['activeField']) && $Model->hasField($tableSendlist['activeField'])) {
             $conditions[$modelName . '.' . $tableSendlist['activeField']] = 1;
         }
         $conditions['NOT'][$modelName . '.' . $tableSendlist['emailField']] = "";
         $conditions[] = $modelName . '.' . $tableSendlist['emailField'] . ' IS NOT NULL';
         if (!empty($tableSendlist['conditions'])) {
             if (!array($tableSendlist['conditions'])) {
                 $tableSendlist['conditions'] = array($tableSendlist['conditions']);
             }
             $conditions = set::merge($conditions, $tableSendlist['conditions']);
         }
         $findOptions = array('conditions' => $conditions);
         $findOptions['model'] = $Model;
         $findOptions['fields'] = $this->tabledEmailGetFindFields($tableSendlist);
         if (!empty($tableSendlist['findOptions']) && is_array($tableSendlist['findOptions'])) {
             $findOptions = set::merge($findOptions, $tableSendlist['findOptions']);
         }
         if (!empty($addfindOptions)) {
             $NewsletterEmail = ClassRegistry::init('Newsletter.NewsletterEmail');
             App::import('Lib', 'Newsletter.SetMulti');
             $replace = array($NewsletterEmail->alias . '.email' => $modelName . '.' . $tableSendlist['emailField'], $NewsletterEmail->alias => $modelName);
             $addfindOptions = SetMulti::replaceTree(array_keys($replace), array_values($replace), $addfindOptions);
             $findOptions = set::merge((array) $addfindOptions, $findOptions);
         }
         return $findOptions;
     }
     return null;
 }