CMS  Version 3.9
section_content_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
44 {
50 
57 
64 
71 }
72 
74 {
75  function getDefaultPage($section) { return $section->default_page; }
76 
78  {
79  try
80  {
81  return Query::create(SectionContent, "WHERE section_id=:section_id AND identifier=:identifier")
82  ->bind(":section_id", $section->section_id, ":identifier", $identifier)
83  ->executeSingle();
84  }
85  catch(DataNotFoundException $e)
86  {
87  return null;
88  }
89  }
90 
92  {
93  try
94  {
95  ComponentManager::fireEvent("ResolveIdentifier", $identifier, true);
96  }
97  catch(FakoliEventNotConsumed $e)
98  {
99  throw new FakoliException("The resource '$identifier' is disabled");
100  }
101 
102  }
103 
105  {
106  return new SectionContentAdminView($section);
107  }
108 }
109 
111 {
112  protected $section;
113 
114  abstract function handlePOST();
115  abstract function drawView();
116 
118  {
119  $this->section = $section;
120  }
121 }
122 
124 {
126  {
127  parent::__construct($section);
128  }
129 
130  function handlePOST()
131  {
132  $doomed = new SectionContent();
133  checkNumeric($_POST["content"]);
134 
135  if (isset($_POST["content"]))
136  {
137  foreach($_POST["content"] as $identifier => $id)
138  {
139  $doomed->delete("WHERE section_content_id=$id");
140  }
141  }
142 
143  if (isset($_POST["available"]))
144  {
145  foreach($_POST["available"] as $identifier => $id)
146  {
147  $content = new SectionContent();
148  $content->section_id = $this->section->section_id;
149  $content->identifier = $identifier;
150  $content->save();
151  }
152  }
153  }
154 
155  function drawView()
156  {
157  global $script;
158  global $dialogs;
159 
160  $content = $this->section->Content("ORDER BY identifier");
161 
162  $contentByIdentifier = reindexList($content, "identifier");
163 
164  $itemsByType = array();
166 
168 
169  $contentTree = new TreeControl("section_content_tree", "Section Content");
170  $contentTree->scroll = true;
171  $contentTree->width = 360;
172  $contentTree->height = 430;
173  $contentTree->selectOnRightClick = true;
174 
175  $availableTree = new TreeControl("available_content_tree", "Available Content");
176  $availableTree->scroll = true;
177  $availableTree->width = 360;
178  $availableTree->height = 430;
179 
180  $categories = array();
181 
182  foreach($itemsByType as $type => $items)
183  {
184  $category = new TreeNode("content_type_".codify($type), $type, null, false, "tree_node_closed", "tree_node_open");
185 
186  $categories[$type] = new TreeNode("category_".codify($type), $type, null, false, "tree_node_closed", "tree_node_open");
187 
188  foreach($items as $item)
189  {
190  if (array_key_exists($item->identifier, $contentByIdentifier)) continue;
191 
192  $child = new TreeNode("available[{$item->identifier}]", $item->identifier, $item->identifier, false, "plain_tree_closed", "plain_tree_open");
193  $child->leafStyle = "file_node_leaf";
194 
195  $category->add($child);
196  }
197 
198  $availableTree->add($category);
199  }
200 
201  foreach($content as $item)
202  {
203  if (!array_key_exists($item->identifier, $types)) continue;
204 
205  $type = $types[$item->identifier];
206  $properties = $contentByIdentifier[$item->identifier];
207 
208  $child = new TreeNode("content['{$item->identifier}']", $item->identifier, $item->section_content_id, false, "plain_tree_closed", "plain_tree_open");
209  $child->leafStyle = ($properties->template || $properties->role || $properties->permissions || $properties->use_SSL) ? "flagged_node_leaf" : "file_node_leaf";
210  $categories[$type]->add($child);
211  }
212 
213  foreach($categories as $category)
214  {
215  $contentTree->add($category);
216  }
217 
218  $script .= <<<ENDSCRIPT
219  <script src="/fakoli/js/section_content_manager.js" type="text/javascript"></script>
220  <script type="text/javascript">
221 
222  var sectionContentManager;
223 
224  window.addEvent("domready", function()
225  {
226  sectionContentManager = new SectionContentManager('section_content_tree_table');
227  });
228 
229  </script>
230 ENDSCRIPT;
231 
232  $contextMenu = new ContextMenu("section_content_menu", "#section_content_tree_table");
233  $contextMenu->command("set_template", "Set Template...", "sectionContentManager.setTemplate()", false)
234  ->command("set_roles", "Set Roles...", "sectionContentManager.setRole()", false)
235  ->command("set_permissions", "Set Permissions...", "sectionContentManager.setPermissions()", false)
236  ->command("set_ssl", "Configure SSL...", "sectionContentManager.setSSL()", false)
237  ->command("set_page_title", "Override Page Title...", "sectionContentManager.setPageTitle()", false)
238  ->command("set_body_class", "Set Body Class...", "sectionContentManager.setBodyClass()", false)
239  ->command("set_all", "All Properties...", "sectionContentManager.allProperties()", "", false)
240  ->separator()
241  ->command("use_defaults", "Use Section Defaults", "sectionContentManager.clearProperties()", "", false)
242  ->separator()
243  ->command("position_modules", "Position Modules", "sectionContentManager.positionModules()", "", false);
244 
245  $script .= $contextMenu->writeScript();
246  $dialogs .= $contextMenu->writeMenu();
247 
248  ?>
249 <form method="POST" action="?section_id=<?echo $this->section->section_id?>">
250 <div style="float: left; width: 365px; margin-left: 10px">
251 <? $contentTree->writeHTML()?>
252 </div>
253 <div id="section_content_buttons">
254 <button class="button" id="section_move_left" title="Add"></button>
255 <button class="button" id="section_move_right" title="Remove"></button>
256 </div>
257 <div style="float: left; width: 365px">
258 <? $availableTree->writeHTML()?>
259 </div>
260 <div style="clear: left"><br/></div>
261 </form>
262 <?
263  }
264 
266  {
267  $types = array();
268 
269  foreach($itemsByType as $type => $items)
270  {
271  foreach($items as $item)
272  {
273  $types[$item->identifier] = $type;
274  }
275  }
276 
277  return $types;
278  }
279 }
280 ?>
$_POST["owner_id"]
Definition: blog_form.inc:54
$section
Definition: event_form.inc:44
$helpTree style
Definition: tree.inc:46
$form action
Definition: edit.inc:67
$bookmark title
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
FakoliEventNotConsumed is thrown when no subscriber has handled an event that was fired with $mustBeC...
Definition: core.inc:69
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
getAdminView($section)
Factory method to build the view class for displaying and manipulating section content for the specif...
getDefaultPage($section)
Returns the identifier for the default page in the section (i.e.
sendContent($section, $identifier)
Renders and sends the specified content for the given section.
getContent($section, $identifier)
Returns a SectionContent object for the specified section and identifier.
$itemsByType
Defines the interface required by a SectionContentManager.
sendContent($section, $identifier)
Renders and sends the specified content for the given section.
getDefaultPage($section)
Returns the identifier for the default page in the section (i.e.
getAdminView($section)
Factory method to build the view class for displaying and manipulating section content for the specif...
getContent($section, $identifier)
Returns a SectionContent object for the specified section and identifier.
$identifier
Definition: rss.inc:37
$types
$tabs section
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER)) $content
Definition: styles.css.inc:24