Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Attributes

ilAdvancedMDFieldDefinition Class Reference
[Services/AdvancedMetaData]

Collaboration diagram for ilAdvancedMDFieldDefinition:

Public Member Functions

 __construct ($a_field_id=0)
 public
 setRecordId ($a_id)
 set record id
 getRecordId ()
 get record id
 getFieldId ()
 get field_id
 setImportId ($a_id_string)
 set import id
 getImportId ()
 get import_id
 setPosition ($a_pos)
 set position
 getPosition ()
 get position
 setFieldType ($a_type_id)
 set field type
 getFieldType ()
 get field type
 setFieldValues ($a_values)
 set field values
 appendFieldValue ($a_value)
 Append field value.
 getFieldValues ()
 get field values
 getFieldValuesForSelect ()
 get field values for select
 setTitle ($a_title)
 set title
 getTitle ()
 get title
 setDescription ($a_desc)
 set description
 getDescription ()
 get description
 enableSearchable ($a_status)
 enable searchable
 isSearchable ()
 is searchable
 isRequired ()
 is required field
 delete ()
 delete field
 add ()
 add new field
 validate ()
 validate
 update ()
 update
 toXML (ilXmlWriter $writer)
 To Xml.

Static Public Member Functions

static _lookupImportId ($a_field_id)
 Lookup import id.
static _lookupFieldId ($a_import_id)
 Lookup field id.
static _lookupDateFields ()
 Lookup date fields.
static _getInstanceByFieldId ($a_field_id)
 Get instance by field_id.
static _getDefinitionsByRecordId ($a_record_id)
 get definitions
static _getActiveDefinitionsByObjType ($a_type)
 get active definitions by obj type
static _getSearchableDefinitionIds ()
 Get searchable definition ids.
static _deleteByRecordId ($a_record_id)
 Delete all fields by record_id.

Data Fields

const TYPE_SELECT = 1
const TYPE_TEXT = 2
const TYPE_DATE = 3

Protected Member Functions

 generateImportId ()
 generate unique record id

Protected Attributes

 $db = null
 $record_id
 $field_id
 $import_id
 $position
 $field_type
 $field_values = array()
 $title
 $description
 $searchable
 $required = false

Private Member Functions

 read ()
 read field definition
 getLastPosition ()
 get last position of record

Static Private Attributes

static $instances = array()

Detailed Description

Author:
Stefan Meyer <smeyer@databay.de>
Version:
$Id$

Definition at line 31 of file class.ilAdvancedMDFieldDefinition.php.


Constructor & Destructor Documentation

ilAdvancedMDFieldDefinition::__construct ( a_field_id = 0  ) 

public

Parameters:
 

Definition at line 58 of file class.ilAdvancedMDFieldDefinition.php.

References read().

        {
                global $ilDB;
                
                $this->db = $ilDB;
                
                $this->field_id = $a_field_id;
                $this->read();
        }

Here is the call graph for this function:


Member Function Documentation

static ilAdvancedMDFieldDefinition::_deleteByRecordId ( a_record_id  )  [static]

Delete all fields by record_id.

public

Parameters:
int record_id

Definition at line 229 of file class.ilAdvancedMDFieldDefinition.php.

References $res, and ilAdvancedMDValues::_deleteByFieldId().

Referenced by ilAdvancedMDRecord::_delete().

        {
                global $ilDB;
                
                $query = "SELECT field_id FROM adv_md_field_definition ".
                        "WHERE record_id = ".$ilDB->quote($a_record_id);
                $res = $ilDB->query($query);    
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        // Delete values
                        include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
                        ilAdvancedMDValues::_deleteByFieldId($row->field_id);
                }               

                // Delete definitions
                $query = "DELETE FROM adv_md_field_definition ".
                        "WHERE record_id  = ".$ilDB->quote($a_record_id)." ";
                $res = $ilDB->query($query);    
        }

Here is the call graph for this function:

Here is the caller graph for this function:

static ilAdvancedMDFieldDefinition::_getActiveDefinitionsByObjType ( a_type  )  [static]

