-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinjector.php
54 lines (48 loc) · 1.56 KB
/
injector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class org_midgardproject_projectsite_injector
{
public function inject_template(midgardmvc_core_request $request)
{
// We inject the template to provide MeeGo styling
$request->add_component_to_chain(midgardmvc_core::get_instance()->component->get('org_midgardproject_projectsite'), true);
}
public static function create_url(org_midgardproject_projectsite_product $product)
{
self::check_category($product);
if ($product->name)
{
return;
}
$product->name = midgardmvc_helper_urlize::string($product->title);
}
public static function check_category(org_midgardproject_projectsite_product $product)
{
if ($product->category)
{
return;
}
$args = midgardmvc_core::get_instance()->context->get_request()->get_arguments();
$product->category = $args[0];
}
public static function check_product(midgard_object $document)
{
if (!$document->name)
{
$document->name = midgardmvc_helper_urlize::string($document->title);
}
if ($document->product)
{
return;
}
$args = midgardmvc_core::get_instance()->context->get_request()->get_arguments();
try
{
$product = org_midgardproject_projectsite_controllers_product::get_product_by_name($args[0]);
$document->product = $product->id;
}
catch (midgardmvc_exception_notfound $e)
{
return;
}
}
}