/** * Publica/despublica registros que no estén bloqueados (published = 2) * * @access public * @param array An array of id numbers * @param integer 0 if unpublishing, 1 if publishing * @param integer The id of the user performnig the operation */ public function publish($cid = null, $publish = 1, $user_id = 0) { $k = $this->_tbl_key; if (count($cid) < 1) { if ($this->{$k}) { $cid = array($this->{$k}); } else { $this->setError("No items selected."); return false; } } $publish = (int) $publish; // Despublicar el proveedor $result = parent::publish($cid, $publish, $user_id); // Si el nuevo estado es inactivo, inactivar los productos asociados if ($result && $publish < 1) { $modelProducts =& JModel::getInstance('producttype', 'CatalogoPlanesModel'); $productTypes = $modelProducts->getActiveProductTypesInfo(); if (is_array($productTypes)) { $cids = $k . '=' . implode(' OR ' . $k . '=', $cid); foreach ($productTypes as $type) { $query = 'UPDATE #__cp_' . $type->product_type_code . '_info SET `published` = 0 WHERE (' . $cids . ')'; $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError(JText::sprintf('CP.SUPPLIER_ERROR_UNPUBLISH_RELATED_PRODUCTS', '')); return false; } } } } return $result; }