get active definitions by obj type

public

Parameters:
string obj_type

Definition at line 180 of file class.ilAdvancedMDFieldDefinition.php.

References $res.

Referenced by ilAdvancedMDValues::_cloneValues(), and ilAdvancedMDSettingsGUI::initFormSubstitutions().

        {
                global $ilDB;
                
                $query = "SELECT field_id FROM adv_md_record_objs AS aro ".
                        "JOIN adv_md_record AS amr ON aro.record_id = amr.record_id ".
                        "JOIN adv_md_field_definition AS amf ON aro.record_id = amf.record_id ".
                        "WHERE active = 1 ".
                        "AND obj_type = ".$ilDB->quote($a_type)." ".
                        "ORDER BY aro.record_id,position ";
                $res = $ilDB->query($query);
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $field_ids[] = $row->field_id;
                }
                return $field_ids ? $field_ids : array();
        }

Here is the caller graph for this function:

static ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId ( a_record_id  )  [static]

get definitions

public

Parameters:
int record_id
Returns:
array array(object) field definition objects

Definition at line 156 of file class.ilAdvancedMDFieldDefinition.php.

References $res, and _getInstanceByFieldId().

Referenced by ilAdvancedMDSettingsGUI::editRecord(), ilAdvancedMDRecordTableGUI::fillRow(), ilAdvancedMDRecordGUI::parseEditor(), ilAdvancedMDRecordGUI::parseInfoPage(), ilAdvancedMDRecordGUI::parseSearch(), and ilAdvancedMDRecord::toXML().

        {
                global $ilDB;
                
                $query = "SELECT field_id FROM adv_md_field_definition ".
                        "WHERE record_id = ".$ilDB->quote($a_record_id)." ".
                        "ORDER BY position ";
                $res = $ilDB->query($query);
                $defs = array();
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $defs[] = self::_getInstanceByFieldId($row->field_id);
                }
                return $defs ? $defs : array(); 
        }

Here is the call graph for this function:

Here is the caller graph for this function:

static ilAdvancedMDFieldDefinition::_getInstanceByFieldId ( a_field_id  )  [static]
static ilAdvancedMDFieldDefinition::_getSearchableDefinitionIds (  )  [static]

Get searchable definition ids.

public

Definition at line 204 of file class.ilAdvancedMDFieldDefinition.php.

References $res.

Referenced by ilAdvancedSearchGUI::setSubTabs().

        {
                global $ilDB;
                
                $query = "SELECT field_id FROM adv_md_record AS amr ".
                        "JOIN adv_md_field_definition AS amfd USING (record_id) ".
                        "WHERE active = 1 ".
                        "AND searchable = 1";
                $res = $ilDB->query($query);
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $field_ids[] = $row->field_id;
                }
                return $field_ids ? $field_ids : array();
        }

Here is the caller graph for this function:

static ilAdvancedMDFieldDefinition::_lookupDateFields (  )  [static]

Lookup date fields.

public

Definition at line 113 of file class.ilAdvancedMDFieldDefinition.php.

References $res.

Referenced by ilAdvancedMDSubstitution::read().

        {
                global $ilDB;
                
                $query = "SELECT field_id FROM adv_md_field_definition ".
                        "WHERE field_type = ".self::TYPE_DATE." ";
                $res = $ilDB->query($query);
                
                $date_fields = array();
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $date_fields[] = $row->field_id; 
                }
                return $date_fields;
        }

Here is the caller graph for this function:

static ilAdvancedMDFieldDefinition::_lookupFieldId ( a_import_id  )  [static]

Lookup field id.

public

Parameters:
string import_id

Definition at line 95 of file class.ilAdvancedMDFieldDefinition.php.

References $res.

Referenced by ilAdvancedMDValueParser::initValue().

        {
                global $ilDB;
                
                $query = "SELECT field_id FROM adv_md_field_definition ".
                        "WHERE import_id = ".$ilDB->quote($a_import_id)." ";
                $res = $ilDB->query($query);
                $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
                return $row['field_id'] ? $row['field_id'] : 0;
        }

