Fix grouping methods

This commit is contained in:
Romain Neutron
2011-12-21 17:49:41 +01:00
parent 903809cff9
commit e1626b20ad
3 changed files with 191 additions and 97 deletions

View File

@@ -1078,31 +1078,6 @@ class basket_adapter implements cache_cacheableInterface
return true;
}
/**
*
* @param databox_descriptionStructure $meta_struct
* @return <type>
*/
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 <type> $sbas_id
* @param caption_record $desc
* @return <type>
*/
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

View File

@@ -140,6 +140,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
const CACHE_GROUPING = 'grouping';
const CACHE_STATUS = 'status';
protected static $_regfields;
/**
*
* @param <int> $base_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)
@@ -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 <type> $sbas_id
* @param caption_record $desc
* @return <type>
*/
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 <type>
*/
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
@@ -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;
}
@@ -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;
}
}

View File

@@ -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]
);