Ejemplo n.º 1
0
 public function getItem($pk = null)
 {
     if ($item = parent::getItem($pk)) {
         if ((!isset($item->categories) || !is_array($item->categories)) && isset($item->id)) {
             $this->_db->setQuery('SELECT category_id FROM #__djc2_items_categories WHERE item_id=\'' . $item->id . '\'');
             $item->categories = $this->_db->loadColumn();
         }
         return $item;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 public function delete(&$cid)
 {
     if (count($cid)) {
         $cids = implode(',', $cid);
         $this->_db->setQuery("SELECT COUNT(*) FROM #__djc2_items_extra_fields WHERE group_id IN ( " . $cids . " )");
         if ($this->_db->loadResult() > 0) {
             $this->setError(JText::_('COM_DJCATALOG2_DELETE_FIELDGROUPS_HAVE_ITEMS'));
             return false;
         }
     }
     if (parent::delete($cid)) {
         $this->_db->setQuery("update #__djc2_items set group_id = 0 WHERE group_id IN ( " . $cids . " )");
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 public function getItem($pk = null)
 {
     if ($item = parent::getItem($pk)) {
         if ((!isset($item->categories) || !is_array($item->categories)) && isset($item->id)) {
             $this->_db->setQuery('SELECT category_id FROM #__djc2_items_categories WHERE item_id=\'' . $item->id . '\'');
             $item->categories = $this->_db->loadColumn();
         }
         if (!isset($item->location) || !is_array($item->location)) {
             $location = array('address' => null, 'city' => null, 'postcode' => null, 'country' => null, 'state' => null, 'latitude' => null, 'longitude' => null, 'phone' => null, 'fax' => null, 'mobile' => null, 'website' => null, 'email' => null);
             foreach ($location as $k => $v) {
                 if (isset($item->{$k})) {
                     $location[$k] = $item->{$k};
                 }
             }
             $item->location = $location;
         }
         if (!is_array($item->group_id)) {
             $query = $this->_db->getQuery(true);
             /*$query->select ('distinct f.group_id');
             		$query->from('#__djc2_items_extra_fields AS f');
             		$query->join('LEFT','#__djc2_items_extra_fields_values_text AS vt ON f.id=vt.field_id AND vt.item_id='.(int)$item->id);
             		$query->join('LEFT','#__djc2_items_extra_fields_values_int AS vi ON f.id=vi.field_id AND vi.item_id='.(int)$item->id);
             		$query->join('LEFT','#__djc2_items_extra_fields_values_date AS vd ON f.id=vd.field_id AND vd.item_id='.(int)$item->id);
             		$query->where('vt.value IS NOT NULL OR vi.value IS NOT NULL OR vd.value IS NOT NULL');
             		*/
             $query->select('distinct group_id');
             $query->from('#__djc2_items_groups');
             $query->where('item_id=' . (int) $item->id);
             $this->_db->setQuery($query);
             $item->group_id = $this->_db->loadColumn();
         }
         return $item;
     } else {
         return false;
     }
 }
Ejemplo n.º 4
0
 public function save($data)
 {
     $return = parent::save($data);
     if ($return) {
         if (isset($data['is_default']) && (int) $data['is_default'] == 1) {
             $id = (int) $this->getState($this->getName() . '.id');
             if ($id > 0) {
                 $db = JFactory::getDbo();
                 $db->setQuery('update #__djc2_customer_groups set is_default=0 where id !=' . $id);
                 if (!$db->query()) {
                     $this->setError($db->getErrorMsg());
                     return false;
                 }
             }
         }
     }
     return $return;
 }
Ejemplo n.º 5
0
 public function delete(&$cid)
 {
     return parent::delete($cid);
 }
Ejemplo n.º 6
0
 public function delete(&$cid)
 {
     if (count($cid)) {
         $cids = implode(',', $cid);
         $this->_db->setQuery("SELECT COUNT(*) FROM #__djc2_items WHERE producer_id IN ( " . $cids . " )");
         if ($this->_db->loadResult() > 0) {
             $this->setError(JText::_('COM_DJCATALOG2_DELETE_PRODUCERS_HAVE_ITEMS'));
             return false;
         }
     }
     return parent::delete($cid);
 }
Ejemplo n.º 7
0
 public function delete(&$cid)
 {
     if (count($cid)) {
         $cids = implode(',', $cid);
         try {
             $db = JFactory::getDbo();
             $db->setQuery('DELETE FROM #__djc2_items_extra_fields_values_text WHERE field_id IN (' . $cids . ') ');
             $db->query();
         } catch (Exception $e) {
             $this->setError($e->getMessage());
             return false;
         }
         try {
             $db = JFactory::getDbo();
             $db->setQuery('DELETE FROM #__djc2_items_extra_fields_values_int WHERE field_id IN (' . $cids . ') ');
             $db->query();
         } catch (Exception $e) {
             $this->setError($e->getMessage());
             return false;
         }
         try {
             $db = JFactory::getDbo();
             $db->setQuery('DELETE FROM #__djc2_items_extra_fields_values_date WHERE field_id IN (' . $cids . ') ');
             $db->query();
         } catch (Exception $e) {
             $this->setError($e->getMessage());
             return false;
         }
     }
     return parent::delete($cid);
 }
Ejemplo n.º 8
0
 public function validate($form, $data, $group = null)
 {
     /*$data = parent::validate($form, $data, $group);
     		if ($data == false) {
     			return false;
     		}*/
     $params = JComponentHelper::getParams('com_djcatalog2');
     $user = JFactory::getUser();
     $recordId = (int) isset($data['id']) ? $data['id'] : 0;
     $ownerId = (int) $user->id;
     $default_state = (int) $params->get('fed_default_state', '0');
     $canEdit = $user->authorise('core.edit.state', $this->option);
     $canEditOwn = $user->authorise('core.edit.state.own', $this->option);
     $record = null;
     if ($recordId) {
         $record = $this->getItem($recordId);
     }
     if ($record) {
         if (!($canEdit || $canEditOwn && $record->created_by == $ownerId)) {
             $data['published'] = $record->published;
         } else {
             if (empty($data['published'])) {
                 $data['published'] = $default_state;
             }
         }
         if (!empty($record->created_by)) {
             $data['created_by'] = $record->created_by;
         } else {
             $data['created_by'] = $user->id;
         }
     } else {
         if (!$canEditOwn && !$canEdit || empty($data['published'])) {
             $data['published'] = $default_state;
         }
         $data['created_by'] = $user->id;
     }
     $form->setValue('created_by', null, $data['created_by']);
     return parent::validate($form, $data, $group);
     //return $data;
 }
Ejemplo n.º 9
0
 public function delete(&$cid = array())
 {
     if (count($cid)) {
         $categories = Djc2Categories::getInstance();
         $categoryList = $cid;
         foreach ($cid as $catid) {
             $sublist = array($catid);
             if ($parent = $categories->get($catid)) {
                 $parent->makeChildrenList($sublist);
             }
             $categoryList = array_merge($categoryList, $sublist);
         }
         $categoryList = array_unique($categoryList);
         $cids = implode(',', $categoryList);
         $this->_db->setQuery("SELECT COUNT(*) FROM #__djc2_items WHERE cat_id IN ( " . $cids . " )");
         if ($this->_db->loadResult() > 0) {
             $this->setError(JText::_('COM_DJCATALOG2_DELETE_CATEGORIES_HAVE_ITEMS'));
             return false;
         }
         $cid = $categoryList;
         if (parent::delete($cid)) {
             // since products may still be assigned to additional categories, we need to break those relations
             $this->_db->setQuery('delete from #__djc2_items_categories where category_id in (' . implode(',', $cid) . ')');
             if (!$this->_db->query()) {
                 $this->setError($this->_db->getErrorMsg());
                 return false;
             }
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 10
0
 public function save($data)
 {
     $new_status = $data['status'];
     $old_status = false;
     if ((int) $data['id'] > 0) {
         $table = $this->getTable();
         $table->load((int) $data['id']);
         $old_status = $table->status;
     }
     if (!parent::save($data)) {
         return false;
     }
     $id = $this->getState($this->getName() . '.id');
     $table = $this->getTable();
     if ($table->load((int) $id) && $table->status != $old_status && !empty($table->email)) {
         $data = $table->getProperties();
         foreach ($data['items'] as $k => $v) {
             $data['items'][$k] = JArrayHelper::fromObject($v);
         }
         return $this->_sendEmail($data);
     }
     return true;
 }
Ejemplo n.º 11
0
 public function save($data)
 {
     return parent::save($data);
 }
Ejemplo n.º 12
0
 public function save($data)
 {
     if (!parent::save($data)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 13
0
 public function delete(&$cid)
 {
     if (count($cid)) {
         $cids = implode(',', $cid);
         $this->_db->setQuery("SELECT COUNT(*) FROM #__djc2_items WHERE tax_rate_id IN ( " . $cids . " )");
         if ($this->_db->loadResult() > 0) {
             $this->setError(JText::_('COM_DJCATALOG2_DELETE_TAXRATES_HAVE_ITEMS'));
             return false;
         }
     }
     /*
     		if (parent::delete($cid)) {
     			
     			$cids = implode(',', $cid);
     			
     			$this->_db->setQuery("update #__djc2_users set user_group_id = 0 WHERE user_group_id IN ( ".$cids." )");
     			if (!$this->_db->query()) {
     				$this->setError($this->_db->getErrorMsg());
     				return false;
     			}
     			return true;
     		}
     		return false;*/
     //return parent::delete($cid);
     if (parent::delete($cid)) {
         $cids = implode(',', $cid);
         $this->_db->setQuery('delete from #__djc2_tax_rules where tax_rate_id in (' . $cids . ')');
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         return true;
     }
     return false;
 }