/** * * @param string $folderName * @param strin(32) $folderParent * @return Ambigous <>|number */ public function createFolder ($folderName, $folderParent = "/", $action = "createifnotexists") { $validActions = array ("createifnotexists","create","update"); if (! in_array( $action, $validActions )) { $action = "createifnotexists"; } //Clean Folder and Parent names (delete spaces...) $folderName = trim( $folderName ); $folderParent = trim( $folderParent ); //Try to Load the folder (Foldername+FolderParent) $oCriteria = new Criteria( 'workflow' ); $oCriteria->add( AppFolderPeer::FOLDER_NAME, $folderName ); $oCriteria->add( AppFolderPeer::FOLDER_PARENT_UID, $folderParent ); $oDataset = AppFolderPeer::doSelectRS( $oCriteria ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); $oDataset->next(); if ($aRow = $oDataset->getRow()) { //Folder exist, then return the ID $response['success'] = false; $response['message'] = $response['error'] = "Can't create folder <br /> A folder with same name already exist. <br /> $folderName"; $response['folderUID'] = $aRow['FOLDER_UID']; //return ($aRow ['FOLDER_UID']); return ($response); } else { //Folder doesn't exist. Create and return the ID $folderUID = G::GenerateUniqueID(); $tr = new AppFolder(); $tr->setFolderUid( $folderUID ); $tr->setFolderParentUid( $folderParent ); $tr->setFolderName( $folderName ); $tr->setFolderCreateDate( 'now' ); $tr->setFolderUpdateDate( 'now' ); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); $response['success'] = true; $response['message'] = "Folder successfully created. <br /> $folderName"; $response['folderUID'] = $folderUID; return ($response); //return $folderUID; } else { // Something went wrong. We can now get the validationFailures and handle them. $msg = ''; $validationFailuresArray = $tr->getValidationFailures(); foreach ($validationFailuresArray as $objValidationFailure) { $msg .= $objValidationFailure->getMessage() . "<br/>"; } $response['success'] = false; $response['message'] = $response['error'] = "Can't create folder \n A \n " . $msg; return ($response); } } }
/** * Method to do selects. * * @param Criteria $criteria The Criteria object used to build the SELECT statement. * @param Connection $con * @return array Array of selected Objects * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelect(Criteria $criteria, $con = null) { return AppFolderPeer::populateObjects(AppFolderPeer::doSelectRS($criteria, $con)); }