. */ /** * @brief Contains the controler of the mr_classification_scheme Object (create, save, modify, etc...) * * * @file * @author Claire Figueras boulio * @author Nicolas Boulio * @date $date$ * @version $Revision$ * @ingroup core */ // To activate de debug mode of the class $_ENV['DEBUG'] = false; define("_PREFIX","CS"); // Loads the required classes try { require_once("modules/moreq/moreq_tables_definition.php"); require_once("core/class/ObjectControlerIF.php"); require_once("modules/moreq/class/ClassifiedObjectControlerAbstract.php"); require_once("modules/moreq/class/mr_classification_scheme.php"); } catch (Exception $e){ echo $e->getMessage().' // '; } /** * @brief Controler of the mr_classification_scheme Object * * * @ingroup core */ class mr_classification_scheme_controler extends ClassifiedObjectControler implements ObjectControlerIF { /** * Returns an mr_classification_scheme Object based on a classification scheme identifier * * @param $mr_classification_scheme_id string mr_classification_scheme identifier * @return mr_classification_scheme object with properties from the database or null */ public function get($mr_classification_scheme_id) { return self::advanced_get($mr_classification_scheme_id,_CLASSIFICATION_SCHEME_TABLE_NAME); } public function get_allowed_schemes($user_id) { } /** * Saves in the database a mr_classification_scheme object * * @param $mr_classification_scheme mr_classification_scheme object to be saved * @return mr_classification_scheme saved object if succeeded, null otherwise */ public function save($mr_classification_scheme) { if(!isset($mr_classification_scheme) ) return null; if($mr_classification_scheme->mr_classification_scheme_id > 0) return self::update($mr_classification_scheme); else return self::insert($mr_classification_scheme); } /** * Inserts in the database (mr_classification_scheme table) a mr_classification_scheme object * * @param $scheme mr_classification_scheme object * @return bool true if the insertion is complete, false otherwise */ private function insert($mr_classification_scheme) { $mr_classification_scheme->mr_classification_scheme_id=time()*1000+time()%1000; $mr_classification_scheme->mr_full_classification_code=self::newCode(); return self::advanced_insert($mr_classification_scheme); } /** * Updates a classification scheme in the database (mr_classification_scheme table) with a mr_classification_scheme object * * @param $scheme mr_classification_scheme object * @return bool true if the update is complete, false otherwise */ private function update($mr_classification_scheme) { return self::advanced_update($mr_classification_scheme); } /** * Deletes in the database (mr_classification_scheme table) a given classification scheme (mr_classification_scheme_id) * * @param $scheme_id string Classification scheme identifier * @return bool true if the deletion is complete, false otherwise */ public function delete($mr_classification_scheme) { return self::advanced_delete($mr_classification_scheme); } /** * Asserts if a given mr_classification_scheme (scheme_id) exists in the database * * @param $scheme_id String mr_classification_scheme identifier * @return bool true if the scheme exists, false otherwise */ public function schemeExists($mr_classification_scheme_id) { if(!isset($mr_classification_scheme_id) || empty($mr_classification_scheme_id)) return false; $select = "select mr_classification_scheme_id from "._CLASSIFICATION_SCHEME_TABLE_NAME." where mr_classification_scheme_id = $mr_classification_scheme_id"; self::$db->connect(); try{ if($_ENV['DEBUG']){echo $query.' // ';} self::$db->query($query); } catch (Exception $e){ echo _UNKNOWN.' '._CLASSIFICATION_SCHEME." ".$mr_classification_scheme_id.' // '; } if(self::$db->nb_result() > 0) { self::$db->disconnect(); return true; } self::$db->disconnect(); return false; } /** * Parse existing classification shemes and * provide a new code, incremented. * @return string */ private function newCode(){ $select="select max(mr_full_classification_code) from "._CLASSIFICATION_SCHEME_TABLE_NAME; self::$db=new dbquery(); self::$db->connect(); try{ self::$db->query($select); if(self::$db->nb_result()>0){ // Main case $queryResult=self::$db->fetch_object(); $suffix=self::extract_suffix($queryResult->max); } else { // First classification scheme $suffix=0; } $suffix=self::format_classification_code($suffix+_CODE_INCREMENT); } catch (Exception $e) { } self::$db->disconnect(); return _PREFIX.$suffix; } private function extract_suffix($code){ return str_replace(_PREFIX,"",$code); } } ?>