mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 10:34:34 +00:00

Conflicts: bin/console bower.json composer.json composer.lock lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Border/Manager.php lib/Alchemy/Phrasea/Controller/Api/V1.php lib/Alchemy/Phrasea/Core/PhraseaEvents.php lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php lib/classes/caption/field.php lib/classes/record/Interface.php templates/web/prod/index.html.twig www/skins/prod/000000/prodcolor.css
180 lines
3.2 KiB
PHP
180 lines
3.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2015 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
abstract class set_abstract implements IteratorAggregate
|
|
{
|
|
/**
|
|
*
|
|
* @var Array
|
|
*/
|
|
protected $elements = [];
|
|
|
|
/**
|
|
*
|
|
* @return ArrayIterator
|
|
*/
|
|
public function getIterator()
|
|
{
|
|
$this->load_elements();
|
|
|
|
return new ArrayIterator($this->elements);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return set
|
|
*/
|
|
protected function load_elements()
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $offset
|
|
* @param string $value
|
|
* @return Void
|
|
*/
|
|
public function offsetSet($offset, $value)
|
|
{
|
|
if (is_null($offset)) {
|
|
$this->elements[] = $value;
|
|
} else {
|
|
$this->elements[$offset] = $value;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $offset
|
|
* @return boolean
|
|
*/
|
|
public function offsetExists($offset)
|
|
{
|
|
return isset($this->elements[$offset]);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $offset
|
|
* @return Void
|
|
*/
|
|
public function offsetUnset($offset)
|
|
{
|
|
unset($this->elements[$offset]);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param string $offset
|
|
* @return record_adapter
|
|
*/
|
|
public function offsetGet($offset)
|
|
{
|
|
return isset($this->elements[$offset]) ? $this->elements[$offset] : null;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return int
|
|
*/
|
|
public function is_empty()
|
|
{
|
|
return count($this->elements) == 0;
|
|
}
|
|
|
|
public function __isset($key)
|
|
{
|
|
trigger_error("Unable to use magic method get for key $key");
|
|
if (isset($this->$key)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get the number of element in the set
|
|
*
|
|
* @return Int
|
|
*/
|
|
public function get_count()
|
|
{
|
|
return count($this->elements);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return int
|
|
*/
|
|
public function get_count_groupings()
|
|
{
|
|
$n = 0;
|
|
foreach ($this->elements as $record) {
|
|
if ($record->is_grouping())
|
|
$n ++;
|
|
}
|
|
|
|
return $n;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return Array
|
|
*/
|
|
public function get_elements()
|
|
{
|
|
$this->load_elements();
|
|
|
|
return $this->elements;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param record_adapter $record
|
|
* @return set
|
|
*/
|
|
public function add_element(\record_adapter $record)
|
|
{
|
|
$this->elements[$record->get_serialize_key()] = $record;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param record_adapter $record
|
|
* @return set
|
|
*/
|
|
public function remove_element(\record_adapter $record)
|
|
{
|
|
$key = $record->get_serialize_key();
|
|
if (isset($this->elements[$key]))
|
|
unset($this->elements[$key]);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return string
|
|
*/
|
|
public function serialize_list()
|
|
{
|
|
$basrec = [];
|
|
foreach ($this->elements as $record) {
|
|
$basrec[] = $record->get_serialize_key();
|
|
}
|
|
|
|
return implode(';', $basrec);
|
|
}
|
|
}
|