Exemplo n.º 1
0
 public function testComment()
 {
     $vm_ret = $this->opt_object->get('ca_item_comments.comment');
     $this->assertEquals('I like this very much.', $vm_ret);
     $this->assertTrue(!is_numeric($this->opt_object->get('ca_item_comments.created_on')));
     // should always be current date/time as tex
 }
 public function testGets()
 {
     $vm_ret = $this->opt_object->get("ca_objects_x_storage_locations.effective_date");
     $this->assertEquals('January 28 1985', $vm_ret);
     $vm_ret = $this->opt_object->get("ca_objects_x_storage_locations.effective_date", array('getDirectDate' => true));
     $this->assertEquals($vm_ret, '1985.01280000000000000000');
     // try legacy version of same option
     $vm_ret = $this->opt_object->get("ca_objects_x_storage_locations.effective_date", array('GET_DIRECT_DATE' => true));
     $this->assertEquals($vm_ret, '1985.01280000000000000000');
 }
 public function testInterstitialTemplateProcessing()
 {
     // should only be one
     $vn_relation_id = $this->opt_object_left->get('ca_objects_x_objects.relation_id');
     $this->assertTrue(is_numeric($vn_relation_id));
     $va_opts = array('resolveLinksUsing' => 'ca_objects', 'primaryIDs' => array('ca_objects' => array($this->opt_object_left->getPrimaryKey())));
     // we're reading from the left side, so the right side pop up
     $this->assertEquals('Test Dataset', caProcessTemplateForIDs('^ca_objects.preferred_labels', 'ca_objects_x_objects', array($vn_relation_id), $va_opts));
     $this->assertEquals('is related to', caProcessTemplateForIDs('^relationship_typename', 'ca_objects_x_objects', array($vn_relation_id), $va_opts));
     $this->assertEquals('is related to', caProcessTemplateForIDs('<unit relativeTo="ca_objects_x_objects">^relationship_typename</unit>', 'ca_objects', array($this->opt_object_left->getPrimaryKey()), $va_opts));
 }
 public function testInterstitialTemplateProcessing()
 {
     // should only be one
     $vn_relation_id = $this->opt_homer->get('ca_entities_x_entities.relation_id');
     $this->assertTrue(is_numeric($vn_relation_id));
     $va_opts = array('resolveLinksUsing' => 'ca_entities', 'primaryIDs' => array('ca_entities' => array($this->opt_bart->getPrimaryKey())));
     // we're reading from Bart, so Homer should pop up
     $this->assertEquals('Homer J. Simpson', caProcessTemplateForIDs('^ca_entities.preferred_labels', 'ca_entities_x_entities', array($vn_relation_id), $va_opts));
     // Try getting the rel type from the relationship record
     // We don't need $va_opts to do that, by the way!
     $this->assertEquals('is related to', caProcessTemplateForIDs('^relationship_typename', 'ca_entities_x_entities', array($vn_relation_id)));
     // Try getting the rel type from the Homer record
     // We don't need $va_opts to do that either
     $this->assertEquals('is related to', caProcessTemplateForIDs('<unit relativeTo="ca_entities_x_entities">^relationship_typename</unit>', 'ca_entities', array($this->opt_homer->getPrimaryKey())));
 }
Exemplo n.º 5
0
 public function testGets()
 {
     $vm_ret = $this->opt_loan_in->get('ca_loans.related');
     $this->assertEquals('New Loan Out', $vm_ret);
     $va_items = $this->opt_loan_in->getRelatedItems('ca_loans');
     $vn_relation_id = array_shift(caExtractArrayValuesFromArrayOfArrays($va_items, 'relation_id'));
     // The relationship we created is Loan Out <-> Loan In, so evaluating with loan in as primary ID should give us the loan out
     $va_opts = array('resolveLinksUsing' => 'ca_loans', 'primaryIDs' => array('ca_loans' => array($this->opt_loan_in->getPrimaryKey())));
     $vm_ret = caProcessTemplateForIDs("^ca_loans.preferred_labels", 'ca_loans_x_loans', array($vn_relation_id), $va_opts);
     $this->assertEquals('New Loan Out', $vm_ret);
     // Now for the other side ...
     $va_opts = array('resolveLinksUsing' => 'ca_loans', 'primaryIDs' => array('ca_loans' => array($this->opt_loan_out->getPrimaryKey())));
     $vm_ret = caProcessTemplateForIDs("^ca_loans.preferred_labels", 'ca_loans_x_loans', array($vn_relation_id), $va_opts);
     $this->assertEquals('New Loan In', $vm_ret);
 }
