From e1626b20ad34864d624bb7ae21e24d55c1a64bed Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 21 Dec 2011 17:49:41 +0100 Subject: [PATCH] Fix grouping methods --- lib/classes/basket/adapter.class.php | 78 ---------- lib/classes/record/adapter.class.php | 206 ++++++++++++++++++++++++--- lib/classes/set/export.class.php | 4 +- 3 files changed, 191 insertions(+), 97 deletions(-) diff --git a/lib/classes/basket/adapter.class.php b/lib/classes/basket/adapter.class.php index fb65eb54ee..c2a3d6f63b 100644 --- a/lib/classes/basket/adapter.class.php +++ b/lib/classes/basket/adapter.class.php @@ -1078,31 +1078,6 @@ class basket_adapter implements cache_cacheableInterface return true; } - /** - * - * @param databox_descriptionStructure $meta_struct - * @return - */ - public function searchRegFields(databox_descriptionStructure $meta_struct) - { - $fields = null; - $fields["regname"] = ""; - $fields["regdesc"] = ""; - $fields["regdate"] = ""; - - foreach ($meta_struct as $meta) - { - if ($meta->is_regname()) - $fields["regname"] = $meta->get_id(); - elseif ($meta->is_regdesc()) - $fields["regdesc"] = $meta->get_id(); - elseif ($meta->is_regdate()) - $fields['regdate'] = $meta->get_id(); - } - - return $fields; - } - /** * * @return string @@ -1176,24 +1151,6 @@ class basket_adapter implements cache_cacheableInterface return $this; } - /** - * get databox reg fields - * - * @todo change this shit - * @return array - */ - public static function load_regfields() - { - $appbox = appbox::get_instance(); - self::$_regfields = array(); - foreach ($appbox->get_databoxes() as $databox) - { - self::$_regfields[$databox->get_sbas_id()] = self::searchRegFields($databox->get_meta_structure()); - } - - return self::$_regfields; - } - /** * * @param appbox $appbox @@ -1657,41 +1614,6 @@ class basket_adapter implements cache_cacheableInterface return $ret; } - /** - * - * @param $sbas_id - * @param caption_record $desc - * @return - */ - public static function getRegFields($sbas_id, caption_record $desc) - { - if (!self::$_regfields) - self::load_regfields(); - - $arrayRegFields = self::$_regfields[$sbas_id]; - - $array = array(); - - foreach ($arrayRegFields as $k => $f) - { - $array[$f] = $k; - } - - $fields = array(); - $fields["regname"] = ""; - $fields["regdesc"] = ""; - $fields["regdate"] = ""; - - foreach ($desc->get_fields() as $caption_field) - { - $meta_struct_id = $caption_field->get_meta_struct_id(); - if (array_key_exists($meta_struct_id, $array)) - $fields[$array[$meta_struct_id]] = $caption_field->get_value(); - } - - return $fields; - } - /** * * @param appbox $appbox diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index 1167f5144b..22bf8b7514 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -140,6 +140,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface const CACHE_GROUPING = 'grouping'; const CACHE_STATUS = 'status'; + + protected static $_regfields; + /** * * @param $base_id @@ -180,7 +183,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } $connbas = $this->databox->get_connection(); @@ -530,7 +533,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } return null; @@ -580,7 +583,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } $sql = 'SELECT BIN(status) as status FROM record WHERE record_id = :record_id'; @@ -617,7 +620,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface throw new Exception_Media_SubdefNotFound (); if (isset($this->subdefs[$name])) - return $this->subdefs[$name]; if (!$this->subdefs) @@ -658,7 +660,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } $connbas = $this->get_databox()->get_connection(); @@ -757,10 +759,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface if ($data) { if (isset($this->technical_datas[$data])) - return $this->technical_datas[$data]; else - return false; } @@ -851,6 +851,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface $sbas_id = $this->get_sbas_id(); $record_id = $this->get_record_id(); + if ($this->is_grouping()) + { + $regfield = self::getRegFields($sbas_id, $this->get_caption()); + + return $regfield['regname']; + } + $title = ''; $appbox = appbox::get_instance(); $session = $appbox->get_session(); @@ -890,6 +897,95 @@ class record_adapter implements record_Interface, cache_cacheableInterface return $title; } + public function get_description() + { + + if (!$this->is_grouping()) + throw new \Exception('This record is not a story'); + + $regfield = self::getRegFields($this->get_sbas_id(), $this->get_caption()); + + return $regfield['regdesc']; + } + + /** + * + * @param $sbas_id + * @param caption_record $desc + * @return + */ + protected static function getRegFields($sbas_id, caption_record $desc) + { + if (!self::$_regfields) + self::load_regfields(); + + $arrayRegFields = self::$_regfields[$sbas_id]; + + $array = array(); + + foreach ($arrayRegFields as $k => $f) + { + $array[$f] = $k; + } + + $fields = array(); + $fields["regname"] = ""; + $fields["regdesc"] = ""; + $fields["regdate"] = ""; + + foreach ($desc->get_fields() as $caption_field) + { + $meta_struct_id = $caption_field->get_meta_struct_id(); + if (array_key_exists($meta_struct_id, $array)) + $fields[$array[$meta_struct_id]] = $caption_field->get_value(); + } + + return $fields; + } + + /** + * get databox reg fields + * + * @todo change this shit + * @return array + */ + protected static function load_regfields() + { + $appbox = appbox::get_instance(); + self::$_regfields = array(); + foreach ($appbox->get_databoxes() as $databox) + { + self::$_regfields[$databox->get_sbas_id()] = self::searchRegFields($databox->get_meta_structure()); + } + + return self::$_regfields; + } + + /** + * + * @param databox_descriptionStructure $meta_struct + * @return + */ + protected function searchRegFields(databox_descriptionStructure $meta_struct) + { + $fields = null; + $fields["regname"] = ""; + $fields["regdesc"] = ""; + $fields["regdate"] = ""; + + foreach ($meta_struct as $meta) + { + if ($meta->is_regname()) + $fields["regname"] = $meta->get_id(); + elseif ($meta->is_regdesc()) + $fields["regdesc"] = $meta->get_id(); + elseif ($meta->is_regdate()) + $fields['regdate'] = $meta->get_id(); + } + + return $fields; + } + /** * * @return media_subdef @@ -1242,7 +1338,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } $this->delete_data_from_cache(self::CACHE_STATUS); @@ -1257,7 +1353,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_reg_name() { if (!$this->is_grouping()) - return false; $balisename = ''; @@ -1296,14 +1391,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface $registry = registry::get_instance(); if ($this->bitly_link !== null) - return $this->bitly_link; $this->bitly_link = false; if (trim($registry->get('GV_bitly_user')) == '' && trim($registry->get('GV_bitly_key')) == '') - return $this->bitly_link; try @@ -1356,7 +1449,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface else { $uuid = $system_file->read_uuid(); - if(!uuid::is_valid($uuid)) + if (!uuid::is_valid($uuid)) { $uuid = uuid::generate_v4(); } @@ -1504,7 +1597,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $hd = $this->get_subdef('document'); if ($hd->is_physically_present()) - return new system_file(p4string::addEndSlash($hd->get_path()) . $hd->get_file()); return null; } @@ -1730,7 +1822,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } $this->delete_data_from_cache(self::CACHE_SUBDEFS); } @@ -1824,7 +1916,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - + } } @@ -1844,7 +1936,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_container_baskets() { if ($this->container_basket) - return $this->container_basket; $appbox = appbox::get_instance(); @@ -1995,4 +2086,87 @@ class record_adapter implements record_Interface, cache_cacheableInterface return $set; } + public function hasChild(\record_adapter $record) + { + return $this->get_children()->offsetExists($record->get_serialize_key()); + } + + public function appendChild(\record_adapter $record) + { + if (!$this->is_grouping()) + throw new \Exception('Only stories can append children'); + + $connbas = $this->get_databox()->get_connection(); + + $ord = 0; + + $sql = "SELECT (max(ord)+1) as ord + FROM regroup WHERE rid_parent = :parent_record_id"; + + $stmt = $connbas->prepare($sql); + + $stmt->execute(array(':parent_record_id' => $this->get_record_id())); + + $row = $stmt->fetch(PDO::FETCH_ASSOC); + + $stmt->closeCursor(); + + if ($row) + { + $ord = is_null($row["ord"]) ? 0 : $row["ord"]; + } + + $sql = 'INSERT INTO regroup (id, rid_parent, rid_child, dateadd, ord) + VALUES (null, :parent_record_id, :record_id, NOW(), :ord)'; + + $params = array( + ':parent_record_id' => $this->get_record_id() + , ':record_id' => $record->get_record_id() + , ':ord' => $ord + ); + + $stmt = $connbas->prepare($sql); + $stmt->execute($params); + + $stmt->closeCursor(); + + $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; + $stmt = $connbas->prepare($sql); + $stmt->execute(array(':record_id' => $this->get_record_id())); + $stmt->closeCursor(); + + $this->delete_data_from_cache(); + + return $this; + } + + public function removeChild(\record_adapter $record) + { + if (!$this->is_grouping()) + throw new \Exception('Only stories can append children'); + + $connbas = $this->get_databox()->get_connection(); + + $sql = "DELETE FROM regroup WHERE rid_parent = :parent_record_id + AND rid_child = :record_id"; + + $params = array( + ':parent_record_id' => $this->get_record_id() + , ':record_id' => $record->get_record_id() + ); + + $stmt = $connbas->prepare($sql); + $stmt->execute($params); + $stmt->closeCursor(); + + $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; + $stmt = $connbas->prepare($sql); + $stmt->execute(array(':record_id' => $this->get_record_id())); + $stmt->closeCursor(); + + $this->delete_data_from_cache(); + + return $this; + } + } diff --git a/lib/classes/set/export.class.php b/lib/classes/set/export.class.php index ac78226378..02f7f94601 100644 --- a/lib/classes/set/export.class.php +++ b/lib/classes/set/export.class.php @@ -102,8 +102,6 @@ class set_export extends set_abstract { $xml = $record->get_xml(); - $regfield = basket_adapter::getRegFields($basrec[0], $xml); - foreach ($record->get_children() as $child_basrec) { $base_id = $child_basrec->get_base_id(); @@ -126,7 +124,7 @@ class set_export extends set_abstract new record_exportElement( $child_basrec->get_sbas_id(), $record_id, - $regfield['regname'] . '_' . $n . '/', + $record->get_title() . '_' . $n . '/', $remain_hd[$base_id] );