Here is the caller graph for this function:

static ilAdvancedMDFieldDefinition::_lookupImportId ( a_field_id  )  [static]

Lookup import id.

public

Parameters:
int field_id

Definition at line 76 of file class.ilAdvancedMDFieldDefinition.php.

References $res.

Referenced by ilAdvancedMDValue::appendXML().

        {
                global $ilDB;
                
                $query = "SELECT import_id FROM adv_md_field_definition ".
                        "WHERE field_id = ".$ilDB->quote($a_field_id)." ";
                $res = $ilDB->query($query);
                $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
                return $row['import_id'] ? $row['import_id'] : '';
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::add (  ) 

add new field

public

Definition at line 510 of file class.ilAdvancedMDFieldDefinition.php.

References $position, generateImportId(), getDescription(), getFieldType(), getFieldValues(), getImportId(), getLastPosition(), getRecordId(), getTitle(), isRequired(), and isSearchable().

        {
                sort($values = $this->getFieldValues(),SORT_STRING);
                
                $position = $this->getLastPosition();
                
                $query = "INSERT INTO adv_md_field_definition ".
                        "SET record_id = ".$this->db->quote($this->getRecordId()).", ".
                        "import_id = ".$this->db->quote($this->getImportId()).", ".
                        "position = ".$this->db->quote($position + 1).", ".
                        "field_type = ".$this->db->quote($this->getFieldType()).", ".
                        "field_values = '".addslashes(serialize($values))."', ".
                        "title = ".$this->db->quote($this->getTitle()).", ".
                        "description = ".$this->db->quote($this->getDescription()).", ".
                        "searchable = ".(int) $this->isSearchable().", ".
                        "required = ".(int) $this->isRequired();
                $this->db->query($query);
                $this->field_id = $this->db->getLastInsertId();
                
                if(!strlen($this->getImportId()))
                {
                        $query = "UPDATE adv_md_field_definition ".
                                "SET import_id = ".$this->db->quote($this->generateImportId())." ".
                                "WHERE field_id = ".$this->db->quote($this->field_id)." ";
                        $this->db->query($query);
                }
                return true;
        }

Here is the call graph for this function:

ilAdvancedMDFieldDefinition::appendFieldValue ( a_value  ) 

Append field value.

public

Parameters:
string value

Definition at line 373 of file class.ilAdvancedMDFieldDefinition.php.

        {
                if(strlen(trim($a_value)))
                {
                        $this->field_values[] = trim($a_value);
                }
        }

ilAdvancedMDFieldDefinition::delete (  ) 

delete field

public

Definition at line 493 of file class.ilAdvancedMDFieldDefinition.php.

References $res, ilAdvancedMDValues::_deleteByFieldId(), and getFieldId().

        {
                $query = "DELETE FROM adv_md_field_definition ".
                        "WHERE field_id = ".$this->db->quote($this->getFieldId())." ";
                $res = $this->db->query($query);
                
                // Also delete all values
                include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
                ilAdvancedMDValues::_deleteByFieldId($this->getFieldId());
                return true;    
        }

Here is the call graph for this function:

ilAdvancedMDFieldDefinition::enableSearchable ( a_status  ) 

enable searchable

public

Parameters:
bool searchable

Definition at line 461 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->searchable = (bool) $a_status;
        }

ilAdvancedMDFieldDefinition::generateImportId (  )  [protected]

generate unique record id

protected

Returns:

Definition at line 682 of file class.ilAdvancedMDFieldDefinition.php.

References getFieldId().

