示例#1
0
 /**
  * Initialize the object.
  *
  * @param \JDatabaseDriver $db
  */
 public function __construct(\JDatabaseDriver $db = null)
 {
     $this->db = $db;
     // Implement JObservableInterface:
     // Create observer updater and attaches all observers interested by $this class:
     $this->observers = new \JObserverUpdater($this);
     \JObserverMapper::attachAllObservers($this);
 }
示例#2
0
文件: item.php 项目: ForAEdesWeb/AEW3
 /**
  * Constructor
  *
  * @param JDatabase A database connector object
  */
 public function __construct(&$db)
 {
     // Set Observer
     if (version_compare(JVERSION, '3.1.4', '<')) {
         $this->_observers = new JObserverUpdater($this);
         JObserverMapper::attachAllObservers($this);
     }
     // Attach Tags Observer
     JObserverMapper::addObserverClassToClass('JTableObserverTags', 'WebgalleryTableItem', array('typeAlias' => 'com_webgallery.item'));
     parent::__construct('#__webgallery_items', 'id', $db);
 }
 /**
  * Constructor.
  *
  * @param   string                    $table  Table name.
  * @param   string|array              $pk     Primary key.
  * @param   DatabaseAdapterInterface  $db     Database adapter.
  */
 public function __construct($table = null, $pk = 'id', DatabaseAdapterInterface $db = null)
 {
     // Implement JObservableInterface:
     // Create observer updater and attaches all observers interested by $this class:
     $this->observers = new \JObserverUpdater($this);
     \JObserverMapper::attachAllObservers($this);
     parent::__construct($table, $pk, $db);
     $this->relation = new Relation(new Table($this->table, $this->pk, $this->db->getDb()));
     $this->attachObserver(new RelationObserver($this));
     $this->observers->update('onAfterConstruction', array());
 }
示例#4
0
 public function __construct($table, $key, $db)
 {
     // Set internal variables.
     $this->_tbl = $table;
     $this->_tbl_key = $key;
     // For Joomla 3.2 onwards
     $this->_tbl_keys = array($key);
     $this->_db = $db;
     // Implement JObservableInterface:
     // Create observer updater and attaches all observers interested by $this class:
     $version = EB::getJoomlaVersion();
     if ($version >= '3.0' && class_exists('JObserverUpdater')) {
         $this->_observers = new JObserverUpdater($this);
         JObserverMapper::attachAllObservers($this);
     }
 }
示例#5
0
 /**
  * @param string $table
  * @param string $key
  * @param JDatabase $db
  */
 function __construct($table, $key, &$db)
 {
     $this->_tbl = $table;
     $this->_db =& $db;
     $this->_pkey = $key;
     if (JVM_VERSION < 3) {
         $this->_tbl_key = $key;
     } else {
         // Set the key to be an array.
         if (is_string($key)) {
             $key = array($key);
         } elseif (is_object($key)) {
             $key = (array) $key;
         }
         $this->_tbl_keys = $key;
         if (count($key) == 1) {
             $this->_autoincrement = true;
         } else {
             $this->_autoincrement = false;
         }
         // Set the singular table key for backwards compatibility.
         $this->_tbl_key = $this->getKeyName();
     }
     // If we are tracking assets, make sure an access field exists and initially set the default.
     if (property_exists($this, 'asset_id')) {
         $this->_trackAssets = true;
     }
     // If the access property exists, set the default.
     if (property_exists($this, 'access')) {
         $this->access = (int) JFactory::getConfig()->get('access');
     }
     if (JVM_VERSION > 2) {
         // Implement JObservableInterface:
         // Create observer updater and attaches all observers interested by $this class:
         $this->_observers = new JObserverUpdater($this);
         JObserverMapper::attachAllObservers($this);
     }
 }
示例#6
0
文件: table.php 项目: klas/joomla-cms
 /**
  * Object constructor to set table and key fields.  In most cases this will
  * be overridden by child classes to explicitly set the table and key fields
  * for a particular database table.
  *
  * @param   string           $table  Name of the table to model.
  * @param   mixed            $key    Name of the primary key field in the table or array of field names that compose the primary key.
  * @param   JDatabaseDriver  $db     JDatabaseDriver object.
  *
  * @since   11.1
  */
 public function __construct($table, $key, $db)
 {
     // Set internal variables.
     $this->_tbl = $table;
     // Set the key to be an array.
     if (is_string($key)) {
         $key = array($key);
     } elseif (is_object($key)) {
         $key = (array) $key;
     }
     $this->_tbl_keys = $key;
     if (count($key) == 1) {
         $this->_autoincrement = true;
     } else {
         $this->_autoincrement = false;
     }
     // Set the singular table key for backwards compatibility.
     $this->_tbl_key = $this->getKeyName();
     $this->_db = $db;
     // Initialise the table properties.
     $fields = $this->getFields();
     if ($fields) {
         foreach ($fields as $name => $v) {
             // Add the field if it is not already present.
             if (!property_exists($this, $name)) {
                 $this->{$name} = null;
             }
         }
     }
     // If we are tracking assets, make sure an access field exists and initially set the default.
     if (property_exists($this, 'asset_id')) {
         $this->_trackAssets = true;
     }
     // If the access property exists, set the default.
     if (property_exists($this, 'access')) {
         $this->access = (int) JFactory::getConfig()->get('access');
     }
     // Implement JObservableInterface:
     // Create observer updater and attaches all observers interested by $this class:
     $this->_observers = new JObserverUpdater($this);
     JObserverMapper::attachAllObservers($this);
 }