Exemplo n.º 6
0
 public function testGets()
 {
     $vm_ret = $this->opt_object->get('ca_entities', array('delimiter' => '; '));
     $this->assertEquals('Homer J. Simpson; Bart Simpson; ACME Inc.', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities.preferred_labels', array('delimiter' => '; '));
     $this->assertEquals('Homer J. Simpson; Bart Simpson; ACME Inc.', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities.nonpreferred_labels');
     $this->assertEquals('Max Power', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('returnWithStructure' => true));
     $vm_ret2 = $this->opt_object->getRelatedItems('ca_entities');
     $this->assertSame($vm_ret, $vm_ret2);
     $vm_ret = $this->opt_object->get('ca_entities', array('restrictToRelationshipTypes' => array('creator')));
     $this->assertEquals('Homer J. Simpson', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('restrictToRelationshipTypes' => array('publisher')));
     $this->assertEquals('Bart Simpson', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('delimiter' => '; ', 'restrictToTypes' => array('ind')));
     $this->assertEquals('Homer J. Simpson; Bart Simpson', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('delimiter' => '; ', 'restrictToTypes' => array('org')));
     $this->assertEquals('ACME Inc.', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('delimiter' => '; ', 'restrictToTypes' => array('ind', 'org')));
     $this->assertEquals('Homer J. Simpson; Bart Simpson; ACME Inc.', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('delimiter' => '; ', 'excludeRelationshipTypes' => array('creator', 'publisher')));
     $this->assertEquals('ACME Inc.', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('delimiter' => '; ', 'excludeTypes' => array('ind')));
     $this->assertEquals('ACME Inc.', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects_x_entities.source_info', array('delimiter' => '; '));
     $this->assertEquals('Me; Homer; Bart', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects_x_entities.effective_date', array('delimiter' => '; '));
     $this->assertEquals('2015; 2014 - 2015; 2013', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities.internal_notes');
     $this->assertEquals('Test notes', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.related.preferred_labels');
     $this->assertEquals('My test dataset', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('template' => '^ca_entities.preferred_labels.displayname (^ca_entities.internal_notes)', 'delimiter' => '; '));
     $this->assertEquals('Homer J. Simpson (); Bart Simpson (); ACME Inc. (Test notes)', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_entities', array('template' => '^ca_entities.preferred_labels', 'delimiter' => '; ', 'returnAsLink' => true));
     $this->assertRegExp("/\\<a href=[\"\\'](.)+[\"\\']>Homer J. Simpson\\<\\/a\\>/", $vm_ret);
     $this->assertRegExp("/\\<a href=[\"\\'](.)+[\"\\']>Bart Simpson\\<\\/a\\>/", $vm_ret);
     $this->assertRegExp("/\\<a href=[\"\\'](.)+[\"\\']>ACME Inc.\\<\\/a\\>/", $vm_ret);
     $va_entity_relationships = $this->opt_object->get('ca_objects_x_entities.relation_id', array('returnAsArray' => true));
     $qr_entity_relationships = caMakeSearchResult('ca_objects_x_entities', $va_entity_relationships);
     $this->assertEquals(3, $qr_entity_relationships->numHits());
     while ($qr_entity_relationships->nextHit()) {
         $this->assertEquals('0', $qr_entity_relationships->get('ca_objects.deleted'));
         $this->assertEquals('0', $qr_entity_relationships->get('ca_entities.deleted'));
     }
     // there are no related list items
     $vm_ret = $this->opt_object->get('ca_list_items', array('returnAsArray' => true));
     $this->assertEmpty($vm_ret);
 }
 public function testDirectivesNestedInStaticHTMLForDisplay()
 {
     // Relative to relationship table as is done for displays
     $va_relation_ids = $this->opt_object->get('ca_objects_x_entities.relation_id', ['returnAsArray' => true]);
     $vm_ret = DisplayTemplateParser::evaluate('<ul style="list-style-type:none"><li><unit relativeTo="ca_entities"><l>^ca_entities.preferred_labels.displayname</l> (^ca_entities.idno)</li></unit></ul>', "ca_objects_x_entities", $va_relation_ids, array('returnAsArray' => true));
     $this->assertInternalType('array', $vm_ret);
     $this->assertCount(2, $vm_ret);
     $this->assertInternalType('string', $vm_ret[0]);
     $this->assertInternalType('string', $vm_ret[1]);
     $this->assertContains("editor/entities/EntityEditor/Summary/entity_id/" . $this->opn_entity_id1 . "\">Homer J. Simpson</a> (hjs)</li></ul>", $vm_ret[0]);
     $this->assertContains("editor/entities/EntityEditor/Summary/entity_id/" . $this->opn_entity_id2 . "\">Bart Simpson</a> (bs)</li></ul>", $vm_ret[1]);
 }
Exemplo n.º 8
0
 public function testExpressionTag()
 {
     // unit tag inside expression
     $this->assertEquals($this->opn_entity_id, caProcessTemplateForIDs('<expression>max(<unit relativeTo="ca_entities" delimiter=",">^ca_entities.entity_id</unit>)</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // just a plain tag .. 'My test image' is 13 chars
     $this->assertEquals(13, caProcessTemplateForIDs('<expression>length(^ca_objects.preferred_labels)</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // plain old scalars
     $this->assertEquals(9, caProcessTemplateForIDs('<expression>5 + 4</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // get entity names and their string lengths
     $this->assertEquals('Homer J. Simpson, 16; Bart Simpson, 12', caProcessTemplateForIDs('<unit relativeTo="ca_entities">^ca_entities.preferred_labels, <expression>length(^ca_entities.preferred_labels)</expression></unit>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // scalars in ifdef (false)
     $this->assertEmpty(caProcessTemplateForIDs('<ifdef code="ca_objects.description"><expression>5+9</expression></ifdef>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // scalars in ifdef (true)
     $this->assertEquals(9, caProcessTemplateForIDs('<ifdef code="ca_entities"><expression>5+4</expression></ifdef>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // hacked up way to count number of relationships
     $this->assertEquals(2, caProcessTemplateForIDs('<expression>sizeof(<unit relativeTo="ca_entities" delimiter=",">^ca_entities.entity_id</unit>)</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // no relationships exist for collections
     $this->assertEquals(0, caProcessTemplateForIDs('<expression>sizeof(<unit relativeTo="ca_collections" delimiter=",">^ca_collections.collection_id</unit>)</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // no relationships exist for collections
     $this->assertEquals(0, caProcessTemplateForIDs('<expression>sizeof(<unit relativeTo="ca_collections" delimiter=",">^ca_collections.collection_id</unit>)</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
     // age calculation
     $this->assertEquals(41, caProcessTemplateForIDs('<expression>age("23 June 1912", "7 June 1954")</expression>', 'ca_objects', array($this->opt_object->getPrimaryKey())));
 }
Exemplo n.º 9
0
 public function tearDown()
 {
     // set parent id to null for both children to avoid FK conflicts during tearDown()
     if ($this->opt_child_object instanceof ca_objects) {
         $this->opt_child_object->setMode(ACCESS_WRITE);
         $this->opt_child_object->set('parent_id', null);
         $this->opt_child_object->update();
     }
     if ($this->opt_another_child_object instanceof ca_objects) {
         $this->opt_another_child_object->setMode(ACCESS_WRITE);
         $this->opt_another_child_object->set('parent_id', null);
         $this->opt_another_child_object->update();
     }
     parent::tearDown();
 }
Exemplo n.º 10
0
 public function testGets()
 {
     $vm_ret = $this->opt_object->get('ca_objects.type_id', array('convertCodesToDisplayText' => true));
     $this->assertEquals('Moving Image', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.preferred_labels');
     $this->assertEquals('My test moving image', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.duration');
     $this->assertEquals('0:23:28', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.access');
     $this->assertEquals('0', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.access', array('convertCodesToDisplayText' => true));
     $this->assertEquals('not accessible to public', $vm_ret);
     $o_tep = new TimeExpressionParser();
     $vn_now = time();
     $vm_ret = $this->opt_object->get('ca_objects.lastModified');
     $this->assertTrue($o_tep->parse($vm_ret));
     $va_modified_unix = $o_tep->getUnixTimestamps();
     //$this->assertEquals($vn_now, $va_modified_unix['start'], 'lastModified timestamp cannot be more than 1 minute off', 60);
 }
Exemplo n.º 11
0
 public function testGets()
 {
     $vm_ret = $this->opt_object->get('ca_objects.type_id', array('convertCodesToDisplayText' => true));
     $this->assertEquals('Moving Image', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.preferred_labels');
     $this->assertEquals('My test moving image', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_objects.duration');
     $this->assertEquals('0:23:28', $vm_ret);
     $vm_ret = $this->opt_object->get('ca_item_comments.comment');
     $this->assertEquals('I like this very much.', $vm_ret);
     $this->assertTrue(!is_numeric($this->opt_object->get('ca_item_comments.created_on')));
     // should always be current date/time as text
     $o_tep = new TimeExpressionParser();
     $vn_now = time();
     $vm_ret = $this->opt_object->get('ca_objects.lastModified');
     $this->assertTrue($o_tep->parse($vm_ret));
     $va_modified_unix = $o_tep->getUnixTimestamps();
     //$this->assertEquals($vn_now, $va_modified_unix['start'], 'lastModified timestamp cannot be more than 1 minute off', 60);
 }
Exemplo n.º 12
0
 public function testGets()
 {
     $vm_ret = $this->opt_object->get('ca_objects.type_id', array('convertCodesToDisplayText' => true));
     $this->assertEquals('Image', $vm_ret);
     // it should get the en_US title here because at this point this is our "UI locale"
     $vm_ret = $this->opt_object->get('ca_objects.preferred_labels');
     $this->assertEquals('My test image', $vm_ret);
     // it should get the en_US title here because at this point this is our "UI locale"
     $vm_ret = $this->opt_object->get('ca_object_labels.name');
     $this->assertEquals('My test image', $vm_ret);
     // extract de_DE locale from array
     $vm_ret = $this->opt_object->get('ca_objects.preferred_labels', array('returnWithStructure' => true, 'returnAllLocales' => true));
     $this->assertInternalType('array', $vm_ret);
     $va_vals = array_shift(array_shift(caExtractValuesByLocale(array('preferred' => array('de_DE')), $vm_ret)));
     $this->assertEquals('Testbild', $va_vals['name']);
     // it should get the en_US title here because at this point this is our "UI locale"
     $vm_ret = $this->opt_object->get('ca_objects.nonpreferred_labels');
     $this->assertEquals('Alternative title for test image', $vm_ret);
     // extract de_DE locale from array
     $vm_ret = $this->opt_object->get('ca_objects.nonpreferred_labels', array('returnWithStructure' => true, 'returnAllLocales' => true));
     $this->assertInternalType('array', $vm_ret);
     $va_vals = array_shift(array_shift(caExtractValuesByLocale(array('preferred' => array('de_DE')), $vm_ret)));
     $this->assertEquals('Alternativer Titel für Testbild', $va_vals['name']);
 }
Exemplo n.º 13
0
/**
 * Perform mapping of extracted media metadata to CollectiveAccess bundles.
 *
 * @param BundlableLabelableBaseModelWithAttributes $po_instance Model instance to insert extracted metadata into
 * @param array $pa_metadata Extracted metadata
 * @param int $pn_locale_id The current locale as a numeric locale_id
 * @return bool True extracted metadata was mapped and the model changed, false if no change was made to the model
 */
function caExtractEmbeddedMetadata($po_instance, $pa_metadata, $pn_locale_id)
{
    if (!is_array($pa_metadata)) {
        return false;
    }
    $vb_did_mapping = false;
    if (!($vs_media_metadata_config = $po_instance->getAppConfig()->get('media_metadata'))) {
        return false;
    }
    $o_metadata_config = Configuration::load($vs_media_metadata_config);
    $va_mappings = $o_metadata_config->getAssoc('import_mappings');
    $vs_tablename = $po_instance->tableName();
    // set extracted georef?
    $va_georef_elements = $o_metadata_config->getList('extract_embedded_exif_georeferencing_to');
    $va_georef_containers = $o_metadata_config->getAssoc('extract_embedded_exif_georeferencing_to_container');
    $va_date_elements = $o_metadata_config->getList('extract_embedded_exif_creation_date_to');
    $va_date_containers = $o_metadata_config->getAssoc('extract_embedded_exif_creation_date_to_container');
    if (isset($pa_metadata['EXIF']) && is_array($pa_metadata['EXIF']) && (is_array($va_georef_elements) && sizeof($va_georef_elements) || is_array($va_georef_containers) && sizeof($va_georef_containers) || is_array($va_date_elements) && sizeof($va_date_elements) || is_array($va_date_containers) && sizeof($va_date_containers))) {
        $va_exif_data = $pa_metadata['EXIF'];
        if (is_array($va_georef_elements)) {
            if (is_array($va_coords = caParseEXIFLatLong($va_exif_data))) {
                foreach ($va_georef_elements as $vs_element) {
                    $va_tmp = explode('.', $vs_element);
                    $po_instance->addAttribute(array($va_tmp[1] => "[" . $va_coords['latitude'] . ", " . $va_coords['longitude'] . "]", 'locale_id' => $pn_locale_id), $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_georef_containers)) {
            if (is_array($va_coords = caParseEXIFLatLong($va_exif_data))) {
                foreach ($va_georef_containers as $vs_container => $va_info) {
                    $va_tmp = explode('.', $vs_container);
                    $vs_value_element = array_pop(explode('.', $va_info['value']));
                    $va_data = array($vs_value_element => "[" . $va_coords['latitude'] . ", " . $va_coords['longitude'] . "]", 'locale_id' => $pn_locale_id);
                    if (isset($va_info['map']) && is_array($va_info['map'])) {
                        foreach ($va_info['map'] as $vs_sub_element => $vs_value) {
                            $va_tmp2 = explode('.', $vs_sub_element);
                            $vs_sub_element = array_pop($va_tmp2);
                            if ($t_element = $po_instance->_getElementInstance($vs_sub_element)) {
                                switch ($t_element->get('datatype')) {
                                    case 3:
                                        // List
                                        $t_list = new ca_lists();
                                        $va_data[$vs_sub_element] = $t_list->getItemIDFromList($t_element->get('list_id'), $vs_value);
                                        break;
                                    default:
                                        $va_data[$vs_sub_element] = $vs_value;
                                        break;
                                }
                            }
                        }
                    }
                    $po_instance->addAttribute($va_data, $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_date_elements)) {
            if (($vs_raw_date = $va_exif_data['IFD0']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['EXIF']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['ExifIFD']['DateTimeOriginal'])) {
                $va_date_tmp = preg_split('![: ]+!', $vs_raw_date);
                $vs_date = $va_date_tmp[0] . '-' . $va_date_tmp[1] . '-' . $va_date_tmp[2] . 'T' . $va_date_tmp[3] . ':' . $va_date_tmp[4] . ':' . $va_date_tmp[5];
                foreach ($va_date_elements as $vs_element) {
                    $va_tmp = explode('.', $vs_element);
                    if (strlen($po_instance->get($vs_element)) > 0) {
                        $po_instance->addAttribute(array($va_tmp[1] => $vs_date, 'locale_id' => $pn_locale_id), $va_tmp[1]);
                    } else {
                        $po_instance->replaceAttribute(array($va_tmp[1] => $vs_date, 'locale_id' => $pn_locale_id), $va_tmp[1]);
                    }
                }
                $vb_did_mapping = true;
            }
        }
        if (is_array($va_date_containers)) {
            $t_list = new ca_lists();
            if (($vs_raw_date = $va_exif_data['IFD0']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['EXIF']['DateTimeOriginal']) || ($vs_raw_date = $va_exif_data['ExifIFD']['DateTimeOriginal'])) {
                $va_date_tmp = preg_split('![: ]+!', $vs_raw_date);
                $vs_date = $va_date_tmp[0] . '-' . $va_date_tmp[1] . '-' . $va_date_tmp[2] . 'T' . $va_date_tmp[3] . ':' . $va_date_tmp[4] . ':' . $va_date_tmp[5];
                foreach ($va_date_containers as $vs_container => $va_info) {
                    $va_tmp = explode('.', $vs_container);
                    $vs_value_element = array_pop(explode('.', $va_info['value']));
                    $va_data = array($vs_value_element => $vs_date, 'locale_id' => $pn_locale_id);
                    if (isset($va_info['map']) && is_array($va_info['map'])) {
                        foreach ($va_info['map'] as $vs_sub_element => $vs_value) {
                            $va_tmp2 = explode('.', $vs_sub_element);
                            $vs_sub_element = array_pop($va_tmp2);
                            if ($t_element = $po_instance->_getElementInstance($vs_sub_element)) {
                                switch ($t_element->get('datatype')) {
                                    case 3:
                                        // List
                                        $va_data[$vs_sub_element] = $t_list->getItemIDFromList($t_element->get('list_id'), $vs_value);
                                        break;
                                    default:
                                        $va_data[$vs_sub_element] = $vs_value;
                                        break;
                                }
                            }
                        }
                    }
                    $po_instance->addAttribute($va_data, $va_tmp[1]);
                }
                $vb_did_mapping = true;
            }
        }
    }
    if (!isset($va_mappings[$po_instance->tableName()])) {
        return $vb_did_mapping;
    }
    $va_mapping = $va_mappings[$vs_tablename];
    $vs_type = $po_instance->getTypeCode();
    if (isset($va_mapping[$vs_type]) && is_array($va_mapping[$vs_type])) {
        $va_mapping = $va_mapping[$vs_type];
    } else {
        if (isset($va_mapping['__default__']) && is_array($va_mapping['__default__'])) {
            $va_mapping = $va_mapping['__default__'];
        } else {
            return $vb_did_mapping;
        }
    }
    foreach ($va_mapping as $vs_metadata => $va_attr) {
        $va_tmp = explode(":", $vs_metadata);
        $vs_delimiter = caGetOption('delimiter', $va_attr, false);
        foreach ($va_attr as $vs_attr) {
            if ($vs_attr == 'delimiter') {
                continue;
            }
            $va_metadata =& $pa_metadata;
            foreach ($va_tmp as $vs_el) {
                if (isset($va_metadata[$vs_el])) {
                    $va_metadata =& $va_metadata[$vs_el];
                } else {
                    continue 2;
                }
            }
            if (is_array($va_metadata)) {
                $va_metadata = join(";", $va_metadata);
            }
            if (!is_int($va_metadata)) {
                // pass ints through for values like WhiteBalance = 0
                if (!trim($va_metadata)) {
                    continue 2;
                }
            }
            if (!caSeemsUTF8($va_metadata)) {
                $va_metadata = caEncodeUTF8Deep($va_metadata);
            }
            $va_tmp2 = explode(".", $vs_attr);
            switch ($va_tmp2[0]) {
                case 'preferred_labels':
                    $po_instance->replaceLabel(array($va_tmp2[1] => $va_metadata), $pn_locale_id, null, true);
                    break;
                case 'nonpreferred_labels':
                    $po_instance->replaceLabel(array($va_tmp2[1] => $va_metadata), $pn_locale_id, null, false);
                    break;
                default:
                    if ($po_instance->hasField($vs_attr)) {
                        $po_instance->set($vs_attr, $va_metadata);
                    } else {
                        // try as attribute
                        if (sizeof($va_tmp2) == 2) {
                            // format ca_objects.foo, we only want "foo"
                            if ($vs_delimiter) {
                                $va_m = explode($vs_delimiter, $va_metadata);
                                $po_instance->removeAttributes($va_tmp2[1]);
                                foreach ($va_m as $vs_m) {
                                    $po_instance->addAttribute(array($va_tmp2[1] => trim($vs_m), 'locale_id' => $pn_locale_id), $va_tmp2[1]);
                                }
                            } else {
                                $po_instance->replaceAttribute(array($va_tmp2[1] => $va_metadata, 'locale_id' => $pn_locale_id), $va_tmp2[1]);
                            }
                        }
                    }
            }
            $vb_did_mapping = true;
        }
    }
    return $vb_did_mapping;
}
Exemplo n.º 14
0
 public function insert($pa_options = null)
 {
     $vn_rc = parent::insert($pa_options);
     if ($this->getPrimaryKey()) {
         // create root in ca_list_items
         $t_item_root = new ca_editor_ui_screens();
         $t_item_root->setMode(ACCESS_WRITE);
         $t_item_root->set('ui_id', $this->getPrimaryKey());
         $t_item_root->set('is_default', 0);
         $t_item_root->insert();
         if ($t_item_root->numErrors()) {
             $this->delete();
             $this->errors = array_merge($this->errors, $t_item_root->errors);
         }
     }
     return $vn_rc;
 }
Exemplo n.º 15
0
/**
 * Get bundle preview for a relationship bundle
 * @param BundlableLabelableBaseModelWithAttributes $t_rel_instance
 * @param array $pa_initial_values
 * @param string $ps_template
 * @param string $ps_delimiter
 * @return string
 */
function caGetBundlePreviewForRelationshipBundle($t_rel_instance, $pa_initial_values, $ps_template, $ps_delimiter = '; ')
{
    if (!is_array($pa_initial_values) || sizeof($pa_initial_values) == 0) {
        return '""';
    }
    // it's very unlikely that the preview will fit more then 10 items
    if (sizeof($pa_initial_values) > 10) {
        $pa_initial_values = array_slice($pa_initial_values, 0, 10);
    }
    if (!$t_rel_instance instanceof BundlableLabelableBaseModelWithAttributes) {
        return '""';
    }
    $va_ids = $va_previews = array();
    foreach ($pa_initial_values as $va_item) {
        $va_ids[] = $va_item['id'];
    }
    $o_res = $t_rel_instance->makeSearchResult($t_rel_instance->tableName(), $va_ids);
    while ($o_res->nextHit()) {
        $va_previews[] = $o_res->getWithTemplate($ps_template);
    }
    return caEscapeForBundlePreview(join($ps_delimiter, $va_previews));
}
Exemplo n.º 16
0
 /**
  * Override BaseModel::delete() because the cascading delete implemented there
  * doesn't properly remove related items if they're organized in a ad-hoc hierarchy.
  */
 public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null)
 {
     if ($pb_delete_related) {
         $this->removeAllItems();
     }
     return parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list);
 }
Exemplo n.º 17
0
 /**
  * @param array $pa_options
  *		duplicate_subitems
  */
 public function duplicate($pa_options = null)
 {
     $vb_we_set_transaction = false;
     if (!$this->inTransaction()) {
         $this->setTransaction($o_trans = new Transaction($this->getDb()));
         $vb_we_set_transaction = true;
     } else {
         $o_trans = $this->getTransaction();
     }
     if ($t_dupe = parent::duplicate($pa_options)) {
         $vb_duplicate_subitems = caGetOption('duplicate_subitems', $pa_options, false);
         if ($vb_duplicate_subitems) {
             // Try to dupe related ca_set_items rows
             $o_db = $this->getDb();
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM ca_set_items\n\t\t\t\t\tWHERE set_id = ?\n\t\t\t\t", (int) $this->getPrimaryKey());
             $va_items = array();
             while ($qr_res->nextRow()) {
                 $va_items[$qr_res->get('item_id')] = $qr_res->getRow();
             }
             foreach ($va_items as $vn_item_id => $va_item) {
                 $t_item = new ca_set_items();
                 $t_item->setTransaction($o_trans);
                 $t_item->setMode(ACCESS_WRITE);
                 $va_item['set_id'] = $t_dupe->getPrimaryKey();
                 $t_item->set($va_item);
                 $t_item->insert();
                 if ($t_item->numErrors()) {
                     $this->errors = $t_item->errors;
                     if ($vb_we_set_transaction) {
                         $this->removeTransaction(false);
                     }
                     return false;
                 }
             }
         }
     }
     if ($vb_we_set_transaction) {
         $this->removeTransaction(true);
     }
     return $t_dupe;
 }
Exemplo n.º 18
0
 protected function initLabelDefinitions($pa_options = null)
 {
     parent::initLabelDefinitions($pa_options);
     $this->BUNDLES['ca_editor_ui_bundle_placements'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Screen content'));
     $this->BUNDLES['ca_editor_ui_screen_type_restrictions'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Type restrictions'));
 }
Exemplo n.º 19
0
 protected function initLabelDefinitions($pa_options = null)
 {
     parent::initLabelDefinitions($pa_options);
     $this->BUNDLES['ca_users'] = array('type' => 'special', 'repeating' => true, 'label' => _t('User access'));
     $this->BUNDLES['ca_user_groups'] = array('type' => 'special', 'repeating' => true, 'label' => _t('Group access'));
     $this->BUNDLES['ca_search_form_placements'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Search form contents'));
     $this->BUNDLES['settings'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Search form settings'));
 }
 /**
  * Override BundlableLabelableBaseModelWithAttribute::get() to allow getting 
  * annotation properties in simple get()-style notations like
  *   ca_representations_annotations.props.w
  */
 public function get($ps_field, $pa_options = null)
 {
     $va_tmp = explode('.', $ps_field);
     // remove table name if needed
     if (isset($va_tmp[0]) && $va_tmp[0] == $this->tableName()) {
         array_shift($va_tmp);
     }
     if (sizeof($va_tmp) == 2 && isset($va_tmp[0]) && $va_tmp[0] == 'props') {
         $vm_val = $this->getPropertyValue($va_tmp[1]);
         // this should be moved into the property implementation but for now, points is the only occurrence
         // of this kind of thing and getProperty() doesn't support any options so this is a reasonable quick&dirty way.
         if (is_array($vm_val) && !caGetOption('returnAsArray', $pa_options)) {
             switch ($va_tmp[1]) {
                 case 'points':
                     $va_return = array();
                     foreach ($vm_val as $va_point) {
                         $va_return[] = $va_point['x'] . ',' . $va_point['y'];
                     }
                     if (!($vs_delimiter = caGetOption('delimiter', $pa_options))) {
                         $vs_delimiter = '; ';
                     }
                     return join($vs_delimiter, $va_return);
                     break;
                 default:
                     return $vm_val;
             }
         }
         return $vm_val;
     }
     return parent::get($ps_field, $pa_options);
 }
Exemplo n.º 21
0
 protected function initLabelDefinitions($pa_options = null)
 {
     parent::initLabelDefinitions($pa_options);
     $this->BUNDLES['preferred_labels'] = array('type' => 'preferred_label', 'repeating' => true, 'label' => _t("Item captions"));
 }
Exemplo n.º 22
0
/**
 * Generates batch mode control HTML for batch editor relationship bundles
 *
 * @param BundlableLabelableBaseModelWithAttributes $t_item 
 * @param string $ps_id_prefix
 * 
 * @return string HTML implementing the control
 */
function caBatchEditorRelationshipModeControl($t_item, $ps_id_prefix)
{
    $vs_buf = "\t<div class='editorBatchModeControl'>" . _t("In batch") . " " . caHTMLSelect($ps_id_prefix . "_batch_mode", array(_t("do not use") => "_disabled_", _t('add to each item') => '_add_', _t('replace value') => '_replace_', _t('remove all values') => '_delete_'), array('id' => $ps_id_prefix . $t_item->tableNum() . '_rel_batch_mode_select')) . "</div>\n\n\n\t<script type=\"text/javascript\">\n\t\tjQuery(document).ready(function() {\n\t\t\tjQuery('#" . $ps_id_prefix . $t_item->tableNum() . "_rel_batch_mode_select').change(function() {\n\t\t\t\tif ((jQuery(this).val() == '_disabled_') || (jQuery(this).val() == '_delete_')) {\n\t\t\t\t\tjQuery('#" . $ps_id_prefix . $t_item->tableNum() . "_rel').slideUp(250);\n\t\t\t\t} else {\n\t\t\t\t\tjQuery('#" . $ps_id_prefix . $t_item->tableNum() . "_rel').slideDown(250);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>\n";
    return $vs_buf;
}
 /**
  * Get cached time expression parser instance. Instance is shared across all models.
  */
 public function getTimeExpressionParser()
 {
     if (!BundlableLabelableBaseModelWithAttributes::$s_tep) {
         BundlableLabelableBaseModelWithAttributes::$s_tep = new TimeExpressionParser();
     }
     return BundlableLabelableBaseModelWithAttributes::$s_tep;
 }
Exemplo n.º 24
0
 protected function initLabelDefinitions($pa_options = null)
 {
     parent::initLabelDefinitions($pa_options);
     $this->BUNDLES['ca_users'] = array('type' => 'special', 'repeating' => true, 'label' => _t('User access'));
     $this->BUNDLES['ca_user_groups'] = array('type' => 'special', 'repeating' => true, 'label' => _t('Group access'));
     $this->BUNDLES['ca_bundle_display_placements'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Display list contents'));
     $this->BUNDLES['settings'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Display settings'));
     $this->BUNDLES['ca_bundle_display_type_restrictions'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Type restrictions'));
 }
 /**
  * Override update() to set table_num to whatever the parent is
  */
 public function update($pa_options = null)
 {
     if ($vn_parent_id = $this->get('parent_id')) {
         $t_root_rel_type = new ca_relationship_types($vn_parent_id);
         if ($vn_table_num = $t_root_rel_type->get('table_num')) {
             $this->set('table_num', $vn_table_num);
         }
     }
     $vb_we_set_transaction = false;
     if (!$this->inTransaction()) {
         $this->setTransaction($o_trans = new Transaction($this->getDb()));
         $vb_we_set_transaction = true;
     } else {
         $o_trans = $this->getTransaction();
     }
     if ($this->get('is_default')) {
         $o_trans->getDb()->query("\n\t\t\t\tUPDATE ca_relationship_types \n\t\t\t\tSET is_default = 0 \n\t\t\t\tWHERE table_num = ?\n\t\t\t", (int) $t_root_rel_type->get('table_num'));
     }
     if (!($vn_rc = parent::update($pa_options))) {
         if ($vb_we_set_transaction) {
             $o_trans->rollback();
         }
     } else {
         if ($vb_we_set_transaction) {
             $o_trans->commit();
         }
     }
     $this->loadSubtypeLists();
     return $vn_rc;
 }
Exemplo n.º 26
0
 /**
  * Override set() to do idno lookups on tours
  *
  */
 public function set($pa_fields, $pm_value = "", $pa_options = null)
 {
     if (!is_array($pa_fields)) {
         $pa_fields = array($pa_fields => $pm_value);
     }
     foreach ($pa_fields as $vs_fld => $vs_val) {
         if ($vs_fld == 'tour_id' && preg_match("![^\\d]+!", $vs_val)) {
             if ($vn_tour_id = caGetTourID($vs_val)) {
                 $pa_fields[$vs_fld] = $vn_tour_id;
             }
         }
     }
     return parent::set($pa_fields, null, $pa_options);
 }
 /**
  * Override export function to do some cleanup in the media_metadata part.
  * XML parsers and wrappers like DOMDocument tend to be rather picky with their input as far as invalid
  * characters go and the return value of this function is usually used for something like that.
  */
 public function getValuesForExport($pa_options = null)
 {
     $va_export = parent::getValuesForExport($pa_options);
     // this section tends to contain wonky chars that are close to impossible to clean up
     // if you read through the EXIF specs you know why ...
     if (isset($va_export['media_metadata']['EXIF']['IFD0'])) {
         unset($va_export['media_metadata']['EXIF']['IFD0']);
     }
     return $va_export;
 }
Exemplo n.º 28
0
 /**
  * Overrides BundlableLabelableBaseModelWithAttributes:isDeletable to implement system list access restrictions
  */
 public function isDeletable($po_request)
 {
     if (parent::isDeletable($po_request)) {
         // user could delete this list
         if ($this->getPrimaryKey()) {
             if ($this->get('is_system_list')) {
                 if (!$po_request->user->canDoAction('can_delete_system_lists')) {
                     return false;
                 }
             }
         }
         return true;
     } else {
         // BundlableLabelableBaseModelWithAttributes:isDeletable returned false
         // => user can't delete this list at all, no matter how is_system_list is set
         return false;
     }
 }
Exemplo n.º 29
0
 /**
  * @param array $pa_options
  *		duplicate_subitems
  */
 public function duplicate($pa_options = null)
 {
     $vb_we_set_transaction = false;
     if (!$this->inTransaction()) {
         $this->setTransaction($o_t = new Transaction($this->getDb()));
         $vb_we_set_transaction = true;
     } else {
         $o_t = $this->getTransaction();
     }
     if ($t_dupe = parent::duplicate($pa_options)) {
         $vb_duplicate_subitems = caGetOption('duplicate_subitems', $pa_options, false);
         if ($vb_duplicate_subitems) {
             // Try to dupe related ca_tour_stops rows
             $o_db = $this->getDb();
             $qr_res = $o_db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM ca_tour_stops\n\t\t\t\t\tWHERE \n\t\t\t\t\t\ttour_id = ? AND deleted = 0\n\t\t\t\t", (int) $this->getPrimaryKey());
             $va_stops = array();
             while ($qr_res->nextRow()) {
                 //$va_stops[$qr_res->get('stop_id')] = $qr_res->getRow();
                 $t_stop = new ca_tour_stops();
                 $t_stop->setTransaction($o_t);
                 $t_stop->load($qr_res->get('stop_id'));
                 if ($t_dupe_stop = $t_stop->duplicate($pa_options)) {
                     $t_dupe_stop->setTransaction($o_t);
                     $t_dupe_stop->setMode(ACCESS_WRITE);
                     $t_dupe_stop->set('tour_id', $t_dupe->getPrimaryKey());
                     $t_dupe_stop->update();
                     if ($t_dupe_stop->numErrors()) {
                         $this->errors = $t_dupe_stop->errors;
                         if ($vb_we_set_transaction) {
                             $this->removeTransaction(false);
                         }
                         return false;
                     }
                 }
             }
         }
     }
     if ($vb_we_set_transaction) {
         $this->removeTransaction(true);
     }
     return $t_dupe;
 }
Exemplo n.º 30
0
 protected function initLabelDefinitions($pa_options = null)
 {
     parent::initLabelDefinitions($pa_options);
 }