ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilBuddySystemRelationStateFactory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Contact/BuddySystem/classes/states/class.ilAbstractBuddySystemRelationState.php';
5
11{
15 protected static $instance;
16
20 protected static $valid_states;
21
25 protected static $state_option_array;
26
30 protected function __construct()
31 {
32 }
33
37 public static function getInstance()
38 {
39 if(null === self::$instance)
40 {
41 self::$instance = new self;
42 }
43
44 return self::$instance;
45 }
46
51 public function getValidStates()
52 {
53 if(null !== self::$valid_states)
54 {
56 }
57
58 $states = array();
59 $iter = new DirectoryIterator(dirname(__FILE__));
60 foreach($iter as $file)
61 {
65 if($file->isDir())
66 {
67 continue;
68 }
69
70 require_once $file->getFilename();
71 $class = str_replace(array('class.', '.php'), '', $file->getBasename());
72 $reflection = new ReflectionClass($class);
73 if(
74 !$reflection->isAbstract() &&
75 $reflection->isSubclassOf('ilBuddySystemRelationState')
76 )
77 {
78 $states[] = new $class();
79 }
80 }
81
82 return (self::$valid_states = $states);
83 }
84
89 public function getInitialState()
90 {
91 foreach($this->getValidStates() as $state)
92 {
93 if($state->isInitial())
94 {
95 return $state;
96 }
97 }
98
99 throw new ilBuddySystemException("Could not find an initial state class");
100 }
101
106 public function getStatesAsOptionArray($with_initial_state = false)
107 {
111 global $lng;
112
113 if(null !== self::$state_option_array[$with_initial_state])
114 {
115 return self::$state_option_array[$with_initial_state];
116 }
117
118 $options = array();
119
120 foreach($this->getValidStates() as $state)
121 {
122 if($with_initial_state || !$state->isInitial())
123 {
124 $options[get_class($state)] = $lng->txt('buddy_bs_state_' . strtolower($state->getName()));
125 }
126 }
127
128 return (self::$state_option_array[$with_initial_state] = $options);
129 }
130
137 public function getRendererByOwnerAndRelation($owner_id, ilBuddySystemRelation $relation)
138 {
139 $state_class = get_class($relation->getState());
140 $renderer_class = $state_class . 'ButtonRenderer';
141 $renderer_path = "Services/Contact/BuddySystem/classes/states/renderer/class.{$renderer_class}.php";
142
143 if(!file_exists($renderer_path))
144 {
145 throw new ilBuddySystemException(sprintf("Could not find a renderer file for state: %s", $state_class));
146 }
147
148 require_once $renderer_path;
149 if(!class_exists($renderer_class))
150 {
151 throw new ilBuddySystemException(sprintf("Could not find a renderer class for state: %s in file: %s", $state_class, $renderer_path));
152 }
153
154 return new $renderer_class($owner_id, $relation);
155 }
156}
print $file
getRendererByOwnerAndRelation($owner_id, ilBuddySystemRelation $relation)
Class ilBuddySystemRelation.
global $lng
Definition: privfeed.php:40
if(!is_array($argv)) $options