1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
6require_once("./Services/COPage/classes/class.ilPageContent.php");
7
8/**
9* Class ilPCProfile
10*
11* Personal data content object (see ILIAS DTD)
12*
13* @author Jörg Lützenkirchen <luetzenkirchen@leifos.com>
14* @version $Id: class.ilPCListItem.php 22210 2009-10-26 09:46:06Z akill $
15*
16* @ingroup ServicesCOPage
17*/
18class ilPCProfile extends ilPageContent
19{
20    /**
21     * @var ilObjUser
22     */
23    protected $user;
24
25    public $dom;
26
27    /**
28    * Init page content component.
29    */
30    public function init()
31    {
32        global $DIC;
33
34        $this->user = $DIC->user();
35        $this->setType("prof");
36    }
37
38    /**
39    * Set node
40    */
41    public function setNode($a_node)
42    {
43        parent::setNode($a_node);		// this is the PageContent node
44        $this->prof_node = $a_node->first_child();		// this is the profile node
45    }
46
47    /**
48    * Create profile node in xml.
49    *
50    * @param	object	$a_pg_obj		Page Object
51    * @param	string	$a_hier_id		Hierarchical ID
52    */
53    public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
54    {
55        $this->node = $this->createPageContentNode();
56        $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
57        $this->prof_node = $this->dom->create_element("Profile");
58        $this->prof_node = $this->node->append_child($this->prof_node);
59    }
60
61    /**
62     * Set profile settings
63     *
64     * @param string $a_mode
65     * @param array $a_fields
66     */
67    public function setFields($a_mode, array $a_fields = null)
68    {
69        $ilUser = $this->user;
70
71        $this->prof_node->set_attribute("Mode", $a_mode);
72        $this->prof_node->set_attribute("User", $ilUser->getId());
73
74        // remove all children first
75        $children = $this->prof_node->child_nodes();
76        if ($children) {
77            foreach ($children as $child) {
78                $this->prof_node->remove_child($child);
79            }
80        }
81
82        if ($a_mode == "manual") {
83            foreach ($a_fields as $field) {
84                $field_node = $this->dom->create_element("ProfileField");
85                $field_node = $this->prof_node->append_child($field_node);
86                $field_node->set_attribute("Name", $field);
87            }
88        }
89    }
90
91    /**
92     * Get profile mode
93     *
94     * @return string
95     */
96    public function getMode()
97    {
98        if (is_object($this->prof_node)) {
99            return $this->prof_node->get_attribute("Mode");
100        }
101    }
102
103    /**
104    * Get profile settings
105    *
106    * @return array
107    */
108    public function getFields()
109    {
110        $res = array();
111        if (is_object($this->prof_node)) {
112            $children = $this->prof_node->child_nodes();
113            if ($children) {
114                foreach ($children as $child) {
115                    $res[] = $child->get_attribute("Name");
116                }
117            }
118        }
119        return $res;
120    }
121
122    /**
123     * Get lang vars needed for editing
124     * @return array array of lang var keys
125     */
126    public static function getLangVars()
127    {
128        return array("pc_prof", "ed_insert_profile");
129    }
130}
131