Example #1
0
 /**
  * Helper method to resolve path for an object
  */
 public static function resolve_path(&$object, $title)
 {
     if (!class_exists('midcom_helper_reflector_tree')) {
         return $title;
     }
     return midcom_helper_reflector_tree::resolve_path($object);
 }
Example #2
0
 private function _get_product_group_tree($up)
 {
     $groups = array();
     $qb = org_openpsa_products_product_group_dba::new_query_builder();
     $qb->add_constraint('up', '=', $up);
     $qb->add_order('metadata.score');
     $results = $qb->execute();
     foreach ($results as $result) {
         $groups[$result->id] = midcom_helper_reflector_tree::resolve_path($result);
         $subgroups = $this->_get_product_group_tree($result->id);
         foreach ($subgroups as $k => $v) {
             $groups[$k] = $v;
         }
     }
     return $groups;
 }
Example #3
0
 /**
  * Helper for name_is_unique, checks uniqueness for each root level class
  *
  * @param array $sibling_classes array of classes to check
  * @return boolean true means no clashes, false means clash.
  */
 private function _name_is_unique_check_roots($sibling_classes)
 {
     if (!$sibling_classes) {
         // We don't know about siblings, allow this to happen.
         // Note: This also happens with the "neverchild" types like midgard_attachment and midgard_parameter
         return true;
     }
     $name_copy = $this->get_object_name();
     foreach ($sibling_classes as $schema_type) {
         $dummy = new $schema_type();
         $child_name_property = midcom_helper_reflector::get_name_property($dummy);
         unset($dummy);
         if (empty($child_name_property)) {
             // This sibling class does not use names
             /**
              * Noise, useful when something is going wrong in *weird* way
              *
             debug_add("Sibling class {$schema_type} does not have 'name' property, skipping from checks");
             */
             continue;
         }
         $resolver =& midcom_helper_reflector_tree::get($schema_type);
         $deleted = false;
         $qb =& $resolver->_root_objects_qb($deleted);
         unset($deleted);
         if (!is_object($qb)) {
             continue;
         }
         $qb->add_constraint($child_name_property, '=', $name_copy);
         // Do not include current object in results, this is the easiest way
         if (isset($this->_object->guid) || !empty($this->_object->guid)) {
             $qb->add_constraint('guid', '<>', $this->_object->guid);
         }
         // One result is enough to know we have a clash
         $qb->set_limit(1);
         $results = $qb->count();
         // Guard against QB failure
         if ($results === false) {
             midcom::get('auth')->drop_sudo();
             debug_add("Querying for siblings of class {$schema_type} failed critically, last Midgard error: " . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR);
             unset($sibling_classes, $schema_type, $qb, $resolver);
             return false;
         }
         if ($results > 0) {
             debug_add("Name clash in sibling class {$schema_type} for " . get_class($this->_object) . " #{$this->_object->id} (path '" . midcom_helper_reflector_tree::resolve_path($this->_object, '/') . "')");
             unset($sibling_classes, $schema_type, $qb, $resolver);
             return false;
         }
     }
     return true;
 }