/** * Return last storage location as an ca_objects_x_storage_locations instance */ public function getLastLocation($pa_options = null) { $pn_object = caGetOption('object_id', $pa_options, null); if (!($vn_object_id = $pn_object_id > 0 ? $pn_object_id : $this->getPrimaryKey())) { return null; } $va_current_date = caDateToHistoricTimestamps(_t('now')); $vn_current_date = $va_current_date['start']; $o_db = $this->getDb(); $qr_res = $o_db->query("\n \t\t\tSELECT csl.relation_id\n \t\t\tFROM ca_objects_x_storage_locations csl\n \t\t\tINNER JOIN ca_storage_locations AS sl ON sl.location_id = csl.location_id\n \t\t\tWHERE\n \t\t\t\t(csl.object_id = ?) AND \n \t\t\t\t(sl.deleted = 0) AND (csl.sdatetime <= ?)\n \t\t\tORDER BY\n \t\t\t\tcsl.sdatetime DESC, csl.relation_id DESC\n \t\t\tLIMIT 1\n \t\t", array($vn_object_id, $vn_current_date)); if ($qr_res->nextRow()) { $t_loc = new ca_objects_x_storage_locations($qr_res->get('relation_id')); if ($this->inTransaction()) { $t_loc->setTransaction($this->getTransaction()); } return $t_loc; } return false; }