Referenced by add(), and toXML().

        {
                return 'il_'.IL_INST_ID.'_adv_md_field_'.$this->getFieldId();
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getDescription (  ) 

get description

public

Definition at line 449 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), toXML(), and update().

        {
                return $this->description;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getFieldId (  ) 

get field_id

public

Parameters:
 

Definition at line 279 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by delete(), generateImportId(), read(), and update().

        {
                return $this->field_id;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getFieldType (  ) 

get field type

public

Definition at line 349 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), toXML(), update(), and validate().

        {
                return $this->field_type;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getFieldValues (  ) 

get field values

public

Definition at line 387 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), toXML(), and update().

        {
                return $this->field_values;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getFieldValuesForSelect (  ) 

get field values for select

public

Definition at line 398 of file class.ilAdvancedMDFieldDefinition.php.

References $lng.

        {
                global $lng;
                
                $values = array(0 => $lng->txt('select_one'));
                foreach($this->field_values as $value)
                {
                        $values[$value] = $value;
                }
                return $values;
        }

ilAdvancedMDFieldDefinition::getImportId (  ) 

get import_id

public

Definition at line 302 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), and update().

        {
                return $this->import_id;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getLastPosition (  )  [private]

get last position of record

private

Definition at line 664 of file class.ilAdvancedMDFieldDefinition.php.

References $res, and getRecordId().

Referenced by add().

        {
                $query = "SELECT max(position) as pos FROM adv_md_field_definition ".
                        "WHERE record_id = ".$this->db->quote($this->getRecordId())." ";
                $res = $this->db->query($query);
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        return $row->pos;
                }
                return 0;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getPosition (  ) 

get position

public

Parameters:
 

Definition at line 326 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by toXML(), and update().

        {
                return $this->position;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getRecordId (  ) 

get record id

public

Definition at line 267 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), getLastPosition(), and update().

        {
                return $this->record_id;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::getTitle (  ) 

get title

public

Definition at line 427 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), toXML(), update(), and validate().

        {
                return $this->title;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::isRequired (  ) 

is required field

public

Definition at line 483 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), and update().

        {
                return $this->required;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::isSearchable (  ) 

is searchable

public

Definition at line 472 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add(), toXML(), and update().

        {
                return (bool) $this->searchable;
        }

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::read (  )  [private]

read field definition

private

Definition at line 635 of file class.ilAdvancedMDFieldDefinition.php.

References $res, and getFieldId().

Referenced by __construct().

        {
                if(!$this->field_id)
                {
                        return false;
                }
                $query = "SELECT * FROM adv_md_field_definition ".
                        "WHERE field_id = ".$this->db->quote($this->getFieldId())." ";
                $res = $this->db->query($query);
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $this->record_id = $row->record_id;
                        $this->import_id = $row->import_id;
                        $this->position = $row->position;
                        $this->field_type = $row->field_type;
                        $this->field_values = unserialize(stripslashes($row->field_values));
                        $this->title = $row->title;
                        $this->description = $row->description;
                        $this->searchable = $row->searchable;
                        $this->required = $row->required;
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilAdvancedMDFieldDefinition::setDescription ( a_desc  ) 

set description

public

Parameters:
string description

Definition at line 439 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->description = $a_desc;
        }

ilAdvancedMDFieldDefinition::setFieldType ( a_type_id  ) 

set field type

public

Parameters:
int field type

Definition at line 338 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->field_type = $a_type_id;
        }

ilAdvancedMDFieldDefinition::setFieldValues ( a_values  ) 

set field values

public

Parameters:
array array(string) valid field values

Definition at line 361 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->field_values = $a_values;
        }

ilAdvancedMDFieldDefinition::setImportId ( a_id_string  ) 

set import id

public

Parameters:
string import id

Definition at line 291 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->import_id = $a_id_string;
        }

ilAdvancedMDFieldDefinition::setPosition ( a_pos  ) 

set position

public

Parameters:
int position

Definition at line 314 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->position = $a_pos;
        }

ilAdvancedMDFieldDefinition::setRecordId ( a_id  ) 

set record id

public

Parameters:
int record id

Definition at line 257 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->record_id = $a_id;
        }

ilAdvancedMDFieldDefinition::setTitle ( a_title  ) 

set title

public

Parameters:
string title

Definition at line 417 of file class.ilAdvancedMDFieldDefinition.php.

        {
                $this->title = $a_title;
        }

ilAdvancedMDFieldDefinition::toXML ( ilXmlWriter writer  ) 

To Xml.

This method writes only the subset Field Use class.ilAdvancedMDRecordXMLWriter to generate a complete xml presentation.

