forked from bergie/org_midgardproject_news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
injector.php
47 lines (43 loc) · 1.42 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
<?php
/**
* @package org_midgardproject_news
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
/**
* News category handler
*
* @package org_midgardproject_news
*/
class org_midgardproject_news_injector
{
public function inject_process(midgardmvc_core_request $request)
{
static $connected = false;
if (!$connected)
{
// Subscribe to content changed signals from Midgard
midgard_object_class::connect_default('org_midgardproject_news_article', 'action-create', array('org_midgardproject_news_injector', 'check'), array($request));
$connected = true;
}
}
public static function check(org_midgardproject_news_article $article, $params)
{
if ($article->metadata->published->getTimestamp() == 0)
{
echo "Setting {$article->title} to time()\n";
$article->metadata->published->setTimestamp(time());
}
if ( !$article->category
&& isset(midgardmvc_core::get_instance()->configuration->categories))
{
$categories = midgardmvc_core::get_instance()->configuration->categories;
if (!empty($categories))
{
$article->category = $categories[0];
}
}
}
}
?>