* @license PHP License * @package WB * @subpackage db */ WBClass::load('WBDatasource_FormAttribute'); /** * Get folder id * * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_FormAttribute_VFSDateFolder extends WBDatasource_FormAttribute { /** * Configuration parameter * * - user: User scope for VFS * - timestamp: date and time to create folders for * - format: time format used to create folder, separate folder with "/" * - subfolder: additional sub folder (optional) * - basedir: start creating folder in basedir instead of root * * @var array */ protected $config = array( 'user' => '1', 'timestamp' => 'now', 'format' => '%Y/%m/%d', 'subfolder' => '', 'basedir' => '0' ); /** * directory browser * @var WBVFS_Explorer */ protected $expl; /** * Get Attribute's Value * * Create subfolder based on date and format. E.g. create subfolder for year, month and day. * * * @param mixed $current actual attribute value * @return array */ protected function getAttributeValue($current) { // default is "now" if (empty($this->config['timestamp'])) { $this->config['timestamp'] = 'now'; } $ts = strtotime($this->config['timestamp']); if (!$ts) { $ts = strtotime('now'); } $ts = strftime($this->config['format'], $ts); $ts = explode('/', $ts); $param = array( 'user' => $this->config['user'] ); $this->expl = WBClass::create('WBVFS_Explorer', $param); $list = $this->expl->lsDir($this->config['basedir']); $parent = $this->config['basedir']; foreach ($ts as $name) { $id = null; foreach ($list as $l) { if ($name == $l['name']) { $id = $l['id']; $parent = $id; $list = $this->expl->lsDir($id); break; } } if ($id) { continue; } $id = $this->expl->mkDir($parent, $name); $parent = $id; $list = array(); } if (empty($this->config['subfolder'])) { return $id; } $list = $this->expl->lsDir($id); foreach ($list as $l) { if ($this->config['subfolder'] == $l['name']) { return $l['id']; } } $id = $this->expl->mkDir($id, $this->config['subfolder']); return $id; } }