public

Parameters:
object ilXmlWriter

Definition at line 590 of file class.ilAdvancedMDFieldDefinition.php.

References generateImportId(), getDescription(), getFieldType(), getFieldValues(), getPosition(), getTitle(), isSearchable(), ilXmlWriter::xmlElement(), ilXmlWriter::xmlEndTag(), and ilXmlWriter::xmlStartTag().

         {
                switch($this->getFieldType())
                {
                        case self::TYPE_TEXT:
                                $type = 'Text';
                                break;
                                
                        case self::TYPE_SELECT:
                                $type = 'Select';
                                break;
                                
                        case self::TYPE_DATE:
                                $type = 'Date';
                                break;
                }
                
                
                $writer->xmlStartTag('Field',array(
                        'id' => $this->generateImportId(),
                        'searchable' => ($this->isSearchable() ? 'Yes' : 'No'),
                        'fieldType'      => $type));
                
                $writer->xmlElement('FieldTitle',null,$this->getTitle());
                $writer->xmlElement('FieldDescription',null,$this->getDescription());
                $writer->xmlElement('FieldPosition',null,$this->getPosition());
                
                foreach($this->getFieldValues() as $value)
                {
                        if(strlen($value))
                        {
                                $writer->xmlElement('FieldValue',null,$value);
                        }
                }
                
                $writer->xmlEndTag('Field');
         }

Here is the call graph for this function:

ilAdvancedMDFieldDefinition::update (  ) 

update

public

Definition at line 563 of file class.ilAdvancedMDFieldDefinition.php.

References getDescription(), getFieldId(), getFieldType(), getFieldValues(), getImportId(), getPosition(), getRecordId(), getTitle(), isRequired(), and isSearchable().

        {
                $query = "UPDATE adv_md_field_definition ".
                        "SET record_id = ".$this->db->quote($this->getRecordId()).", ".
                        "import_id = ".$this->db->quote($this->getImportId()).", ".
                        "position = ".$this->db->quote($this->getPosition()).", ".
                        "field_type = ".$this->db->quote($this->getFieldType()).", ".
                        "field_values = '".addslashes(serialize($this->getFieldValues()))."', ".
                        "title = ".$this->db->quote($this->getTitle()).", ".
                        "description = ".$this->db->quote($this->getDescription()).", ".
                        "searchable = ".(int) $this->isSearchable().", ".
                        "required = ".(int) $this->isRequired()." ".
                        "WHERE field_id = ".$this->db->quote($this->getFieldId())." ";
                                                
                $this->db->query($query);
                return true;
        }

Here is the call graph for this function:

ilAdvancedMDFieldDefinition::validate (  ) 

validate

public

Definition at line 545 of file class.ilAdvancedMDFieldDefinition.php.

References $ilErr, $lng, getFieldType(), and getTitle().

        {
                global $ilErr,$lng;
                
                if(!strlen($this->getTitle()) or !$this->getFieldType())
                {
                        $ilErr->setMessage('fill_out_all_required_fields');
                        return false;
                }
                return true;
        }

Here is the call graph for this function:


Field Documentation

ilAdvancedMDFieldDefinition::$db = null [protected]

Definition at line 39 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$description [protected]

Definition at line 48 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$field_id [protected]

Definition at line 42 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$field_type [protected]

Definition at line 45 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$field_values = array() [protected]

Definition at line 46 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$import_id [protected]

Definition at line 43 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$instances = array() [static, private]

Definition at line 37 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$position [protected]

Definition at line 44 of file class.ilAdvancedMDFieldDefinition.php.

Referenced by add().

ilAdvancedMDFieldDefinition::$record_id [protected]

Definition at line 41 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$required = false [protected]

Definition at line 50 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$searchable [protected]

Definition at line 49 of file class.ilAdvancedMDFieldDefinition.php.

ilAdvancedMDFieldDefinition::$title [protected]

Definition at line 47 of file class.ilAdvancedMDFieldDefinition.php.


The documentation for this class was generated from the following file: