CMS  Version 3.9
select_related.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("connectable");
3 Fakoli::usingFeature("auto_form");
4 
5 list($sourceClass, $sourceID) = explode(":", $_GET["from"]);
6 checkIdentifier($sourceClass);
7 checkNumeric($sourceID);
8 
9 $to = checkIdentifier($_GET["to"]);
10 
11 $source = new $sourceClass;
12 if (!$source instanceof Connectable)
13 {
14  throw new FakoliException("$source is not a connectable class");
15 }
16 
17 $source->filter = new InclusionFilter($source->getPrimaryKey());
18 $source->load($sourceID);
19 
20 $form = new AutoForm($source, "POST", "/action/connectable/select_related?from={$_GET['from']}&to=$to", "ConnectableSelect");
21 
22 $form->ajaxSubmit("function(result) { ConnectableNavigator.selectResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
23 
24 $form->submitLabel = "Save";
25 
26 $target = new $to;
27 
28 $from = get_class($source).":".$source->get($source->getPrimaryKey());
30 $isScript = false;;
31 
32 if (method_exists($target, getConnectableCreateHandler))
33 {
34  $createHandler = $target->getConnectableCreateHandler();
35  $createURL = "{$createHandler}('{$createURL}'); return false;";
36  $isScript = true;
37 }
38 
39 $form->button("Create New ".$target->prettifyClassName(), $createURL, null, $isScript);
40 
41 $selectFieldRenderer = new ConnectableTableFieldRenderer($form, "related_items", "Related Items", $to);
42 
43 if ($method == "POST")
44 {
45  if ($form->save())
46  {
47  Fakoli::end("OK");
48  }
49  else
50  {
51  Fakoli::end($form->msg);
52  }
53 }
54 
55 $script .= $form->writeScript();
56 $form->drawForm();
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573