openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b161af3c6594673b17dbf4596e539a1c272d91cd
parent e0e08523e7f6e6b764e37a94989413eb423af9db
Author: Jan Dankert <devnull@localhost>
Date:   Sun,  2 Sep 2018 23:08:35 +0200

Fix der Suche. Die Suche sucht jetzt immer über alle Projekte hinweg.

Diffstat:
modules/cms-core/action/SearchAction.class.php | 123++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
modules/cms-core/model/BaseObject.class.php | 227+++++++++++++++++++++++++++++++++++--------------------------------------------
modules/cms-core/model/File.class.php | 8+++-----
modules/cms-core/model/Template.class.php | 8+++-----
modules/cms-core/model/User.class.php | 4++++
5 files changed, 181 insertions(+), 189 deletions(-)

diff --git a/modules/cms-core/action/SearchAction.class.php b/modules/cms-core/action/SearchAction.class.php @@ -2,6 +2,7 @@ namespace cms\action; +use cms\model\Project; use cms\model\User; use cms\model\Value; use cms\model\Template; @@ -127,64 +128,84 @@ class SearchAction extends Action * Durchf?hren der Suche * und Anzeige der Ergebnisse */ - private function performSearch( $text, $flag) + private function performSearch($searchText, $searchFlag) { - global $conf; - $listObjectIds = array(); $listTemplateIds = array(); $resultList = array(); - $user = User::loadWithName($text); - if ( is_object($user) ) + + if ( $searchFlag & SEARCH_FLAG_ID ) { - $userResult = array( 'url' => Html::url('template','',$templateid), - 'type' => 'user', - 'name' => $user->name, - 'desc' => lang('NO_DESCRIPTION_AVAILABLE'), - 'lastchange_date' => 0 ); + if ( BaseObject::available( intval($searchText) ) ) + $listObjectIds[] = intval( $searchText ); + + if ( $this->userIsAdmin() ) { + + $user = new User( intval($searchText) ); + + try { + $user->load(); + + $userResult = array( 'url' => '', + 'type' => 'user', + 'id' => $user->userid, + 'name' => $user->name, + 'desc' => $user->desc, + 'lastchange_date' => 0 ); + $resultList[] = $userResult; + } + catch( \ObjectNotFoundException $e) { + ; // userid is unknown + } + } } - $resultList[] = $userResult; - $this->setTemplateVar( 'result',$resultList ); - if ( $flag & SEARCH_FLAG_ID && BaseObject::available( intval($text) ) ) - $listObjectIds[] = intval( $text ); - - if ( $flag & SEARCH_FLAG_NAME ) + if ( $searchFlag & SEARCH_FLAG_NAME ) { - $o = new BaseObject(); - $listObjectIds += $o->getObjectIdsByName( $text ); + if ( $this->userIsAdmin() ) { + + $user = User::loadWithName($searchText); + if (is_object($user)) { + $userResult = array('url' => '', + 'type' => 'user', + 'id' => $user->userid, + 'name' => $user->name, + 'desc' => $user->desc, + 'lastchange_date' => 0); + $resultList[] = $userResult; + } + } + + $listObjectIds += BaseObject::getObjectIdsByName( $searchText ); } - if ( $flag & SEARCH_FLAG_DESCRIPTION ) + if ( $searchFlag & SEARCH_FLAG_DESCRIPTION ) { - $o = new BaseObject(); - $listObjectIds += $o->getObjectIdsByDescription( $text ); + $listObjectIds += BaseObject::getObjectIdsByDescription( $searchText ); } - if ( $flag & SEARCH_FLAG_FILENAME ) + if ( $searchFlag & SEARCH_FLAG_FILENAME ) { - $o = new BaseObject(); - $listObjectIds += $o->getObjectIdsByFilename( $text ); + $listObjectIds += BaseObject::getObjectIdsByFilename( $searchText ); - $f = new File(); - $listObjectIds += $f->getObjectIdsByExtension( $text ); + $listObjectIds += File::getObjectIdsByExtension( $searchText ); } // Inhalte durchsuchen - if ( $flag & SEARCH_FLAG_VALUE ) + if ( $searchFlag & SEARCH_FLAG_VALUE ) { $e = new Value(); - $listObjectIds += $e->getObjectIdsByValue( $text ); + $listObjectIds += $e->getObjectIdsByValue( $searchText ); - $template = new Template(); - $listTemplateIds += $template->getTemplateIdsByValue( $text ); + $listTemplateIds += Template::getTemplateIdsByValue( $searchText ); } - $this->explainResult( $listObjectIds, $listTemplateIds ); + $resultList = array_merge( $resultList, $this->explainResult( $listObjectIds, $listTemplateIds ) ); - } + $this->setTemplateVar( 'result',$resultList ); + } /** @@ -198,33 +219,33 @@ class SearchAction extends Action { $o = new BaseObject( $objectid ); $o->load(); - $resultList[$objectid] = array(); - $resultList[$objectid]['id' ] = $objectid; - $resultList[$objectid]['url' ] = Html::url($o->getType(),'',$objectid); - $resultList[$objectid]['type'] = $o->getType(); - $resultList[$objectid]['name'] = $o->name; - $resultList[$objectid]['lastchange_date'] = $o->lastchangeDate; - - if ( $o->desc != '' ) - $resultList[$objectid]['desc'] = $o->desc; - else - $resultList[$objectid]['desc'] = lang('NO_DESCRIPTION_AVAILABLE'); + if ($o->hasRight( ACL_READ )) + $resultList[] = array( + 'id' => $objectid, + 'type' => $o->getType(), + 'name' => $o->name, + 'lastchange_date' => $o->lastchangeDate, + 'desc' => $o->desc + ); } foreach( $listTemplateIds as $templateid ) { $t = new Template( $templateid ); $t->load(); - $resultList['t'.$templateid] = array(); - $resultList['t'.$templateid]['id' ] = $templateid; - $resultList['t'.$templateid]['url' ] = Html::url('template','',$templateid); - $resultList['t'.$templateid]['type'] = 'template'; - $resultList['t'.$templateid]['name'] = $t->name; - $resultList['t'.$templateid]['desc'] = lang('NO_DESCRIPTION_AVAILABLE'); - $resultList['t'.$templateid]['lastchange_date'] = 0; + $p = new Project( $t->projectid ); + $o = new BaseObject( $p->getRootObjectId() ); + if ($o->hasRight( ACL_READ )) + $resultList[] = array( + 'id' => $templateid, + 'type'=> 'template', + 'name'=> $t->name, + 'desc'=> '', + 'lastchange_date'=> 0 + ); } - $this->setTemplateVar( 'result',$resultList ); + return $resultList; } } diff --git a/modules/cms-core/model/BaseObject.class.php b/modules/cms-core/model/BaseObject.class.php @@ -226,7 +226,6 @@ namespace cms\model { { if ( is_null($this->aclMask) ) { - $language = $this->languageid; $user = \Session::getUser(); if ( $user->isAdmin ) @@ -262,7 +261,7 @@ SELECT {{acl}}.* FROM {{acl}} SQL ); - $sql->setInt ( 'languageid' ,$language->languageid ); + $sql->setInt ( 'languageid' ,$this->languageid ); $sql->setInt ( 'objectid' ,$this->objectid ); $sql->setInt ( 'userid' ,$user->userid ); @@ -1093,132 +1092,6 @@ SQL } - /** - * Es werden Objekte mit einem bestimmten Namen ermittelt - * @param String Suchbegriff - * @return Array Liste der gefundenen Objekt-IDs - */ - function getObjectIdsByFileName( $text ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT id FROM {{object}} '. - ' WHERE filename LIKE {filename}'. - ' AND projectid={projectid}'. - ' ORDER BY lastchange_date DESC' ); - $sql->setInt ( 'projectid',$this->projectid ); - $sql->setString( 'filename','%'.$text.'%' ); - - return $sql->getCol(); - } - - - /** - * Es werden Objekte mit einem Namen ermittelt - * @param String Suchbegriff - * @return Array Liste der gefundenen Objekt-IDs - */ - function getObjectIdsByName( $text ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT {{object}}.id FROM {{object}} '. - ' LEFT JOIN {{name}} '. - ' ON {{object}}.id={{name}}.objectid'. - ' WHERE {{name}}.name LIKE {name}'. - ' AND {{name}}.languageid={languageid}'. - ' AND {{object}}.projectid={projectid}'. - ' ORDER BY lastchange_date DESC' ); - $sql->setInt ( 'projectid' ,$this->projectid ); - $sql->setInt ( 'languageid',$this->languageid ); - $sql->setString( 'name' ,'%'.$text.'%' ); - - return $sql->getCol(); - } - - - /** - * Es werden Objekte mit einer Beschreibung ermittelt - * @param String Suchbegriff - * @return Array Liste der gefundenen Objekt-IDs - */ - function getObjectIdsByDescription( $text ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT {{object}}.id FROM {{object}} '. - ' LEFT JOIN {{name}} '. - ' ON {{object}}.id={{name}}.objectid'. - ' WHERE {{name}}.descr LIKE {desc}'. - ' AND {{name}}.languageid={languageid}'. - ' AND {{object}}.projectid={projectid}'. - ' ORDER BY lastchange_date DESC' ); - $sql->setInt ( 'projectid' ,$this->projectid ); - $sql->setInt ( 'languageid',$this->languageid ); - $sql->setString( 'desc' ,'%'.$text.'%' ); - - return $sql->getCol(); - } - - - /** - * Es werden Objekte mit einer UserId ermittelt - * @param Integer Benutzer-Id der Erstellung - * @return Array Liste der gefundenen Objekt-IDs - */ - function getObjectIdsByCreateUserId( $userid ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT id FROM {{object}} '. - ' WHERE create_userid={userid}'. - ' AND projectid={projectid}'. - ' ORDER BY lastchange_date DESC' ); - $sql->setInt ( 'projectid',$this->projectid ); - $sql->setInt ( 'userid' ,$userid ); - - return $sql->getCol(); - } - - - /** - * Es werden Objekte mit einer UserId ermittelt - * @param Integer Benutzer-Id der letzten ?nderung - * @return Array Liste der gefundenen Objekt-IDs - */ - function getObjectIdsByLastChangeUserId( $userid ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT id FROM {{object}} '. - ' WHERE lastchange_userid={userid}'. - ' AND projectid={projectid}'. - ' ORDER BY lastchange_date DESC' ); - $sql->setInt ( 'projectid',$this->projectid ); - $sql->setInt ( 'userid' ,$userid ); - - return $sql->getCol(); - } - - - /** - * Gibt true zur?ck, wenn die angegebene Objekt-ID existiert - * @param Integer Objekt-ID - * @return Boolean - */ - function isObjectId( $id ) - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT id FROM {{object}} '. - ' WHERE id={objectid}'. - ' AND projectid={projectid}' ); - $sql->setInt ( 'projectid' ,$this->projectid ); - $sql->setInt ( 'objectid' ,$id ); - - return ($sql->getOne() == intval($id) ); - } - /** @@ -1417,6 +1290,104 @@ SQL return Project::create( $this->projectid ); } + + + + /** + * Es werden Objekte mit einem bestimmten Namen ermittelt + * @param String Suchbegriff + * @return array Liste der gefundenen Objekt-IDs + */ + public static function getObjectIdsByFileName( $text ) + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT id FROM {{object}} '. + ' WHERE filename LIKE {filename}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setString( 'filename','%'.$text.'%' ); + + return $sql->getCol(); + } + + + /** + * Es werden Objekte mit einem Namen ermittelt + * @param String Suchbegriff + * @return array Liste der gefundenen Objekt-IDs + */ + public static function getObjectIdsByName( $text ) + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT {{object}}.id FROM {{object}} '. + ' LEFT JOIN {{name}} '. + ' ON {{object}}.id={{name}}.objectid'. + ' WHERE {{name}}.name LIKE {name}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setString( 'name' ,'%'.$text.'%' ); + + return $sql->getCol(); + } + + + /** + * Es werden Objekte mit einer Beschreibung ermittelt + * @param String Suchbegriff + * @return array Liste der gefundenen Objekt-IDs + */ + public static function getObjectIdsByDescription( $text ) + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT {{object}}.id FROM {{object}} '. + ' LEFT JOIN {{name}} '. + ' ON {{object}}.id={{name}}.objectid'. + ' WHERE {{name}}.descr LIKE {desc}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setString( 'desc' ,'%'.$text.'%' ); + + return $sql->getCol(); + } + + + /** + * Es werden Objekte mit einer UserId ermittelt + * @param Integer Benutzer-Id der Erstellung + * @return array Liste der gefundenen Objekt-IDs + */ + public static function getObjectIdsByCreateUserId( $userid ) + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT id FROM {{object}} '. + ' WHERE create_userid={userid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'userid' ,$userid ); + + return $sql->getCol(); + } + + + /** + * Es werden Objekte mit einer UserId ermittelt + * @param Integer Benutzer-Id der letzten ?nderung + * @return array Liste der gefundenen Objekt-IDs + */ + public static function getObjectIdsByLastChangeUserId( $userid ) + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT id FROM {{object}} '. + ' WHERE lastchange_userid={userid}'. + ' ORDER BY lastchange_date DESC' ); + $sql->setInt ( 'userid' ,$userid ); + + return $sql->getCol(); + } + + + } diff --git a/modules/cms-core/model/File.class.php b/modules/cms-core/model/File.class.php @@ -168,18 +168,16 @@ class File extends BaseObject * Es werden Objekte zu einer Dateierweiterung ermittelt * * @param String Dateierweiterung ohne fuehrenden Punkt (z.B. 'jpeg') - * @return Array Liste der gefundenen Objekt-IDs + * @return array Liste der gefundenen Objekt-IDs */ - function getObjectIdsByExtension( $extension ) + public static function getObjectIdsByExtension( $extension ) { $db = db_connection(); $sql = $db->sql( 'SELECT {{file}}.objectid FROM {{file}} '. ' LEFT JOIN {{object}} '. ' ON {{object}}.id={{file}}.objectid'. - ' WHERE {{file}}.extension={extension}'. - ' AND {{object}}.projectid={projectid}' ); - $sql->setInt ( 'projectid',$this->projectid ); + ' WHERE {{file}}.extension={extension}' ); $sql->setString( 'extension',$extension ); return $sql->getCol(); diff --git a/modules/cms-core/model/Template.class.php b/modules/cms-core/model/Template.class.php @@ -166,17 +166,15 @@ class Template /** * Es werden Templates mit einem Inhalt gesucht * @param String Suchbegriff - * @return Array Liste der gefundenen Template-IDs + * @return array Liste der gefundenen Template-IDs */ - function getTemplateIdsByValue( $text ) + public static function getTemplateIdsByValue( $text ) { $db = db_connection(); $stmt = $db->sql( 'SELECT templateid FROM {{templatemodel}}'. - ' WHERE text LIKE {text} '. - ' AND projectmodelid={modelid}' ); + ' WHERE text LIKE {text} ' ); - $stmt->setInt ( 'modelid',$this->modelid ); $stmt->setString( 'text' ,'%'.$text.'%' ); return $stmt->getCol(); diff --git a/modules/cms-core/model/User.class.php b/modules/cms-core/model/User.class.php @@ -286,8 +286,12 @@ SQL ' WHERE name={name}' ); //Html::debug($sql); $sql->setString( 'name',$name ); + $userId = $sql->getOne(); + if (empty($userId)) + return null; // no user found. + // Benutzer �ber Id instanziieren $neuerUser = new \cms\model\User( $userId );