xtech Posted August 3, 2016 Posted August 3, 2016 Hi, i've been checking the function getReciprocalItems() and it return an array as {field_id} => array( object, object... ) The problem is, the objects are not ordered by anything (other by the order they are got from the cms_database_fields_reciprocal_map records order, which sucks. There is no easy solution for this. I suggest providing another function to return all the records as an array( object, object... ), as people can then test for what type of record it is. For example, i've created a new function that orders all the records (regardless of the field_id) by date (descending), yet this is far from an optimal solution: static function jmorder($a, $b) { $result = 0; if ($a->record_saved > $b->record_saved) $result = 1; else if ($a->record_saved < $b->record_saved) $result = -1; return $result; } public function getReciprocalItemsJM() { /* Check to see if any fields are linking to this database in this easy to use method wot I writted myself */ if ( \IPS\cms\Databases::hasReciprocalLinking( static::database()->_id ) ) { $return = array(); /* Oh that's just lovely then. Lets be a good fellow and fetch the items then! */ foreach( \IPS\Db::i()->select( '*', 'cms_database_fields_reciprocal_map', array( 'map_foreign_database_id=? and map_foreign_item_id=?', static::database()->_id, $this->primary_id_field ) ) as $record ) { try { $recordClass = 'IPS\cms\Records' . $record['map_origin_database_id']; $return[] = $recordClass::load( $record['map_origin_item_id'] ); } catch ( \Exception $ex ) { } } /* Has something gone all kinds of wonky? */ if ( ! count( $return ) ) { return FALSE; } usort($return, array($this, "jmorder")); return $return; } I guess providing some overloading functions / additional functions to get more flexibility concerning the results of the getReciprocalItems() would be great. The way it works now is is very very limited.
Jacques Corby-Tuech Posted April 29, 2017 Posted April 29, 2017 @xtech if I understand this right, it means I can't create separate lookups for reciprocal items based on what database they're in? That sucks
Recommended Posts
Archived
This topic is now archived and is closed to further replies.