示例#7
0
 function getImportInfo()
 {
     $this->onExecuteBefore('getImportInfo');
     $encoding = $this->getState('encoding');
     if ($encoding == 'cp1251') {
         setLocale(LC_ALL, 'ru_RU.CP1251');
     }
     if ($_FILES['photos_zip']['tmp_name'] != '') {
         $import_dir = JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'import' . DS;
         JFolder::delete($import_dir);
         JFolder::create($import_dir, 0777);
         copy($_FILES['photos_zip']['tmp_name'], $import_dir . 'import.zip');
         $result = JArchive::extract(JPath::clean($import_dir . 'import.zip'), JPath::clean($import_dir));
     }
     $unic = JRequest::getVar('unic');
     $f = fopen(JPATH_COMPONENT . DS . 'tmp' . DS . 'import.csv', "rt") or die("Ошибка!");
     $info = array('insert' => '', 'update' => '');
     $relatives = array();
     for ($k = 0; $data = fgetcsv($f, 10000, ";"); $k++) {
         if ($k == 0) {
             $headers = $data;
             continue;
         }
         $product_data = array();
         if ($k > 0) {
             if (isset($_POST['title']) && $_POST['title'] != '') {
                 $product_data['title'] = $this->encode($data[$_POST['title']]);
             }
             if (isset($_POST['parent_id']) && $_POST['parent_id'] != '') {
                 $product_data['parent_id'] = $this->encode($data[$_POST['parent_id']]);
             }
             if (isset($_POST['categories']) && $_POST['categories'] != '') {
                 $product_data['categories'] = $this->encode($data[$_POST['categories']]);
             }
             if (isset($_POST['childs_group']) && $_POST['childs_group'] != '') {
                 $product_data['childs_group'] = $this->encode($data[$_POST['childs_group']]);
             }
             if (isset($_POST['price']) && $_POST['price'] != '') {
                 $product_data['price'] = str_replace(' ', '', $this->encode($data[$_POST['price']]));
             }
             if (isset($_POST['promotion_price']) && $_POST['promotion_price'] != '') {
                 $product_data['promotion_price'] = (double) str_replace(' ', '', $this->encode($data[$_POST['promotion_price']]));
             }
             if (isset($_POST['price_type']) && $_POST['price_type'] != '') {
                 $product_data['price_type'] = str_replace(' ', '', $this->encode($data[$_POST['price_type']]));
             }
             if (isset($_POST['product_code']) && $_POST['product_code'] != '') {
                 $product_data['product_code'] = $this->encode($data[$_POST['product_code']]);
             }
             if (isset($_POST['product_packaging']) && $_POST['product_packaging'] != '') {
                 $product_data['product_packaging'] = (double) str_replace(' ', '', $this->encode($data[$_POST['product_packaging']]));
             }
             if (isset($_POST['product_unit']) && $_POST['product_unit'] != '') {
                 $product_data['product_unit'] = str_replace(' ', '', $this->encode($data[$_POST['product_unit']]));
             }
             if (isset($_POST['in_stock']) && $_POST['in_stock'] != '') {
                 $product_data['in_stock'] = (double) $this->encode($data[$_POST['in_stock']]);
             }
             if (isset($_POST['promotion']) && $_POST['promotion'] != '') {
                 $product_data['promotion'] = $this->encode($data[$_POST['promotion']]);
             }
             if (isset($_POST['manufacturer']) && $_POST['manufacturer'] != '') {
                 $product_data['manufacturer'] = $this->encode($data[$_POST['manufacturer']]);
             }
             if (isset($_POST['country']) && $_POST['country'] != '') {
                 $product_data['country'] = $this->encode($data[$_POST['country']]);
             }
             if (isset($_POST['content']) && $_POST['content'] != '') {
                 $product_data['content'] = $this->encode($data[$_POST['content']]);
             }
             if (isset($_POST['photos']) && $_POST['photos'] != '') {
                 $product_data['photos'] = $this->encode($data[$_POST['photos']]);
             }
             if (isset($_POST['relative']) && $_POST['relative'] != '') {
                 $product_data['relative'] = $this->encode($data[$_POST['relative']]);
             }
             if (isset($_POST['tags']) && $_POST['tags'] != '') {
                 $product_data['tags'] = $this->encode($data[$_POST['tags']]);
             }
             if (isset($_POST['metatitle']) && $_POST['metatitle'] != '') {
                 $product_data['metatitle'] = $this->encode($data[$_POST['metatitle']]);
             } else {
                 $product_data['metatitle'] = '';
             }
             if (isset($_POST['metadescription']) && $_POST['metadescription'] != '') {
                 $product_data['metadescription'] = $this->encode($data[$_POST['metadescription']]);
             } else {
                 $product_data['metadescription'] = '';
             }
             if (isset($_POST['metakeywords']) && $_POST['metakeywords'] != '') {
                 $product_data['metakeywords'] = $this->encode($data[$_POST['metakeywords']]);
             } else {
                 $product_data['metakeywords'] = '';
             }
             $product_data['type'] = 'product';
             $query = $this->_db->getQuery(true);
             $query->select('*')->from('#__ksenmart_properties')->order('ordering');
             $this->_db->setQuery($query);
             $properties = $this->_db->loadObjectList();
             foreach ($properties as $property) {
                 if (isset($_POST['property_' . $property->id]) && $_POST['property_' . $property->id] != '') {
                     $product_data['property_' . $property->id] = $this->encode($data[$_POST['property_' . $property->id]]);
                 }
             }
             $query = $this->_db->getQuery(true);
             $query->select('id')->from('#__ksenmart_currencies')->where('`default`=1');
             $this->_db->setQuery($query);
             $def_price_type = $this->_db->loadResult();
             $query = $this->_db->getQuery(true);
             $query->select('id')->from('#__ksenmart_product_units');
             $this->_db->setQuery($query, 0, 1);
             $def_unit = $this->_db->loadResult();
             if (isset($product_data['parent_id']) && $product_data['parent_id'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('id')->from('#__ksenmart_products')->where($unic . '=' . $this->_db->quote($product_data['parent_id']))->where('parent_id=0');
                 $this->_db->setQuery($query);
                 $parent_id = $this->_db->loadResult();
                 if (empty($parent_id)) {
                     $product_data['parent_id'] = 0;
                 } else {
                     $product_data['type'] = 'child';
                     $product_data['parent_id'] = $parent_id;
                     $query = $this->_db->getQuery(true);
                     $query->update('#__ksenmart_products')->set('is_parent=1')->where('id=' . $parent_id);
                     $this->_db->setQuery($query);
                     $this->_db->query();
                 }
             } else {
                 $product_data['parent_id'] = 0;
             }
             if (isset($product_data['childs_group']) && $product_data['childs_group'] != '' && $product_data['parent_id'] != 0) {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_products_child_groups')->where('title like ' . $this->_db->quote($product_data['childs_group']))->where('product_id=' . $product_data['parent_id']);
                 $this->_db->setQuery($query);
                 $childs_group = $this->_db->loadObject();
                 if (count($childs_group) == 0) {
                     $qvalues = array($this->_db->quote($product_data['childs_group']), $product_data['parent_id']);
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_products_child_groups')->columns('title,product_id')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $childs_group_id = $this->_db->insertid();
                     $product_data['childs_group'] = $childs_group_id;
                 } else {
                     $product_data['childs_group'] = $childs_group->id;
                 }
             } else {
                 $product_data['childs_group'] = 0;
             }
             if (isset($product_data['price_type']) && $product_data['price_type'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_currencies')->where('title=' . $this->_db->quote($product_data['price_type']));
                 $this->_db->setQuery($query);
                 $price_type = $this->_db->loadObject();
                 if (count($price_type) == 0) {
                     $product_data['price_type'] = $def_price_type;
                 } else {
                     $product_data['price_type'] = $price_type->id;
                 }
             } else {
                 $product_data['price_type'] = $def_price_type;
             }
             if (isset($product_data['product_unit']) && $product_data['product_unit'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_product_units')->where('form1=' . $this->_db->quote($product_data['product_unit']));
                 $this->_db->setQuery($query);
                 $unit = $this->_db->loadObject();
                 if (count($unit) == 0) {
                     $qvalues = array($this->_db->quote($product_data['product_unit']), $this->_db->quote($product_data['product_unit']), $this->_db->quote($product_data['product_unit']));
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_product_units')->columns('form1,form2,form5')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $unit_id = $this->_db->insertid();
                     $product_data['product_unit'] = $unit_id;
                 } else {
                     $product_data['product_unit'] = $unit->id;
                 }
             } else {
                 $product_data['product_unit'] = $def_unit;
             }
             if (isset($product_data['promotion_price']) && $product_data['promotion_price'] != '') {
                 $product_data['promotion'] = 1;
                 $product_data['old_price'] = $product_data['price'];
                 $product_data['price'] = $product_data['promotion_price'];
             } else {
                 $product_data['promotion'] = 0;
                 $product_data['old_price'] = 0;
             }
             if (isset($product_data['country']) && $product_data['country'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_countries')->where('title=' . $this->_db->quote($product_data['country']));
                 $this->_db->setQuery($query);
                 $country = $this->_db->loadObject();
                 if (count($country) == 0) {
                     $alias = KSFunctions::GenAlias($product_data['country']);
                     $qvalues = array($this->_db->quote($product_data['country']), $this->_db->quote($alias), 1, $this->_db->quote($product_data['country']));
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_countries')->columns('title,alias,published,metatitle')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $country_id = $this->_db->insertid();
                     $product_data['country'] = $country_id;
                 } else {
                     $product_data['country'] = $country->id;
                 }
             } else {
                 $product_data['country'] = 0;
             }
             if (isset($product_data['manufacturer']) && $product_data['manufacturer'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_manufacturers')->where('title=' . $this->_db->quote($product_data['manufacturer']));
                 $this->_db->setQuery($query);
                 $manufacturer = $this->_db->loadObject();
                 if (count($manufacturer) == 0) {
                     $alias = KSFunctions::GenAlias($product_data['manufacturer']);
                     $qvalues = array($this->_db->quote($product_data['manufacturer']), $this->_db->quote($alias), $this->_db->quote($product_data['country']), 1, $this->_db->quote($product_data['manufacturer']));
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_manufacturers')->columns('title,alias,country,published,metatitle')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $manufacturer_id = $this->_db->insertid();
                     $product_data['manufacturer'] = $manufacturer_id;
                 } else {
                     $product_data['manufacturer'] = $manufacturer->id;
                 }
             } else {
                 $product_data['manufacturer'] = 0;
             }
             $categories = explode(';', $product_data['categories']);
             $prd_cats = array();
             foreach ($categories as $cats) {
                 $parent = 0;
                 $prd_cat = 0;
                 $cats = explode(':', $cats);
                 foreach ($cats as $cat) {
                     $cat = trim($cat);
                     if ($cat != '') {
                         $query = $this->_db->getQuery(true);
                         $query->select('*')->from('#__ksenmart_categories')->where('title=' . $this->_db->quote($cat))->where('parent_id=' . $parent);
                         $this->_db->setQuery($query);
                         $category = $this->_db->loadObject();
                         if (!$category) {
                             $alias = KSFunctions::GenAlias($cat);
                             $qvalues = array($this->_db->quote($cat), $this->_db->quote($alias), $parent, 1);
                             $query = $this->_db->getQuery(true);
                             $query->insert('#__ksenmart_categories')->columns('title,alias,parent_id,published')->values(implode(',', $qvalues));
                             $this->_db->setQuery($query);
                             $this->_db->query();
                             $prd_cat = $this->_db->insertid();
                             $parent = $prd_cat;
                         } else {
                             $prd_cat = $category->id;
                             $parent = $prd_cat;
                         }
                         $prd_cats[] = $prd_cat;
                     }
                 }
             }
             if ($product_data['parent_id'] != 0) {
                 $prd_cats = array();
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_products_categories')->where('product_id=' . $product_data['parent_id']);
                 $this->_db->setQuery($query);
                 $cats = $this->_db->loadObjectList();
                 foreach ($cats as $cat) {
                     $prd_cats[] = $cat->category_id;
                 }
             }
             if (!isset($product_data['price'])) {
                 $product_data['price'] = 0;
             }
             if (!isset($product_data['product_code'])) {
                 $product_data['product_code'] = '';
             }
             if (!isset($product_data['product_packaging'])) {
                 $product_data['product_packaging'] = 1;
             }
             if (!isset($product_data['in_stock'])) {
                 $product_data['in_stock'] = 1;
             }
             if (!isset($product_data['content'])) {
                 $product_data['content'] = '';
             }
             if ($unic != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_products')->where($unic . '=' . $this->_db->quote($product_data[$unic]))->where('parent_id=' . $product_data['parent_id']);
                 $this->_db->setQuery($query);
                 $product = $this->_db->loadObjectList();
             }
             if (count($product) == 0) {
                 $alias = KSFunctions::GenAlias($product_data['title']);
                 $values = array('parent_id' => $product_data['parent_id'], 'childs_group' => $product_data['childs_group'], 'title' => $this->_db->quote($product_data['title']), 'alias' => $this->_db->quote($alias), 'price' => $this->_db->quote($product_data['price']), 'old_price' => $this->_db->quote($product_data['old_price']), 'price_type' => $product_data['price_type'], 'in_stock' => $product_data['in_stock'], 'product_code' => $this->_db->quote($product_data['product_code']), 'product_packaging' => $product_data['product_packaging'], 'product_unit' => $product_data['product_unit'], 'content' => $this->_db->quote($product_data['content']), 'promotion' => $product_data['promotion'], 'manufacturer' => $product_data['manufacturer'], 'published' => 1, 'metatitle' => $this->_db->quote($product_data['metatitle']), 'metadescription' => $this->_db->quote($product_data['metadescription']), 'metakeywords' => $this->_db->quote($product_data['metakeywords']), 'date_added' => 'NOW()', 'type' => $this->_db->quote($product_data['type']));
                 $query = $this->_db->getQuery(true);
                 $query->update('#__ksenmart_products')->set('ordering=ordering+1');
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 $query = $this->_db->getQuery(true);
                 $query->insert('#__ksenmart_products')->columns(implode(',', array_keys($values)))->values(implode(',', $values));
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 $product_id = $this->_db->insertid();
                 $is_default = true;
                 foreach ($prd_cats as $prd_cat) {
                     $qvalues = array($product_id, $prd_cat, (int) $is_default);
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_products_categories')->columns('product_id,category_id,is_default')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $is_default = false;
                 }
                 $info['insert']++;
             } else {
                 $product_id = $product[0]->id;
                 $to_update = array();
                 $to_update[] = 'date_added=NOW()';
                 if (isset($product_data['title'])) {
                     $to_update[] = 'title=' . $this->_db->quote($product_data['title']);
                 }
                 if (isset($product_data['product_code'])) {
                     $to_update[] = 'product_code=' . $this->_db->quote($product_data['product_code']);
                 }
                 if (isset($product_data['in_stock'])) {
                     $to_update[] = 'in_stock=' . $this->_db->quote($product_data['in_stock']);
                 }
                 if (isset($product_data['content'])) {
                     $to_update[] = 'content=' . $this->_db->quote($product_data['content']);
                 }
                 if (isset($product_data['introcontent'])) {
                     $to_update[] = 'introcontent=' . $this->_db->quote($product_data['introcontent']);
                 }
                 if (isset($product_data['product_packaging'])) {
                     $to_update[] = 'product_packaging=' . $this->_db->quote($product_data['product_packaging']);
                 }
                 if ($product_data['metatitle'] != '') {
                     $to_update[] = 'metatitle=' . $this->_db->quote($product_data['metatitle']);
                 }
                 if ($product_data['metadescription'] != '') {
                     $to_update[] = 'metadescription=' . $this->_db->quote($product_data['metadescription']);
                 }
                 if ($product_data['metakeywords'] != '') {
                     $to_update[] = 'metakeywords=' . $this->_db->quote($product_data['metakeywords']);
                 }
                 if (isset($product_data['price'])) {
                     $to_update[] = 'price=' . $this->_db->quote($product_data['price']);
                 }
                 if (isset($product_data['manufacturer'])) {
                     $to_update[] = 'manufacturer=' . $this->_db->quote($product_data['manufacturer']);
                 }
                 if (isset($product_data['price_type'])) {
                     $to_update[] = 'price_type=' . $this->_db->quote($product_data['price_type']);
                 }
                 if (isset($product_data['product_unit'])) {
                     $to_update[] = 'product_unit=' . $this->_db->quote($product_data['product_unit']);
                 }
                 if (isset($product_data['old_price'])) {
                     $to_update[] = 'old_price=' . $this->_db->quote($product_data['old_price']);
                 }
                 if (isset($product_data['promotion'])) {
                     $to_update[] = 'promotion=' . $this->_db->quote($product_data['promotion']);
                 }
                 foreach ($prd_cats as $prd_cat) {
                     $query = $this->_db->getQuery(true);
                     $query->select('*')->from('#__ksenmart_products_categories')->where('product_id=' . $product_id)->where('category_id=' . $prd_cat);
                     $this->_db->setQuery($query);
                     $db_cat = $this->_db->loadObject();
                     if (count($db_cat) == 0) {
                         $qvalues = array($product_id, $prd_cat);
                         $query = $this->_db->getQuery(true);
                         $query->insert('#__ksenmart_products_categories')->columns('product_id,category_id')->values(implode(',', $qvalues));
                         $this->_db->setQuery($query);
                         $this->_db->query();
                     }
                 }
                 $query = $this->_db->getQuery(true);
                 $query->update('#__ksenmart_products')->set($to_update)->where('id=' . $product_id);
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 if (isset($product_data['photos']) && $product_data['photos'] != '') {
                     $query = $this->_db->getQuery(true);
                     $query->select('*')->from('#__ksenmart_files')->where(array("media_type='image'", "owner_type='product'", "owner_id=" . $product_id))->order('ordering');
                     $this->_db->setQuery($query);
                     $images = $this->_db->loadObjectList('id');
                     $i = count($images);
                     foreach ($images as $image) {
                         $this->delPhoto($image->filename, $image->folder);
                     }
                 }
                 $info['update']++;
             }
             if (isset($product_data['relative']) && $product_data['relative'] != '') {
                 $relatives[$product_id] = $product_data['relative'];
             }
             if (isset($product_data['tags']) && $product_data['tags'] != '') {
                 $product_data['tags'] = explode(',', $product_data['tags']);
                 foreach ($product_data['tags'] as $key => $value) {
                     $value = trim($value);
                     $query = $this->_db->getQuery(true);
                     $query->select('id')->from('#__tags')->where('title=' . $this->_db->quote($value));
                     $this->_db->setQuery($query);
                     $tag_id = $this->_db->loadResult();
                     if (!empty($tag_id)) {
                         $product_data['tags'][$key] = $tag_id;
                     } else {
                         $product_data['tags'][$key] = '#new#' . $value;
                     }
                 }
                 $tableProducts = $this->getTable('Products');
                 JObserverMapper::attachAllObservers($tableProducts);
                 JObserverMapper::addObserverClassToClass('JTableObserverTags', 'KsenmartTableProducts', array('typeAlias' => 'com_ksenmart.product'));
                 $tableProducts->load($product_id);
                 $tagsObserver = $tableProducts->getObserverOfClass('JTableObserverTags');
                 $result = $tagsObserver->setNewTags($product_data['tags'], true);
             }
             if (isset($product_data['photos']) && $product_data['photos'] != '') {
                 $product_data['photos'] = explode(',', $product_data['photos']);
                 $i = 1;
                 foreach ($product_data['photos'] as $photo) {
                     $photo = trim($photo);
                     if (!empty($photo)) {
                         $file = basename($photo);
                         $nameParts = explode('.', $file);
                         $file = microtime(true) . '.' . $nameParts[count($nameParts) - 1];
                         $copied = false;
                         if (strpos($photo, 'http://') !== false) {
                             if ($photo_content = file_get_contents($photo)) {
                                 if (file_put_contents(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'images' . DS . 'products' . DS . 'original' . DS . $file, $photo_content)) {
                                     $copied = true;
                                 }
                             }
                         } else {
                             if (file_exists(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'import' . DS . $photo)) {
                                 if (copy(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'import' . DS . $photo, JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'images' . DS . 'products' . DS . 'original' . DS . $file)) {
                                     $copied = true;
                                 }
                             }
                         }
                         if ($copied) {
                             $mime = mime_content_type(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'images' . DS . 'products' . DS . 'original' . DS . $file);
                             $qvalues = array($product_id, $this->_db->quote('image'), $this->_db->quote('product'), $this->_db->quote('products'), $this->_db->quote($file), $this->_db->quote($mime), $this->_db->quote(''), $i);
                             $query = $this->_db->getQuery(true);
                             $query->insert('#__ksenmart_files')->columns('owner_id,media_type,owner_type,folder,filename,mime_type,title,ordering')->values(implode(',', $qvalues));
                             $this->_db->setQuery($query);
                             $this->_db->query();
                             $i++;
                         }
                     }
                 }
             }
             foreach ($properties as $property) {
                 if (isset($product_data['property_' . $property->id]) && $product_data['property_' . $property->id] != '') {
                     switch ($property->type) {
                         case 'text':
                             if ($product_data['property_' . $property->id] != '') {
                                 $query = $this->_db->getQuery(true);
                                 $query->select('*')->from('#__ksenmart_property_values')->where('property_id=' . $property->id)->where('title=' . $this->_db->quote($product_data['property_' . $property->id]));
                                 $this->_db->setQuery($query);
                                 $prop_value = $this->_db->loadObject();
                                 if (count($prop_value) == 0) {
                                     $alias = KSFunctions::GenAlias($product_data['property_' . $property->id]);
                                     $qvalues = array($property->id, $this->_db->quote($product_data['property_' . $property->id]), $this->_db->quote($alias));
                                     $query = $this->_db->getQuery(true);
                                     $query->insert('#__ksenmart_property_values')->columns('property_id,title,alias')->values(implode(',', $qvalues));
                                     $this->_db->setQuery($query);
                                     $this->_db->query();
                                     $prop_value_id = $this->_db->insertid();
                                 } else {
                                     $prop_value_id = $prop_value->id;
                                 }
                                 $query = $this->_db->getQuery(true);
                                 $query->select('*')->from('#__ksenmart_product_properties_values')->where('product_id=' . $product_id)->where('property_id=' . $property->id)->where('value_id=' . $prop_value_id);
                                 $this->_db->setQuery($query);
                                 $prod_prop_value = $this->_db->loadObject();
                                 if (count($prod_prop_value) == 0) {
                                     $qvalues = array($product_id, $property->id, $prop_value_id, $this->_db->quote($product_data['property_' . $property->id]));
                                     $query = $this->_db->getQuery(true);
                                     $query->insert('#__ksenmart_product_properties_values')->columns('product_id,property_id,value_id,text')->values(implode(',', $qvalues));
                                     $this->_db->setQuery($query);
                                     $this->_db->query();
                                 }
                             }
                             break;
                         default:
                             $prop_vals = explode(';', $product_data['property_' . $property->id]);
                             $prop_values = '';
                             foreach ($prop_vals as $prop_val) {
                                 if ($prop_val != '') {
                                     $val_parts = explode('=', $prop_val);
                                     if (count($val_parts) == 2) {
                                         $prop_val = $val_parts[0];
                                         $val_price = $val_parts[1];
                                     } else {
                                         $val_price = '';
                                     }
                                     $query = $this->_db->getQuery(true);
                                     $query->select('*')->from('#__ksenmart_property_values')->where('property_id=' . $property->id)->where('title=' . $this->_db->quote($prop_val));
                                     $this->_db->setQuery($query);
                                     $prop_value = $this->_db->loadObject();
                                     if (count($prop_value) == 0) {
                                         $alias = KSFunctions::GenAlias($prop_val);
                                         $qvalues = array($property->id, $this->_db->quote($prop_val), $this->_db->quote($alias));
                                         $query = $this->_db->getQuery(true);
                                         $query->insert('#__ksenmart_property_values')->columns('property_id,title,alias')->values(implode(',', $qvalues));
                                         $this->_db->setQuery($query);
                                         $this->_db->query();
                                         $prop_value_id = $this->_db->insertid();
                                     } else {
                                         $prop_value_id = $prop_value->id;
                                     }
                                     $query = $this->_db->getQuery(true);
                                     $query->select('*')->from('#__ksenmart_product_properties_values')->where('product_id=' . $product_id)->where('property_id=' . $property->id)->where('value_id=' . $prop_value_id);
                                     $this->_db->setQuery($query);
                                     $prod_prop_value = $this->_db->loadObject();
                                     if (count($prod_prop_value) == 0) {
                                         $qvalues = array($product_id, $property->id, $prop_value_id, $this->_db->quote($val_price));
                                         $query = $this->_db->getQuery(true);
                                         $query->insert('#__ksenmart_product_properties_values')->columns('product_id,property_id,value_id,price')->values(implode(',', $qvalues));
                                         $this->_db->setQuery($query);
                                         $this->_db->query();
                                     } else {
                                         $query = $this->_db->getQuery(true);
                                         $query->update('#__ksenmart_product_properties_values')->set('price=' . $this->_db->quote($val_price))->where('id=' . $prod_prop_value->id);
                                         $this->_db->setQuery($query);
                                         $this->_db->query();
                                     }
                                 }
                             }
                     }
                     foreach ($prd_cats as $prd_cat) {
                         $query = $this->_db->getQuery(true);
                         $query->select('id')->from('#__ksenmart_product_categories_properties')->where('category_id=' . $prd_cat)->where('property_id=' . $property->id);
                         $this->_db->setQuery($query);
                         $res = $this->_db->loadResult();
                         if (empty($res)) {
                             $qvalues = array($prd_cat, $property->id);
                             $query = $this->_db->getQuery(true);
                             $query->insert('#__ksenmart_product_categories_properties')->columns('category_id,property_id')->values(implode(',', $qvalues));
                             $this->_db->setQuery($query);
                             $this->_db->query();
                         }
                     }
                 }
             }
         }
     }
     foreach ($relatives as $product_id => $relative) {
         $relative = explode(';', $relative);
         foreach ($relative as $relative_title) {
             if (!empty($relative_title)) {
                 $query = $this->_db->getQuery(true);
                 $query->select('id')->from('#__ksenmart_products')->where('title like ' . $this->_db->quote($relative_title));
                 $this->_db->setQuery($query);
                 $relative_id = $this->_db->loadResult();
                 if (!empty($relative_id)) {
                     $query = $this->_db->getQuery(true);
                     $query->select('*')->from('#__ksenmart_products_relations')->where('product_id=' . $product_id)->where('relative_id=' . $relative_id)->where('relation_type=' . $this->_db->quote('relation'));
                     $this->_db->setQuery($query);
                     $db_rel = $this->_db->loadObject();
                     if (count($db_rel) == 0) {
                         $qvalues = array($product_id, $relative_id, $this->_db->quote('relation'));
                         $query = $this->_db->getQuery(true);
                         $query->insert('#__ksenmart_products_relations')->columns('product_id,relative_id,relation_type')->values(implode(',', $qvalues));
                         $this->_db->setQuery($query);
                         $this->_db->query();
                     }
                 }
             }
         }
     }
     fclose($f);
     $dir = scandir(JPATH_COMPONENT . DS . 'tmp' . DS);
     foreach ($dir as $d) {
         if ($d != '.' && $d != '..') {
             unlink(JPATH_COMPONENT . DS . 'tmp' . DS . $d);
         }
     }
     $this->onExecuteAfter('getImportInfo', array(&$info));
     return $info;
 }
示例#8
0
文件: mapper.php 项目: adjaika/J3Base
 /**
  * Helper wrapper method for attachAllObservers
  *
  * @param   JObservableInterface  $observableObject  The observable subject object.
  *
  * @return void
  *
  * @see     JObserverMapper::attachAllObservers
  * @since   3.4
  */
 public function attachAllObservers(JObservableInterface $observableObject)
 {
     return JObserverMapper::attachAllObservers($observableObject);
 }
示例#9
0
 /**
  * @param string $table
  * @param string $key
  * @param JDatabase $db
  */
 function __construct($table, $key, &$db)
 {
     $this->_tbl = $table;
     $this->_db =& $db;
     $this->_pkey = $key;
     /*$fields=$db->getTableColumns($this->_tbl);
     		foreach($fields as $field=>$type)
     		{
     			$this->$field=null;
     		}*/
     $this->_pkeyForm = 'cid';
     if (JVM_VERSION < 3) {
         $this->_tbl_key = $key;
         $this->_tbl_keys = array($key);
     } else {
         // Set the key to be an array.
         if (is_string($key)) {
             $key = array($key);
         } elseif (is_object($key)) {
             $key = (array) $key;
         }
         $this->_tbl_keys = $key;
         $this->_tbl_key = $key[0];
         if (count($key) == 1) {
             $this->_autoincrement = true;
         } else {
             $this->_autoincrement = false;
         }
     }
     // If we are tracking assets, make sure an access field exists and initially set the default.
     if (property_exists($this, 'asset_id')) {
         $this->_trackAssets = true;
     }
     // If the access property exists, set the default.
     if (property_exists($this, 'access')) {
         $this->access = (int) JFactory::getConfig()->get('access');
     }
     if (JVM_VERSION > 2) {
         // Implement JObservableInterface:
         // Create observer updater and attaches all observers interested by $this class:
         $this->_observers = new JObserverUpdater($this);
         JObserverMapper::attachAllObservers($this);
     }
 }
示例#10
0
 /**
  * Object constructor to set table and key fields.  In most cases this will
  * be overridden by child classes to explicitly set the table and key fields
  * for a particular database table.
  *
  * @param   string           $table  Name of the table to model.
  * @param   string           $key    Name of the primary key field in the table.
  * @param   JDatabaseDriver  $db     JDatabaseDriver object.
  *
  * @since   11.1
  */
 public function __construct($table, $key, $db)
 {
     // Set internal variables.
     $this->_tbl = $table;
     $this->_tbl_key = $key;
     $this->_db = $db;
     // Initialise the table properties.
     $fields = $this->getFields();
     if ($fields) {
         foreach ($fields as $name => $v) {
             // Add the field if it is not already present.
             if (!property_exists($this, $name)) {
                 $this->{$name} = null;
             }
         }
     }
     // If we are tracking assets, make sure an access field exists and initially set the default.
     if (property_exists($this, 'asset_id')) {
         $this->_trackAssets = true;
     }
     // If the access property exists, set the default.
     if (property_exists($this, 'access')) {
         $this->access = (int) JFactory::getConfig()->get('access');
     }
     // Implement JObservableInterface:
     // Create observer updater and attaches all observers interested by $this class:
     $this->_observers = new JObserverUpdater($this);
     JObserverMapper::attachAllObservers($this);
 }