CMS  Version 3.9
connectable_navigator.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("connectable");
8 
10 {
11  var $id;
12  var $title;
13  var $source;
14  var $panel;
15  var $handler;
16  var $enabled = true;
17 
19  {
20  $this->id = $id;
21  $this->title = $title;
22  $this->source = $source;
23  $this->handler = $handler;
24  $this->createPanel();
25  }
26 
27  function createPanel()
28  {
29  $url = $this->handler."?".($this->source->getPrimaryKey())."=".($this->source->get($this->source->getPrimaryKey()));
30 
31  trace($url, 3);
32  $this->panel = new Panel($this->id."_panel", $url);
33  }
34 
35  function writeScript()
36  {
37  $script = <<<ENDSCRIPT
38 <script type="text/javascript" src="/components/connectable/js/connectable_navigator.js"></script>
39 <script type="text/javascript">
40 var {$this->id}_ConnectableNavigator;
41 window.addEvent('load', function()
42 {
43  {$this->id}_ConnectableNavigator = new ConnectableNavigator('{$this->id}_panel');
44 });
45 </script>
46 ENDSCRIPT;
47  return $script;
48  }
49 
50  function drawTarget($target)
51  {
52  trace("Drawing target: $target for source ".get_class($this->source), 3);
53 
54  $obj = new $target;
55  $name = $obj->prettifyClassName(true);
56 
57  if (!$this->enabled)
58  {
59  $icon = $obj->getConnectableDisabledIcon();
60 ?>
61  <li><img src="<?echo $icon?>" alt="<?echo $name?>" title="<?echo $name?>" class="disabled"/>
62 <?
63  return;
64  }
65 
66  $icon = $obj->getConnectableIcon();
67 
68  $items = ConnectableManager::getConnectedItems($this->source, $target, $obj->getConnectableConstraint());
69  $count = count($items);
70 ?>
71  <li><img src="<?echo $icon?>" alt="<?echo $name?>" title="<?echo $name?>" data-count="<?echo $count?>"/>
72  <div>
73  <span class='title'><?echo $name?></span><br/>
74 <?
75  if ($count > 0)
76  {
77  foreach($items as $item)
78  {
79  echo $item->getConnectableLink($this->source)."<br/>";
80  }
81  }
82  else
83  {
84  echo "There are no related $name<br/>";
85  }
86 
87  $from = get_class($this->source).":".$this->source->get($this->source->getPrimaryKey());
88  $createURL = ConnectableManager::$contextRouter . "?from=$from&to=$target";
89  $createHandler = "";
90 
91  if (method_exists($obj, getConnectableCreateHandler))
92  {
93  $createHandler = $obj->getConnectableCreateHandler();
94  $createHandler = " onclick='{$createHandler}(\"{$createURL}\"); return false;'";
95  $createURL = "#";
96  }
97 ?>
98  <br/>
99  <a class='button small' href='#' onclick='ConnectableNavigator.selectConnectables("<?echo $from?>", "<?echo $target?>", "<?echo $name?>"); return false'>Select...</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='button small' href='<?echo $createURL?>'<?echo $createHandler?>>Create...</a>
100  </div>
101  </li>
102 <?
103  }
104 
105  function drawNavigator()
106  {
108 
109  if (!$this->source->get($this->source->getPrimaryKey())) $this->enabled = false;
110 ?>
111 <div id="<?echo $this->id?>" class="connectable_navigator">
112 <span class="title"><?echo $this->title?></span>
113 <ul>
114 <?
115  foreach($targets as $target)
116  {
117  $this->drawTarget($target);
118  }
119 ?>
120 </ul>
121 </div>
122 <?
123  }
124 
125  function draw()
126  {
127  $this->panel->draw();
128  }
129 }?>
& nbsp
Definition: index.inc:49
$name
Definition: upload.inc:54
$icon
Definition: upload.inc:92
$bookmark title
static getConnectedItems($sourceItem, $targetClass, $constraint="")
Returns the connected items for the specified source that are of the specified class.
static getTargetClasses($sourceItem)
Return an array of connectable target classes for the specified item.
__construct($id, $title, $source, $handler)
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Panel provides a reloadable panel tied to an action handler.
Definition: panel.inc:51
if(! $blog->published||! $blog->enable_rss_feed||!checkRole($blog->allow_read)) $url
Definition: rss.inc:58
$text enabled