示例#1
0
 /**
  * Returns the relation ids for the variable specified of the object
  * @param epObject $o the object
  * @param epFieldMap $fm the field map of the variable
  * @param epClassMap $cm the class map of the object
  * @return false|string|array
  */
 public function getRelationIds(&$o, $fm, $cm)
 {
     // make sure we are dealing with valid object and non-primitive field
     if (!$o || !$fm || !$cm) {
         return false;
     }
     // object needs to have a valid id and has to be non-primitive
     if (!($oid_a = $o->epGetObjectId())) {
         return false;
     }
     // get class_a, var_a, and the related class
     $base_a = $fm->getBase_a();
     $class_a = $cm->getName();
     $var_a = $fm->getName();
     $base_b = $fm->getBase_b();
     if (!$base_a || !$class_a || !$var_a || !$base_b) {
         throw new epExceptionManager('Cannot find related class for var [' . $class_a . '::' . $var_a . ']');
         return false;
     }
     // switch relations table
     $this->_setRelationTable($base_a, $base_b);
     // make an example relation objects
     if (!($eo =& $this->_relationExample($class_a, $oid_a, $var_a, $base_b))) {
         return false;
     }
     // find all relation objects using the example object
     // (find from db only, false: no cache, false: don't convert to objects)
     $rs =& parent::find($eo, EP_GET_FROM_DB, false, false);
     // convert result into oids
     $oids_b = null;
     if ($fm->isSingle()) {
         if (is_array($rs) && count($rs) > 1) {
             throw new epExceptionManager('Field ' . $fm->getName() . ' mapped as composed_of_/has_one but is associated with > 1 objects');
             return false;
         }
         if ($rs) {
             $oids_b = $rs[0];
         }
     } else {
         if ($fm->isMany()) {
             $oids_b = array();
             if ($rs) {
                 $oids_b = $rs;
             }
         }
     }
     return $oids_b;
 }