Example #1
0
 public function getById($id, $cache = true)
 {
     if ($cache == true) {
         $cacheId = 'SxModule_Pageform_Subscription_getById_' . sha1($id);
         $cache = Zend_Registry::get('cache');
         if (true == ($result = $cache->load($cacheId))) {
             return $result;
         }
     }
     $db = Zend_Registry::get('db');
     $select = $db->select()->from(array('pfsu' => $this->_tablename()), array('*'))->join(array('pf' => 'pageform'), 'pfsu.pfsu_pageform_id = pf.pf_id')->where('pfsu.' . $this->_primary_key() . ' = ?', $id);
     $result = $db->fetchRow($select);
     $data = $this->_mapper->toObject(is_array($result) ? $result : array());
     $pageformMapper = new SxModule_Pageform_Mapper();
     $data->setPageform($pageformMapper->toObject(is_array($result) ? $result : array()));
     $select_meta = $db->select()->from(array('sum' => 'pageform_subscription_meta'), array('*'))->where('pfsum_subscription_id = ?', (int) $data->getId());
     $meta_results = $db->fetchAll($select_meta);
     $metaMapper = new SxModule_Pageform_Subscription_Meta_Mapper();
     foreach ($meta_results as $meta) {
         if ($data->getId() == $meta['pfsum_subscription_id']) {
             $mapped = $metaMapper->toObject($meta);
             $data->addMeta($mapped);
         }
     }
     if ($cache == true) {
         $cacheTags = array('SxModule_Pageform_Subscription_getById', 'SxModule_Pageform_Subscription', 'SxModule_Pageform_Subscription_Id' . $id);
         $cache->save($data, $cacheId, $cacheTags);
     }
     return $data;
 }
Example #2
0
 public function save($item_params = '*')
 {
     $db = Zend_Registry::get('db');
     $mapper = new SxModule_Pageform_Mapper();
     $pageform = new SxModule_Pageform();
     $pageform->setTsl($this);
     $item = $mapper->toArray($pageform, 'tsl');
     if (is_array($item_params)) {
         $item = $mapper->fromInput($item, $item_params);
     }
     if ($this->getId()) {
         $item['pf_tsl_date_updated'] = new Zend_Db_Expr('NOW()');
         $db->update($this->_tablename(), $item, $this->_primary_key() . ' = ' . (int) $this->getId());
     } else {
         $item['pf_tsl_date_created'] = new Zend_Db_Expr('NOW()');
         $item['pf_tsl_date_updated'] = '0000-00-00 00:00:00';
         $config = Zend_Registry::get('config');
         foreach ($config->system->language as $lng => $slng) {
             $item['language'] = $lng;
             if ($lng != $_SESSION['System']['lng']) {
                 $item['active'] = 0;
                 $item['confirm'] = 0;
                 $item['confirmto'] = '';
             }
             $db->insert($this->_tablename(), $item);
         }
     }
     return $this;
 }
Example #3
0
 public function save($item_params = '*')
 {
     $db = Zend_Registry::get('db');
     $mapper = new SxModule_Pageform_Mapper();
     $item = $mapper->toArray($this, 'item');
     if (is_array($item_params)) {
         $item = $mapper->fromInput($item, $item_params);
     }
     if ($this->getId()) {
         $item['pf_date_updated'] = new Zend_Db_Expr('NOW()');
         $db->update($this->_tablename(), $item, $this->_primary_key() . ' = ' . (int) $this->getId());
     } else {
         $item['pf_date_created'] = new Zend_Db_Expr('NOW()');
         $item['pf_date_updated'] = '0000-00-00 00:00:00';
         $db->insert($this->_tablename(), $item);
         $this->setId($db->lastInsertId());
     }
     return $this;
 }