Exemplo n.º 1
0
 /**
  * @todo: docs
  */
 public function getCategory($group_string)
 {
     $prev = null;
     foreach (explode('/', $group_string) as $piece) {
         $qc = new midgard_query_constraint_group('AND');
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('name'), '=', new midgard_query_value($piece)));
         $qc->add_constraint(new midgard_query_constraint(new midgard_query_property('up'), '=', new midgard_query_value($prev === null ? 0 : $prev->id)));
         $q = new midgard_query_select(new midgard_query_storage('com_meego_package_category'));
         $q->set_constraint($qc);
         $q->execute();
         $results = $q->list_objects();
         if (count($results) === 0) {
             $category = new com_meego_package_category();
             $category->name = $piece;
             $category->up = $prev === null ? 0 : $prev->id;
             $category->create();
             $prev = $category;
         } else {
             $prev = $results[0];
         }
     }
     // check if this category is already mapped to a base category
     $q = new midgard_query_select(new midgard_query_storage('com_meego_package_category_relation'));
     $qc = new midgard_query_constraint(new midgard_query_property('packagecategory'), '=', new midgard_query_value($prev->id));
     $q->set_constraint($qc);
     $q->execute();
     $results = $q->list_objects();
     if (!count($results)) {
         // check if there is an "Other" basecategory
         $q = new midgard_query_select(new midgard_query_storage('com_meego_package_basecategory'));
         $qc = new midgard_query_constraint(new midgard_query_property('name'), '=', new midgard_query_value('Other'));
         $q->set_constraint($qc);
         $q->execute();
         $results = $q->list_objects();
         if (count($results)) {
             // map this category to "Other" by default
             $relation = new com_meego_package_category_relation();
             $relation->basecategory = $results[0]->id;
             $relation->packagecategory = $prev->id;
             $relation->create();
             $this->log('           package category ' . $group_string . ' is mapped to ' . $results[0]->name);
         }
     }
     return $prev->id;
 }
Exemplo n.º 2
0
 /**
  * Update, delete, undelete a basecategory
  */
 public function post_manage_basecategory(array $args)
 {
     $this->mvc->authorization->require_admin();
     $this->data['category'] = false;
     $this->data['undelete'] = false;
     $this->data['undelete_error'] = false;
     $this->data['form_action'] = $this->get_url_read($args['basecategory']);
     $this->data['indexurl'] = $this->get_url_admin_index();
     // some counters need to be reset
     $this->data['mapping_counter'] = 0;
     $this->data['package_counter'] = 0;
     if (array_key_exists('undelete', $_POST)) {
         if (!midgard_object_class::undelete($args['basecategory'])) {
             $this->data['undelete_error'] = true;
             $this->data['status'] = 'error';
             $this->data['feedback_objectname'] = $args['basecategory'];
             $this->data['feedback'] = 'feedback_basecategory_undelete_failed';
             return;
         }
     }
     try {
         $this->load_object($args);
     } catch (midgard_error_exception $e) {
         $this->data['status'] = 'error';
         $this->data['feedback_objectname'] = $args['basecategory'];
         $this->data['feedback'] = 'feedback_basecategory_does_not_exist';
         $this->data['undelete_error'] = true;
         return;
     }
     if (array_key_exists('undelete', $_POST)) {
         $relations = self::load_relations_for_basecategory($this->object->id, true);
         if (is_array($relations)) {
             foreach ($relations as $relation) {
                 midgard_object_class::undelete($relation->guid);
             }
         }
         // refresh mapping table
         $this->prepare_mapping($this->object);
         // set feedback and let it go
         $this->data['feedback'] = 'feedback_basecategory_undelete_ok';
     }
     $this->data['status'] = 'status';
     $this->data['category'] = $this->object;
     $this->data['feedback_objectname'] = $this->object->name;
     if (array_key_exists('update', $_POST)) {
         $new_name = trim(htmlentities($_POST['categories'][$this->object->name]['name']));
         $new_description = trim(htmlentities($_POST['categories'][$this->object->name]['description']));
         if (strlen($new_name) == 0) {
             $this->data['status'] = 'error';
             $this->data['feedback'] = 'error_basecategory_name_empty';
             return;
         }
         if ($new_name == $this->object->name) {
             if ($new_description == $this->object->description) {
                 $this->data['feedback'] = 'feedback_basecategory_no_change';
                 return;
             }
         }
         $this->prepare_mapping($this->object);
         $this->object->name = $new_name;
         $this->object->description = $new_description;
         $this->object->update();
         $this->data['feedback_objectname'] = $this->object->name;
         $this->data['feedback'] = 'feedback_basecategory_update_ok';
     } elseif (array_key_exists('updatemapping', $_POST)) {
         // delete all mappings of this base category
         $this->delete_relations($this->object->id, true);
         // set relations to db if they were posted
         if (array_key_exists('mapped', $_POST)) {
             foreach ($_POST['mapped'] as $packagecategory) {
                 $newrelation = new com_meego_package_category_relation();
                 $newrelation->basecategory = $this->object->id;
                 $newrelation->packagecategory = $packagecategory;
                 if ($newrelation->basecategory != 0 && $newrelation->packagecategory != 0) {
                     $newrelation->create();
                 }
             }
             $this->data['feedback'] = 'feedback_category_mapping_updated_ok';
         }
         // set the list of all package categories, but set it so
         // that parents are also part of the category name, e.g. Application:Games, not just Games
         $this->prepare_mapping($this->object);
     } elseif (array_key_exists('delete', $_POST)) {
         // delete the base category
         $this->object->delete();
         // delete all its relations
         self::delete_relations($this->object->id, false);
         // allow undelete
         $this->data['undelete'] = true;
         // set feedback
         $this->data['feedback'] = 'feedback_basecategory_delete_ok';
         // some counters need to be reset
         $this->data['mapping_counter'] = 0;
         $this->data['package_counter'] = 0;
     } elseif (array_key_exists('index', $_POST)) {
         $this->mvc->head->relocate($this->get_url_admin_index());
     }
 }