54 $obj =
new $connectable;
67 if (array_key_exists($primaryKey, $_GET))
69 $id = checkNumeric($_GET[$primaryKey]);
116 if ($t ==
$target)
return true;
129 return Query::create(
ConnectionRecord,
"WHERE source_class=:sc AND source_id=:si AND target_class=:tc AND target_id=:ti")
130 ->bind(
":sc", get_class(
$source),
151 $sourceClass = get_class(
$source);
152 $targetClass = get_class(
$target);
154 if (!$sourceDefn || !$targetDefn)
156 throw new FakoliException(
"Attempt to link an object that is not a registered Connectable");
161 throw new FakoliException(
"Cannot create a link between a $sourceClass and a $targetClass");
165 $record->source_class = $sourceClass;
167 $record->target_class = $targetClass;
176 $record->source_class = $sourceClass;
178 $record->target_class = $targetClass;
197 $sourceClass = get_class(
$source);
198 $targetClass = get_class(
$target);
200 $record->delete(
"WHERE (source_class='{$sourceClass}' AND source_id={$sourceID} AND target_class='{$targetClass}' AND target_id={$targetID}') " .
201 "OR (source_class='{$targetClass}' AND source_id={$targetID} AND target_class='{$sourceClass}' AND target_id={$sourceID})");
213 $sourceClass = get_class(
$source);
216 $record->delete(
"WHERE (source_class='{$sourceClass}' AND source_id={$sourceID} AND target_class='{$targetClass}') " .
217 "OR (source_class='{$targetClass}' AND target_class='{$sourceClass}' AND target_id={$sourceID})");
229 $objectID = $object->get($object->getPrimaryKey());
230 $class = get_class($object);
231 $record->delete(
"WHERE (source_class='{$class}' AND source_id={$objectID}) OR (target_class='{$class}' AND target_id={$objectID})");
242 $sourceClass = is_object($sourceItem) ? get_class($sourceItem) : $sourceItem;
246 throw new FakoliException(
"$sourceClass is not a registered connectable class");
264 $query = ConnectableManager::generateConnectedQuery($sourceItem, $targetClass,
$constraint);
265 return Query::create($targetClass, $query)
266 ->bind(
":sc", get_class($sourceItem),
":si", $sourceItem->get($sourceItem->getPrimaryKey()),
":tc", $targetClass)
280 $query = ConnectableManager::generateConnectedQuery($sourceItem, $targetClass,
$constraint);
281 return Query::create($targetClass, $query)
282 ->bind(
":sc", get_class($sourceItem),
":si", $sourceItem->get($sourceItem->getPrimaryKey()),
":tc", $targetClass)
283 ->executeValue(
"COUNT(1)");
286 private static function generateConnectedQuery($sourceItem, $targetClass,
$constraint)
290 $sourceClass = get_class($sourceItem);
294 trace(print_r($targetClasses,
true), 3);
298 throw new FakoliException(
"$sourceClass cannot be connected to $targetClass");
301 $obj =
new $targetClass;
304 return "WHERE $pk in (SELECT target_id FROM connection_record WHERE source_class=:sc AND source_id=:si AND target_class = :tc) $constraint";
309 $mgr->upgrade($version);
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
Provides a central management class for event handlers and common functionality for the connectable c...
static getConnectableFromRequest()
Create and populate a Connectable DataItem based on its primary key as passed in on the requesting UR...
static canConnect($source, $target)
Determine whether two objects or classes can connect based on the registered connectable map.
static instantiate($class, $id)
Safely instantiate a Connectable.
static addConnection($source, $target)
Add a connection between the given source and target objects.
static removeConnection($source, $target)
Remove any connection that exists between the source and target object (including back-links if they ...
static getConnectedItems($sourceItem, $targetClass, $constraint="")
Returns the connected items for the specified source that are of the specified class.
static removeAllConnections($object)
Remove all the connections to and from the given object.
static removeConnections($source, $targetClass)
Remove any connection that exists between the source and objects of the specified target class (inclu...
static getConnectedItemCount($sourceItem, $targetClass, $constraint="")
Returns the number of connected items for the specified source that are of the specified class.
static registerConnectable($connectable, $targets)
Register a connectable class and the list of classes it can connect with.
static upgradeComponent($version)
static $connectables
Connectable type map defining which items can be connected together.
static connectionExists($source, $target)
Check whether a connection exists between the given source and target objects.
static getTargetClasses($sourceItem)
Return an array of connectable target classes for the specified item.
static $classLookup
Look-up table of connectable classes from their primary keys.
FakoliException is the base exception class for all Fakoli errors.
getConnectableLink($source)
getConnectableConstraint()
populateSelectionTable($table)
getConnectableDisabledIcon()