/** * * @param $pid * @param $safinstancesId * @param int $fileFilesId * @param null $checked * @param null $usersId * @return array|bool */ public function getMultiArrayRelations($pid, $safinstancesId, $fileFilesId = 0, $checked = null, $usersId = null) { if ($this->cacheStructureArray) { $cache = Zend_Registry::get('cache'); } $cacheName = 'FilfoldersOp_getMultiArrayRelations_' . $pid . '_' . $safinstancesId . '_' . $fileFilesId; if ($this->cacheStructureArray) { $toReturn = $cache->load($cacheName); } else { $toReturn = false; } if (!$toReturn) { $where = ' safinstances_id = ' . $safinstancesId . ' '; $refs = array(); $list = array(); foreach ($this->fetchAll($where, 'pagorder') as $f) { $data = $f->toArray(); $thisRef =& $refs[$data['id']]; $thisRef['parent_id'] = $data['parent_id']; $thisRef['label'] = $data['label']; $thisRef['id'] = $data['id']; $thisRef['isnode'] = $data['isnode']; $thisRef['pagorder'] = $data['pagorder']; $thisRef['checked'] = false; $thisRef['statval'] = 0; if ($usersId != null) { $thisRef['statval'] = $this->getstatvalq($data['id'], $usersId); } if (is_array($checked) && in_array($data['id'], $checked)) { $thisRef['checked'] = true; } if ($fileFilesId > 0) { $foldersDb = new FilfoldersFilfiles(); $where = 'filfolders_id = ' . $data['id'] . ' AND filfiles_id = ' . $fileFilesId . ' '; if (count($foldersDb->fetchAll($where)) == 1) { $thisRef['checked'] = true; } } if ($data['parent_id'] <= 0) { $list[$data['id']] =& $thisRef; } else { $refs[$data['parent_id']]['children'][$data['id']] =& $thisRef; } } if ($pid > 0 && isset($list[$pid]) && isset($list[$pid]['children'])) { $toReturn = $list[$pid]['children']; } else { $toReturn = $list; } if ($this->cacheStructureArray) { $cache->save($toReturn, $cacheName); } } return $toReturn; }
/** * Saves the file into folders and create the folders if they do not exist * * @param $tags String all the folders name separated by a comma * @param $fid The file ID * @return void */ private function saveFolders($tags, $fid) { $cor = new FilfoldersFilfiles(); $cor->delete("filfiles_id = '" . $fid . "'"); foreach (preg_split('/,/', $tags) as $tag) { if (trim($tag) != '') { $folderLabel = ucfirst(strtolower(trim($tag))); $folderDb = new Filfolders(); $where = "safinstances_id = '" . $this->safinstancesId . "' AND label LIKE '" . addslashes($folderLabel) . "' "; $rows = $folderDb->fetchAll($where); if (count($rows) == 1) { $folderRow = $rows[0]; } elseif (count($rows) == 0) { // create the folder $folderRow = $folderDb->createRow(); $folderRow->label = $folderLabel; $folderRow->safinstances_id = $this->safinstancesId; $folderRow->save(); } else { break; } // add data in the correspondance table $cor = new FilfoldersFilfiles(); $rows2 = $cor->fetchAll("filfolders_id = '" . $folderRow->id . "' AND filfiles_id = '" . $fid . "' "); if (count($rows2) == 0) { $corrE = $cor->createRow(); $corrE->filfolders_id = $folderRow->id; $corrE->filfiles_id = $fid; $corrE->save(); } } } }