public function actionGetForTopic($id, $page = 1) { if ($id == 'null') { $item = Topic::findByTitle('Все объявления'); } else { $item = Topic::findByPK($id); } $lft = $item->__lft; $rgt = $item->__rgt; $offset = ($page - 1) * self::PAGE_SIZE; $limit = self::PAGE_SIZE; $items_count = Story::findALLByQuery('SELECT * FROM news_stories WHERE __topic_id IN (SELECT __id FROM news_topics WHERE __lft >=' . $lft . ' AND __rgt <= ' . $rgt . ' ORDER BY __lft) AND published IS NOT NULL')->count(); $items = Story::findAllByQuery('SELECT * FROM news_stories WHERE __topic_id IN (SELECT __id FROM news_topics WHERE __lft >=' . $lft . ' AND __rgt <= ' . $rgt . ' ORDER BY __lft) AND published IS NOT NULL ORDER BY published DESC LIMIT ' . $offset . ',' . $limit); $this->data->items = new Collection(); foreach ($items as $subkey => $subvalue) { $this->data->items[$subkey] = new Collection(); foreach ($subvalue as $subinkey => $subinvalue) { $this->data->items[$subkey][$subinkey] = $subvalue->{$subinkey}; } } $parents = $item->findAllParents($id); $this->data->parents = new Collection(); $this->data->parents_id = new Collection(); foreach ($parents as $parent) { $this->data->parents[] = $parent->title; $this->data->parents_id[] = $parent->__id; } $this->data->parents[] = $item->title; $this->data->items_count = $items_count; $this->data->pagesize = self::PAGE_SIZE; }
public function actionTopicMoveAfter($id, $to) { try { $item = Topic::findByPK($id); if (empty($item)) { throw new Exception('Source element does not exist'); } $destination = Topic::findByPK($to); if (empty($destination)) { throw new Exception('Destination element does not exist'); } $item->insertAfter($destination); $this->data->result = true; } catch (Exception $e) { $this->data->result = false; $this->data->error = $e->getMessage(); } }