| 61 | | |
| 62 | | protected function buildQuery() |
| 63 | | { |
| 64 | | $tableMethod = $this->configuration->getTableMethod(); |
| 65 | | if (is_null($this->filters)) |
| 66 | | { |
| 67 | | $this->filters = $this->configuration->getFilterForm($this->getFilters()); |
| 68 | | } |
| 69 | | |
| 70 | | $this->filters->setTableMethod($tableMethod); |
| 71 | | |
| 72 | | $query = $this->filters->buildQuery($this->getFilters()); |
| 73 | | |
| 74 | | $this->addSortQuery($query); |
| 75 | | |
| 76 | | if(!$this->getUser()->hasCredential('admin')) |
| 77 | | { |
| 78 | | Doctrine::getTable('aBlogPost')->filterByEditable($query, $this->getUser()->getGuardUser()->getId()); |
| 79 | | } |
| 80 | | |
| 81 | | $event = $this->dispatcher->filter(new sfEvent($this, 'admin.build_query'), $query); |
| 82 | | $query = $event->getReturnValue(); |
| 83 | | |
| 84 | | return $query; |
| 85 | | } |
| 86 | | |
| 87 | | protected function executeBatchPublish(sfWebRequest $request) |
| 88 | | { |
| 89 | | $ids = $request->getParameter('ids'); |
| 90 | | |
| 91 | | $items = Doctrine_Query::create() |
| 92 | | ->from('aBlogPost') |
| 93 | | ->whereIn('id', $ids) |
| 94 | | ->execute(); |
| 95 | | $count = count($items); |
| 96 | | $error = false; |
| 97 | | try |
| 98 | | { |
| 99 | | foreach($items as $item) |
| 100 | | { |
| 101 | | $item->publish(); |
| 102 | | } |
| 103 | | $items->save(); |
| 104 | | } catch (Exception $e) |
| 105 | | { |
| 106 | | $error = true; |
| 107 | | } |
| 108 | | |
| 109 | | if (($count == count($ids)) && (!$error)) |
| 110 | | { |
| 111 | | $this->getUser()->setFlash('notice', 'The selected items have been published successfully.'); |
| 112 | | } |
| 113 | | else |
| 114 | | { |
| 115 | | $this->getUser()->setFlash('error', 'An error occurred while publishing the selected items.'); |
| 116 | | } |
| 117 | | |
| 118 | | $this->redirect('@a_blog_admin'); |
| 119 | | } |
| 120 | | |
| 121 | | protected function executeBatchUnpublish(sfWebRequest $request) |
| 122 | | { |
| 123 | | $ids = $request->getParameter('ids'); |
| 124 | | |
| 125 | | $items = Doctrine_Query::create() |
| 126 | | ->from('aBlogPost') |
| 127 | | ->whereIn('id', $ids) |
| 128 | | ->execute(); |
| 129 | | $count = count($items); |
| 130 | | $error = false; |
| 131 | | try |
| 132 | | { |
| 133 | | foreach($items as $item) |
| 134 | | { |
| 135 | | $item->unpublish(); |
| 136 | | } |
| 137 | | $items->save(); |
| 138 | | } catch (Exception $e) |
| 139 | | { |
| 140 | | $error = true; |
| 141 | | } |
| 142 | | |
| 143 | | if (($count == count($ids)) && (!$error)) |
| 144 | | { |
| 145 | | $this->getUser()->setFlash('notice', 'The selected items have been unpublished successfully.'); |
| 146 | | } |
| 147 | | else |
| 148 | | { |
| 149 | | $this->getUser()->setFlash('error', 'An error occurred while unpublishing the selected items.'); |
| 150 | | } |
| 151 | | |
| 152 | | $this->redirect('@a_blog_admin'); |
| 153 | | } |
| 154 | | |