public function saveSorting() { if (count($_POST['sorting'])) { foreach ($_POST['sorting'] as $topic_id => $sorting_value) { $oTopic = new ilShopTopic($topic_id); $oTopic->setCustomSorting((int) $sorting_value); $oTopic->saveCustomSorting(); } } ilUtil::sendInfo($this->lng->txt('saved_successfully')); return $this->showTopicsSortingTable(); }
public function read() { global $ilUser; // $oSettings = ilPaymentSettings::_getInstance(); $this->topics = array(); if (!in_array($this->getSortingType(), array(self::TOPICS_SORT_BY_TITLE, self::TOPICS_SORT_BY_CREATEDATE, self::TOPICS_SORT_MANUALLY))) { $this->setSortingType(self::DEFAULT_SORTING_TYPE); } if (!in_array(strtoupper($this->getSortingDirection()), array('ASC', 'DESC'))) { $this->setSortingDirection(self::DEFAULT_SORTING_DIRECTION); } if (!$this->isCustomSortingEnabled()) { $data_types = array(); $data_values = array(); $query = 'SELECT * FROM payment_topics WHERE 1 = 1 '; if ((int) $this->getIdFilter() > 0) { $query .= ' AND pt_topic_pk = %s'; array_push($data_types, 'integer'); array_push($data_values, $this->getIdFilter()); } switch ($this->getSortingType()) { case 3: $query .= ' ORDER BY pt_topic_sort '; break; case 2: $query .= ' ORDER BY pt_topic_created '; break; case 1: default: $query .= ' ORDER BY pt_topic_title '; break; } $query .= ' ' . strtoupper($this->getSortingDirection()) . ' '; $query .= " , pt_topic_title "; $query .= ' ' . strtoupper($this->getSortingDirection()) . ' '; } else { $data_types = array(); $data_values = array(); $query = 'SELECT * FROM payment_topics '; switch ($this->getSortingType()) { case 3: $query .= ' LEFT JOIN payment_topic_usr_sort ON ptus_pt_topic_fk = pt_topic_pk AND ptus_usr_id = %s'; array_push($data_types, 'integer'); array_push($data_values, $ilUser->getId()); break; } $query .= ' WHERE 1 = 1 '; if ((int) $this->id_filter > 0) { $query .= ' AND pt_topic_pk = %s'; array_push($data_types, 'integer'); array_push($data_values, $this->getIdFilter()); } switch ($this->getSortingType()) { case 3: $query .= ' ORDER BY ptus_sorting '; break; case 2: $query .= ' ORDER BY pt_topic_created '; break; case 1: default: $query .= ' ORDER BY pt_topic_title '; break; } $query .= ' ' . strtoupper($this->getSortingDirection()) . ' '; $query .= " , pt_topic_sort "; $query .= ' ' . strtoupper($this->getSortingDirection()) . ' '; } if (count($data_types) > 0 && count($data_values > 0)) { $res = $this->db->queryf($query, $data_types, $data_values); } else { $res = $this->db->query($query); } $counter = 0; while ($row = $this->db->fetchObject($res)) { $oTopic = new ilShopTopic(); $oTopic->setId($row->pt_topic_pk); $oTopic->setTitle($row->pt_topic_title); $oTopic->setSorting($row->pt_topic_sort); $oTopic->setCustomSorting((int) $row->ptus_sorting); $oTopic->setCreateDate($row->pt_topic_created); $oTopic->setChangeDate($row->pt_topic_changed); $this->topics[$row->pt_topic_pk] = $oTopic; ++$counter; } return $this; }