ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $lng;
31
35 protected function __construct()
36 {
37 global $DIC;
38
39 $this->lng = $DIC['lng'];
40 }
41
45 public static function getInstance()
46 {
47 if (null === self::$instance) {
48 self::$instance = new self;
49 }
50
51 return self::$instance;
52 }
53
58 public function getValidStates()
59 {
60 if (null !== self::$valid_states) {
62 }
63
64 $states = array();
65 $iter = new DirectoryIterator(dirname(__FILE__));
66 foreach ($iter as $file) {
70 if ($file->isDir()) {
71 continue;
72 }
73
74 require_once $file->getFilename();
75 $class = str_replace(array('class.', '.php'), '', $file->getBasename());
76 $reflection = new ReflectionClass($class);
77 if (
78 !$reflection->isAbstract() &&
79 $reflection->isSubclassOf('ilBuddySystemRelationState')
80 ) {
81 $states[] = new $class();
82 }
83 }
84
85 return (self::$valid_states = $states);
86 }
87
92 public function getInitialState()
93 {
94 foreach ($this->getValidStates() as $state) {
95 if ($state->isInitial()) {
96 return $state;
97 }
98 }
99
100 throw new ilBuddySystemException("Could not find an initial state class");
101 }
102
107 public function getStatesAsOptionArray($with_initial_state = false)
108 {
109 if (null !== self::$state_option_array[$with_initial_state]) {
110 return self::$state_option_array[$with_initial_state];
111 }
112
113 $options = array();
114
115 foreach ($this->getValidStates() as $state) {
116 if ($with_initial_state || !$state->isInitial()) {
117 $options[get_class($state)] = $this->lng->txt('buddy_bs_state_' . strtolower($state->getName()));
118 }
119 }
120
121 return (self::$state_option_array[$with_initial_state] = $options);
122 }
123
130 public function getRendererByOwnerAndRelation($owner_id, ilBuddySystemRelation $relation)
131 {
132 $state_class = get_class($relation->getState());
133 $renderer_class = $state_class . 'ButtonRenderer';
134 $renderer_path = "Services/Contact/BuddySystem/classes/states/renderer/class.{$renderer_class}.php";
135
136 if (!file_exists($renderer_path)) {
137 throw new ilBuddySystemException(sprintf("Could not find a renderer file for state: %s", $state_class));
138 }
139
140 require_once $renderer_path;
141 if (!class_exists($renderer_class)) {
142 throw new ilBuddySystemException(sprintf("Could not find a renderer class for state: %s in file: %s", $state_class, $renderer_path));
143 }
144
145 return new $renderer_class($owner_id, $relation);
146 }
147}
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
An exception for terminatinating execution or to throw for unit testing.
getRendererByOwnerAndRelation($owner_id, ilBuddySystemRelation $relation)
Class ilBuddySystemRelation.
global $DIC
Definition: saml.php:7