1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CoreBundle\Entity\Repository\CourseRepository;
- use Chamilo\CoreBundle\Entity\Repository\ItemPropertyRepository;
- use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
- use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
- use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
- use Chamilo\CourseBundle\Entity\CDocument;
- use Chamilo\CourseBundle\Entity\CItemProperty;
- use Chamilo\CourseBundle\Entity\CLp;
- use Chamilo\CourseBundle\Entity\CLpCategory;
- use Chamilo\CourseBundle\Entity\CLpItem;
- use Chamilo\CourseBundle\Entity\CLpItemView;
- use Chamilo\CourseBundle\Entity\CTool;
- use Chamilo\UserBundle\Entity\User;
- use ChamiloSession as Session;
- use Gedmo\Sortable\Entity\Repository\SortableRepository;
- use Symfony\Component\Filesystem\Filesystem;
- use Symfony\Component\Finder\Finder;
- /**
- * Class learnpath
- * This class defines the parent attributes and methods for Chamilo learnpaths
- * and SCORM learnpaths. It is used by the scorm class.
- *
- * @todo decouple class
- *
- * @package chamilo.learnpath
- *
- * @author Yannick Warnier <ywarnier@beeznest.org>
- * @author Julio Montoya <gugli100@gmail.com> Several improvements and fixes
- */
- class learnpath
- {
- const MAX_LP_ITEM_TITLE_LENGTH = 32;
- public $attempt = 0; // The number for the current ID view.
- public $cc; // Course (code) this learnpath is located in. @todo change name for something more comprensible ...
- public $current; // Id of the current item the user is viewing.
- public $current_score; // The score of the current item.
- public $current_time_start; // The time the user loaded this resource (this does not mean he can see it yet).
- public $current_time_stop; // The time the user closed this resource.
- public $default_status = 'not attempted';
- public $encoding = 'UTF-8';
- public $error = '';
- public $force_commit = false; // For SCORM only- if true will send a scorm LMSCommit() request on each LMSSetValue()
- public $index; // The index of the active learnpath_item in $ordered_items array.
- public $items = [];
- public $last; // item_id of last item viewed in the learning path.
- public $last_item_seen = 0; // In case we have already come in this lp, reuse the last item seen if authorized.
- public $license; // Which license this course has been given - not used yet on 20060522.
- public $lp_id; // DB iid for this learnpath.
- public $lp_view_id; // DB ID for lp_view
- public $maker; // Which maker has conceived the content (ENI, Articulate, ...).
- public $message = '';
- public $mode = 'embedded'; // Holds the video display mode (fullscreen or embedded).
- public $name; // Learnpath name (they generally have one).
- public $ordered_items = []; // List of the learnpath items in the order they are to be read.
- public $path = ''; // Path inside the scorm directory (if scorm).
- public $theme; // The current theme of the learning path.
- public $preview_image; // The current image of the learning path.
- public $accumulateScormTime; // Flag to decide whether to accumulate SCORM time or not
- public $accumulateWorkTime; // The min time of learnpath
- // Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1).
- public $prevent_reinit = 1;
- // Describes the mode of progress bar display.
- public $seriousgame_mode = 0;
- public $progress_bar_mode = '%';
- // Percentage progress as saved in the db.
- public $progress_db = 0;
- public $proximity; // Wether the content is distant or local or unknown.
- public $refs_list = []; //list of items by ref => db_id. Used only for prerequisites match.
- // !!!This array (refs_list) is built differently depending on the nature of the LP.
- // If SCORM, uses ref, if Chamilo, uses id to keep a unique value.
- public $type; //type of learnpath. Could be 'chamilo', 'scorm', 'scorm2004', 'aicc', ...
- // TODO: Check if this type variable is useful here (instead of just in the controller script).
- public $user_id; //ID of the user that is viewing/using the course
- public $update_queue = [];
- public $scorm_debug = 0;
- public $arrMenu = []; // Array for the menu items.
- public $debug = 0; // Logging level.
- public $lp_session_id = 0;
- public $lp_view_session_id = 0; // The specific view might be bound to a session.
- public $prerequisite = 0;
- public $use_max_score = 1; // 1 or 0
- public $subscribeUsers = 0; // Subscribe users or not
- public $created_on = '';
- public $modified_on = '';
- public $publicated_on = '';
- public $expired_on = '';
- public $ref = null;
- public $course_int_id;
- public $course_info = [];
- public $categoryId;
- /**
- * Constructor.
- * Needs a database handler, a course code and a learnpath id from the database.
- * Also builds the list of items into $this->items.
- *
- * @param string $course Course code
- * @param int $lp_id c_lp.iid
- * @param int $user_id
- */
- public function __construct($course, $lp_id, $user_id)
- {
- $debug = $this->debug;
- $this->encoding = api_get_system_encoding();
- if ($debug) {
- error_log('In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')');
- }
- if (empty($course)) {
- $course = api_get_course_id();
- }
- $course_info = api_get_course_info($course);
- if (!empty($course_info)) {
- $this->cc = $course_info['code'];
- $this->course_info = $course_info;
- $course_id = $course_info['real_id'];
- } else {
- $this->error = 'Course code does not exist in database.';
- }
- $lp_id = (int) $lp_id;
- $course_id = (int) $course_id;
- $this->set_course_int_id($course_id);
- // Check learnpath ID.
- if (empty($lp_id) || empty($course_id)) {
- $this->error = "Parameter is empty: LpId:'$lp_id', courseId: '$lp_id'";
- } else {
- // TODO: Make it flexible to use any course_code (still using env course code here).
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table
- WHERE iid = $lp_id";
- if ($debug) {
- error_log('learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0);
- }
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $this->lp_id = $lp_id;
- $row = Database::fetch_array($res);
- $this->type = $row['lp_type'];
- $this->name = stripslashes($row['name']);
- $this->proximity = $row['content_local'];
- $this->theme = $row['theme'];
- $this->maker = $row['content_maker'];
- $this->prevent_reinit = $row['prevent_reinit'];
- $this->seriousgame_mode = $row['seriousgame_mode'];
- $this->license = $row['content_license'];
- $this->scorm_debug = $row['debug'];
- $this->js_lib = $row['js_lib'];
- $this->path = $row['path'];
- $this->preview_image = $row['preview_image'];
- $this->author = $row['author'];
- $this->hide_toc_frame = $row['hide_toc_frame'];
- $this->lp_session_id = $row['session_id'];
- $this->use_max_score = $row['use_max_score'];
- $this->subscribeUsers = $row['subscribe_users'];
- $this->created_on = $row['created_on'];
- $this->modified_on = $row['modified_on'];
- $this->ref = $row['ref'];
- $this->categoryId = $row['category_id'];
- $this->accumulateScormTime = isset($row['accumulate_scorm_time']) ? $row['accumulate_scorm_time'] : 'true';
- $this->accumulateWorkTime = isset($row['accumulate_work_time']) ? $row['accumulate_work_time'] : 0;
- if (!empty($row['publicated_on'])) {
- $this->publicated_on = $row['publicated_on'];
- }
- if (!empty($row['expired_on'])) {
- $this->expired_on = $row['expired_on'];
- }
- if ($this->type == 2) {
- if ($row['force_commit'] == 1) {
- $this->force_commit = true;
- }
- }
- $this->mode = $row['default_view_mod'];
- // Check user ID.
- if (empty($user_id)) {
- $this->error = 'User ID is empty';
- } else {
- $userInfo = api_get_user_info($user_id);
- if (!empty($userInfo)) {
- $this->user_id = $userInfo['user_id'];
- } else {
- $this->error = 'User ID does not exist in database #'.$user_id;
- }
- }
- // End of variables checking.
- $session_id = api_get_session_id();
- // Get the session condition for learning paths of the base + session.
- $session = api_get_session_condition($session_id);
- // Now get the latest attempt from this user on this LP, if available, otherwise create a new one.
- $lp_table = Database::get_course_table(TABLE_LP_VIEW);
- // Selecting by view_count descending allows to get the highest view_count first.
- $sql = "SELECT * FROM $lp_table
- WHERE
- c_id = $course_id AND
- lp_id = $lp_id AND
- user_id = $user_id
- $session
- ORDER BY view_count DESC";
- $res = Database::query($sql);
- if ($debug) {
- error_log('learnpath::__construct() '.__LINE__.' - querying lp_view: '.$sql, 0);
- }
- if (Database::num_rows($res) > 0) {
- if ($debug) {
- error_log('learnpath::__construct() '.__LINE__.' - Found previous view');
- }
- $row = Database::fetch_array($res);
- $this->attempt = $row['view_count'];
- $this->lp_view_id = $row['id'];
- $this->last_item_seen = $row['last_item'];
- $this->progress_db = $row['progress'];
- $this->lp_view_session_id = $row['session_id'];
- } elseif (!api_is_invitee()) {
- if ($debug) {
- error_log('learnpath::__construct() '.__LINE__.' - NOT Found previous view');
- }
- $this->attempt = 1;
- $params = [
- 'c_id' => $course_id,
- 'lp_id' => $lp_id,
- 'user_id' => $user_id,
- 'view_count' => 1,
- 'session_id' => $session_id,
- 'last_item' => 0,
- ];
- $this->last_item_seen = 0;
- $this->lp_view_session_id = $session_id;
- $this->lp_view_id = Database::insert($lp_table, $params);
- if (!empty($this->lp_view_id)) {
- $sql = "UPDATE $lp_table SET id = iid
- WHERE iid = ".$this->lp_view_id;
- Database::query($sql);
- }
- }
- // Initialise items.
- $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $lp_item_table
- WHERE c_id = $course_id AND lp_id = '".$this->lp_id."'
- ORDER BY parent_item_id, display_order";
- $res = Database::query($sql);
- $lp_item_id_list = [];
- while ($row = Database::fetch_array($res)) {
- $lp_item_id_list[] = $row['iid'];
- switch ($this->type) {
- case 3: //aicc
- $oItem = new aiccItem('db', $row['iid'], $course_id);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id, $course_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change.
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($debug) {
- error_log(
- 'learnpath::__construct() - '.
- 'aicc object with id '.$my_item_id.
- ' set in items[]',
- 0
- );
- }
- }
- break;
- case 2:
- $oItem = new scormItem('db', $row['iid'], $course_id);
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- $oItem->set_lp_view($this->lp_view_id, $course_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change.
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$oItem->ref] = $my_item_id;
- if ($debug) {
- error_log('object with id '.$my_item_id.' set in items[]');
- }
- }
- break;
- case 1:
- default:
- if ($debug) {
- error_log('learnpath::__construct() '.__LINE__.' - calling learnpathItem');
- }
- $oItem = new learnpathItem($row['iid'], $user_id, $course_id, $row);
- if ($debug) {
- error_log('learnpath::__construct() '.__LINE__.' - end calling learnpathItem');
- }
- if (is_object($oItem)) {
- $my_item_id = $oItem->get_id();
- // Moved down to when we are sure the item_view exists.
- //$oItem->set_lp_view($this->lp_view_id);
- $oItem->set_prevent_reinit($this->prevent_reinit);
- // Don't use reference here as the next loop will make the pointed object change.
- $this->items[$my_item_id] = $oItem;
- $this->refs_list[$my_item_id] = $my_item_id;
- if ($debug) {
- error_log(
- 'learnpath::__construct() '.__LINE__.
- ' - object with id '.$my_item_id.' set in items[]'
- );
- }
- }
- break;
- }
- // Setting the object level with variable $this->items[$i][parent]
- foreach ($this->items as $itemLPObject) {
- $level = self::get_level_for_item(
- $this->items,
- $itemLPObject->db_id
- );
- $itemLPObject->level = $level;
- }
- // Setting the view in the item object.
- if (is_object($this->items[$row['iid']])) {
- $this->items[$row['iid']]->set_lp_view($this->lp_view_id, $course_id);
- if ($this->items[$row['iid']]->get_type() == TOOL_HOTPOTATOES) {
- $this->items[$row['iid']]->current_start_time = 0;
- $this->items[$row['iid']]->current_stop_time = 0;
- }
- }
- }
- if (!empty($lp_item_id_list)) {
- $lp_item_id_list_to_string = implode("','", $lp_item_id_list);
- if (!empty($lp_item_id_list_to_string)) {
- // Get last viewing vars.
- $itemViewTable = Database::get_course_table(TABLE_LP_ITEM_VIEW);
- // This query should only return one or zero result.
- $sql = "SELECT lp_item_id, status
- FROM $itemViewTable
- WHERE
- c_id = $course_id AND
- lp_view_id = ".$this->get_view_id()." AND
- lp_item_id IN ('".$lp_item_id_list_to_string."')
- ORDER BY view_count DESC ";
- $status_list = [];
- $res = Database::query($sql);
- while ($row = Database:: fetch_array($res)) {
- $status_list[$row['lp_item_id']] = $row['status'];
- }
- foreach ($lp_item_id_list as $item_id) {
- if (isset($status_list[$item_id])) {
- $status = $status_list[$item_id];
- if (is_object($this->items[$item_id])) {
- $this->items[$item_id]->set_status($status);
- if (empty($status)) {
- $this->items[$item_id]->set_status(
- $this->default_status
- );
- }
- }
- } else {
- if (!api_is_invitee()) {
- if (is_object($this->items[$item_id])) {
- $this->items[$item_id]->set_status(
- $this->default_status
- );
- }
- if (!empty($this->lp_view_id)) {
- // Add that row to the lp_item_view table so that
- // we have something to show in the stats page.
- $params = [
- 'c_id' => $course_id,
- 'lp_item_id' => $item_id,
- 'lp_view_id' => $this->lp_view_id,
- 'view_count' => 1,
- 'status' => 'not attempted',
- 'start_time' => time(),
- 'total_time' => 0,
- 'score' => 0,
- ];
- $insertId = Database::insert($itemViewTable, $params);
- if ($insertId) {
- $sql = "UPDATE $itemViewTable SET id = iid
- WHERE iid = $insertId";
- Database::query($sql);
- }
- $this->items[$item_id]->set_lp_view(
- $this->lp_view_id,
- $course_id
- );
- }
- }
- }
- }
- }
- }
- $this->ordered_items = self::get_flat_ordered_items_list(
- $this->get_id(),
- 0,
- $course_id
- );
- $this->max_ordered_items = 0;
- foreach ($this->ordered_items as $index => $dummy) {
- if ($index > $this->max_ordered_items && !empty($dummy)) {
- $this->max_ordered_items = $index;
- }
- }
- // TODO: Define the current item better.
- $this->first();
- if ($debug) {
- error_log('lp_view_session_id '.$this->lp_view_session_id);
- error_log('End of learnpath constructor for learnpath '.$this->get_id());
- }
- } else {
- $this->error = 'Learnpath ID does not exist in database ('.$sql.')';
- }
- }
- }
- /**
- * @return string
- */
- public function getCourseCode()
- {
- return $this->cc;
- }
- /**
- * @return int
- */
- public function get_course_int_id()
- {
- return isset($this->course_int_id) ? $this->course_int_id : api_get_course_int_id();
- }
- /**
- * @param $course_id
- *
- * @return int
- */
- public function set_course_int_id($course_id)
- {
- return $this->course_int_id = (int) $course_id;
- }
- /**
- * Function rewritten based on old_add_item() from Yannick Warnier.
- * Due the fact that users can decide where the item should come, I had to overlook this function and
- * I found it better to rewrite it. Old function is still available.
- * Added also the possibility to add a description.
- *
- * @param int $parent
- * @param int $previous
- * @param string $type
- * @param int $id resource ID (ref)
- * @param string $title
- * @param string $description
- * @param int $prerequisites
- * @param int $max_time_allowed
- * @param int $userId
- *
- * @return int
- */
- public function add_item(
- $parent,
- $previous,
- $type = 'dir',
- $id,
- $title,
- $description,
- $prerequisites = 0,
- $max_time_allowed = 0,
- $userId = 0
- ) {
- $course_id = $this->course_info['real_id'];
- if (empty($course_id)) {
- // Sometimes Oogie doesn't catch the course info but sets $this->cc
- $this->course_info = api_get_course_info($this->cc);
- $course_id = $this->course_info['real_id'];
- }
- $userId = empty($userId) ? api_get_user_id() : $userId;
- $sessionId = api_get_session_id();
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $_course = $this->course_info;
- $parent = (int) $parent;
- $previous = (int) $previous;
- $id = (int) $id;
- $max_time_allowed = htmlentities($max_time_allowed);
- if (empty($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- $sql = "SELECT COUNT(iid) AS num
- FROM $tbl_lp_item
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- parent_item_id = $parent ";
- $res_count = Database::query($sql);
- $row = Database::fetch_array($res_count);
- $num = $row['num'];
- $tmp_previous = 0;
- $display_order = 0;
- $next = 0;
- if ($num > 0) {
- if (empty($previous)) {
- $sql = "SELECT iid, next_item_id, display_order
- FROM $tbl_lp_item
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- parent_item_id = $parent AND
- previous_item_id = 0 OR
- previous_item_id = $parent";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if ($row) {
- $next = $row['iid'];
- }
- } else {
- $previous = (int) $previous;
- $sql = "SELECT iid, previous_item_id, next_item_id, display_order
- FROM $tbl_lp_item
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- id = $previous";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if ($row) {
- $tmp_previous = $row['iid'];
- $next = $row['next_item_id'];
- $display_order = $row['display_order'];
- }
- }
- }
- $id = (int) $id;
- $typeCleaned = Database::escape_string($type);
- $max_score = 100;
- if ($type === 'quiz') {
- $sql = 'SELECT SUM(ponderation)
- FROM '.Database::get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
- INNER JOIN '.Database::get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
- ON
- quiz_question.id = quiz_rel_question.question_id AND
- quiz_question.c_id = quiz_rel_question.c_id
- WHERE
- quiz_rel_question.exercice_id = '.$id." AND
- quiz_question.c_id = $course_id AND
- quiz_rel_question.c_id = $course_id ";
- $rsQuiz = Database::query($sql);
- $max_score = Database::result($rsQuiz, 0, 0);
- // Disabling the exercise if we add it inside a LP
- $exercise = new Exercise($course_id);
- $exercise->read($id);
- $exercise->disable();
- $exercise->save();
- }
- $params = [
- 'c_id' => $course_id,
- 'lp_id' => $this->get_id(),
- 'item_type' => $typeCleaned,
- 'ref' => '',
- 'title' => $title,
- 'description' => $description,
- 'path' => $id,
- 'max_score' => $max_score,
- 'parent_item_id' => $parent,
- 'previous_item_id' => $previous,
- 'next_item_id' => (int) $next,
- 'display_order' => $display_order + 1,
- 'prerequisite' => $prerequisites,
- 'max_time_allowed' => $max_time_allowed,
- 'min_score' => 0,
- 'launch_data' => '',
- ];
- if ($prerequisites != 0) {
- $params['prerequisite'] = $prerequisites;
- }
- $new_item_id = Database::insert($tbl_lp_item, $params);
- if ($new_item_id) {
- $sql = "UPDATE $tbl_lp_item SET id = iid WHERE iid = $new_item_id";
- Database::query($sql);
- if (!empty($next)) {
- $sql = "UPDATE $tbl_lp_item
- SET previous_item_id = $new_item_id
- WHERE c_id = $course_id AND id = $next AND item_type != '".TOOL_LP_FINAL_ITEM."'";
- Database::query($sql);
- }
- // Update the item that should be before the new item.
- if (!empty($tmp_previous)) {
- $sql = "UPDATE $tbl_lp_item
- SET next_item_id = $new_item_id
- WHERE c_id = $course_id AND id = $tmp_previous";
- Database::query($sql);
- }
- // Update all the items after the new item.
- $sql = "UPDATE $tbl_lp_item
- SET display_order = display_order + 1
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- iid <> $new_item_id AND
- parent_item_id = $parent AND
- display_order > $display_order";
- Database::query($sql);
- // Update the item that should come after the new item.
- $sql = "UPDATE $tbl_lp_item
- SET ref = $new_item_id
- WHERE c_id = $course_id AND iid = $new_item_id";
- Database::query($sql);
- $sql = "UPDATE $tbl_lp_item
- SET previous_item_id = ".$this->getLastInFirstLevel()."
- WHERE c_id = $course_id AND lp_id = {$this->lp_id} AND item_type = '".TOOL_LP_FINAL_ITEM."'";
- Database::query($sql);
- // Upload audio.
- if (!empty($_FILES['mp3']['name'])) {
- // Create the audio folder if it does not exist yet.
- $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
- if (!is_dir($filepath.'audio')) {
- mkdir(
- $filepath.'audio',
- api_get_permissions_for_new_directories()
- );
- $audio_id = add_document(
- $_course,
- '/audio',
- 'folder',
- 0,
- 'audio',
- '',
- 0,
- true,
- null,
- $sessionId,
- $userId
- );
- api_item_property_update(
- $_course,
- TOOL_DOCUMENT,
- $audio_id,
- 'FolderCreated',
- $userId,
- null,
- null,
- null,
- null,
- $sessionId
- );
- api_item_property_update(
- $_course,
- TOOL_DOCUMENT,
- $audio_id,
- 'invisible',
- $userId,
- null,
- null,
- null,
- null,
- $sessionId
- );
- }
- $file_path = handle_uploaded_document(
- $_course,
- $_FILES['mp3'],
- api_get_path(SYS_COURSE_PATH).$_course['path'].'/document',
- '/audio',
- $userId,
- '',
- '',
- '',
- '',
- false
- );
- // Getting the filename only.
- $file_components = explode('/', $file_path);
- $file = $file_components[count($file_components) - 1];
- // Store the mp3 file in the lp_item table.
- $sql = "UPDATE $tbl_lp_item SET
- audio = '".Database::escape_string($file)."'
- WHERE iid = '".intval($new_item_id)."'";
- Database::query($sql);
- }
- }
- return $new_item_id;
- }
- /**
- * Static admin function allowing addition of a learnpath to a course.
- *
- * @param string $courseCode
- * @param string $name
- * @param string $description
- * @param string $learnpath
- * @param string $origin
- * @param string $zipname Zip file containing the learnpath or directory containing the learnpath
- * @param string $publicated_on
- * @param string $expired_on
- * @param int $categoryId
- * @param int $userId
- *
- * @return int The new learnpath ID on success, 0 on failure
- */
- public static function add_lp(
- $courseCode,
- $name,
- $description = '',
- $learnpath = 'guess',
- $origin = 'zip',
- $zipname = '',
- $publicated_on = '',
- $expired_on = '',
- $categoryId = 0,
- $userId = 0
- ) {
- global $charset;
- if (!empty($courseCode)) {
- $courseInfo = api_get_course_info($courseCode);
- $course_id = $courseInfo['real_id'];
- } else {
- $course_id = api_get_course_int_id();
- $courseInfo = api_get_course_info();
- }
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- // Check course code exists.
- // Check lp_name doesn't exist, otherwise append something.
- $i = 0;
- $name = Database::escape_string($name);
- $categoryId = (int) $categoryId;
- // Session id.
- $session_id = api_get_session_id();
- $userId = empty($userId) ? api_get_user_id() : $userId;
- $check_name = "SELECT * FROM $tbl_lp
- WHERE c_id = $course_id AND name = '$name'";
- $res_name = Database::query($check_name);
- if (empty($publicated_on)) {
- $publicated_on = null;
- } else {
- $publicated_on = Database::escape_string(api_get_utc_datetime($publicated_on));
- }
- if (empty($expired_on)) {
- $expired_on = null;
- } else {
- $expired_on = Database::escape_string(api_get_utc_datetime($expired_on));
- }
- while (Database::num_rows($res_name)) {
- // There is already one such name, update the current one a bit.
- $i++;
- $name = $name.' - '.$i;
- $check_name = "SELECT * FROM $tbl_lp
- WHERE c_id = $course_id AND name = '$name'";
- $res_name = Database::query($check_name);
- }
- // New name does not exist yet; keep it.
- // Escape description.
- // Kevin: added htmlentities().
- $description = Database::escape_string(api_htmlentities($description, ENT_QUOTES, $charset));
- $type = 1;
- switch ($learnpath) {
- case 'guess':
- break;
- case 'dokeos':
- case 'chamilo':
- $type = 1;
- break;
- case 'aicc':
- break;
- }
- switch ($origin) {
- case 'zip':
- // Check zip name string. If empty, we are currently creating a new Chamilo learnpath.
- break;
- case 'manual':
- default:
- $get_max = "SELECT MAX(display_order)
- FROM $tbl_lp WHERE c_id = $course_id";
- $res_max = Database::query($get_max);
- if (Database::num_rows($res_max) < 1) {
- $dsp = 1;
- } else {
- $row = Database::fetch_array($res_max);
- $dsp = $row[0] + 1;
- }
- $params = [
- 'c_id' => $course_id,
- 'lp_type' => $type,
- 'name' => $name,
- 'description' => $description,
- 'path' => '',
- 'default_view_mod' => 'embedded',
- 'default_encoding' => 'UTF-8',
- 'display_order' => $dsp,
- 'content_maker' => 'Chamilo',
- 'content_local' => 'local',
- 'js_lib' => '',
- 'session_id' => $session_id,
- 'created_on' => api_get_utc_datetime(),
- 'modified_on' => api_get_utc_datetime(),
- 'publicated_on' => $publicated_on,
- 'expired_on' => $expired_on,
- 'category_id' => $categoryId,
- 'force_commit' => 0,
- 'content_license' => '',
- 'debug' => 0,
- 'theme' => '',
- 'preview_image' => '',
- 'author' => '',
- 'prerequisite' => 0,
- 'hide_toc_frame' => 0,
- 'seriousgame_mode' => 0,
- 'autolaunch' => 0,
- 'max_attempts' => 0,
- 'subscribe_users' => 0,
- 'accumulate_scorm_time' => 1,
- ];
- $id = Database::insert($tbl_lp, $params);
- if ($id > 0) {
- $sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id";
- Database::query($sql);
- // Insert into item_property.
- api_item_property_update(
- $courseInfo,
- TOOL_LEARNPATH,
- $id,
- 'LearnpathAdded',
- $userId
- );
- api_set_default_visibility(
- $id,
- TOOL_LEARNPATH,
- 0,
- $courseInfo,
- $session_id,
- $userId
- );
- return $id;
- }
- break;
- }
- }
- /**
- * Auto completes the parents of an item in case it's been completed or passed.
- *
- * @param int $item Optional ID of the item from which to look for parents
- */
- public function autocomplete_parents($item)
- {
- $debug = $this->debug;
- if (empty($item)) {
- $item = $this->current;
- }
- $currentItem = $this->getItem($item);
- if ($currentItem) {
- $parent_id = $currentItem->get_parent();
- $parent = $this->getItem($parent_id);
- if ($parent) {
- // if $item points to an object and there is a parent.
- if ($debug) {
- error_log(
- 'Autocompleting parent of item '.$item.' '.
- $currentItem->get_title().'" (item '.$parent_id.' "'.$parent->get_title().'") ',
- 0
- );
- }
- // New experiment including failed and browsed in completed status.
- //$current_status = $currentItem->get_status();
- //if ($currentItem->is_done() || $current_status == 'browsed' || $current_status == 'failed') {
- // Fixes chapter auto complete
- if (true) {
- // If the current item is completed or passes or succeeded.
- $updateParentStatus = true;
- if ($debug) {
- error_log('Status of current item is alright');
- }
- foreach ($parent->get_children() as $childItemId) {
- $childItem = $this->getItem($childItemId);
- // If children was not set try to get the info
- if (empty($childItem->db_item_view_id)) {
- $childItem->set_lp_view($this->lp_view_id, $this->course_int_id);
- }
- // Check all his brothers (parent's children) for completion status.
- if ($childItemId != $item) {
- if ($debug) {
- error_log(
- 'Looking at brother #'.$childItemId.' "'.$childItem->get_title().'", status is '.$childItem->get_status(),
- 0
- );
- }
- // Trying completing parents of failed and browsed items as well.
- if ($childItem->status_is(
- [
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- 'failed',
- ]
- )
- ) {
- // Keep completion status to true.
- continue;
- } else {
- if ($debug > 2) {
- error_log(
- 'Found one incomplete child of parent #'.$parent_id.': child #'.$childItemId.' "'.$childItem->get_title().'", is '.$childItem->get_status().' db_item_view_id:#'.$childItem->db_item_view_id,
- 0
- );
- }
- $updateParentStatus = false;
- break;
- }
- }
- }
- if ($updateParentStatus) {
- // If all the children were completed:
- $parent->set_status('completed');
- $parent->save(false, $this->prerequisites_match($parent->get_id()));
- // Force the status to "completed"
- //$this->update_queue[$parent->get_id()] = $parent->get_status();
- $this->update_queue[$parent->get_id()] = 'completed';
- if ($debug) {
- error_log(
- 'Added parent #'.$parent->get_id().' "'.$parent->get_title().'" to update queue status: completed '.
- print_r($this->update_queue, 1),
- 0
- );
- }
- // Recursive call.
- $this->autocomplete_parents($parent->get_id());
- }
- }
- } else {
- if ($debug) {
- error_log("Parent #$parent_id does not exists");
- }
- }
- } else {
- if ($debug) {
- error_log("#$item is an item that doesn't have parents");
- }
- }
- }
- /**
- * Closes the current resource.
- *
- * Stops the timer
- * Saves into the database if required
- * Clears the current resource data from this object
- *
- * @return bool True on success, false on failure
- */
- public function close()
- {
- if (empty($this->lp_id)) {
- $this->error = 'Trying to close this learnpath but no ID is set';
- return false;
- }
- $this->current_time_stop = time();
- $this->ordered_items = [];
- $this->index = 0;
- unset($this->lp_id);
- //unset other stuff
- return true;
- }
- /**
- * Static admin function allowing removal of a learnpath.
- *
- * @param array $courseInfo
- * @param int $id Learnpath ID
- * @param string $delete Whether to delete data or keep it (default: 'keep', others: 'remove')
- *
- * @return bool True on success, false on failure (might change that to return number of elements deleted)
- */
- public function delete($courseInfo = null, $id = null, $delete = 'keep')
- {
- $course_id = api_get_course_int_id();
- if (!empty($courseInfo)) {
- $course_id = isset($courseInfo['real_id']) ? $courseInfo['real_id'] : $course_id;
- }
- // TODO: Implement a way of getting this to work when the current object is not set.
- // In clear: implement this in the item class as well (abstract class) and use the given ID in queries.
- // If an ID is specifically given and the current LP is not the same, prevent delete.
- if (!empty($id) && ($id != $this->lp_id)) {
- return false;
- }
- $lp = Database::get_course_table(TABLE_LP_MAIN);
- $lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $lp_view = Database::get_course_table(TABLE_LP_VIEW);
- $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
- // Delete lp item id.
- foreach ($this->items as $lpItemId => $dummy) {
- $sql = "DELETE FROM $lp_item_view
- WHERE c_id = $course_id AND lp_item_id = '".$lpItemId."'";
- Database::query($sql);
- }
- // Proposed by Christophe (nickname: clefevre)
- $sql = "DELETE FROM $lp_item
- WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
- Database::query($sql);
- $sql = "DELETE FROM $lp_view
- WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
- Database::query($sql);
- self::toggle_publish($this->lp_id, 'i');
- if ($this->type == 2 || $this->type == 3) {
- // This is a scorm learning path, delete the files as well.
- $sql = "SELECT path FROM $lp
- WHERE iid = ".$this->lp_id;
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $path = $row['path'];
- $sql = "SELECT id FROM $lp
- WHERE
- c_id = $course_id AND
- path = '$path' AND
- iid != ".$this->lp_id;
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- // Another learning path uses this directory, so don't delete it.
- if ($this->debug > 2) {
- error_log('In learnpath::delete(), found other LP using path '.$path.', keeping directory', 0);
- }
- } else {
- // No other LP uses that directory, delete it.
- $course_rel_dir = api_get_course_path().'/scorm/'; // scorm dir web path starting from /courses
- // The absolute system path for this course.
- $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir;
- if ($delete == 'remove' && is_dir($course_scorm_dir.$path) && !empty($course_scorm_dir)) {
- if ($this->debug > 2) {
- error_log('In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path, 0);
- }
- // Proposed by Christophe (clefevre).
- if (strcmp(substr($path, -2), "/.") == 0) {
- $path = substr($path, 0, -1); // Remove "." at the end.
- }
- //exec('rm -rf ' . $course_scorm_dir . $path); // See Bug #5208, this is not OS-portable way.
- rmdirr($course_scorm_dir.$path);
- }
- }
- }
- }
- $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
- $link = 'lp/lp_controller.php?action=view&lp_id='.$this->lp_id;
- // Delete tools
- $sql = "DELETE FROM $tbl_tool
- WHERE c_id = $course_id AND (link LIKE '$link%' AND image='scormbuilder.gif')";
- Database::query($sql);
- $sql = "DELETE FROM $lp
- WHERE iid = ".$this->lp_id;
- Database::query($sql);
- // Updates the display order of all lps.
- $this->update_display_order();
- api_item_property_update(
- api_get_course_info(),
- TOOL_LEARNPATH,
- $this->lp_id,
- 'delete',
- api_get_user_id()
- );
- $link_info = GradebookUtils::isResourceInCourseGradebook(
- api_get_course_id(),
- 4,
- $id,
- api_get_session_id()
- );
- if ($link_info !== false) {
- GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
- }
- if (api_get_setting('search_enabled') == 'true') {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id);
- }
- }
- /**
- * Removes all the children of one item - dangerous!
- *
- * @param int $id Element ID of which children have to be removed
- *
- * @return int Total number of children removed
- */
- public function delete_children_items($id)
- {
- $course_id = $this->course_info['real_id'];
- $num = 0;
- $id = (int) $id;
- if (empty($id) || empty($course_id)) {
- return false;
- }
- $lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $lp_item
- WHERE c_id = $course_id AND parent_item_id = $id";
- $res = Database::query($sql);
- while ($row = Database::fetch_array($res)) {
- $num += $this->delete_children_items($row['iid']);
- $sql = "DELETE FROM $lp_item
- WHERE c_id = $course_id AND iid = ".$row['iid'];
- Database::query($sql);
- $num++;
- }
- return $num;
- }
- /**
- * Removes an item from the current learnpath.
- *
- * @param int $id Elem ID (0 if first)
- *
- * @return int Number of elements moved
- *
- * @todo implement resource removal
- */
- public function delete_item($id)
- {
- $course_id = api_get_course_int_id();
- $id = (int) $id;
- // TODO: Implement the resource removal.
- if (empty($id) || empty($course_id)) {
- return false;
- }
- // First select item to get previous, next, and display order.
- $lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql_sel = "SELECT * FROM $lp_item WHERE iid = $id";
- $res_sel = Database::query($sql_sel);
- if (Database::num_rows($res_sel) < 1) {
- return false;
- }
- $row = Database::fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
- // Delete children items.
- $this->delete_children_items($id);
- // Now delete the item.
- $sql_del = "DELETE FROM $lp_item WHERE iid = $id";
- Database::query($sql_del);
- // Now update surrounding items.
- $sql_upd = "UPDATE $lp_item SET next_item_id = $next
- WHERE iid = $previous";
- Database::query($sql_upd);
- $sql_upd = "UPDATE $lp_item SET previous_item_id = $previous
- WHERE iid = $next AND item_type != '".TOOL_LP_FINAL_ITEM."'";
- Database::query($sql_upd);
- // Now update all following items with new display order.
- $sql_all = "UPDATE $lp_item SET display_order = display_order-1
- WHERE
- c_id = $course_id AND
- lp_id = $lp AND
- parent_item_id = $parent AND
- display_order > $display";
- Database::query($sql_all);
- //Removing prerequisites since the item will not longer exist
- $sql_all = "UPDATE $lp_item SET prerequisite = ''
- WHERE c_id = $course_id AND prerequisite = $id";
- Database::query($sql_all);
- $sql = "UPDATE $lp_item
- SET previous_item_id = ".$this->getLastInFirstLevel()."
- WHERE c_id = $course_id AND lp_id = {$this->lp_id} AND item_type = '".TOOL_LP_FINAL_ITEM."'";
- Database::query($sql);
- // Remove from search engine if enabled.
- if (api_get_setting('search_enabled') === 'true') {
- $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'SELECT * FROM %s
- WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d
- LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row2 = Database::fetch_array($res);
- $di = new ChamiloIndexer();
- $di->remove_document($row2['search_did']);
- }
- $sql = 'DELETE FROM %s
- WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d
- LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id);
- Database::query($sql);
- }
- }
- /**
- * Updates an item's content in place.
- *
- * @param int $id Element ID
- * @param int $parent Parent item ID
- * @param int $previous Previous item ID
- * @param string $title Item title
- * @param string $description Item description
- * @param string $prerequisites Prerequisites (optional)
- * @param array $audio The array resulting of the $_FILES[mp3] element
- * @param int $max_time_allowed
- * @param string $url
- *
- * @return bool True on success, false on error
- */
- public function edit_item(
- $id,
- $parent,
- $previous,
- $title,
- $description,
- $prerequisites = '0',
- $audio = [],
- $max_time_allowed = 0,
- $url = ''
- ) {
- $course_id = api_get_course_int_id();
- $_course = api_get_course_info();
- $id = (int) $id;
- if (empty($max_time_allowed)) {
- $max_time_allowed = 0;
- }
- if (empty($id) || empty($_course)) {
- return false;
- }
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE iid = $id";
- $res_select = Database::query($sql);
- $row_select = Database::fetch_array($res_select);
- $audio_update_sql = '';
- if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error'] === 0) {
- // Create the audio folder if it does not exist yet.
- $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
- if (!is_dir($filepath.'audio')) {
- mkdir($filepath.'audio', api_get_permissions_for_new_directories());
- $audio_id = add_document(
- $_course,
- '/audio',
- 'folder',
- 0,
- 'audio'
- );
- api_item_property_update(
- $_course,
- TOOL_DOCUMENT,
- $audio_id,
- 'FolderCreated',
- api_get_user_id(),
- null,
- null,
- null,
- null,
- api_get_session_id()
- );
- api_item_property_update(
- $_course,
- TOOL_DOCUMENT,
- $audio_id,
- 'invisible',
- api_get_user_id(),
- null,
- null,
- null,
- null,
- api_get_session_id()
- );
- }
- // Upload file in documents.
- $pi = pathinfo($audio['name']);
- if ($pi['extension'] === 'mp3') {
- $c_det = api_get_course_info($this->cc);
- $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document';
- $path = handle_uploaded_document(
- $c_det,
- $audio,
- $bp,
- '/audio',
- api_get_user_id(),
- 0,
- null,
- 0,
- 'rename',
- false,
- 0
- );
- $path = substr($path, 7);
- // Update reference in lp_item - audio path is the path from inside de document/audio/ dir.
- $audio_update_sql = ", audio = '".Database::escape_string($path)."' ";
- }
- }
- $same_parent = $row_select['parent_item_id'] == $parent ? true : false;
- $same_previous = $row_select['previous_item_id'] == $previous ? true : false;
- // TODO: htmlspecialchars to be checked for encoding related problems.
- if ($same_parent && $same_previous) {
- // Only update title and description.
- $sql = "UPDATE $tbl_lp_item
- SET title = '".Database::escape_string($title)."',
- prerequisite = '".$prerequisites."',
- description = '".Database::escape_string($description)."'
- ".$audio_update_sql.",
- max_time_allowed = '".Database::escape_string($max_time_allowed)."'
- WHERE iid = $id";
- Database::query($sql);
- } else {
- $old_parent = $row_select['parent_item_id'];
- $old_previous = $row_select['previous_item_id'];
- $old_next = $row_select['next_item_id'];
- $old_order = $row_select['display_order'];
- $old_prerequisite = $row_select['prerequisite'];
- $old_max_time_allowed = $row_select['max_time_allowed'];
- /* BEGIN -- virtually remove the current item id */
- /* for the next and previous item it is like the current item doesn't exist anymore */
- if ($old_previous != 0) {
- // Next
- $sql = "UPDATE $tbl_lp_item
- SET next_item_id = $old_next
- WHERE iid = $old_previous";
- Database::query($sql);
- }
- if (!empty($old_next)) {
- // Previous
- $sql = "UPDATE $tbl_lp_item
- SET previous_item_id = $old_previous
- WHERE iid = $old_next";
- Database::query($sql);
- }
- // display_order - 1 for every item with a display_order
- // bigger then the display_order of the current item.
- $sql = "UPDATE $tbl_lp_item
- SET display_order = display_order - 1
- WHERE
- c_id = $course_id AND
- display_order > $old_order AND
- lp_id = ".$this->lp_id." AND
- parent_item_id = $old_parent";
- Database::query($sql);
- /* END -- virtually remove the current item id */
- /* BEGIN -- update the current item id to his new location */
- if ($previous == 0) {
- // Select the data of the item that should come after the current item.
- $sql = "SELECT id, display_order
- FROM $tbl_lp_item
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->lp_id." AND
- parent_item_id = $parent AND
- previous_item_id = $previous";
- $res_select_old = Database::query($sql);
- $row_select_old = Database::fetch_array($res_select_old);
- // If the new parent didn't have children before.
- if (Database::num_rows($res_select_old) == 0) {
- $new_next = 0;
- $new_order = 1;
- } else {
- $new_next = $row_select_old['id'];
- $new_order = $row_select_old['display_order'];
- }
- } else {
- // Select the data of the item that should come before the current item.
- $sql = "SELECT next_item_id, display_order
- FROM $tbl_lp_item
- WHERE iid = $previous";
- $res_select_old = Database::query($sql);
- $row_select_old = Database::fetch_array($res_select_old);
- $new_next = $row_select_old['next_item_id'];
- $new_order = $row_select_old['display_order'] + 1;
- }
- // TODO: htmlspecialchars to be checked for encoding related problems.
- // Update the current item with the new data.
- $sql = "UPDATE $tbl_lp_item
- SET
- title = '".Database::escape_string($title)."',
- description = '".Database::escape_string($description)."',
- parent_item_id = $parent,
- previous_item_id = $previous,
- next_item_id = $new_next,
- display_order = $new_order
- $audio_update_sql
- WHERE iid = $id";
- Database::query($sql);
- if ($previous != 0) {
- // Update the previous item's next_item_id.
- $sql = "UPDATE $tbl_lp_item
- SET next_item_id = $id
- WHERE iid = $previous";
- Database::query($sql);
- }
- if (!empty($new_next)) {
- // Update the next item's previous_item_id.
- $sql = "UPDATE $tbl_lp_item
- SET previous_item_id = $id
- WHERE iid = $new_next";
- Database::query($sql);
- }
- if ($old_prerequisite != $prerequisites) {
- $sql = "UPDATE $tbl_lp_item
- SET prerequisite = '$prerequisites'
- WHERE iid = $id";
- Database::query($sql);
- }
- if ($old_max_time_allowed != $max_time_allowed) {
- // update max time allowed
- $sql = "UPDATE $tbl_lp_item
- SET max_time_allowed = $max_time_allowed
- WHERE iid = $id";
- Database::query($sql);
- }
- // Update all the items with the same or a bigger display_order than the current item.
- $sql = "UPDATE $tbl_lp_item
- SET display_order = display_order + 1
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- iid <> $id AND
- parent_item_id = $parent AND
- display_order >= $new_order";
- Database::query($sql);
- }
- if ($row_select['item_type'] == 'link') {
- $link = new Link();
- $linkId = $row_select['path'];
- $link->updateLink($linkId, $url);
- }
- }
- /**
- * Updates an item's prereq in place.
- *
- * @param int $id Element ID
- * @param string $prerequisite_id Prerequisite Element ID
- * @param int $minScore Prerequisite min score
- * @param int $maxScore Prerequisite max score
- *
- * @return bool True on success, false on error
- */
- public function edit_item_prereq(
- $id,
- $prerequisite_id,
- $minScore = 0,
- $maxScore = 100
- ) {
- $id = (int) $id;
- $prerequisite_id = (int) $prerequisite_id;
- if (empty($id)) {
- return false;
- }
- if (empty($minScore) || $minScore < 0) {
- $minScore = 0;
- }
- if (empty($maxScore) || $maxScore < 0) {
- $maxScore = 100;
- }
- $minScore = floatval($minScore);
- $maxScore = floatval($maxScore);
- if (empty($prerequisite_id)) {
- $prerequisite_id = 'NULL';
- $minScore = 0;
- $maxScore = 100;
- }
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = " UPDATE $tbl_lp_item
- SET
- prerequisite = $prerequisite_id ,
- prerequisite_min_score = $minScore ,
- prerequisite_max_score = $maxScore
- WHERE iid = $id";
- Database::query($sql);
- return true;
- }
- /**
- * Gets all the chapters belonging to the same parent as the item/chapter given
- * Can also be called as abstract method.
- *
- * @deprecated not used
- *
- * @param int $id Item ID
- *
- * @return array A list of all the "brother items" (or an empty array on failure)
- */
- public function getSiblingDirectories($id)
- {
- $course_id = api_get_course_int_id();
- if (empty($id) || $id != strval(intval($id))) {
- return [];
- }
- $lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item
- WHERE iid = $id AND item_type='dir'";
- $res_parent = Database::query($sql_parent);
- if (Database::num_rows($res_parent) > 0) {
- $row_parent = Database::fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql = "SELECT * FROM $lp_item
- WHERE
- parent_item_id = $parent AND
- iid = $id AND
- item_type='dir'
- ORDER BY display_order";
- $res_bros = Database::query($sql);
- $list = [];
- while ($row_bro = Database::fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return [];
- }
- /**
- * Gets all the items belonging to the same parent as the item given
- * Can also be called as abstract method.
- *
- * @deprecated not used
- *
- * @param int $id Item ID
- *
- * @return array A list of all the "brother items" (or an empty array on failure)
- */
- public function get_brother_items($id)
- {
- $course_id = api_get_course_int_id();
- if (empty($id) || $id != strval(intval($id))) {
- return [];
- }
- $lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql_parent = "SELECT * FROM $lp_item
- WHERE iid = $id";
- $res_parent = Database::query($sql_parent);
- if (Database::num_rows($res_parent) > 0) {
- $row_parent = Database::fetch_array($res_parent);
- $parent = $row_parent['parent_item_id'];
- $sql = "SELECT * FROM $lp_item
- WHERE c_id = $course_id AND parent_item_id = $parent
- ORDER BY display_order";
- $res_bros = Database::query($sql);
- $list = [];
- while ($row_bro = Database::fetch_array($res_bros)) {
- $list[] = $row_bro;
- }
- return $list;
- }
- return [];
- }
- /**
- * Get the specific prefix index terms of this learning path.
- *
- * @param string $prefix
- *
- * @return array Array of terms
- */
- public function get_common_index_terms_by_prefix($prefix)
- {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $terms = get_specific_field_values_list_by_prefix(
- $prefix,
- $this->cc,
- TOOL_LEARNPATH,
- $this->lp_id
- );
- $prefix_terms = [];
- if (!empty($terms)) {
- foreach ($terms as $term) {
- $prefix_terms[] = $term['value'];
- }
- }
- return $prefix_terms;
- }
- /**
- * Gets the number of items currently completed.
- *
- * @param bool $failedStatusException flag to determine the failed status is not considered progressed
- *
- * @return int The number of items currently completed
- */
- public function get_complete_items_count($failedStatusException = false)
- {
- $i = 0;
- $completedStatusList = [
- 'completed',
- 'passed',
- 'succeeded',
- 'browsed',
- ];
- if (!$failedStatusException) {
- $completedStatusList[] = 'failed';
- }
- foreach ($this->items as $id => $dummy) {
- // Trying failed and browsed considered "progressed" as well.
- if ($this->items[$id]->status_is($completedStatusList) &&
- $this->items[$id]->get_type() != 'dir'
- ) {
- $i++;
- }
- }
- return $i;
- }
- /**
- * Gets the current item ID.
- *
- * @return int The current learnpath item id
- */
- public function get_current_item_id()
- {
- $current = 0;
- if (!empty($this->current)) {
- $current = (int) $this->current;
- }
- return $current;
- }
- /**
- * Force to get the first learnpath item id.
- *
- * @return int The current learnpath item id
- */
- public function get_first_item_id()
- {
- $current = 0;
- if (is_array($this->ordered_items)) {
- $current = $this->ordered_items[0];
- }
- return $current;
- }
- /**
- * Gets the total number of items available for viewing in this SCORM.
- *
- * @return int The total number of items
- */
- public function get_total_items_count()
- {
- return count($this->items);
- }
- /**
- * Gets the total number of items available for viewing in this SCORM but without chapters.
- *
- * @return int The total no-chapters number of items
- */
- public function getTotalItemsCountWithoutDirs()
- {
- $total = 0;
- $typeListNotToCount = self::getChapterTypes();
- foreach ($this->items as $temp2) {
- if (!in_array($temp2->get_type(), $typeListNotToCount)) {
- $total++;
- }
- }
- return $total;
- }
- /**
- * Sets the first element URL.
- */
- public function first()
- {
- if ($this->debug > 0) {
- error_log('In learnpath::first()', 0);
- error_log('$this->last_item_seen '.$this->last_item_seen);
- }
- // Test if the last_item_seen exists and is not a dir.
- if (count($this->ordered_items) == 0) {
- $this->index = 0;
- }
- if (!empty($this->last_item_seen) &&
- !empty($this->items[$this->last_item_seen]) &&
- $this->items[$this->last_item_seen]->get_type() != 'dir'
- //with this change (below) the LP will NOT go to the next item, it will take lp item we left
- //&& !$this->items[$this->last_item_seen]->is_done()
- ) {
- if ($this->debug > 2) {
- error_log(
- 'In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.
- $this->items[$this->last_item_seen]->get_type()
- );
- }
- $index = -1;
- foreach ($this->ordered_items as $myindex => $item_id) {
- if ($item_id == $this->last_item_seen) {
- $index = $myindex;
- break;
- }
- }
- if ($index == -1) {
- // Index hasn't changed, so item not found - panic (this shouldn't happen).
- if ($this->debug > 2) {
- error_log('Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!', 0);
- }
- return false;
- } else {
- $this->last = $this->last_item_seen;
- $this->current = $this->last_item_seen;
- $this->index = $index;
- }
- } else {
- if ($this->debug > 2) {
- error_log('In learnpath::first() - No last item seen', 0);
- }
- $index = 0;
- // Loop through all ordered items and stop at the first item that is
- // not a directory *and* that has not been completed yet.
- while (!empty($this->ordered_items[$index]) &&
- is_a($this->items[$this->ordered_items[$index]], 'learnpathItem') &&
- (
- $this->items[$this->ordered_items[$index]]->get_type() == 'dir' ||
- $this->items[$this->ordered_items[$index]]->is_done() === true
- ) && $index < $this->max_ordered_items) {
- $index++;
- }
- $this->last = $this->current;
- // current is
- $this->current = isset($this->ordered_items[$index]) ? $this->ordered_items[$index] : null;
- $this->index = $index;
- if ($this->debug > 2) {
- error_log('$index '.$index);
- error_log('In learnpath::first() - No last item seen');
- error_log('New last = '.$this->last.'('.$this->ordered_items[$index].')');
- }
- }
- if ($this->debug > 2) {
- error_log('In learnpath::first() - First item is '.$this->get_current_item_id());
- }
- }
- /**
- * Gets the js library from the database.
- *
- * @return string The name of the javascript library to be used
- */
- public function get_js_lib()
- {
- $lib = '';
- if (!empty($this->js_lib)) {
- $lib = $this->js_lib;
- }
- return $lib;
- }
- /**
- * Gets the learnpath database ID.
- *
- * @return int Learnpath ID in the lp table
- */
- public function get_id()
- {
- if (!empty($this->lp_id)) {
- return (int) $this->lp_id;
- }
- return 0;
- }
- /**
- * Gets the last element URL.
- *
- * @return string URL to load into the viewer
- */
- public function get_last()
- {
- // This is just in case the lesson doesn't cointain a valid scheme, just to avoid "Notices"
- if (count($this->ordered_items) > 0) {
- $this->index = count($this->ordered_items) - 1;
- return $this->ordered_items[$this->index];
- }
- return false;
- }
- /**
- * Get the last element in the first level.
- * Unlike learnpath::get_last this function doesn't consider the subsection' elements.
- *
- * @return mixed
- */
- public function getLastInFirstLevel()
- {
- try {
- $lastId = Database::getManager()
- ->createQuery('SELECT i.iid FROM ChamiloCourseBundle:CLpItem i
- WHERE i.lpId = :lp AND i.parentItemId = 0 AND i.itemType != :type ORDER BY i.displayOrder DESC')
- ->setMaxResults(1)
- ->setParameters(['lp' => $this->lp_id, 'type' => TOOL_LP_FINAL_ITEM])
- ->getSingleScalarResult();
- return $lastId;
- } catch (Exception $exception) {
- return 0;
- }
- }
- /**
- * Gets the navigation bar for the learnpath display screen.
- *
- * @param string $barId
- *
- * @return string The HTML string to use as a navigation bar
- */
- public function get_navigation_bar($barId = '')
- {
- if (empty($barId)) {
- $barId = 'control-top';
- }
- $lpId = $this->lp_id;
- $mycurrentitemid = $this->get_current_item_id();
- $reportingText = get_lang('Reporting');
- $previousText = get_lang('ScormPrevious');
- $nextText = get_lang('ScormNext');
- $fullScreenText = get_lang('ScormExitFullScreen');
- $settings = api_get_configuration_value('lp_view_settings');
- $display = isset($settings['display']) ? $settings['display'] : false;
- $reportingIcon = '
- <a class="icon-toolbar"
- id="stats_link"
- href="lp_controller.php?action=stats&'.api_get_cidreq(true).'&lp_id='.$lpId.'"
- onclick="window.parent.API.save_asset(); return true;"
- target="content_name" title="'.$reportingText.'">
- <span class="fa fa-info"></span><span class="sr-only">'.$reportingText.'</span>
- </a>';
- if (!empty($display)) {
- $showReporting = isset($display['show_reporting_icon']) ? $display['show_reporting_icon'] : true;
- if ($showReporting === false) {
- $reportingIcon = '';
- }
- }
- $hideArrows = false;
- if (isset($settings['display']) && isset($settings['display']['hide_lp_arrow_navigation'])) {
- $hideArrows = $settings['display']['hide_lp_arrow_navigation'];
- }
- $previousIcon = '';
- $nextIcon = '';
- if ($hideArrows === false) {
- $previousIcon = '
- <a class="icon-toolbar" id="scorm-previous" href="#"
- onclick="switch_item('.$mycurrentitemid.',\'previous\');return false;" title="'.$previousText.'">
- <span class="fa fa-chevron-left"></span><span class="sr-only">'.$previousText.'</span>
- </a>';
- $nextIcon = '
- <a class="icon-toolbar" id="scorm-next" href="#"
- onclick="switch_item('.$mycurrentitemid.',\'next\');return false;" title="'.$nextText.'">
- <span class="fa fa-chevron-right"></span><span class="sr-only">'.$nextText.'</span>
- </a>';
- }
- if ($this->mode === 'fullscreen') {
- $navbar = '
- <span id="'.$barId.'" class="buttons">
- '.$reportingIcon.'
- '.$previousIcon.'
- '.$nextIcon.'
- <a class="icon-toolbar" id="view-embedded"
- href="lp_controller.php?action=mode&mode=embedded" target="_top" title="'.$fullScreenText.'">
- <span class="fa fa-columns"></span><span class="sr-only">'.$fullScreenText.'</span>
- </a>
- </span>';
- } else {
- $navbar = '
- <span id="'.$barId.'" class="buttons text-right">
- '.$reportingIcon.'
- '.$previousIcon.'
- '.$nextIcon.'
- </span>';
- }
- return $navbar;
- }
- /**
- * Gets the next resource in queue (url).
- *
- * @return string URL to load into the viewer
- */
- public function get_next_index()
- {
- // TODO
- $index = $this->index;
- $index++;
- while (
- !empty($this->ordered_items[$index]) && ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') &&
- $index < $this->max_ordered_items
- ) {
- $index++;
- if ($index == $this->max_ordered_items) {
- if ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') {
- return $this->index;
- }
- return $index;
- }
- }
- if (empty($this->ordered_items[$index])) {
- return $this->index;
- }
- return $index;
- }
- /**
- * Gets item_id for the next element.
- *
- * @return int Next item (DB) ID
- */
- public function get_next_item_id()
- {
- $new_index = $this->get_next_index();
- if (!empty($new_index)) {
- if (isset($this->ordered_items[$new_index])) {
- return $this->ordered_items[$new_index];
- }
- }
- return 0;
- }
- /**
- * Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...).
- *
- * Generally, the package provided is in the form of a zip file, so the function
- * has been written to test a zip file. If not a zip, the function will return the
- * default return value: ''
- *
- * @param string $file_path the path to the file
- * @param string $file_name the original name of the file
- *
- * @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
- */
- public static function get_package_type($file_path, $file_name)
- {
- // Get name of the zip file without the extension.
- $file_info = pathinfo($file_name);
- $extension = $file_info['extension']; // Extension only.
- if (!empty($_POST['ppt2lp']) && !in_array(strtolower($extension), [
- 'dll',
- 'exe',
- ])) {
- return 'oogie';
- }
- if (!empty($_POST['woogie']) && !in_array(strtolower($extension), [
- 'dll',
- 'exe',
- ])) {
- return 'woogie';
- }
- $zipFile = new PclZip($file_path);
- // Check the zip content (real size and file extension).
- $zipContentArray = $zipFile->listContent();
- $package_type = '';
- $manifest = '';
- $aicc_match_crs = 0;
- $aicc_match_au = 0;
- $aicc_match_des = 0;
- $aicc_match_cst = 0;
- // The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?).
- if (is_array($zipContentArray) && count($zipContentArray) > 0) {
- foreach ($zipContentArray as $thisContent) {
- if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
- // New behaviour: Don't do anything. These files will be removed in scorm::import_package.
- } elseif (stristr($thisContent['filename'], 'imsmanifest.xml') !== false) {
- $manifest = $thisContent['filename']; // Just the relative directory inside scorm/
- $package_type = 'scorm';
- break; // Exit the foreach loop.
- } elseif (
- preg_match('/aicc\//i', $thisContent['filename']) ||
- in_array(
- strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION)),
- ['crs', 'au', 'des', 'cst']
- )
- ) {
- $ext = strtolower(pathinfo($thisContent['filename'], PATHINFO_EXTENSION));
- switch ($ext) {
- case 'crs':
- $aicc_match_crs = 1;
- break;
- case 'au':
- $aicc_match_au = 1;
- break;
- case 'des':
- $aicc_match_des = 1;
- break;
- case 'cst':
- $aicc_match_cst = 1;
- break;
- default:
- break;
- }
- //break; // Don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC.
- } else {
- $package_type = '';
- }
- }
- }
- if (empty($package_type) && 4 == ($aicc_match_crs + $aicc_match_au + $aicc_match_des + $aicc_match_cst)) {
- // If found an aicc directory... (!= false means it cannot be false (error) or 0 (no match)).
- $package_type = 'aicc';
- }
- // Try with chamilo course builder
- if (empty($package_type)) {
- $package_type = 'chamilo';
- }
- return $package_type;
- }
- /**
- * Gets the previous resource in queue (url). Also initialises time values for this viewing.
- *
- * @return string URL to load into the viewer
- */
- public function get_previous_index()
- {
- $index = $this->index;
- if (isset($this->ordered_items[$index - 1])) {
- $index--;
- while (isset($this->ordered_items[$index]) &&
- ($this->items[$this->ordered_items[$index]]->get_type() == 'dir')
- ) {
- $index--;
- if ($index < 0) {
- return $this->index;
- }
- }
- }
- return $index;
- }
- /**
- * Gets item_id for the next element.
- *
- * @return int Previous item (DB) ID
- */
- public function get_previous_item_id()
- {
- $index = $this->get_previous_index();
- return $this->ordered_items[$index];
- }
- /**
- * Returns the HTML necessary to print a mediaplayer block inside a page.
- *
- * @param int $lpItemId
- * @param string $autostart
- *
- * @return string The mediaplayer HTML
- */
- public function get_mediaplayer($lpItemId, $autostart = 'true')
- {
- $course_id = api_get_course_int_id();
- $_course = api_get_course_info();
- if (empty($_course)) {
- return '';
- }
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
- $lpItemId = (int) $lpItemId;
- /** @var learnpathItem $item */
- $item = isset($this->items[$lpItemId]) ? $this->items[$lpItemId] : null;
- $itemViewId = 0;
- if ($item) {
- $itemViewId = (int) $item->db_item_view_id;
- }
- // Getting all the information about the item.
- $sql = "SELECT lpi.audio, lpi.item_type, lp_view.status
- FROM $tbl_lp_item as lpi
- INNER JOIN $tbl_lp_item_view as lp_view
- ON (lpi.iid = lp_view.lp_item_id)
- WHERE
- lp_view.iid = $itemViewId AND
- lpi.iid = $lpItemId AND
- lp_view.c_id = $course_id";
- $result = Database::query($sql);
- $row = Database::fetch_assoc($result);
- $output = '';
- if (!empty($row['audio'])) {
- $list = $_SESSION['oLP']->get_toc();
- switch ($row['item_type']) {
- case 'quiz':
- $type_quiz = false;
- foreach ($list as $toc) {
- if ($toc['id'] == $_SESSION['oLP']->current) {
- $type_quiz = true;
- }
- }
- if ($type_quiz) {
- if ($_SESSION['oLP']->prevent_reinit == 1) {
- $autostart_audio = $row['status'] === 'completed' ? 'false' : 'true';
- } else {
- $autostart_audio = $autostart;
- }
- }
- break;
- case TOOL_READOUT_TEXT:;
- $autostart_audio = 'false';
- break;
- default:
- $autostart_audio = 'true';
- }
- $courseInfo = api_get_course_info();
- $audio = $row['audio'];
- $file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
- $url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio.'?'.api_get_cidreq();
- if (!file_exists($file)) {
- $lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
- $file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
- $url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio.'?'.api_get_cidreq();
- }
- $player = Display::getMediaPlayer(
- $file,
- [
- 'id' => 'lp_audio_media_player',
- 'url' => $url,
- 'autoplay' => $autostart_audio,
- 'width' => '100%',
- ]
- );
- // The mp3 player.
- $output = '<div id="container">';
- $output .= $player;
- $output .= '</div>';
- }
- return $output;
- }
- /**
- * @param int $studentId
- * @param int $prerequisite
- * @param array $courseInfo
- * @param int $sessionId
- *
- * @return bool
- */
- public static function isBlockedByPrerequisite(
- $studentId,
- $prerequisite,
- $courseInfo,
- $sessionId
- ) {
- if (empty($courseInfo)) {
- return false;
- }
- $courseId = $courseInfo['real_id'];
- $allow = api_get_configuration_value('allow_teachers_to_access_blocked_lp_by_prerequisite');
- if ($allow) {
- if (api_is_allowed_to_edit() ||
- api_is_platform_admin(true) ||
- api_is_drh() ||
- api_is_coach($sessionId, $courseId, false)
- ) {
- return false;
- }
- }
- $isBlocked = false;
- if (!empty($prerequisite)) {
- $progress = self::getProgress(
- $prerequisite,
- $studentId,
- $courseId,
- $sessionId
- );
- if ($progress < 100) {
- $isBlocked = true;
- }
- if (Tracking::minimumTimeAvailable($sessionId, $courseId)) {
- // Block if it does not exceed minimum time
- // Minimum time (in minutes) to pass the learning path
- $accumulateWorkTime = self::getAccumulateWorkTimePrerequisite($prerequisite, $courseId);
- if ($accumulateWorkTime > 0) {
- // Total time in course (sum of times in learning paths from course)
- $accumulateWorkTimeTotal = self::getAccumulateWorkTimeTotal($courseId);
- // Connect with the plugin_licences_course_session table
- // which indicates what percentage of the time applies
- // Minimum connection percentage
- $perc = 100;
- // Time from the course
- $tc = $accumulateWorkTimeTotal;
- // Percentage of the learning paths
- $pl = $accumulateWorkTime / $accumulateWorkTimeTotal;
- // Minimum time for each learning path
- $accumulateWorkTime = ($pl * $tc * $perc / 100);
- // Spent time (in seconds) so far in the learning path
- $lpTimeList = Tracking::getCalculateTime($studentId, $courseId, $sessionId);
- $lpTime = isset($lpTimeList[TOOL_LEARNPATH][$prerequisite]) ? $lpTimeList[TOOL_LEARNPATH][$prerequisite] : 0;
- if ($lpTime < ($accumulateWorkTime * 60)) {
- $isBlocked = true;
- }
- }
- }
- }
- return $isBlocked;
- }
- /**
- * Checks if the learning path is visible for student after the progress
- * of its prerequisite is completed, considering the time availability and
- * the LP visibility.
- *
- * @param int $lp_id
- * @param int $student_id
- * @param array $courseInfo
- * @param int $sessionId
- *
- * @return bool
- */
- public static function is_lp_visible_for_student(
- $lp_id,
- $student_id,
- $courseInfo = [],
- $sessionId = 0
- ) {
- $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
- $lp_id = (int) $lp_id;
- $sessionId = (int) $sessionId;
- if (empty($courseInfo)) {
- return false;
- }
- if (empty($sessionId)) {
- $sessionId = api_get_session_id();
- }
- $courseId = $courseInfo['real_id'];
- $itemInfo = api_get_item_property_info(
- $courseId,
- TOOL_LEARNPATH,
- $lp_id,
- $sessionId
- );
- // If the item was deleted.
- if (isset($itemInfo['visibility']) && $itemInfo['visibility'] == 2) {
- return false;
- }
- // @todo remove this query and load the row info as a parameter
- $table = Database::get_course_table(TABLE_LP_MAIN);
- // Get current prerequisite
- $sql = "SELECT id, prerequisite, subscribe_users, publicated_on, expired_on
- FROM $table
- WHERE iid = $lp_id";
- $rs = Database::query($sql);
- $now = time();
- if (Database::num_rows($rs) > 0) {
- $row = Database::fetch_array($rs, 'ASSOC');
- $prerequisite = $row['prerequisite'];
- $is_visible = true;
- $isBlocked = self::isBlockedByPrerequisite(
- $student_id,
- $prerequisite,
- $courseInfo,
- $sessionId
- );
- if ($isBlocked) {
- $is_visible = false;
- }
- // Also check the time availability of the LP
- if ($is_visible) {
- // Adding visibility restrictions
- if (!empty($row['publicated_on'])) {
- if ($now < api_strtotime($row['publicated_on'], 'UTC')) {
- $is_visible = false;
- }
- }
- // Blocking empty start times see BT#2800
- global $_custom;
- if (isset($_custom['lps_hidden_when_no_start_date']) &&
- $_custom['lps_hidden_when_no_start_date']
- ) {
- if (empty($row['publicated_on'])) {
- $is_visible = false;
- }
- }
- if (!empty($row['expired_on'])) {
- if ($now > api_strtotime($row['expired_on'], 'UTC')) {
- $is_visible = false;
- }
- }
- }
- if ($is_visible) {
- $subscriptionSettings = self::getSubscriptionSettings();
- // Check if the subscription users/group to a LP is ON
- if (isset($row['subscribe_users']) && $row['subscribe_users'] == 1 &&
- $subscriptionSettings['allow_add_users_to_lp'] === true
- ) {
- // Try group
- $is_visible = false;
- // Checking only the user visibility
- $userVisibility = api_get_item_visibility(
- $courseInfo,
- 'learnpath',
- $row['id'],
- $sessionId,
- $student_id,
- 'LearnpathSubscription'
- );
- if ($userVisibility == 1) {
- $is_visible = true;
- } else {
- $userGroups = GroupManager::getAllGroupPerUserSubscription($student_id, $courseId);
- if (!empty($userGroups)) {
- foreach ($userGroups as $groupInfo) {
- $groupId = $groupInfo['iid'];
- $userVisibility = api_get_item_visibility(
- $courseInfo,
- 'learnpath',
- $row['id'],
- $sessionId,
- null,
- 'LearnpathSubscription',
- $groupId
- );
- if ($userVisibility == 1) {
- $is_visible = true;
- break;
- }
- }
- }
- }
- }
- }
- return $is_visible;
- }
- return false;
- }
- /**
- * @param int $lpId
- * @param int $userId
- * @param int $courseId
- * @param int $sessionId
- *
- * @return int
- */
- public static function getProgress($lpId, $userId, $courseId, $sessionId = 0)
- {
- $lpId = (int) $lpId;
- $userId = (int) $userId;
- $courseId = (int) $courseId;
- $sessionId = (int) $sessionId;
- $sessionCondition = api_get_session_condition($sessionId);
- $table = Database::get_course_table(TABLE_LP_VIEW);
- $sql = "SELECT progress FROM $table
- WHERE
- c_id = $courseId AND
- lp_id = $lpId AND
- user_id = $userId $sessionCondition ";
- $res = Database::query($sql);
- $progress = 0;
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $progress = (int) $row['progress'];
- }
- return $progress;
- }
- /**
- * @param array $lpList
- * @param int $userId
- * @param int $courseId
- * @param int $sessionId
- *
- * @return array
- */
- public static function getProgressFromLpList($lpList, $userId, $courseId, $sessionId = 0)
- {
- $lpList = array_map('intval', $lpList);
- if (empty($lpList)) {
- return [];
- }
- $lpList = implode("','", $lpList);
- $userId = (int) $userId;
- $courseId = (int) $courseId;
- $sessionId = (int) $sessionId;
- $sessionCondition = api_get_session_condition($sessionId);
- $table = Database::get_course_table(TABLE_LP_VIEW);
- $sql = "SELECT lp_id, progress FROM $table
- WHERE
- c_id = $courseId AND
- lp_id IN ('".$lpList."') AND
- user_id = $userId $sessionCondition ";
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $list = [];
- while ($row = Database::fetch_array($res)) {
- $list[$row['lp_id']] = $row['progress'];
- }
- return $list;
- }
- return [];
- }
- /**
- * Displays a progress bar
- * completed so far.
- *
- * @param int $percentage Progress value to display
- * @param string $text_add Text to display near the progress value
- *
- * @return string HTML string containing the progress bar
- */
- public static function get_progress_bar($percentage = -1, $text_add = '')
- {
- $text = $percentage.$text_add;
- $output = '<div class="progress">
- <div id="progress_bar_value"
- class="progress-bar progress-bar-success" role="progressbar"
- aria-valuenow="'.$percentage.'" aria-valuemin="0" aria-valuemax="100" style="width: '.$text.';">
- '.$text.'
- </div>
- </div>';
- return $output;
- }
- /**
- * @param string $mode can be '%' or 'abs'
- * otherwise this value will be used $this->progress_bar_mode
- *
- * @return string
- */
- public function getProgressBar($mode = null)
- {
- list($percentage, $text_add) = $this->get_progress_bar_text($mode);
- return self::get_progress_bar($percentage, $text_add);
- }
- /**
- * Gets the progress bar info to display inside the progress bar.
- * Also used by scorm_api.php.
- *
- * @param string $mode Mode of display (can be '%' or 'abs').abs means
- * we display a number of completed elements per total elements
- * @param int $add Additional steps to fake as completed
- *
- * @return array Percentage or number and symbol (% or /xx)
- */
- public function get_progress_bar_text($mode = '', $add = 0)
- {
- if (empty($mode)) {
- $mode = $this->progress_bar_mode;
- }
- $total_items = $this->getTotalItemsCountWithoutDirs();
- $completeItems = $this->get_complete_items_count();
- if ($add != 0) {
- $completeItems += $add;
- }
- $text = '';
- if ($completeItems > $total_items) {
- $completeItems = $total_items;
- }
- $percentage = 0;
- if ($mode == '%') {
- if ($total_items > 0) {
- $percentage = ((float) $completeItems / (float) $total_items) * 100;
- }
- $percentage = number_format($percentage, 0);
- $text = '%';
- } elseif ($mode === 'abs') {
- $percentage = $completeItems;
- $text = '/'.$total_items;
- }
- return [
- $percentage,
- $text,
- ];
- }
- /**
- * Gets the progress bar mode.
- *
- * @return string The progress bar mode attribute
- */
- public function get_progress_bar_mode()
- {
- if (!empty($this->progress_bar_mode)) {
- return $this->progress_bar_mode;
- }
- return '%';
- }
- /**
- * Gets the learnpath theme (remote or local).
- *
- * @return string Learnpath theme
- */
- public function get_theme()
- {
- if (!empty($this->theme)) {
- return $this->theme;
- }
- return '';
- }
- /**
- * Gets the learnpath session id.
- *
- * @return int
- */
- public function get_lp_session_id()
- {
- if (!empty($this->lp_session_id)) {
- return (int) $this->lp_session_id;
- }
- return 0;
- }
- /**
- * Gets the learnpath image.
- *
- * @return string Web URL of the LP image
- */
- public function get_preview_image()
- {
- if (!empty($this->preview_image)) {
- return $this->preview_image;
- }
- return '';
- }
- /**
- * @param string $size
- * @param string $path_type
- *
- * @return bool|string
- */
- public function get_preview_image_path($size = null, $path_type = 'web')
- {
- $preview_image = $this->get_preview_image();
- if (isset($preview_image) && !empty($preview_image)) {
- $image_sys_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/';
- $image_path = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/';
- if (isset($size)) {
- $info = pathinfo($preview_image);
- $image_custom_size = $info['filename'].'.'.$size.'.'.$info['extension'];
- if (file_exists($image_sys_path.$image_custom_size)) {
- if ($path_type == 'web') {
- return $image_path.$image_custom_size;
- } else {
- return $image_sys_path.$image_custom_size;
- }
- }
- } else {
- if ($path_type == 'web') {
- return $image_path.$preview_image;
- } else {
- return $image_sys_path.$preview_image;
- }
- }
- }
- return false;
- }
- /**
- * Gets the learnpath author.
- *
- * @return string LP's author
- */
- public function get_author()
- {
- if (!empty($this->author)) {
- return $this->author;
- }
- return '';
- }
- /**
- * Gets hide table of contents.
- *
- * @return int
- */
- public function getHideTableOfContents()
- {
- return (int) $this->hide_toc_frame;
- }
- /**
- * Generate a new prerequisites string for a given item. If this item was a sco and
- * its prerequisites were strings (instead of IDs), then transform those strings into
- * IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
- * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
- * same rule as the scormExport() method.
- *
- * @param int $item_id Item ID
- *
- * @return string Prerequisites string ready for the export as SCORM
- */
- public function get_scorm_prereq_string($item_id)
- {
- if ($this->debug > 0) {
- error_log('In learnpath::get_scorm_prereq_string()');
- }
- if (!is_object($this->items[$item_id])) {
- return false;
- }
- /** @var learnpathItem $oItem */
- $oItem = $this->items[$item_id];
- $prereq = $oItem->get_prereq_string();
- if (empty($prereq)) {
- return '';
- }
- if (preg_match('/^\d+$/', $prereq) &&
- isset($this->items[$prereq]) &&
- is_object($this->items[$prereq])
- ) {
- // If the prerequisite is a simple integer ID and this ID exists as an item ID,
- // then simply return it (with the ITEM_ prefix).
- //return 'ITEM_' . $prereq;
- return $this->items[$prereq]->ref;
- } else {
- if (isset($this->refs_list[$prereq])) {
- // It's a simple string item from which the ID can be found in the refs list,
- // so we can transform it directly to an ID for export.
- return $this->items[$this->refs_list[$prereq]]->ref;
- } elseif (isset($this->refs_list['ITEM_'.$prereq])) {
- return $this->items[$this->refs_list['ITEM_'.$prereq]]->ref;
- } else {
- // The last case, if it's a complex form, then find all the IDs (SCORM strings)
- // and replace them, one by one, by the internal IDs (chamilo db)
- // TODO: Modify the '*' replacement to replace the multiplier in front of it
- // by a space as well.
- $find = [
- '&',
- '|',
- '~',
- '=',
- '<>',
- '{',
- '}',
- '*',
- '(',
- ')',
- ];
- $replace = [
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ];
- $prereq_mod = str_replace($find, $replace, $prereq);
- $ids = explode(' ', $prereq_mod);
- foreach ($ids as $id) {
- $id = trim($id);
- if (isset($this->refs_list[$id])) {
- $prereq = preg_replace(
- '/[^a-zA-Z_0-9]('.$id.')[^a-zA-Z_0-9]/',
- 'ITEM_'.$this->refs_list[$id],
- $prereq
- );
- }
- }
- return $prereq;
- }
- }
- }
- /**
- * Returns the XML DOM document's node.
- *
- * @param resource $children Reference to a list of objects to search for the given ITEM_*
- * @param string $id The identifier to look for
- *
- * @return mixed The reference to the element found with that identifier. False if not found
- */
- public function get_scorm_xml_node(&$children, $id)
- {
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp->nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == $id) {
- return $item_temp;
- }
- }
- $subchildren = $item_temp->childNodes;
- if ($subchildren && $subchildren->length > 0) {
- $val = $this->get_scorm_xml_node($subchildren, $id);
- if (is_object($val)) {
- return $val;
- }
- }
- }
- return false;
- }
- /**
- * Gets the status list for all LP's items.
- *
- * @return array Array of [index] => [item ID => current status]
- */
- public function get_items_status_list()
- {
- $list = [];
- foreach ($this->ordered_items as $item_id) {
- $list[] = [
- $item_id => $this->items[$item_id]->get_status(),
- ];
- }
- return $list;
- }
- /**
- * Return the number of interactions for the given learnpath Item View ID.
- * This method can be used as static.
- *
- * @param int $lp_iv_id Item View ID
- * @param int $course_id course id
- *
- * @return int
- */
- public static function get_interactions_count_from_db($lp_iv_id, $course_id)
- {
- $table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
- $lp_iv_id = (int) $lp_iv_id;
- $course_id = (int) $course_id;
- $sql = "SELECT count(*) FROM $table
- WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
- $res = Database::query($sql);
- $num = 0;
- if (Database::num_rows($res)) {
- $row = Database::fetch_array($res);
- $num = $row[0];
- }
- return $num;
- }
- /**
- * Return the interactions as an array for the given lp_iv_id.
- * This method can be used as static.
- *
- * @param int $lp_iv_id Learnpath Item View ID
- *
- * @return array
- *
- * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP)
- */
- public static function get_iv_interactions_array($lp_iv_id, $course_id = 0)
- {
- $course_id = empty($course_id) ? api_get_course_int_id() : (int) $course_id;
- $list = [];
- $table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
- $lp_iv_id = (int) $lp_iv_id;
- if (empty($lp_iv_id) || empty($course_id)) {
- return [];
- }
- $sql = "SELECT * FROM $table
- WHERE c_id = ".$course_id." AND lp_iv_id = $lp_iv_id
- ORDER BY order_id ASC";
- $res = Database::query($sql);
- $num = Database::num_rows($res);
- if ($num > 0) {
- $list[] = [
- 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
- 'id' => api_htmlentities(get_lang('InteractionID'), ENT_QUOTES),
- 'type' => api_htmlentities(get_lang('Type'), ENT_QUOTES),
- 'time' => api_htmlentities(get_lang('TimeFinished'), ENT_QUOTES),
- 'correct_responses' => api_htmlentities(get_lang('CorrectAnswers'), ENT_QUOTES),
- 'student_response' => api_htmlentities(get_lang('StudentResponse'), ENT_QUOTES),
- 'result' => api_htmlentities(get_lang('Result'), ENT_QUOTES),
- 'latency' => api_htmlentities(get_lang('LatencyTimeSpent'), ENT_QUOTES),
- 'student_response_formatted' => '',
- ];
- while ($row = Database::fetch_array($res)) {
- $studentResponseFormatted = urldecode($row['student_response']);
- $content_student_response = explode('__|', $studentResponseFormatted);
- if (count($content_student_response) > 0) {
- if (count($content_student_response) >= 3) {
- // Pop the element off the end of array.
- array_pop($content_student_response);
- }
- $studentResponseFormatted = implode(',', $content_student_response);
- }
- $list[] = [
- 'order_id' => $row['order_id'] + 1,
- 'id' => urldecode($row['interaction_id']), //urldecode because they often have %2F or stuff like that
- 'type' => $row['interaction_type'],
- 'time' => $row['completion_time'],
- 'correct_responses' => '', // Hide correct responses from students.
- 'student_response' => $row['student_response'],
- 'result' => $row['result'],
- 'latency' => $row['latency'],
- 'student_response_formatted' => $studentResponseFormatted,
- ];
- }
- }
- return $list;
- }
- /**
- * Return the number of objectives for the given learnpath Item View ID.
- * This method can be used as static.
- *
- * @param int $lp_iv_id Item View ID
- * @param int $course_id Course ID
- *
- * @return int Number of objectives
- */
- public static function get_objectives_count_from_db($lp_iv_id, $course_id)
- {
- $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
- $course_id = (int) $course_id;
- $lp_iv_id = (int) $lp_iv_id;
- $sql = "SELECT count(*) FROM $table
- WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
- //@todo seems that this always returns 0
- $res = Database::query($sql);
- $num = 0;
- if (Database::num_rows($res)) {
- $row = Database::fetch_array($res);
- $num = $row[0];
- }
- return $num;
- }
- /**
- * Return the objectives as an array for the given lp_iv_id.
- * This method can be used as static.
- *
- * @param int $lpItemViewId Learnpath Item View ID
- * @param int $course_id
- *
- * @return array
- *
- * @todo Translate labels
- */
- public static function get_iv_objectives_array($lpItemViewId = 0, $course_id = 0)
- {
- $course_id = empty($course_id) ? api_get_course_int_id() : (int) $course_id;
- $lpItemViewId = (int) $lpItemViewId;
- if (empty($course_id) || empty($lpItemViewId)) {
- return [];
- }
- $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
- $sql = "SELECT * FROM $table
- WHERE c_id = $course_id AND lp_iv_id = $lpItemViewId
- ORDER BY order_id ASC";
- $res = Database::query($sql);
- $num = Database::num_rows($res);
- $list = [];
- if ($num > 0) {
- $list[] = [
- 'order_id' => api_htmlentities(get_lang('Order'), ENT_QUOTES),
- 'objective_id' => api_htmlentities(get_lang('ObjectiveID'), ENT_QUOTES),
- 'score_raw' => api_htmlentities(get_lang('ObjectiveRawScore'), ENT_QUOTES),
- 'score_max' => api_htmlentities(get_lang('ObjectiveMaxScore'), ENT_QUOTES),
- 'score_min' => api_htmlentities(get_lang('ObjectiveMinScore'), ENT_QUOTES),
- 'status' => api_htmlentities(get_lang('ObjectiveStatus'), ENT_QUOTES),
- ];
- while ($row = Database::fetch_array($res)) {
- $list[] = [
- 'order_id' => $row['order_id'] + 1,
- 'objective_id' => urldecode($row['objective_id']), // urldecode() because they often have %2F
- 'score_raw' => $row['score_raw'],
- 'score_max' => $row['score_max'],
- 'score_min' => $row['score_min'],
- 'status' => $row['status'],
- ];
- }
- }
- return $list;
- }
- /**
- * Generate and return the table of contents for this learnpath. The (flat) table returned can be
- * used by get_html_toc() to be ready to display.
- *
- * @return array TOC as a table with 4 elements per row: title, link, status and level
- */
- public function get_toc()
- {
- $toc = [];
- foreach ($this->ordered_items as $item_id) {
- // TODO: Change this link generation and use new function instead.
- $toc[] = [
- 'id' => $item_id,
- 'title' => $this->items[$item_id]->get_title(),
- 'status' => $this->items[$item_id]->get_status(),
- 'level' => $this->items[$item_id]->get_level(),
- 'type' => $this->items[$item_id]->get_type(),
- 'description' => $this->items[$item_id]->get_description(),
- 'path' => $this->items[$item_id]->get_path(),
- 'parent' => $this->items[$item_id]->get_parent(),
- ];
- }
- return $toc;
- }
- /**
- * Generate and return the table of contents for this learnpath. The JS
- * table returned is used inside of scorm_api.php.
- *
- * @param string $varname
- *
- * @return string A JS array variable construction
- */
- public function get_items_details_as_js($varname = 'olms.lms_item_types')
- {
- $toc = $varname.' = new Array();';
- foreach ($this->ordered_items as $item_id) {
- $toc .= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
- }
- return $toc;
- }
- /**
- * Gets the learning path type.
- *
- * @param bool $get_name Return the name? If false, return the ID. Default is false.
- *
- * @return mixed Type ID or name, depending on the parameter
- */
- public function get_type($get_name = false)
- {
- $res = false;
- if (!empty($this->type) && (!$get_name)) {
- $res = $this->type;
- }
- return $res;
- }
- /**
- * Gets the learning path type as static method.
- *
- * @param int $lp_id
- *
- * @return mixed Type ID or name, depending on the parameter
- */
- public static function get_type_static($lp_id = 0)
- {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = (int) $lp_id;
- $sql = "SELECT lp_type FROM $tbl_lp
- WHERE iid = $lp_id";
- $res = Database::query($sql);
- if ($res === false) {
- return null;
- }
- if (Database::num_rows($res) <= 0) {
- return null;
- }
- $row = Database::fetch_array($res);
- return $row['lp_type'];
- }
- /**
- * Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
- * This method can be used as abstract and is recursive.
- *
- * @param int $lp Learnpath ID
- * @param int $parent Parent ID of the items to look for
- * @param int $course_id
- *
- * @return array Ordered list of item IDs (empty array on error)
- */
- public static function get_flat_ordered_items_list($lp = 1, $parent = 0, $course_id = 0)
- {
- if (empty($course_id)) {
- $course_id = api_get_course_int_id();
- } else {
- $course_id = (int) $course_id;
- }
- $list = [];
- if (empty($lp)) {
- return $list;
- }
- $lp = (int) $lp;
- $parent = (int) $parent;
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT iid FROM $tbl_lp_item
- WHERE c_id = $course_id AND lp_id = $lp AND parent_item_id = $parent
- ORDER BY display_order";
- $res = Database::query($sql);
- while ($row = Database::fetch_array($res)) {
- $sublist = self::get_flat_ordered_items_list(
- $lp,
- $row['iid'],
- $course_id
- );
- $list[] = $row['iid'];
- foreach ($sublist as $item) {
- $list[] = $item;
- }
- }
- return $list;
- }
- /**
- * @return array
- */
- public static function getChapterTypes()
- {
- return [
- 'dir',
- ];
- }
- /**
- * Uses the table generated by get_toc() and returns an HTML-formattedstring ready to display.
- *
- * @param $tree
- *
- * @return array HTML TOC ready to display
- */
- public function getParentToc($tree)
- {
- if (empty($tree)) {
- $tree = $this->get_toc();
- }
- $dirTypes = self::getChapterTypes();
- $myCurrentId = $this->get_current_item_id();
- $listParent = [];
- $listChildren = [];
- $listNotParent = [];
- $list = [];
- foreach ($tree as $subtree) {
- if (in_array($subtree['type'], $dirTypes)) {
- $listChildren = $this->getChildrenToc($tree, $subtree['id']);
- $subtree['children'] = $listChildren;
- if (!empty($subtree['children'])) {
- foreach ($subtree['children'] as $subItem) {
- if ($subItem['id'] == $this->current) {
- $subtree['parent_current'] = 'in';
- $subtree['current'] = 'on';
- }
- }
- }
- $listParent[] = $subtree;
- }
- if (!in_array($subtree['type'], $dirTypes) && $subtree['parent'] == null) {
- $classStatus = [
- 'not attempted' => 'scorm_not_attempted',
- 'incomplete' => 'scorm_not_attempted',
- 'failed' => 'scorm_failed',
- 'completed' => 'scorm_completed',
- 'passed' => 'scorm_completed',
- 'succeeded' => 'scorm_completed',
- 'browsed' => 'scorm_completed',
- ];
- if (isset($classStatus[$subtree['status']])) {
- $cssStatus = $classStatus[$subtree['status']];
- }
- $title = Security::remove_XSS($subtree['title']);
- unset($subtree['title']);
- if (empty($title)) {
- $title = self::rl_get_resource_name(api_get_course_id(), $this->get_id(), $subtree['id']);
- }
- $classStyle = null;
- if ($subtree['id'] == $this->current) {
- $classStyle = 'scorm_item_normal '.$classStyle.'scorm_highlight';
- } elseif (!in_array($subtree['type'], $dirTypes)) {
- $classStyle = 'scorm_item_normal '.$classStyle.' ';
- }
- $subtree['title'] = $title;
- $subtree['class'] = $classStyle.' '.$cssStatus;
- $subtree['url'] = $this->get_link('http', $subtree['id'], $tree);
- $subtree['current_id'] = $myCurrentId;
- $listNotParent[] = $subtree;
- }
- }
- $list['are_parents'] = $listParent;
- $list['not_parents'] = $listNotParent;
- return $list;
- }
- /**
- * Uses the table generated by get_toc() and returns an HTML-formattedstring ready to display.
- *
- * @param array $tree
- * @param int $id
- * @param bool $parent
- *
- * @return array HTML TOC ready to display
- */
- public function getChildrenToc($tree, $id, $parent = true)
- {
- if (empty($tree)) {
- $tree = $this->get_toc();
- }
- $dirTypes = self::getChapterTypes();
- $currentItemId = $this->get_current_item_id();
- $list = [];
- $classStatus = [
- 'not attempted' => 'scorm_not_attempted',
- 'incomplete' => 'scorm_not_attempted',
- 'failed' => 'scorm_failed',
- 'completed' => 'scorm_completed',
- 'passed' => 'scorm_completed',
- 'succeeded' => 'scorm_completed',
- 'browsed' => 'scorm_completed',
- ];
- foreach ($tree as $subtree) {
- $subtree['tree'] = null;
- if (!in_array($subtree['type'], $dirTypes) && $subtree['parent'] == $id) {
- if ($subtree['id'] == $this->current) {
- $subtree['current'] = 'active';
- } else {
- $subtree['current'] = null;
- }
- if (isset($classStatus[$subtree['status']])) {
- $cssStatus = $classStatus[$subtree['status']];
- }
- $title = Security::remove_XSS($subtree['title']);
- unset($subtree['title']);
- if (empty($title)) {
- $title = self::rl_get_resource_name(api_get_course_id(), $this->get_id(), $subtree['id']);
- }
- $classStyle = null;
- if ($subtree['id'] == $this->current) {
- $classStyle = 'scorm_item_normal '.$classStyle.'scorm_highlight';
- } elseif (!in_array($subtree['type'], $dirTypes)) {
- $classStyle = 'scorm_item_normal '.$classStyle.' ';
- }
- if (in_array($subtree['type'], $dirTypes)) {
- $subtree['title'] = stripslashes($title);
- } else {
- $subtree['title'] = $title;
- $subtree['class'] = $classStyle.' '.$cssStatus;
- $subtree['url'] = $this->get_link('http', $subtree['id'], $tree);
- $subtree['current_id'] = $currentItemId;
- }
- $list[] = $subtree;
- }
- }
- return $list;
- }
- /**
- * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display.
- *
- * @param array $toc_list
- *
- * @return array HTML TOC ready to display
- */
- public function getListArrayToc($toc_list = [])
- {
- if (empty($toc_list)) {
- $toc_list = $this->get_toc();
- }
- // Temporary variables.
- $currentItemId = $this->get_current_item_id();
- $list = [];
- $arrayList = [];
- $classStatus = [
- 'not attempted' => 'scorm_not_attempted',
- 'incomplete' => 'scorm_not_attempted',
- 'failed' => 'scorm_failed',
- 'completed' => 'scorm_completed',
- 'passed' => 'scorm_completed',
- 'succeeded' => 'scorm_completed',
- 'browsed' => 'scorm_completed',
- ];
- foreach ($toc_list as $item) {
- $list['id'] = $item['id'];
- $list['status'] = $item['status'];
- $cssStatus = null;
- if (isset($classStatus[$item['status']])) {
- $cssStatus = $classStatus[$item['status']];
- }
- $classStyle = ' ';
- $dirTypes = self::getChapterTypes();
- if (in_array($item['type'], $dirTypes)) {
- $classStyle = 'scorm_item_section ';
- }
- if ($item['id'] == $this->current) {
- $classStyle = 'scorm_item_normal '.$classStyle.'scorm_highlight';
- } elseif (!in_array($item['type'], $dirTypes)) {
- $classStyle = 'scorm_item_normal '.$classStyle.' ';
- }
- $title = $item['title'];
- if (empty($title)) {
- $title = self::rl_get_resource_name(
- api_get_course_id(),
- $this->get_id(),
- $item['id']
- );
- }
- $title = Security::remove_XSS($item['title']);
- if (empty($item['description'])) {
- $list['description'] = $title;
- } else {
- $list['description'] = $item['description'];
- }
- $list['class'] = $classStyle.' '.$cssStatus;
- $list['level'] = $item['level'];
- $list['type'] = $item['type'];
- if (in_array($item['type'], $dirTypes)) {
- $list['css_level'] = 'level_'.$item['level'];
- } else {
- $list['css_level'] = 'level_'.$item['level'].' scorm_type_'.self::format_scorm_type_item($item['type']);
- }
- if (in_array($item['type'], $dirTypes)) {
- $list['title'] = stripslashes($title);
- } else {
- $list['title'] = stripslashes($title);
- $list['url'] = $this->get_link('http', $item['id'], $toc_list);
- $list['current_id'] = $currentItemId;
- }
- $arrayList[] = $list;
- }
- return $arrayList;
- }
- /**
- * Returns an HTML-formatted string ready to display with teacher buttons
- * in LP view menu.
- *
- * @return string HTML TOC ready to display
- */
- public function get_teacher_toc_buttons()
- {
- $isAllow = api_is_allowed_to_edit(null, true, false, false);
- $hideIcons = api_get_configuration_value('hide_teacher_icons_lp');
- $html = '';
- if ($isAllow && $hideIcons == false) {
- if ($this->get_lp_session_id() == api_get_session_id()) {
- $html .= '<div id="actions_lp" class="actions_lp"><hr>';
- $html .= '<div class="btn-group">';
- $html .= "<a class='btn btn-sm btn-default' href='lp_controller.php?".api_get_cidreq()."&action=build&lp_id=".$this->lp_id."&isStudentView=false' target='_parent'>".
- Display::returnFontAwesomeIcon('street-view').get_lang('Overview')."</a>";
- $html .= "<a class='btn btn-sm btn-default' href='lp_controller.php?".api_get_cidreq()."&action=add_item&type=step&lp_id=".$this->lp_id."&isStudentView=false' target='_parent'>".
- Display::returnFontAwesomeIcon('pencil').get_lang('Edit')."</a>";
- $html .= '<a class="btn btn-sm btn-default" href="lp_controller.php?'.api_get_cidreq()."&action=edit&lp_id=".$this->lp_id.'&isStudentView=false">'.
- Display::returnFontAwesomeIcon('cog').get_lang('Settings').'</a>';
- $html .= '</div>';
- $html .= '</div>';
- }
- }
- return $html;
- }
- /**
- * Gets the learnpath maker name - generally the editor's name.
- *
- * @return string Learnpath maker name
- */
- public function get_maker()
- {
- if (!empty($this->maker)) {
- return $this->maker;
- }
- return '';
- }
- /**
- * Gets the learnpath name/title.
- *
- * @return string Learnpath name/title
- */
- public function get_name()
- {
- if (!empty($this->name)) {
- return $this->name;
- }
- return 'N/A';
- }
- /**
- * @return string
- */
- public function getNameNoTags()
- {
- return strip_tags($this->get_name());
- }
- /**
- * Gets a link to the resource from the present location, depending on item ID.
- *
- * @param string $type Type of link expected
- * @param int $item_id Learnpath item ID
- * @param bool $provided_toc
- *
- * @return string $provided_toc Link to the lp_item resource
- */
- public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
- {
- $course_id = $this->get_course_int_id();
- $item_id = (int) $item_id;
- if (empty($item_id)) {
- $item_id = $this->get_current_item_id();
- if (empty($item_id)) {
- //still empty, this means there was no item_id given and we are not in an object context or
- //the object property is empty, return empty link
- $this->first();
- return '';
- }
- }
- $file = '';
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_item_table = Database::get_course_table(TABLE_LP_ITEM);
- $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
- $sql = "SELECT
- l.lp_type as ltype,
- l.path as lpath,
- li.item_type as litype,
- li.path as lipath,
- li.parameters as liparams
- FROM $lp_table l
- INNER JOIN $lp_item_table li
- ON (li.lp_id = l.iid)
- WHERE
- li.iid = $item_id
- ";
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $lp_type = $row['ltype'];
- $lp_path = $row['lpath'];
- $lp_item_type = $row['litype'];
- $lp_item_path = $row['lipath'];
- $lp_item_params = $row['liparams'];
- if (empty($lp_item_params) && strpos($lp_item_path, '?') !== false) {
- list($lp_item_path, $lp_item_params) = explode('?', $lp_item_path);
- }
- $sys_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
- if ($type === 'http') {
- //web path
- $course_path = api_get_path(WEB_COURSE_PATH).api_get_course_path();
- } else {
- $course_path = $sys_course_path; //system path
- }
- // Fixed issue BT#1272 - If the item type is a Chamilo Item (quiz, link, etc),
- // then change the lp type to thread it as a normal Chamilo LP not a SCO.
- if (in_array(
- $lp_item_type,
- ['quiz', 'document', 'final_item', 'link', 'forum', 'thread', 'student_publication']
- )
- ) {
- $lp_type = 1;
- }
- // Now go through the specific cases to get the end of the path
- // @todo Use constants instead of int values.
- switch ($lp_type) {
- case 1:
- $file = self::rl_get_resource_link_for_learnpath(
- $course_id,
- $this->get_id(),
- $item_id,
- $this->get_view_id()
- );
- switch ($lp_item_type) {
- case 'document':
- // Shows a button to download the file instead of just downloading the file directly.
- $documentPathInfo = pathinfo($file);
- if (isset($documentPathInfo['extension'])) {
- $parsed = parse_url($documentPathInfo['extension']);
- if (isset($parsed['path'])) {
- $extension = $parsed['path'];
- $extensionsToDownload = [
- 'zip',
- 'ppt',
- 'pptx',
- 'ods',
- 'xlsx',
- 'xls',
- 'csv',
- 'doc',
- 'docx',
- 'dot',
- ];
- if (in_array($extension, $extensionsToDownload)) {
- $file = api_get_path(WEB_CODE_PATH).
- 'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
- }
- }
- }
- break;
- case 'dir':
- $file = 'lp_content.php?type=dir';
- break;
- case 'link':
- if (Link::is_youtube_link($file)) {
- $src = Link::get_youtube_video_id($file);
- $file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=youtube&source='.$src;
- } elseif (Link::isVimeoLink($file)) {
- $src = Link::getVimeoLinkId($file);
- $file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=vimeo&source='.$src;
- } else {
- // If the current site is HTTPS and the link is
- // HTTP, browsers will refuse opening the link
- $urlId = api_get_current_access_url_id();
- $url = api_get_access_url($urlId, false);
- $protocol = substr($url['url'], 0, 5);
- if ($protocol === 'https') {
- $linkProtocol = substr($file, 0, 5);
- if ($linkProtocol === 'http:') {
- //this is the special intervention case
- $file = api_get_path(WEB_CODE_PATH).'lp/embed.php?type=nonhttps&source='.urlencode($file);
- }
- }
- }
- break;
- case 'quiz':
- // Check how much attempts of a exercise exits in lp
- $lp_item_id = $this->get_current_item_id();
- $lp_view_id = $this->get_view_id();
- $prevent_reinit = null;
- if (isset($this->items[$this->current])) {
- $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
- }
- if (empty($provided_toc)) {
- if ($this->debug > 0) {
- error_log('In learnpath::get_link() Loading get_toc ', 0);
- }
- $list = $this->get_toc();
- } else {
- if ($this->debug > 0) {
- error_log('In learnpath::get_link() Loading get_toc from "cache" ', 0);
- }
- $list = $provided_toc;
- }
- $type_quiz = false;
- foreach ($list as $toc) {
- if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') {
- $type_quiz = true;
- }
- }
- if ($type_quiz) {
- $lp_item_id = (int) $lp_item_id;
- $lp_view_id = (int) $lp_view_id;
- $sql = "SELECT count(*) FROM $lp_item_view_table
- WHERE
- c_id = $course_id AND
- lp_item_id='".$lp_item_id."' AND
- lp_view_id ='".$lp_view_id."' AND
- status='completed'";
- $result = Database::query($sql);
- $row_count = Database:: fetch_row($result);
- $count_item_view = (int) $row_count[0];
- $not_multiple_attempt = 0;
- if ($prevent_reinit === 1 && $count_item_view > 0) {
- $not_multiple_attempt = 1;
- }
- $file .= '¬_multiple_attempt='.$not_multiple_attempt;
- }
- break;
- }
- $tmp_array = explode('/', $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- }
- break;
- case 2:
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type, 0);
- }
- if ($lp_item_type != 'dir') {
- // Quite complex here:
- // We want to make sure 'http://' (and similar) links can
- // be loaded as is (withouth the Chamilo path in front) but
- // some contents use this form: resource.htm?resource=http://blablabla
- // which means we have to find a protocol at the path's start, otherwise
- // it should not be considered as an external URL.
- // if ($this->prerequisites_match($item_id)) {
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path, 0);
- }
- // Distant url, return as is.
- $file = $lp_item_path;
- } else {
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path, 0);
- }
- // Prevent getting untranslatable urls.
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
- // Prepare the path.
- $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
- // TODO: Fix this for urls with protocol header.
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- if (substr($lp_path, -1) == '/') {
- $lp_path = substr($lp_path, 0, -1);
- }
- if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$lp_item_path))) {
- // if file not found.
- $decoded = html_entity_decode($lp_item_path);
- list($decoded) = explode('?', $decoded);
- if (!is_file(realpath($sys_course_path.'/scorm/'.$lp_path.'/'.$decoded))) {
- $file = self::rl_get_resource_link_for_learnpath(
- $course_id,
- $this->get_id(),
- $item_id,
- $this->get_view_id()
- );
- if (empty($file)) {
- $file = 'blank.php?error=document_not_found';
- } else {
- $tmp_array = explode('/', $file);
- $document_name = $tmp_array[count($tmp_array) - 1];
- if (strpos($document_name, '_DELETED_')) {
- $file = 'blank.php?error=document_deleted';
- } else {
- $file = 'blank.php?error=document_not_found';
- }
- }
- } else {
- $file = $course_path.'/scorm/'.$lp_path.'/'.$decoded;
- }
- }
- }
- // We want to use parameters if they were defined in the imsmanifest
- if (strpos($file, 'blank.php') === false) {
- $lp_item_params = ltrim($lp_item_params, '?');
- $file .= (strstr($file, '?') === false ? '?' : '').$lp_item_params;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 3:
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() '.__LINE__.' - Item type: '.$lp_item_type, 0);
- }
- // Formatting AICC HACP append URL.
- $aicc_append = '?aicc_sid='.urlencode(session_id()).'&aicc_url='.urlencode(api_get_path(WEB_CODE_PATH).'lp/aicc_hacp.php').'&';
- if (!empty($lp_item_params)) {
- $aicc_append .= $lp_item_params.'&';
- }
- if ($lp_item_type != 'dir') {
- // Quite complex here:
- // We want to make sure 'http://' (and similar) links can
- // be loaded as is (withouth the Chamilo path in front) but
- // some contents use this form: resource.htm?resource=http://blablabla
- // which means we have to find a protocol at the path's start, otherwise
- // it should not be considered as an external URL.
- if (preg_match('#^[a-zA-Z]{2,5}://#', $lp_item_path) != 0) {
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() '.__LINE__.' - Found match for protocol in '.$lp_item_path, 0);
- }
- // Distant url, return as is.
- $file = $lp_item_path;
- // Enabled and modified by Ivan Tcholakov, 16-OCT-2008.
- /*
- if (stristr($file,'<servername>') !== false) {
- $file = str_replace('<servername>', $course_path.'/scorm/'.$lp_path.'/', $lp_item_path);
- }
- */
- if (stripos($file, '<servername>') !== false) {
- //$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
- $web_course_path = str_replace('https://', '', str_replace('http://', '', $course_path));
- $file = str_replace('<servername>', $web_course_path.'/scorm/'.$lp_path, $lp_item_path);
- }
- $file .= $aicc_append;
- } else {
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() '.__LINE__.' - No starting protocol in '.$lp_item_path, 0);
- }
- // Prevent getting untranslatable urls.
- $lp_item_path = preg_replace('/%2F/', '/', $lp_item_path);
- $lp_item_path = preg_replace('/%3A/', ':', $lp_item_path);
- // Prepare the path - lp_path might be unusable because it includes the "aicc" subdir name.
- $file = $course_path.'/scorm/'.$lp_path.'/'.$lp_item_path;
- // TODO: Fix this for urls with protocol header.
- $file = str_replace('//', '/', $file);
- $file = str_replace(':/', '://', $file);
- $file .= $aicc_append;
- }
- } else {
- $file = 'lp_content.php?type=dir';
- }
- break;
- case 4:
- break;
- default:
- break;
- }
- // Replace & by & because & will break URL with params
- $file = !empty($file) ? str_replace('&', '&', $file) : '';
- }
- if ($this->debug > 2) {
- error_log('In learnpath::get_link() - returning "'.$file.'" from get_link', 0);
- }
- return $file;
- }
- /**
- * Gets the latest usable view or generate a new one.
- *
- * @param int $attempt_num Optional attempt number. If none given, takes the highest from the lp_view table
- *
- * @return int DB lp_view id
- */
- public function get_view($attempt_num = 0)
- {
- $search = '';
- // Use $attempt_num to enable multi-views management (disabled so far).
- if ($attempt_num != 0 && intval(strval($attempt_num)) == $attempt_num) {
- $search = 'AND view_count = '.$attempt_num;
- }
- // When missing $attempt_num, search for a unique lp_view record for this lp and user.
- $lp_view_table = Database::get_course_table(TABLE_LP_VIEW);
- $course_id = api_get_course_int_id();
- $sessionId = api_get_session_id();
- $sql = "SELECT iid, view_count FROM $lp_view_table
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- user_id = ".$this->get_user_id()." AND
- session_id = $sessionId
- $search
- ORDER BY view_count DESC";
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $this->lp_view_id = $row['iid'];
- } elseif (!api_is_invitee()) {
- // There is no database record, create one.
- $sql = "INSERT INTO $lp_view_table (c_id, lp_id, user_id, view_count, session_id) VALUES
- ($course_id, ".$this->get_id().",".$this->get_user_id().", 1, $sessionId)";
- Database::query($sql);
- $id = Database::insert_id();
- $this->lp_view_id = $id;
- $sql = "UPDATE $lp_view_table SET id = iid WHERE iid = $id";
- Database::query($sql);
- }
- return $this->lp_view_id;
- }
- /**
- * Gets the current view id.
- *
- * @return int View ID (from lp_view)
- */
- public function get_view_id()
- {
- if (!empty($this->lp_view_id)) {
- return (int) $this->lp_view_id;
- }
- return 0;
- }
- /**
- * Gets the update queue.
- *
- * @return array Array containing IDs of items to be updated by JavaScript
- */
- public function get_update_queue()
- {
- return $this->update_queue;
- }
- /**
- * Gets the user ID.
- *
- * @return int User ID
- */
- public function get_user_id()
- {
- if (!empty($this->user_id)) {
- return (int) $this->user_id;
- }
- return false;
- }
- /**
- * Checks if any of the items has an audio element attached.
- *
- * @return bool True or false
- */
- public function has_audio()
- {
- $has = false;
- foreach ($this->items as $i => $item) {
- if (!empty($this->items[$i]->audio)) {
- $has = true;
- break;
- }
- }
- return $has;
- }
- /**
- * Moves an item up and down at its level.
- *
- * @param int $id Item to move up and down
- * @param string $direction Direction 'up' or 'down'
- *
- * @return bool|int
- */
- public function move_item($id, $direction)
- {
- $course_id = api_get_course_int_id();
- if (empty($id) || empty($direction)) {
- return false;
- }
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql_sel = "SELECT *
- FROM $tbl_lp_item
- WHERE
- iid = $id
- ";
- $res_sel = Database::query($sql_sel);
- // Check if elem exists.
- if (Database::num_rows($res_sel) < 1) {
- return false;
- }
- // Gather data.
- $row = Database::fetch_array($res_sel);
- $previous = $row['previous_item_id'];
- $next = $row['next_item_id'];
- $display = $row['display_order'];
- $parent = $row['parent_item_id'];
- $lp = $row['lp_id'];
- // Update the item (switch with previous/next one).
- switch ($direction) {
- case 'up':
- if ($display > 1) {
- $sql_sel2 = "SELECT * FROM $tbl_lp_item
- WHERE iid = $previous";
- $res_sel2 = Database::query($sql_sel2);
- if (Database::num_rows($res_sel2) < 1) {
- $previous_previous = 0;
- }
- // Gather data.
- $row2 = Database::fetch_array($res_sel2);
- $previous_previous = $row2['previous_item_id'];
- // Update previous_previous item (switch "next" with current).
- if ($previous_previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET
- next_item_id = $id
- WHERE iid = $previous_previous";
- Database::query($sql_upd2);
- }
- // Update previous item (switch with current).
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET
- next_item_id = $next,
- previous_item_id = $id,
- display_order = display_order +1
- WHERE iid = $previous";
- Database::query($sql_upd2);
- }
- // Update current item (switch with previous).
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET
- next_item_id = $previous,
- previous_item_id = $previous_previous,
- display_order = display_order-1
- WHERE c_id = ".$course_id." AND id = $id";
- Database::query($sql_upd2);
- }
- // Update next item (new previous item).
- if (!empty($next)) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous
- WHERE iid = $next";
- Database::query($sql_upd2);
- }
- $display = $display - 1;
- }
- break;
- case 'down':
- if ($next != 0) {
- $sql_sel2 = "SELECT * FROM $tbl_lp_item
- WHERE iid = $next";
- $res_sel2 = Database::query($sql_sel2);
- if (Database::num_rows($res_sel2) < 1) {
- $next_next = 0;
- }
- // Gather data.
- $row2 = Database::fetch_array($res_sel2);
- $next_next = $row2['next_item_id'];
- // Update previous item (switch with current).
- if ($previous != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item
- SET next_item_id = $next
- WHERE iid = $previous";
- Database::query($sql_upd2);
- }
- // Update current item (switch with previous).
- if ($id != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET
- previous_item_id = $next,
- next_item_id = $next_next,
- display_order = display_order + 1
- WHERE iid = $id";
- Database::query($sql_upd2);
- }
- // Update next item (new previous item).
- if ($next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET
- previous_item_id = $previous,
- next_item_id = $id,
- display_order = display_order-1
- WHERE iid = $next";
- Database::query($sql_upd2);
- }
- // Update next_next item (switch "previous" with current).
- if ($next_next != 0) {
- $sql_upd2 = "UPDATE $tbl_lp_item SET
- previous_item_id = $id
- WHERE iid = $next_next";
- Database::query($sql_upd2);
- }
- $display = $display + 1;
- }
- break;
- default:
- return false;
- }
- return $display;
- }
- /**
- * Move a LP up (display_order).
- *
- * @param int $lp_id Learnpath ID
- * @param int $categoryId Category ID
- *
- * @return bool
- */
- public static function move_up($lp_id, $categoryId = 0)
- {
- $courseId = api_get_course_int_id();
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $categoryCondition = '';
- if (!empty($categoryId)) {
- $categoryId = (int) $categoryId;
- $categoryCondition = " AND category_id = $categoryId";
- }
- $sql = "SELECT * FROM $lp_table
- WHERE c_id = $courseId
- $categoryCondition
- ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false) {
- return false;
- }
- $lps = [];
- $lp_order = [];
- $num = Database::num_rows($res);
- // First check the order is correct, globally (might be wrong because
- // of versions < 1.8.4)
- if ($num > 0) {
- $i = 1;
- while ($row = Database::fetch_array($res)) {
- if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
- $sql = "UPDATE $lp_table SET display_order = $i
- WHERE iid = ".$row['iid'];
- Database::query($sql);
- }
- $row['display_order'] = $i;
- $lps[$row['iid']] = $row;
- $lp_order[$i] = $row['iid'];
- $i++;
- }
- }
- if ($num > 1) { // If there's only one element, no need to sort.
- $order = $lps[$lp_id]['display_order'];
- if ($order > 1) { // If it's the first element, no need to move up.
- $sql = "UPDATE $lp_table SET display_order = $order
- WHERE iid = ".$lp_order[$order - 1];
- Database::query($sql);
- $sql = "UPDATE $lp_table SET display_order = ".($order - 1)."
- WHERE iid = $lp_id";
- Database::query($sql);
- }
- }
- return true;
- }
- /**
- * Move a learnpath down (display_order).
- *
- * @param int $lp_id Learnpath ID
- * @param int $categoryId Category ID
- *
- * @return bool
- */
- public static function move_down($lp_id, $categoryId = 0)
- {
- $courseId = api_get_course_int_id();
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $categoryCondition = '';
- if (!empty($categoryId)) {
- $categoryId = (int) $categoryId;
- $categoryCondition = " AND category_id = $categoryId";
- }
- $sql = "SELECT * FROM $lp_table
- WHERE c_id = $courseId
- $categoryCondition
- ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false) {
- return false;
- }
- $lps = [];
- $lp_order = [];
- $num = Database::num_rows($res);
- $max = 0;
- // First check the order is correct, globally (might be wrong because
- // of versions < 1.8.4).
- if ($num > 0) {
- $i = 1;
- while ($row = Database::fetch_array($res)) {
- $max = $i;
- if ($row['display_order'] != $i) {
- // If we find a gap in the order, we need to fix it.
- $sql = "UPDATE $lp_table SET display_order = $i
- WHERE iid = ".$row['iid'];
- Database::query($sql);
- }
- $row['display_order'] = $i;
- $lps[$row['iid']] = $row;
- $lp_order[$i] = $row['iid'];
- $i++;
- }
- }
- if ($num > 1) { // If there's only one element, no need to sort.
- $order = $lps[$lp_id]['display_order'];
- if ($order < $max) { // If it's the first element, no need to move up.
- $sql = "UPDATE $lp_table SET display_order = $order
- WHERE iid = ".$lp_order[$order + 1];
- Database::query($sql);
- $sql = "UPDATE $lp_table SET display_order = ".($order + 1)."
- WHERE iid = $lp_id";
- Database::query($sql);
- }
- }
- return true;
- }
- /**
- * Updates learnpath attributes to point to the next element
- * The last part is similar to set_current_item but processing the other way around.
- */
- public function next()
- {
- if ($this->debug > 0) {
- error_log('In learnpath::next()', 0);
- }
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(
- false,
- $this->prerequisites_match($this->last)
- );
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_next_index();
- if ($this->debug > 2) {
- error_log('New index: '.$new_index, 0);
- }
- $this->index = $new_index;
- if ($this->debug > 2) {
- error_log('Now having orderedlist['.$new_index.'] = '.$this->ordered_items[$new_index], 0);
- }
- $this->current = $this->ordered_items[$new_index];
- if ($this->debug > 2) {
- error_log('new item id is '.$this->current.'-'.$this->get_current_item_id(), 0);
- }
- }
- /**
- * Open a resource = initialise all local variables relative to this resource. Depending on the child
- * class, this might be redefined to allow several behaviours depending on the document type.
- *
- * @param int $id Resource ID
- */
- public function open($id)
- {
- // TODO:
- // set the current resource attribute to this resource
- // switch on element type (redefine in child class?)
- // set status for this item to "opened"
- // start timer
- // initialise score
- $this->index = 0; //or = the last item seen (see $this->last)
- }
- /**
- * Check that all prerequisites are fulfilled. Returns true and an
- * empty string on success, returns false
- * and the prerequisite string on error.
- * This function is based on the rules for aicc_script language as
- * described in the SCORM 1.2 CAM documentation page 108.
- *
- * @param int $itemId Optional item ID. If none given, uses the current open item.
- *
- * @return bool true if prerequisites are matched, false otherwise - Empty string if true returned, prerequisites
- * string otherwise
- */
- public function prerequisites_match($itemId = null)
- {
- $allow = api_get_configuration_value('allow_teachers_to_access_blocked_lp_by_prerequisite');
- if ($allow) {
- if (api_is_allowed_to_edit() ||
- api_is_platform_admin(true) ||
- api_is_drh() ||
- api_is_coach(api_get_session_id(), api_get_course_int_id())
- ) {
- return true;
- }
- }
- $debug = $this->debug;
- if ($debug > 0) {
- error_log('In learnpath::prerequisites_match()');
- }
- if (empty($itemId)) {
- $itemId = $this->current;
- }
- $currentItem = $this->getItem($itemId);
- if ($currentItem) {
- if ($this->type == 2) {
- // Getting prereq from scorm
- $prereq_string = $this->get_scorm_prereq_string($itemId);
- } else {
- $prereq_string = $currentItem->get_prereq_string();
- }
- if (empty($prereq_string)) {
- if ($debug > 0) {
- error_log('Found prereq_string is empty return true');
- }
- return true;
- }
- // Clean spaces.
- $prereq_string = str_replace(' ', '', $prereq_string);
- if ($debug > 0) {
- error_log('Found prereq_string: '.$prereq_string, 0);
- }
- // Now send to the parse_prereq() function that will check this component's prerequisites.
- $result = $currentItem->parse_prereq(
- $prereq_string,
- $this->items,
- $this->refs_list,
- $this->get_user_id()
- );
- if ($result === false) {
- $this->set_error_msg($currentItem->prereq_alert);
- }
- } else {
- $result = true;
- if ($debug > 1) {
- error_log('$this->items['.$itemId.'] was not an object', 0);
- }
- }
- if ($debug > 1) {
- error_log('End of prerequisites_match(). Error message is now '.$this->error, 0);
- }
- return $result;
- }
- /**
- * Updates learnpath attributes to point to the previous element
- * The last part is similar to set_current_item but processing the other way around.
- */
- public function previous()
- {
- $this->last = $this->get_current_item_id();
- $this->items[$this->last]->save(
- false,
- $this->prerequisites_match($this->last)
- );
- $this->autocomplete_parents($this->last);
- $new_index = $this->get_previous_index();
- $this->index = $new_index;
- $this->current = $this->ordered_items[$new_index];
- }
- /**
- * Publishes a learnpath. This basically means show or hide the learnpath
- * to normal users.
- * Can be used as abstract.
- *
- * @param int $lp_id Learnpath ID
- * @param int $set_visibility New visibility
- *
- * @return bool
- */
- public static function toggle_visibility($lp_id, $set_visibility = 1)
- {
- $action = 'visible';
- if ($set_visibility != 1) {
- $action = 'invisible';
- self::toggle_publish($lp_id, 'i');
- }
- return api_item_property_update(
- api_get_course_info(),
- TOOL_LEARNPATH,
- $lp_id,
- $action,
- api_get_user_id()
- );
- }
- /**
- * Publishes a learnpath category.
- * This basically means show or hide the learnpath category to normal users.
- *
- * @param int $id
- * @param int $visibility
- *
- * @throws \Doctrine\ORM\NonUniqueResultException
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- *
- * @return bool
- */
- public static function toggleCategoryVisibility($id, $visibility = 1)
- {
- $action = 'visible';
- if ($visibility != 1) {
- $action = 'invisible';
- $list = new LearnpathList(
- api_get_user_id(),
- null,
- null,
- null,
- false,
- $id
- );
- $lpList = $list->get_flat_list();
- foreach ($lpList as $lp) {
- self::toggle_visibility($lp['iid'], 0);
- }
- self::toggleCategoryPublish($id, 0);
- }
- return api_item_property_update(
- api_get_course_info(),
- TOOL_LEARNPATH_CATEGORY,
- $id,
- $action,
- api_get_user_id()
- );
- }
- /**
- * Publishes a learnpath. This basically means show or hide the learnpath
- * on the course homepage
- * Can be used as abstract.
- *
- * @param int $lp_id Learnpath id
- * @param string $set_visibility New visibility (v/i - visible/invisible)
- *
- * @return bool
- */
- public static function toggle_publish($lp_id, $set_visibility = 'v')
- {
- $course_id = api_get_course_int_id();
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = (int) $lp_id;
- $sql = "SELECT * FROM $tbl_lp
- WHERE iid = $lp_id";
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- $row = Database::fetch_array($result);
- $name = Database::escape_string($row['name']);
- if ($set_visibility == 'i') {
- $v = 0;
- }
- if ($set_visibility == 'v') {
- $v = 1;
- }
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id);
- $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
- $link = 'lp/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id;
- $oldLink = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id;
- $sql = "SELECT * FROM $tbl_tool
- WHERE
- c_id = $course_id AND
- (link = '$link' OR link = '$oldLink') AND
- image = 'scormbuilder.gif' AND
- (
- link LIKE '$link%' OR
- link LIKE '$oldLink%'
- )
- $session_condition
- ";
- $result = Database::query($sql);
- $num = Database::num_rows($result);
- if ($set_visibility == 'i' && $num > 0) {
- $sql = "DELETE FROM $tbl_tool
- WHERE
- c_id = $course_id AND
- (link = '$link' OR link = '$oldLink') AND
- image='scormbuilder.gif'
- $session_condition";
- Database::query($sql);
- } elseif ($set_visibility == 'v' && $num == 0) {
- $sql = "INSERT INTO $tbl_tool (category, c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES
- ('authoring', $course_id, '$name', '$link', 'scormbuilder.gif', '$v', '0','pastillegris.gif', 0, $session_id)";
- Database::query($sql);
- $insertId = Database::insert_id();
- if ($insertId) {
- $sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $insertId";
- Database::query($sql);
- }
- } elseif ($set_visibility == 'v' && $num > 0) {
- $sql = "UPDATE $tbl_tool SET
- c_id = $course_id,
- name = '$name',
- link = '$link',
- image = 'scormbuilder.gif',
- visibility = '$v',
- admin = '0',
- address = 'pastillegris.gif',
- added_tool = 0,
- session_id = $session_id
- WHERE
- c_id = ".$course_id." AND
- (link = '$link' OR link = '$oldLink') AND
- image='scormbuilder.gif'
- $session_condition
- ";
- Database::query($sql);
- } else {
- // Parameter and database incompatible, do nothing, exit.
- return false;
- }
- } else {
- return false;
- }
- }
- /**
- * Publishes a learnpath.
- * Show or hide the learnpath category on the course homepage.
- *
- * @param int $id
- * @param int $setVisibility
- *
- * @throws \Doctrine\ORM\NonUniqueResultException
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- *
- * @return bool
- */
- public static function toggleCategoryPublish($id, $setVisibility = 1)
- {
- $courseId = api_get_course_int_id();
- $sessionId = api_get_session_id();
- $sessionCondition = api_get_session_condition(
- $sessionId,
- true,
- false,
- 't.sessionId'
- );
- $em = Database::getManager();
- /** @var CLpCategory $category */
- $category = $em->find('ChamiloCourseBundle:CLpCategory', $id);
- if (!$category) {
- return false;
- }
- if (empty($courseId)) {
- return false;
- }
- $link = self::getCategoryLinkForTool($id);
- /** @var CTool $tool */
- $tool = $em->createQuery("
- SELECT t FROM ChamiloCourseBundle:CTool t
- WHERE
- t.cId = :course AND
- t.link = :link1 AND
- t.image = 'lp_category.gif' AND
- t.link LIKE :link2
- $sessionCondition
- ")
- ->setParameters([
- 'course' => (int) $courseId,
- 'link1' => $link,
- 'link2' => "$link%",
- ])
- ->getOneOrNullResult();
- if ($setVisibility == 0 && $tool) {
- $em->remove($tool);
- $em->flush();
- return true;
- }
- if ($setVisibility == 1 && !$tool) {
- $tool = new CTool();
- $tool
- ->setCategory('authoring')
- ->setCId($courseId)
- ->setName(strip_tags($category->getName()))
- ->setLink($link)
- ->setImage('lp_category.gif')
- ->setVisibility(1)
- ->setAdmin(0)
- ->setAddress('pastillegris.gif')
- ->setAddedTool(0)
- ->setSessionId($sessionId)
- ->setTarget('_self');
- $em->persist($tool);
- $em->flush();
- $tool->setId($tool->getIid());
- $em->persist($tool);
- $em->flush();
- return true;
- }
- if ($setVisibility == 1 && $tool) {
- $tool
- ->setName(strip_tags($category->getName()))
- ->setVisibility(1);
- $em->persist($tool);
- $em->flush();
- return true;
- }
- return false;
- }
- /**
- * Check if the learnpath category is visible for a user.
- *
- * @param CLpCategory $category
- * @param User $user
- * @param int
- * @param int
- *
- * @return bool
- */
- public static function categoryIsVisibleForStudent(
- CLpCategory $category,
- User $user,
- $courseId = 0,
- $sessionId = 0
- ) {
- $subscriptionSettings = self::getSubscriptionSettings();
- if ($subscriptionSettings['allow_add_users_to_lp_category'] == false) {
- return true;
- }
- $isAllowedToEdit = api_is_allowed_to_edit(null, true);
- if ($isAllowedToEdit) {
- return true;
- }
- if (empty($category)) {
- return false;
- }
- $users = $category->getUsers();
- if (empty($users) || !$users->count()) {
- return true;
- }
- $courseId = empty($courseId) ? api_get_course_int_id() : (int) $courseId;
- $sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId;
- if ($category->hasUserAdded($user)) {
- return true;
- }
- $groups = GroupManager::getAllGroupPerUserSubscription($user->getId());
- if (!empty($groups)) {
- $em = Database::getManager();
- /** @var ItemPropertyRepository $itemRepo */
- $itemRepo = $em->getRepository('ChamiloCourseBundle:CItemProperty');
- /** @var CourseRepository $courseRepo */
- $courseRepo = $em->getRepository('ChamiloCoreBundle:Course');
- $session = null;
- if (!empty($sessionId)) {
- $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId);
- }
- $course = $courseRepo->find($courseId);
- // Subscribed groups to a LP
- $subscribedGroupsInLp = $itemRepo->getGroupsSubscribedToItem(
- TOOL_LEARNPATH_CATEGORY,
- $category->getId(),
- $course,
- $session
- );
- if (!empty($subscribedGroupsInLp)) {
- $groups = array_column($groups, 'iid');
- /** @var CItemProperty $item */
- foreach ($subscribedGroupsInLp as $item) {
- if ($item->getGroup() &&
- in_array($item->getGroup()->getId(), $groups)
- ) {
- return true;
- }
- }
- }
- }
- return false;
- }
- /**
- * Check if a learnpath category is published as course tool.
- *
- * @param CLpCategory $category
- * @param int $courseId
- *
- * @return bool
- */
- public static function categoryIsPublished(
- CLpCategory $category,
- $courseId
- ) {
- $link = self::getCategoryLinkForTool($category->getId());
- $em = Database::getManager();
- $tools = $em
- ->createQuery("
- SELECT t FROM ChamiloCourseBundle:CTool t
- WHERE t.cId = :course AND
- t.name = :name AND
- t.image = 'lp_category.gif' AND
- t.link LIKE :link
- ")
- ->setParameters([
- 'course' => $courseId,
- 'name' => strip_tags($category->getName()),
- 'link' => "$link%",
- ])
- ->getResult();
- /** @var CTool $tool */
- $tool = current($tools);
- return $tool ? $tool->getVisibility() : false;
- }
- /**
- * Restart the whole learnpath. Return the URL of the first element.
- * Make sure the results are saved with anoter method. This method should probably be redefined in children classes.
- * To use a similar method statically, use the create_new_attempt() method.
- *
- * @return bool
- */
- public function restart()
- {
- if ($this->debug > 0) {
- error_log('In learnpath::restart()', 0);
- }
- // TODO
- // Call autosave method to save the current progress.
- //$this->index = 0;
- if (api_is_invitee()) {
- return false;
- }
- $session_id = api_get_session_id();
- $course_id = api_get_course_int_id();
- $lp_view_table = Database::get_course_table(TABLE_LP_VIEW);
- $sql = "INSERT INTO $lp_view_table (c_id, lp_id, user_id, view_count, session_id)
- VALUES ($course_id, ".$this->lp_id.",".$this->get_user_id().",".($this->attempt + 1).", $session_id)";
- if ($this->debug > 2) {
- error_log('Inserting new lp_view for restart: '.$sql, 0);
- }
- Database::query($sql);
- $view_id = Database::insert_id();
- if ($view_id) {
- $sql = "UPDATE $lp_view_table SET id = iid WHERE iid = $view_id";
- Database::query($sql);
- $this->lp_view_id = $view_id;
- $this->attempt = $this->attempt + 1;
- } else {
- $this->error = 'Could not insert into item_view table...';
- return false;
- }
- $this->autocomplete_parents($this->current);
- foreach ($this->items as $index => $dummy) {
- $this->items[$index]->restart();
- $this->items[$index]->set_lp_view($this->lp_view_id);
- }
- $this->first();
- return true;
- }
- /**
- * Saves the current item.
- *
- * @return bool
- */
- public function save_current()
- {
- $debug = $this->debug;
- // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
- // on $ordered_items[] but not sure it's always safe to use with $items[]).
- if ($debug) {
- error_log('save_current() saving item '.$this->current, 0);
- error_log(''.print_r($this->items, true), 0);
- }
- if (isset($this->items[$this->current]) &&
- is_object($this->items[$this->current])
- ) {
- if ($debug) {
- error_log('Before save last_scorm_session_time: '.$this->items[$this->current]->getLastScormSessionTime());
- }
- $res = $this->items[$this->current]->save(
- false,
- $this->prerequisites_match($this->current)
- );
- $this->autocomplete_parents($this->current);
- $status = $this->items[$this->current]->get_status();
- $this->update_queue[$this->current] = $status;
- if ($debug) {
- error_log('After save last_scorm_session_time: '.$this->items[$this->current]->getLastScormSessionTime());
- }
- return $res;
- }
- return false;
- }
- /**
- * Saves the given item.
- *
- * @param int $item_id Optional (will take from $_REQUEST if null)
- * @param bool $from_outside Save from url params (true) or from current attributes (false). Default true
- *
- * @return bool
- */
- public function save_item($item_id = null, $from_outside = true)
- {
- $debug = $this->debug;
- if ($debug) {
- error_log('In learnpath::save_item('.$item_id.','.intval($from_outside).')', 0);
- }
- // TODO: Do a better check on the index pointing to the right item (it is supposed to be working
- // on $ordered_items[] but not sure it's always safe to use with $items[]).
- if (empty($item_id)) {
- $item_id = (int) $_REQUEST['id'];
- }
- if (empty($item_id)) {
- $item_id = $this->get_current_item_id();
- }
- if (isset($this->items[$item_id]) &&
- is_object($this->items[$item_id])
- ) {
- if ($debug) {
- error_log('Object exists');
- }
- // Saving the item.
- $res = $this->items[$item_id]->save(
- $from_outside,
- $this->prerequisites_match($item_id)
- );
- if ($debug) {
- error_log('update_queue before:');
- error_log(print_r($this->update_queue, 1));
- }
- $this->autocomplete_parents($item_id);
- $status = $this->items[$item_id]->get_status();
- $this->update_queue[$item_id] = $status;
- if ($debug) {
- error_log('get_status(): '.$status);
- error_log('update_queue after:');
- error_log(print_r($this->update_queue, 1));
- }
- return $res;
- }
- return false;
- }
- /**
- * Saves the last item seen's ID only in case.
- */
- public function save_last()
- {
- $course_id = api_get_course_int_id();
- $debug = $this->debug;
- if ($debug) {
- error_log('In learnpath::save_last()', 0);
- }
- $session_condition = api_get_session_condition(
- api_get_session_id(),
- true,
- false
- );
- $table = Database::get_course_table(TABLE_LP_VIEW);
- if (isset($this->current) && !api_is_invitee()) {
- if ($debug) {
- error_log('Saving current item ('.$this->current.') for later review', 0);
- }
- $sql = "UPDATE $table SET
- last_item = ".$this->get_current_item_id()."
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- user_id = ".$this->get_user_id()." ".$session_condition;
- if ($debug) {
- error_log('Saving last item seen : '.$sql, 0);
- }
- Database::query($sql);
- }
- if (!api_is_invitee()) {
- // Save progress.
- list($progress) = $this->get_progress_bar_text('%');
- if ($progress >= 0 && $progress <= 100) {
- $progress = (int) $progress;
- $sql = "UPDATE $table SET
- progress = $progress
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->get_id()." AND
- user_id = ".$this->get_user_id()." ".$session_condition;
- // Ignore errors as some tables might not have the progress field just yet.
- Database::query($sql);
- $this->progress_db = $progress;
- }
- }
- }
- /**
- * Sets the current item ID (checks if valid and authorized first).
- *
- * @param int $item_id New item ID. If not given or not authorized, defaults to current
- */
- public function set_current_item($item_id = null)
- {
- $debug = $this->debug;
- if ($debug) {
- error_log('In learnpath::set_current_item('.$item_id.')', 0);
- }
- if (empty($item_id)) {
- if ($debug) {
- error_log('No new current item given, ignore...', 0);
- }
- // Do nothing.
- } else {
- if ($debug) {
- error_log('New current item given is '.$item_id.'...', 0);
- }
- if (is_numeric($item_id)) {
- $item_id = (int) $item_id;
- // TODO: Check in database here.
- $this->last = $this->current;
- $this->current = $item_id;
- // TODO: Update $this->index as well.
- foreach ($this->ordered_items as $index => $item) {
- if ($item == $this->current) {
- $this->index = $index;
- break;
- }
- }
- if ($debug) {
- error_log('set_current_item('.$item_id.') done. Index is now : '.$this->index);
- }
- } else {
- if ($debug) {
- error_log('set_current_item('.$item_id.') failed. Not a numeric value: ');
- }
- }
- }
- }
- /**
- * Sets the encoding.
- *
- * @param string $enc New encoding
- *
- * @return bool
- *
- * @todo (as of Chamilo 1.8.8): Check in the future whether this method is needed.
- */
- public function set_encoding($enc = 'UTF-8')
- {
- $enc = api_refine_encoding_id($enc);
- if (empty($enc)) {
- $enc = api_get_system_encoding();
- }
- if (api_is_encoding_supported($enc)) {
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET default_encoding = '$enc'
- WHERE iid = ".$lp;
- $res = Database::query($sql);
- return $res;
- }
- }
- return false;
- }
- /**
- * Sets the JS lib setting in the database directly.
- * This is the JavaScript library file this lp needs to load on startup.
- *
- * @param string $lib Proximity setting
- *
- * @return bool True on update success. False otherwise.
- */
- public function set_jslib($lib = '')
- {
- $lp = $this->get_id();
- if ($lp != 0) {
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $lib = Database::escape_string($lib);
- $sql = "UPDATE $tbl_lp SET js_lib = '$lib'
- WHERE iid = $lp";
- $res = Database::query($sql);
- return $res;
- }
- return false;
- }
- /**
- * Sets the name of the LP maker (publisher) (and save).
- *
- * @param string $name Optional string giving the new content_maker of this learnpath
- *
- * @return bool True
- */
- public function set_maker($name = '')
- {
- if (empty($name)) {
- return false;
- }
- $this->maker = $name;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET
- content_maker = '".Database::escape_string($this->maker)."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the name of the current learnpath (and save).
- *
- * @param string $name Optional string giving the new name of this learnpath
- *
- * @return bool True/False
- */
- public function set_name($name = null)
- {
- if (empty($name)) {
- return false;
- }
- $this->name = Database::escape_string($name);
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $course_id = $this->course_info['real_id'];
- $sql = "UPDATE $lp_table SET
- name = '".Database::escape_string($this->name)."'
- WHERE iid = $lp_id";
- $result = Database::query($sql);
- // If the lp is visible on the homepage, change his name there.
- if (Database::affected_rows($result)) {
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id);
- $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
- $link = 'lp/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id;
- $sql = "UPDATE $tbl_tool SET name = '$this->name'
- WHERE
- c_id = $course_id AND
- (link='$link' AND image='scormbuilder.gif' $session_condition)";
- Database::query($sql);
- return true;
- }
- return false;
- }
- /**
- * Set index specified prefix terms for all items in this path.
- *
- * @param string $terms_string Comma-separated list of terms
- * @param string $prefix Xapian term prefix
- *
- * @return bool False on error, true otherwise
- */
- public function set_terms_by_prefix($terms_string, $prefix)
- {
- $course_id = api_get_course_int_id();
- if (api_get_setting('search_enabled') !== 'true') {
- return false;
- }
- if (!extension_loaded('xapian')) {
- return false;
- }
- $terms_string = trim($terms_string);
- $terms = explode(',', $terms_string);
- array_walk($terms, 'trim_value');
- $stored_terms = $this->get_common_index_terms_by_prefix($prefix);
- // Don't do anything if no change, verify only at DB, not the search engine.
- if ((count(array_diff($terms, $stored_terms)) == 0) && (count(array_diff($stored_terms, $terms)) == 0)) {
- return false;
- }
- require_once 'xapian.php'; // TODO: Try catch every xapian use or make wrappers on API.
- require_once api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php';
- $items_table = Database::get_course_table(TABLE_LP_ITEM);
- // TODO: Make query secure agains XSS : use member attr instead of post var.
- $lp_id = (int) $_POST['lp_id'];
- $sql = "SELECT * FROM $items_table WHERE c_id = $course_id AND lp_id = $lp_id";
- $result = Database::query($sql);
- $di = new ChamiloIndexer();
- while ($lp_item = Database::fetch_array($result)) {
- // Get search_did.
- $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'SELECT * FROM %s
- WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d
- LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
- //echo $sql; echo '<br>';
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $se_ref = Database::fetch_array($res);
- // Compare terms.
- $doc = $di->get_document($se_ref['search_did']);
- $xapian_terms = xapian_get_doc_terms($doc, $prefix);
- $xterms = [];
- foreach ($xapian_terms as $xapian_term) {
- $xterms[] = substr($xapian_term['name'], 1);
- }
- $dterms = $terms;
- $missing_terms = array_diff($dterms, $xterms);
- $deprecated_terms = array_diff($xterms, $dterms);
- // Save it to search engine.
- foreach ($missing_terms as $term) {
- $doc->add_term($prefix.$term, 1);
- }
- foreach ($deprecated_terms as $term) {
- $doc->remove_term($prefix.$term);
- }
- $di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
- $di->getDb()->flush();
- }
- }
- return true;
- }
- /**
- * Sets the theme of the LP (local/remote) (and save).
- *
- * @param string $name Optional string giving the new theme of this learnpath
- *
- * @return bool Returns true if theme name is not empty
- */
- public function set_theme($name = '')
- {
- $this->theme = $name;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table
- SET theme = '".Database::escape_string($this->theme)."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the image of an LP (and save).
- *
- * @param string $name Optional string giving the new image of this learnpath
- *
- * @return bool Returns true if theme name is not empty
- */
- public function set_preview_image($name = '')
- {
- $this->preview_image = $name;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET
- preview_image = '".Database::escape_string($this->preview_image)."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the author of a LP (and save).
- *
- * @param string $name Optional string giving the new author of this learnpath
- *
- * @return bool Returns true if author's name is not empty
- */
- public function set_author($name = '')
- {
- $this->author = $name;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET author = '".Database::escape_string($name)."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the hide_toc_frame parameter of a LP (and save).
- *
- * @param int $hide 1 if frame is hidden 0 then else
- *
- * @return bool Returns true if author's name is not empty
- */
- public function set_hide_toc_frame($hide)
- {
- if (intval($hide) == $hide) {
- $this->hide_toc_frame = $hide;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET
- hide_toc_frame = '".(int) $this->hide_toc_frame."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- return false;
- }
- /**
- * Sets the prerequisite of a LP (and save).
- *
- * @param int $prerequisite integer giving the new prerequisite of this learnpath
- *
- * @return bool returns true if prerequisite is not empty
- */
- public function set_prerequisite($prerequisite)
- {
- $this->prerequisite = (int) $prerequisite;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET prerequisite = '".$this->prerequisite."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the location/proximity of the LP (local/remote) (and save).
- *
- * @param string $name Optional string giving the new location of this learnpath
- *
- * @return bool True on success / False on error
- */
- public function set_proximity($name = '')
- {
- if (empty($name)) {
- return false;
- }
- $this->proximity = $name;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET
- content_local = '".Database::escape_string($name)."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item.
- *
- * @param int $id DB ID of the item
- */
- public function set_previous_item($id)
- {
- if ($this->debug > 0) {
- error_log('In learnpath::set_previous_item()', 0);
- }
- $this->last = $id;
- }
- /**
- * Sets use_max_score.
- *
- * @param int $use_max_score Optional string giving the new location of this learnpath
- *
- * @return bool True on success / False on error
- */
- public function set_use_max_score($use_max_score = 1)
- {
- $use_max_score = (int) $use_max_score;
- $this->use_max_score = $use_max_score;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET
- use_max_score = '".$this->use_max_score."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets and saves the expired_on date.
- *
- * @param string $expired_on Optional string giving the new author of this learnpath
- *
- * @throws \Doctrine\ORM\OptimisticLockException
- *
- * @return bool Returns true if author's name is not empty
- */
- public function set_expired_on($expired_on)
- {
- $em = Database::getManager();
- /** @var CLp $lp */
- $lp = $em
- ->getRepository('ChamiloCourseBundle:CLp')
- ->findOneBy(
- [
- 'iid' => $this->get_id(),
- ]
- );
- if (!$lp) {
- return false;
- }
- $this->expired_on = !empty($expired_on) ? api_get_utc_datetime($expired_on, false, true) : null;
- $lp->setExpiredOn($this->expired_on);
- $em->persist($lp);
- $em->flush();
- return true;
- }
- /**
- * Sets and saves the publicated_on date.
- *
- * @param string $publicated_on Optional string giving the new author of this learnpath
- *
- * @throws \Doctrine\ORM\OptimisticLockException
- *
- * @return bool Returns true if author's name is not empty
- */
- public function set_publicated_on($publicated_on)
- {
- $em = Database::getManager();
- /** @var CLp $lp */
- $lp = $em
- ->getRepository('ChamiloCourseBundle:CLp')
- ->findOneBy(
- [
- 'iid' => $this->get_id(),
- ]
- );
- if (!$lp) {
- return false;
- }
- $this->publicated_on = !empty($publicated_on) ? api_get_utc_datetime($publicated_on, false, true) : null;
- $lp->setPublicatedOn($this->publicated_on);
- $em->persist($lp);
- $em->flush();
- return true;
- }
- /**
- * Sets and saves the expired_on date.
- *
- * @return bool Returns true if author's name is not empty
- */
- public function set_modified_on()
- {
- $this->modified_on = api_get_utc_datetime();
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET modified_on = '".$this->modified_on."'
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Sets the object's error message.
- *
- * @param string $error Error message. If empty, reinits the error string
- */
- public function set_error_msg($error = '')
- {
- if ($this->debug > 0) {
- error_log('In learnpath::set_error_msg()', 0);
- }
- if (empty($error)) {
- $this->error = '';
- } else {
- $this->error .= $error;
- }
- }
- /**
- * Launches the current item if not 'sco'
- * (starts timer and make sure there is a record ready in the DB).
- *
- * @param bool $allow_new_attempt Whether to allow a new attempt or not
- *
- * @return bool
- */
- public function start_current_item($allow_new_attempt = false)
- {
- $debug = $this->debug;
- if ($debug) {
- error_log('In learnpath::start_current_item()');
- error_log('current: '.$this->current);
- }
- if ($this->current != 0 && isset($this->items[$this->current]) && is_object($this->items[$this->current])) {
- $type = $this->get_type();
- $item_type = $this->items[$this->current]->get_type();
- if (($type == 2 && $item_type != 'sco') ||
- ($type == 3 && $item_type != 'au') ||
- ($type == 1 && $item_type != TOOL_QUIZ && $item_type != TOOL_HOTPOTATOES)
- ) {
- if ($debug) {
- error_log('item type: '.$item_type);
- error_log('lp type: '.$type);
- }
- $this->items[$this->current]->open($allow_new_attempt);
- $this->autocomplete_parents($this->current);
- $prereq_check = $this->prerequisites_match($this->current);
- if ($debug) {
- error_log('start_current_item will save item with prereq: '.$prereq_check);
- }
- $this->items[$this->current]->save(false, $prereq_check);
- }
- // If sco, then it is supposed to have been updated by some other call.
- if ($item_type == 'sco') {
- $this->items[$this->current]->restart();
- }
- }
- if ($debug) {
- error_log('lp_view_session_id');
- error_log($this->lp_view_session_id);
- error_log('api session id');
- error_log(api_get_session_id());
- error_log('End of learnpath::start_current_item()');
- }
- return true;
- }
- /**
- * Stops the processing and counters for the old item (as held in $this->last).
- *
- * @return bool True/False
- */
- public function stop_previous_item()
- {
- $debug = $this->debug;
- if ($debug) {
- error_log('In learnpath::stop_previous_item()', 0);
- }
- if ($this->last != 0 && $this->last != $this->current &&
- isset($this->items[$this->last]) && is_object($this->items[$this->last])
- ) {
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - '.$this->last.' is object');
- }
- switch ($this->get_type()) {
- case '3':
- if ($this->items[$this->last]->get_type() != 'au') {
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - '.$this->last.' in lp_type 3 is <> au');
- }
- $this->items[$this->last]->close();
- } else {
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals');
- }
- }
- break;
- case '2':
- if ($this->items[$this->last]->get_type() != 'sco') {
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - '.$this->last.' in lp_type 2 is <> sco');
- }
- $this->items[$this->last]->close();
- } else {
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals');
- }
- }
- break;
- case '1':
- default:
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - '.$this->last.' in lp_type 1 is asset');
- }
- $this->items[$this->last]->close();
- break;
- }
- } else {
- if ($debug) {
- error_log('In learnpath::stop_previous_item() - No previous element found, ignoring...');
- }
- return false;
- }
- return true;
- }
- /**
- * Updates the default view mode from fullscreen to embedded and inversely.
- *
- * @return string The current default view mode ('fullscreen' or 'embedded')
- */
- public function update_default_view_mode()
- {
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $table
- WHERE iid = ".$this->get_id();
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $default_view_mode = $row['default_view_mod'];
- $view_mode = $default_view_mode;
- switch ($default_view_mode) {
- case 'fullscreen': // default with popup
- $view_mode = 'embedded';
- break;
- case 'embedded': // default view with left menu
- $view_mode = 'embedframe';
- break;
- case 'embedframe': //folded menu
- $view_mode = 'impress';
- break;
- case 'impress':
- $view_mode = 'fullscreen';
- break;
- }
- $sql = "UPDATE $table SET default_view_mod = '$view_mode'
- WHERE iid = ".$this->get_id();
- Database::query($sql);
- $this->mode = $view_mode;
- return $view_mode;
- }
- return -1;
- }
- /**
- * Updates the default behaviour about auto-commiting SCORM updates.
- *
- * @return bool True if auto-commit has been set to 'on', false otherwise
- */
- public function update_default_scorm_commit()
- {
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table
- WHERE iid = ".$this->get_id();
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $force = $row['force_commit'];
- if ($force == 1) {
- $force = 0;
- $force_return = false;
- } elseif ($force == 0) {
- $force = 1;
- $force_return = true;
- }
- $sql = "UPDATE $lp_table SET force_commit = $force
- WHERE iid = ".$this->get_id();
- Database::query($sql);
- $this->force_commit = $force_return;
- return $force_return;
- }
- return -1;
- }
- /**
- * Updates the order of learning paths (goes through all of them by order and fills the gaps).
- *
- * @return bool True on success, false on failure
- */
- public function update_display_order()
- {
- $course_id = api_get_course_int_id();
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $table
- WHERE c_id = $course_id
- ORDER BY display_order";
- $res = Database::query($sql);
- if ($res === false) {
- return false;
- }
- $num = Database::num_rows($res);
- // First check the order is correct, globally (might be wrong because
- // of versions < 1.8.4).
- if ($num > 0) {
- $i = 1;
- while ($row = Database::fetch_array($res)) {
- if ($row['display_order'] != $i) {
- // If we find a gap in the order, we need to fix it.
- $sql = "UPDATE $table SET display_order = $i
- WHERE iid = ".$row['iid'];
- Database::query($sql);
- }
- $i++;
- }
- }
- return true;
- }
- /**
- * Updates the "prevent_reinit" value that enables control on reinitialising items on second view.
- *
- * @return bool True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
- */
- public function update_reinit()
- {
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table
- WHERE iid = ".$this->get_id();
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $force = $row['prevent_reinit'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET prevent_reinit = $force
- WHERE iid = ".$this->get_id();
- Database::query($sql);
- $this->prevent_reinit = $force;
- return $force;
- }
- return -1;
- }
- /**
- * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag.
- *
- * @return string 'single', 'multi' or 'seriousgame'
- *
- * @author ndiechburg <noel@cblue.be>
- */
- public function get_attempt_mode()
- {
- //Set default value for seriousgame_mode
- if (!isset($this->seriousgame_mode)) {
- $this->seriousgame_mode = 0;
- }
- // Set default value for prevent_reinit
- if (!isset($this->prevent_reinit)) {
- $this->prevent_reinit = 1;
- }
- if ($this->seriousgame_mode == 1 && $this->prevent_reinit == 1) {
- return 'seriousgame';
- }
- if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 1) {
- return 'single';
- }
- if ($this->seriousgame_mode == 0 && $this->prevent_reinit == 0) {
- return 'multiple';
- }
- return 'single';
- }
- /**
- * Register the attempt mode into db thanks to flags prevent_reinit and seriousgame_mode flags.
- *
- * @param string 'seriousgame', 'single' or 'multiple'
- *
- * @return bool
- *
- * @author ndiechburg <noel@cblue.be>
- */
- public function set_attempt_mode($mode)
- {
- switch ($mode) {
- case 'seriousgame':
- $sg_mode = 1;
- $prevent_reinit = 1;
- break;
- case 'single':
- $sg_mode = 0;
- $prevent_reinit = 1;
- break;
- case 'multiple':
- $sg_mode = 0;
- $prevent_reinit = 0;
- break;
- default:
- $sg_mode = 0;
- $prevent_reinit = 0;
- break;
- }
- $this->prevent_reinit = $prevent_reinit;
- $this->seriousgame_mode = $sg_mode;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $table SET
- prevent_reinit = $prevent_reinit ,
- seriousgame_mode = $sg_mode
- WHERE iid = ".$this->get_id();
- $res = Database::query($sql);
- if ($res) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * Switch between multiple attempt, single attempt or serious_game mode (only for scorm).
- *
- * @author ndiechburg <noel@cblue.be>
- */
- public function switch_attempt_mode()
- {
- $mode = $this->get_attempt_mode();
- switch ($mode) {
- case 'single':
- $next_mode = 'multiple';
- break;
- case 'multiple':
- $next_mode = 'seriousgame';
- break;
- case 'seriousgame':
- default:
- $next_mode = 'single';
- break;
- }
- $this->set_attempt_mode($next_mode);
- }
- /**
- * Switch the lp in ktm mode. This is a special scorm mode with unique attempt
- * but possibility to do again a completed item.
- *
- * @return bool true if seriousgame_mode has been set to 1, false otherwise
- *
- * @author ndiechburg <noel@cblue.be>
- */
- public function set_seriousgame_mode()
- {
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table
- WHERE iid = ".$this->get_id();
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $force = $row['seriousgame_mode'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET seriousgame_mode = $force
- WHERE iid = ".$this->get_id();
- Database::query($sql);
- $this->seriousgame_mode = $force;
- return $force;
- }
- return -1;
- }
- /**
- * Updates the "scorm_debug" value that shows or hide the debug window.
- *
- * @return bool True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
- */
- public function update_scorm_debug()
- {
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT * FROM $lp_table
- WHERE iid = ".$this->get_id();
- $res = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- $force = $row['debug'];
- if ($force == 1) {
- $force = 0;
- } elseif ($force == 0) {
- $force = 1;
- }
- $sql = "UPDATE $lp_table SET debug = $force
- WHERE iid = ".$this->get_id();
- Database::query($sql);
- $this->scorm_debug = $force;
- return $force;
- }
- return -1;
- }
- /**
- * Function that makes a call to the function sort_tree_array and create_tree_array.
- *
- * @author Kevin Van Den Haute
- *
- * @param array
- */
- public function tree_array($array)
- {
- $array = $this->sort_tree_array($array);
- $this->create_tree_array($array);
- }
- /**
- * Creates an array with the elements of the learning path tree in it.
- *
- * @author Kevin Van Den Haute
- *
- * @param array $array
- * @param int $parent
- * @param int $depth
- * @param array $tmp
- */
- public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = [])
- {
- if (is_array($array)) {
- for ($i = 0; $i < count($array); $i++) {
- if ($array[$i]['parent_item_id'] == $parent) {
- if (!in_array($array[$i]['parent_item_id'], $tmp)) {
- $tmp[] = $array[$i]['parent_item_id'];
- $depth++;
- }
- $preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
- $audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
- $path = isset($array[$i]['path']) ? $array[$i]['path'] : null;
- $prerequisiteMinScore = isset($array[$i]['prerequisite_min_score']) ? $array[$i]['prerequisite_min_score'] : null;
- $prerequisiteMaxScore = isset($array[$i]['prerequisite_max_score']) ? $array[$i]['prerequisite_max_score'] : null;
- $ref = isset($array[$i]['ref']) ? $array[$i]['ref'] : '';
- $this->arrMenu[] = [
- 'id' => $array[$i]['id'],
- 'ref' => $ref,
- 'item_type' => $array[$i]['item_type'],
- 'title' => $array[$i]['title'],
- 'path' => $path,
- 'description' => $array[$i]['description'],
- 'parent_item_id' => $array[$i]['parent_item_id'],
- 'previous_item_id' => $array[$i]['previous_item_id'],
- 'next_item_id' => $array[$i]['next_item_id'],
- 'min_score' => $array[$i]['min_score'],
- 'max_score' => $array[$i]['max_score'],
- 'mastery_score' => $array[$i]['mastery_score'],
- 'display_order' => $array[$i]['display_order'],
- 'prerequisite' => $preq,
- 'depth' => $depth,
- 'audio' => $audio,
- 'prerequisite_min_score' => $prerequisiteMinScore,
- 'prerequisite_max_score' => $prerequisiteMaxScore,
- ];
- $this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
- }
- }
- }
- }
- /**
- * Sorts a multi dimensional array by parent id and display order.
- *
- * @author Kevin Van Den Haute
- *
- * @param array $array (array with al the learning path items in it)
- *
- * @return array
- */
- public function sort_tree_array($array)
- {
- foreach ($array as $key => $row) {
- $parent[$key] = $row['parent_item_id'];
- $position[$key] = $row['display_order'];
- }
- if (count($array) > 0) {
- array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
- }
- return $array;
- }
- /**
- * Function that creates a html list of learning path items so that we can add audio files to them.
- *
- * @author Kevin Van Den Haute
- *
- * @return string
- */
- public function overview()
- {
- $return = '';
- $update_audio = isset($_GET['updateaudio']) ? $_GET['updateaudio'] : null;
- // we need to start a form when we want to update all the mp3 files
- if ($update_audio == 'true') {
- $return .= '<form action="'.api_get_self().'?'.api_get_cidreq().'&updateaudio='.Security::remove_XSS($_GET['updateaudio']).'&action='.Security::remove_XSS($_GET['action']).'&lp_id='.$_SESSION['oLP']->lp_id.'" method="post" enctype="multipart/form-data" name="updatemp3" id="updatemp3">';
- }
- $return .= '<div id="message"></div>';
- if (count($this->items) == 0) {
- $return .= Display::return_message(get_lang('YouShouldAddItemsBeforeAttachAudio'), 'normal');
- } else {
- $return_audio = '<table class="data_table">';
- $return_audio .= '<tr>';
- $return_audio .= '<th width="40%">'.get_lang('Title').'</th>';
- $return_audio .= '<th>'.get_lang('Audio').'</th>';
- $return_audio .= '</tr>';
- if ($update_audio != 'true') {
- $return .= '<div class="col-md-12">';
- $return .= self::return_new_tree($update_audio);
- $return .= '</div>';
- $return .= Display::div(
- Display::url(get_lang('Save'), '#', ['id' => 'listSubmit', 'class' => 'btn btn-primary']),
- ['style' => 'float:left; margin-top:15px;width:100%']
- );
- } else {
- $return_audio .= self::return_new_tree($update_audio);
- $return .= $return_audio.'</table>';
- }
- // We need to close the form when we are updating the mp3 files.
- if ($update_audio == 'true') {
- $return .= '<div class="footer-audio">';
- $return .= Display::button(
- 'save_audio',
- '<em class="fa fa-file-audio-o"></em> '.get_lang('SaveAudioAndOrganization'),
- ['class' => 'btn btn-primary', 'type' => 'submit']
- );
- $return .= '</div>';
- }
- }
- // We need to close the form when we are updating the mp3 files.
- if ($update_audio == 'true' && isset($this->arrMenu) && count($this->arrMenu) != 0) {
- $return .= '</form>';
- }
- return $return;
- }
- /**
- * @param string $update_audio
- *
- * @return array
- */
- public function processBuildMenuElements($update_audio = 'false')
- {
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- $default_data = null;
- $default_content = null;
- $elements = [];
- $return_audio = null;
- $iconPath = api_get_path(SYS_CODE_PATH).'img/';
- $mainUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq();
- $countItems = count($arrLP);
- $upIcon = Display::return_icon(
- 'up.png',
- get_lang('Up'),
- [],
- ICON_SIZE_TINY
- );
- $disableUpIcon = Display::return_icon(
- 'up_na.png',
- get_lang('Up'),
- [],
- ICON_SIZE_TINY
- );
- $downIcon = Display::return_icon(
- 'down.png',
- get_lang('Down'),
- [],
- ICON_SIZE_TINY
- );
- $disableDownIcon = Display::return_icon(
- 'down_na.png',
- get_lang('Down'),
- [],
- ICON_SIZE_TINY
- );
- for ($i = 0; $i < $countItems; $i++) {
- $parent_id = $arrLP[$i]['parent_item_id'];
- $title = $arrLP[$i]['title'];
- $title_cut = cut($arrLP[$i]['title'], self::MAX_LP_ITEM_TITLE_LENGTH);
- // Link for the documents
- if ($arrLP[$i]['item_type'] === 'document' || $arrLP[$i]['item_type'] == TOOL_READOUT_TEXT) {
- $url = $mainUrl.'&action=view_item&mode=preview_document&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
- $title_cut = Display::url(
- $title_cut,
- $url,
- [
- 'class' => 'ajax moved',
- 'data-title' => $title,
- 'title' => $title,
- ]
- );
- }
- // Detect if type is FINAL_ITEM to set path_id to SESSION
- if ($arrLP[$i]['item_type'] == TOOL_LP_FINAL_ITEM) {
- Session::write('pathItem', $arrLP[$i]['path']);
- }
- $oddClass = 'row_even';
- if (($i % 2) == 0) {
- $oddClass = 'row_odd';
- }
- $return_audio .= '<tr id ="lp_item_'.$arrLP[$i]['id'].'" class="'.$oddClass.'">';
- $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']);
- if (file_exists($iconPath.'lp_'.$icon_name.'.png')) {
- $icon = Display::return_icon('lp_'.$icon_name.'.png');
- } else {
- if (file_exists($iconPath.'lp_'.$icon_name.'.gif')) {
- $icon = Display::return_icon('lp_'.$icon_name.'.gif');
- } else {
- if ($arrLP[$i]['item_type'] === TOOL_LP_FINAL_ITEM) {
- $icon = Display::return_icon('certificate.png');
- } else {
- $icon = Display::return_icon('folder_document.gif');
- }
- }
- }
- // The audio column.
- $return_audio .= '<td align="left" style="padding-left:10px;">';
- $audio = '';
- if (!$update_audio || $update_audio != 'true') {
- if (empty($arrLP[$i]['audio'])) {
- $audio .= '';
- }
- } else {
- $types = self::getChapterTypes();
- if (!in_array($arrLP[$i]['item_type'], $types)) {
- $audio .= '<input type="file" name="mp3file'.$arrLP[$i]['id'].'" id="mp3file" />';
- if (!empty($arrLP[$i]['audio'])) {
- $audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<br />
- <input type="checkbox" name="removemp3'.$arrLP[$i]['id'].'" id="checkbox'.$arrLP[$i]['id'].'" />'.get_lang('RemoveAudio');
- }
- }
- }
- $return_audio .= Display::span($icon.' '.$title).
- Display::tag(
- 'td',
- $audio,
- ['style' => '']
- );
- $return_audio .= '</td>';
- $move_icon = '';
- $move_item_icon = '';
- $edit_icon = '';
- $delete_icon = '';
- $audio_icon = '';
- $prerequisities_icon = '';
- $forumIcon = '';
- $previewIcon = '';
- $pluginCalendarIcon = '';
- $orderIcons = '';
- $pluginCalendar = api_get_plugin_setting('learning_calendar', 'enabled') === 'true';
- $plugin = null;
- if ($pluginCalendar) {
- $plugin = LearningCalendarPlugin::create();
- }
- $pluginUrl = api_get_path(WEB_PLUGIN_PATH).'learning_calendar/start.php?';
- if ($is_allowed_to_edit) {
- if (!$update_audio || $update_audio != 'true') {
- if ($arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) {
- $move_icon .= '<a class="moved" href="#">';
- $move_icon .= Display::return_icon(
- 'move_everywhere.png',
- get_lang('Move'),
- [],
- ICON_SIZE_TINY
- );
- $move_icon .= '</a>';
- }
- }
- // No edit for this item types
- if (!in_array($arrLP[$i]['item_type'], ['sco', 'asset', 'final_item'])) {
- if ($arrLP[$i]['item_type'] != 'dir') {
- $edit_icon .= '<a href="'.$mainUrl.'&action=edit_item&view=build&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id.'&path_item='.$arrLP[$i]['path'].'" class="btn btn-default">';
- $edit_icon .= Display::return_icon(
- 'edit.png',
- get_lang('LearnpathEditModule'),
- [],
- ICON_SIZE_TINY
- );
- $edit_icon .= '</a>';
- if (!in_array($arrLP[$i]['item_type'], ['forum', 'thread'])) {
- $forumThread = null;
- if (isset($this->items[$arrLP[$i]['id']])) {
- $forumThread = $this->items[$arrLP[$i]['id']]->getForumThread(
- $this->course_int_id,
- $this->lp_session_id
- );
- }
- if ($forumThread) {
- $forumIconUrl = $mainUrl.'&'.http_build_query([
- 'action' => 'dissociate_forum',
- 'id' => $arrLP[$i]['id'],
- 'lp_id' => $this->lp_id,
- ]);
- $forumIcon = Display::url(
- Display::return_icon(
- 'forum.png',
- get_lang('DissociateForumToLPItem'),
- [],
- ICON_SIZE_TINY
- ),
- $forumIconUrl,
- ['class' => 'btn btn-default lp-btn-dissociate-forum']
- );
- } else {
- $forumIconUrl = $mainUrl.'&'.http_build_query([
- 'action' => 'create_forum',
- 'id' => $arrLP[$i]['id'],
- 'lp_id' => $this->lp_id,
- ]);
- $forumIcon = Display::url(
- Display::return_icon(
- 'forum.png',
- get_lang('AssociateForumToLPItem'),
- [],
- ICON_SIZE_TINY
- ),
- $forumIconUrl,
- ['class' => 'btn btn-default lp-btn-associate-forum']
- );
- }
- }
- } else {
- $edit_icon .= '<a href="'.$mainUrl.'&action=edit_item&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id.'&path_item='.$arrLP[$i]['path'].'" class="btn btn-default">';
- $edit_icon .= Display::return_icon(
- 'edit.png',
- get_lang('LearnpathEditModule'),
- [],
- ICON_SIZE_TINY
- );
- $edit_icon .= '</a>';
- }
- } else {
- if ($arrLP[$i]['item_type'] == TOOL_LP_FINAL_ITEM) {
- $edit_icon .= '<a href="'.$mainUrl.'&action=edit_item&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id.'" class="btn btn-default">';
- $edit_icon .= Display::return_icon(
- 'edit.png',
- get_lang('Edit'),
- [],
- ICON_SIZE_TINY
- );
- $edit_icon .= '</a>';
- }
- }
- if ($pluginCalendar) {
- $pluginLink = $pluginUrl.
- '&action=toggle_visibility&lp_item_id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
- $iconCalendar = Display::return_icon('agenda_na.png', get_lang('OneDay'), [], ICON_SIZE_TINY);
- $itemInfo = $plugin->getItemVisibility($arrLP[$i]['id']);
- if ($itemInfo && $itemInfo['value'] == 1) {
- $iconCalendar = Display::return_icon('agenda.png', get_lang('OneDay'), [], ICON_SIZE_TINY);
- }
- $pluginCalendarIcon = Display::url(
- $iconCalendar,
- $pluginLink,
- ['class' => 'btn btn-default']
- );
- }
- if ($arrLP[$i]['item_type'] != 'final_item') {
- $orderIcons = Display::url(
- $upIcon,
- 'javascript:void(0)',
- ['class' => 'btn btn-default order_items', 'data-dir' => 'up', 'data-id' => $arrLP[$i]['id']]
- );
- $orderIcons .= Display::url(
- $downIcon,
- 'javascript:void(0)',
- ['class' => 'btn btn-default order_items', 'data-dir' => 'down', 'data-id' => $arrLP[$i]['id']]
- );
- }
- $delete_icon .= ' <a
- href="'.$mainUrl.'&action=delete_item&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id.'"
- onclick="return confirmation(\''.addslashes($title).'\');"
- class="btn btn-default">';
- $delete_icon .= Display::return_icon(
- 'delete.png',
- get_lang('LearnpathDeleteModule'),
- [],
- ICON_SIZE_TINY
- );
- $delete_icon .= '</a>';
- $url = $mainUrl.'&view=build&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
- $previewImage = Display::return_icon(
- 'preview_view.png',
- get_lang('Preview'),
- [],
- ICON_SIZE_TINY
- );
- switch ($arrLP[$i]['item_type']) {
- case TOOL_DOCUMENT:
- case TOOL_LP_FINAL_ITEM:
- case TOOL_READOUT_TEXT:
- $urlPreviewLink = $mainUrl.'&action=view_item&mode=preview_document&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id;
- $previewIcon = Display::url(
- $previewImage,
- $urlPreviewLink,
- [
- 'target' => '_blank',
- 'class' => 'btn btn-default',
- 'data-title' => $arrLP[$i]['title'],
- 'title' => $arrLP[$i]['title'],
- ]
- );
- break;
- case TOOL_THREAD:
- case TOOL_FORUM:
- case TOOL_QUIZ:
- case TOOL_STUDENTPUBLICATION:
- case TOOL_LP_FINAL_ITEM:
- case TOOL_LINK:
- $class = 'btn btn-default';
- $target = '_blank';
- $link = self::rl_get_resource_link_for_learnpath(
- $this->course_int_id,
- $this->lp_id,
- $arrLP[$i]['id'],
- 0
- );
- $previewIcon = Display::url(
- $previewImage,
- $link,
- [
- 'class' => $class,
- 'data-title' => $arrLP[$i]['title'],
- 'title' => $arrLP[$i]['title'],
- 'target' => $target,
- ]
- );
- break;
- default:
- $previewIcon = Display::url(
- $previewImage,
- $url.'&action=view_item',
- ['class' => 'btn btn-default', 'target' => '_blank']
- );
- break;
- }
- if ($arrLP[$i]['item_type'] != 'dir') {
- $prerequisities_icon = Display::url(
- Display::return_icon(
- 'accept.png',
- get_lang('LearnpathPrerequisites'),
- [],
- ICON_SIZE_TINY
- ),
- $url.'&action=edit_item_prereq',
- ['class' => 'btn btn-default']
- );
- if ($arrLP[$i]['item_type'] != 'final_item') {
- $move_item_icon = Display::url(
- Display::return_icon(
- 'move.png',
- get_lang('Move'),
- [],
- ICON_SIZE_TINY
- ),
- $url.'&action=move_item',
- ['class' => 'btn btn-default']
- );
- }
- $audio_icon = Display::url(
- Display::return_icon(
- 'audio.png',
- get_lang('UplUpload'),
- [],
- ICON_SIZE_TINY
- ),
- $url.'&action=add_audio',
- ['class' => 'btn btn-default']
- );
- }
- }
- if ($update_audio != 'true') {
- $row = $move_icon.' '.$icon.
- Display::span($title_cut).
- Display::tag(
- 'div',
- "<div class=\"btn-group btn-group-xs\">
- $previewIcon
- $audio
- $edit_icon
- $pluginCalendarIcon
- $forumIcon
- $prerequisities_icon
- $move_item_icon
- $audio_icon
- $orderIcons
- $delete_icon
- </div>",
- ['class' => 'btn-toolbar button_actions']
- );
- } else {
- $row =
- Display::span($title.$icon).
- Display::span($audio, ['class' => 'button_actions']);
- }
- $default_data[$arrLP[$i]['id']] = $row;
- $default_content[$arrLP[$i]['id']] = $arrLP[$i];
- if (empty($parent_id)) {
- $elements[$arrLP[$i]['id']]['data'] = $row;
- $elements[$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
- } else {
- $parent_arrays = [];
- if ($arrLP[$i]['depth'] > 1) {
- //Getting list of parents
- for ($j = 0; $j < $arrLP[$i]['depth']; $j++) {
- foreach ($arrLP as $item) {
- if ($item['id'] == $parent_id) {
- if ($item['parent_item_id'] == 0) {
- $parent_id = $item['id'];
- break;
- } else {
- $parent_id = $item['parent_item_id'];
- if (empty($parent_arrays)) {
- $parent_arrays[] = intval($item['id']);
- }
- $parent_arrays[] = $parent_id;
- break;
- }
- }
- }
- }
- }
- if (!empty($parent_arrays)) {
- $parent_arrays = array_reverse($parent_arrays);
- $val = '$elements';
- $x = 0;
- foreach ($parent_arrays as $item) {
- if ($x != count($parent_arrays) - 1) {
- $val .= '["'.$item.'"]["children"]';
- } else {
- $val .= '["'.$item.'"]["children"]';
- }
- $x++;
- }
- $val .= "";
- $code_str = $val."[".$arrLP[$i]['id']."][\"load_data\"] = '".$arrLP[$i]['id']."' ; ";
- eval($code_str);
- } else {
- $elements[$parent_id]['children'][$arrLP[$i]['id']]['data'] = $row;
- $elements[$parent_id]['children'][$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type'];
- }
- }
- }
- return [
- 'elements' => $elements,
- 'default_data' => $default_data,
- 'default_content' => $default_content,
- 'return_audio' => $return_audio,
- ];
- }
- /**
- * @param string $updateAudio true/false strings
- *
- * @return string
- */
- public function returnLpItemList($updateAudio)
- {
- $result = $this->processBuildMenuElements($updateAudio);
- $html = self::print_recursive(
- $result['elements'],
- $result['default_data'],
- $result['default_content']
- );
- if (!empty($html)) {
- $html .= Display::return_message(get_lang('DragAndDropAnElementHere'));
- }
- return $html;
- }
- /**
- * @param string $update_audio
- * @param bool $drop_element_here
- *
- * @return string
- */
- public function return_new_tree($update_audio = 'false', $drop_element_here = false)
- {
- $result = $this->processBuildMenuElements($update_audio);
- $list = '<ul id="lp_item_list">';
- $tree = $this->print_recursive(
- $result['elements'],
- $result['default_data'],
- $result['default_content']
- );
- if (!empty($tree)) {
- $list .= $tree;
- } else {
- if ($drop_element_here) {
- $list .= Display::return_message(get_lang('DragAndDropAnElementHere'));
- }
- }
- $list .= '</ul>';
- $return = Display::panelCollapse(
- $this->name,
- $list,
- 'scorm-list',
- null,
- 'scorm-list-accordion',
- 'scorm-list-collapse'
- );
- if ($update_audio === 'true') {
- $return = $result['return_audio'];
- }
- return $return;
- }
- /**
- * @param array $elements
- * @param array $default_data
- * @param array $default_content
- *
- * @return string
- */
- public function print_recursive($elements, $default_data, $default_content)
- {
- $return = '';
- foreach ($elements as $key => $item) {
- if (isset($item['load_data']) || empty($item['data'])) {
- $item['data'] = $default_data[$item['load_data']];
- $item['type'] = $default_content[$item['load_data']]['item_type'];
- }
- $sub_list = '';
- if (isset($item['type']) && $item['type'] === 'dir') {
- // empty value
- $sub_list = Display::tag('li', '', ['class' => 'sub_item empty']);
- }
- if (empty($item['children'])) {
- $sub_list = Display::tag('ul', $sub_list, ['id' => 'UL_'.$key, 'class' => 'record li_container']);
- $active = null;
- if (isset($_REQUEST['id']) && $key == $_REQUEST['id']) {
- $active = 'active';
- }
- $return .= Display::tag(
- 'li',
- Display::div($item['data'], ['class' => "item_data $active"]).$sub_list,
- ['id' => $key, 'class' => 'record li_container']
- );
- } else {
- // Sections
- $data = '';
- if (isset($item['children'])) {
- $data = self::print_recursive($item['children'], $default_data, $default_content);
- }
- $sub_list = Display::tag('ul', $sub_list.$data, ['id' => 'UL_'.$key, 'class' => 'record li_container']);
- $return .= Display::tag(
- 'li',
- Display::div($item['data'], ['class' => 'item_data']).$sub_list,
- ['id' => $key, 'class' => 'record li_container']
- );
- }
- }
- return $return;
- }
- /**
- * This function builds the action menu.
- *
- * @param bool $returnContent Optional
- * @param bool $showRequirementButtons Optional. Allow show the requirements button
- * @param bool $isConfigPage Optional. If is the config page, show the edit button
- * @param bool $allowExpand Optional. Allow show the expand/contract button
- *
- * @return string
- */
- public function build_action_menu(
- $returnContent = false,
- $showRequirementButtons = true,
- $isConfigPage = false,
- $allowExpand = true
- ) {
- $actionsLeft = '';
- $actionsRight = '';
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'back.png',
- get_lang('ReturnToLearningPaths'),
- '',
- ICON_SIZE_MEDIUM
- ),
- 'lp_controller.php?'.api_get_cidreq()
- );
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'preview_view.png',
- get_lang('Preview'),
- '',
- ICON_SIZE_MEDIUM
- ),
- 'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'view',
- 'lp_id' => $this->lp_id,
- 'isStudentView' => 'true',
- ])
- );
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'upload_audio.png',
- get_lang('UpdateAllAudioFragments'),
- '',
- ICON_SIZE_MEDIUM
- ),
- 'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'admin_view',
- 'lp_id' => $this->lp_id,
- 'updateaudio' => 'true',
- ])
- );
- if (!$isConfigPage) {
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'settings.png',
- get_lang('CourseSettings'),
- '',
- ICON_SIZE_MEDIUM
- ),
- 'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'edit',
- 'lp_id' => $this->lp_id,
- ])
- );
- } else {
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'edit.png',
- get_lang('Edit'),
- '',
- ICON_SIZE_MEDIUM
- ),
- 'lp_controller.php?'.http_build_query([
- 'action' => 'build',
- 'lp_id' => $this->lp_id,
- ]).'&'.api_get_cidreq()
- );
- }
- if ($allowExpand) {
- $actionsLeft .= Display::url(
- Display::return_icon(
- 'expand.png',
- get_lang('Expand'),
- ['id' => 'expand'],
- ICON_SIZE_MEDIUM
- ).
- Display::return_icon(
- 'contract.png',
- get_lang('Collapse'),
- ['id' => 'contract', 'class' => 'hide'],
- ICON_SIZE_MEDIUM
- ),
- '#',
- ['role' => 'button', 'id' => 'hide_bar_template']
- );
- }
- if ($showRequirementButtons) {
- $buttons = [
- [
- 'title' => get_lang('SetPrerequisiteForEachItem'),
- 'href' => 'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'set_previous_step_as_prerequisite',
- 'lp_id' => $this->lp_id,
- ]),
- ],
- [
- 'title' => get_lang('ClearAllPrerequisites'),
- 'href' => 'lp_controller.php?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'clear_prerequisites',
- 'lp_id' => $this->lp_id,
- ]),
- ],
- ];
- $actionsRight = Display::groupButtonWithDropDown(
- get_lang('PrerequisitesOptions'),
- $buttons,
- true
- );
- }
- $toolbar = Display::toolbarAction(
- 'actions-lp-controller',
- [$actionsLeft, $actionsRight]
- );
- if ($returnContent) {
- return $toolbar;
- }
- echo $toolbar;
- }
- /**
- * Creates the default learning path folder.
- *
- * @param array $course
- * @param int $creatorId
- *
- * @return bool
- */
- public static function generate_learning_path_folder($course, $creatorId = 0)
- {
- // Creating learning_path folder
- $dir = '/learning_path';
- $filepath = api_get_path(SYS_COURSE_PATH).$course['path'].'/document';
- $creatorId = empty($creatorId) ? api_get_user_id() : $creatorId;
- $folder = false;
- if (!is_dir($filepath.'/'.$dir)) {
- $folderData = create_unexisting_directory(
- $course,
- $creatorId,
- 0,
- null,
- 0,
- $filepath,
- $dir,
- get_lang('LearningPaths'),
- 0
- );
- if (!empty($folderData)) {
- $folder = true;
- }
- } else {
- $folder = true;
- }
- return $folder;
- }
- /**
- * @param array $course
- * @param string $lp_name
- * @param int $creatorId
- *
- * @return array
- */
- public function generate_lp_folder($course, $lp_name = '', $creatorId = 0)
- {
- $filepath = '';
- $dir = '/learning_path/';
- if (empty($lp_name)) {
- $lp_name = $this->name;
- }
- $creatorId = empty($creatorId) ? api_get_user_id() : $creatorId;
- $folder = self::generate_learning_path_folder($course, $creatorId);
- // Limits title size
- $title = api_substr(api_replace_dangerous_char($lp_name), 0, 80);
- $dir = $dir.$title;
- // Creating LP folder
- $documentId = null;
- if ($folder) {
- $filepath = api_get_path(SYS_COURSE_PATH).$course['path'].'/document';
- if (!is_dir($filepath.'/'.$dir)) {
- $folderData = create_unexisting_directory(
- $course,
- $creatorId,
- 0,
- 0,
- 0,
- $filepath,
- $dir,
- $lp_name
- );
- if (!empty($folderData)) {
- $folder = true;
- }
- $documentId = $folderData['id'];
- } else {
- $folder = true;
- }
- $dir = $dir.'/';
- if ($folder) {
- $filepath = api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$dir;
- }
- }
- if (empty($documentId)) {
- $dir = api_remove_trailing_slash($dir);
- $documentId = DocumentManager::get_document_id($course, $dir, 0);
- }
- $array = [
- 'dir' => $dir,
- 'filepath' => $filepath,
- 'folder' => $folder,
- 'id' => $documentId,
- ];
- return $array;
- }
- /**
- * Create a new document //still needs some finetuning.
- *
- * @param array $courseInfo
- * @param string $content
- * @param string $title
- * @param string $extension
- * @param int $parentId
- * @param int $creatorId creator id
- *
- * @return int
- */
- public function create_document(
- $courseInfo,
- $content = '',
- $title = '',
- $extension = 'html',
- $parentId = 0,
- $creatorId = 0
- ) {
- if (!empty($courseInfo)) {
- $course_id = $courseInfo['real_id'];
- } else {
- $course_id = api_get_course_int_id();
- }
- $creatorId = empty($creatorId) ? api_get_user_id() : $creatorId;
- $sessionId = api_get_session_id();
- // Generates folder
- $result = $this->generate_lp_folder($courseInfo);
- $dir = $result['dir'];
- if (empty($parentId) || $parentId == '/') {
- $postDir = isset($_POST['dir']) ? $_POST['dir'] : $dir;
- $dir = isset($_GET['dir']) ? $_GET['dir'] : $postDir; // Please, do not modify this dirname formatting.
- if ($parentId === '/') {
- $dir = '/';
- }
- // Please, do not modify this dirname formatting.
- if (strstr($dir, '..')) {
- $dir = '/';
- }
- if (!empty($dir[0]) && $dir[0] == '.') {
- $dir = substr($dir, 1);
- }
- if (!empty($dir[0]) && $dir[0] != '/') {
- $dir = '/'.$dir;
- }
- if (isset($dir[strlen($dir) - 1]) && $dir[strlen($dir) - 1] != '/') {
- $dir .= '/';
- }
- } else {
- $parentInfo = DocumentManager::get_document_data_by_id(
- $parentId,
- $courseInfo['code']
- );
- if (!empty($parentInfo)) {
- $dir = $parentInfo['path'].'/';
- }
- }
- $filepath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$dir;
- if (!is_dir($filepath)) {
- $dir = '/';
- $filepath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$dir;
- }
- // stripslashes() before calling api_replace_dangerous_char() because $_POST['title']
- // is already escaped twice when it gets here.
- $originalTitle = !empty($title) ? $title : $_POST['title'];
- if (!empty($title)) {
- $title = api_replace_dangerous_char(stripslashes($title));
- } else {
- $title = api_replace_dangerous_char(stripslashes($_POST['title']));
- }
- $title = disable_dangerous_file($title);
- $filename = $title;
- $content = !empty($content) ? $content : $_POST['content_lp'];
- $tmp_filename = $filename;
- $i = 0;
- while (file_exists($filepath.$tmp_filename.'.'.$extension)) {
- $tmp_filename = $filename.'_'.++$i;
- }
- $filename = $tmp_filename.'.'.$extension;
- if ($extension == 'html') {
- $content = stripslashes($content);
- $content = str_replace(
- api_get_path(WEB_COURSE_PATH),
- api_get_path(REL_PATH).'courses/',
- $content
- );
- // Change the path of mp3 to absolute.
- // The first regexp deals with :// urls.
- $content = preg_replace(
- "|(flashvars=\"file=)([^:/]+)/|",
- "$1".api_get_path(
- REL_COURSE_PATH
- ).$courseInfo['path'].'/document/',
- $content
- );
- // The second regexp deals with audio/ urls.
- $content = preg_replace(
- "|(flashvars=\"file=)([^/]+)/|",
- "$1".api_get_path(
- REL_COURSE_PATH
- ).$courseInfo['path'].'/document/$2/',
- $content
- );
- // For flv player: To prevent edition problem with firefox,
- // we have to use a strange tip (don't blame me please).
- $content = str_replace(
- '</body>',
- '<style type="text/css">body{}</style></body>',
- $content
- );
- }
- if (!file_exists($filepath.$filename)) {
- if ($fp = @fopen($filepath.$filename, 'w')) {
- fputs($fp, $content);
- fclose($fp);
- $file_size = filesize($filepath.$filename);
- $save_file_path = $dir.$filename;
- $document_id = add_document(
- $courseInfo,
- $save_file_path,
- 'file',
- $file_size,
- $tmp_filename,
- '',
- 0, //readonly
- true,
- null,
- $sessionId,
- $creatorId
- );
- if ($document_id) {
- api_item_property_update(
- $courseInfo,
- TOOL_DOCUMENT,
- $document_id,
- 'DocumentAdded',
- $creatorId,
- null,
- null,
- null,
- null,
- $sessionId
- );
- $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
- $new_title = $originalTitle;
- if ($new_comment || $new_title) {
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $ct = '';
- if ($new_comment) {
- $ct .= ", comment='".Database::escape_string($new_comment)."'";
- }
- if ($new_title) {
- $ct .= ", title='".Database::escape_string($new_title)."' ";
- }
- $sql = "UPDATE ".$tbl_doc." SET ".substr($ct, 1)."
- WHERE c_id = ".$course_id." AND id = ".$document_id;
- Database::query($sql);
- }
- }
- return $document_id;
- }
- }
- }
- /**
- * Edit a document based on $_POST and $_GET parameters 'dir' and 'path'.
- *
- * @param array $_course array
- */
- public function edit_document($_course)
- {
- $course_id = api_get_course_int_id();
- $urlAppend = api_get_configuration_value('url_append');
- // Please, do not modify this dirname formatting.
- $postDir = isset($_POST['dir']) ? $_POST['dir'] : '';
- $dir = isset($_GET['dir']) ? $_GET['dir'] : $postDir;
- if (strstr($dir, '..')) {
- $dir = '/';
- }
- if (isset($dir[0]) && $dir[0] == '.') {
- $dir = substr($dir, 1);
- }
- if (isset($dir[0]) && $dir[0] != '/') {
- $dir = '/'.$dir;
- }
- if (isset($dir[strlen($dir) - 1]) && $dir[strlen($dir) - 1] != '/') {
- $dir .= '/';
- }
- $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$dir;
- if (!is_dir($filepath)) {
- $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
- }
- $table_doc = Database::get_course_table(TABLE_DOCUMENT);
- if (isset($_POST['path']) && !empty($_POST['path'])) {
- $document_id = (int) $_POST['path'];
- $documentInfo = DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), false, null, true);
- if (empty($documentInfo)) {
- // Try with iid
- $table = Database::get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT id, path FROM $table
- WHERE c_id = $course_id AND iid = $document_id AND path NOT LIKE '%_DELETED_%' ";
- $res_doc = Database::query($sql);
- $row = Database::fetch_array($res_doc);
- if ($row) {
- $document_id = $row['id'];
- $documentPath = $row['path'];
- }
- } else {
- $documentPath = $documentInfo['path'];
- }
- $content = stripslashes($_POST['content_lp']);
- $file = $filepath.$documentPath;
- if (!file_exists($file)) {
- return false;
- }
- if ($fp = @fopen($file, 'w')) {
- $content = str_replace(
- api_get_path(WEB_COURSE_PATH),
- $urlAppend.api_get_path(REL_COURSE_PATH),
- $content
- );
- // Change the path of mp3 to absolute.
- // The first regexp deals with :// urls.
- $content = preg_replace(
- "|(flashvars=\"file=)([^:/]+)/|",
- "$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',
- $content
- );
- // The second regexp deals with audio/ urls.
- $content = preg_replace(
- "|(flashvars=\"file=)([^:/]+)/|",
- "$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',
- $content
- );
- fputs($fp, $content);
- fclose($fp);
- $sql = "UPDATE $table_doc SET
- title='".Database::escape_string($_POST['title'])."'
- WHERE c_id = $course_id AND id = ".$document_id;
- Database::query($sql);
- }
- }
- }
- /**
- * Displays the selected item, with a panel for manipulating the item.
- *
- * @param int $item_id
- * @param string $msg
- * @param bool $show_actions
- *
- * @return string
- */
- public function display_item($item_id, $msg = null, $show_actions = true)
- {
- $course_id = api_get_course_int_id();
- $return = '';
- if (is_numeric($item_id)) {
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT lp.* FROM $tbl_lp_item as lp
- WHERE lp.iid = ".intval($item_id);
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $_SESSION['parent_item_id'] = $row['item_type'] == 'dir' ? $item_id : 0;
- // Prevents wrong parent selection for document, see Bug#1251.
- if ($row['item_type'] != 'dir') {
- $_SESSION['parent_item_id'] = $row['parent_item_id'];
- }
- if ($show_actions) {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- }
- $return .= '<div style="padding:10px;">';
- if ($msg != '') {
- $return .= $msg;
- }
- $return .= '<h3>'.$row['title'].'</h3>';
- switch ($row['item_type']) {
- case TOOL_THREAD:
- $link = $this->rl_get_resource_link_for_learnpath(
- $course_id,
- $row['lp_id'],
- $item_id,
- 0
- );
- $return .= Display::url(
- get_lang('GoToThread'),
- $link,
- ['class' => 'btn btn-primary']
- );
- break;
- case TOOL_FORUM:
- $return .= Display::url(
- get_lang('GoToForum'),
- api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$row['path'],
- ['class' => 'btn btn-primary']
- );
- break;
- case TOOL_QUIZ:
- if (!empty($row['path'])) {
- $exercise = new Exercise();
- $exercise->read($row['path']);
- $return .= $exercise->description.'<br />';
- $return .= Display::url(
- get_lang('GoToExercise'),
- api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq().'&exerciseId='.$exercise->id,
- ['class' => 'btn btn-primary']
- );
- }
- break;
- case TOOL_LP_FINAL_ITEM:
- $return .= $this->getSavedFinalItem();
- break;
- case TOOL_DOCUMENT:
- case TOOL_READOUT_TEXT:
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT path FROM $tbl_doc
- WHERE c_id = $course_id AND iid = ".intval($row['path']);
- $result = Database::query($sql_doc);
- $path_file = Database::result($result, 0, 0);
- $path_parts = pathinfo($path_file);
- // TODO: Correct the following naive comparisons.
- if (in_array($path_parts['extension'], [
- 'html',
- 'txt',
- 'png',
- 'jpg',
- 'JPG',
- 'jpeg',
- 'JPEG',
- 'gif',
- 'swf',
- 'pdf',
- 'htm',
- ])) {
- $return .= $this->display_document($row['path'], true, true);
- }
- break;
- case TOOL_HOTPOTATOES:
- $return .= $this->display_document($row['path'], false, true);
- break;
- }
- $return .= '</div>';
- }
- }
- return $return;
- }
- /**
- * Shows the needed forms for editing a specific item.
- *
- * @param int $item_id
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string
- */
- public function display_edit_item($item_id)
- {
- $course_id = api_get_course_int_id();
- $return = '';
- $item_id = (int) $item_id;
- if (empty($item_id)) {
- return '';
- }
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE iid = ".$item_id;
- $res = Database::query($sql);
- $row = Database::fetch_array($res);
- switch ($row['item_type']) {
- case 'dir':
- case 'asset':
- case 'sco':
- if (isset($_GET['view']) && $_GET['view'] == 'build') {
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form(
- $row['item_type'],
- get_lang('EditCurrentChapter').' :',
- 'edit',
- $item_id,
- $row
- );
- } else {
- $return .= $this->display_item_form(
- $row['item_type'],
- get_lang('EditCurrentChapter').' :',
- 'edit_item',
- $item_id,
- $row
- );
- }
- break;
- case TOOL_DOCUMENT:
- case TOOL_READOUT_TEXT:
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT lp.*, doc.path as dir
- FROM $tbl_lp_item as lp
- LEFT JOIN $tbl_doc as doc
- ON (doc.iid = lp.path AND lp.c_id = doc.c_id)
- WHERE
- doc.c_id = $course_id AND
- lp.iid = ".$item_id;
- $res_step = Database::query($sql);
- $row_step = Database::fetch_array($res_step, 'ASSOC');
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- if ($row['item_type'] === TOOL_DOCUMENT) {
- $return .= $this->display_document_form('edit', $item_id, $row_step);
- }
- if ($row['item_type'] === TOOL_READOUT_TEXT) {
- $return .= $this->displayFrmReadOutText('edit', $item_id, $row_step);
- }
- break;
- case TOOL_LINK:
- $linkId = (int) $row['path'];
- if (!empty($linkId)) {
- $table = Database::get_course_table(TABLE_LINK);
- $sql = 'SELECT url FROM '.$table.'
- WHERE c_id = '.$course_id.' AND iid = '.$linkId;
- $res_link = Database::query($sql);
- $row_link = Database::fetch_array($res_link);
- if (empty($row_link)) {
- // Try with id
- $sql = 'SELECT url FROM '.$table.'
- WHERE c_id = '.$course_id.' AND id = '.$linkId;
- $res_link = Database::query($sql);
- $row_link = Database::fetch_array($res_link);
- }
- if (is_array($row_link)) {
- $row['url'] = $row_link['url'];
- }
- }
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('edit', $item_id, $row);
- break;
- case TOOL_LP_FINAL_ITEM:
- Session::write('finalItem', true);
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT lp.*, doc.path as dir
- FROM $tbl_lp_item as lp
- LEFT JOIN $tbl_doc as doc
- ON (doc.iid = lp.path AND lp.c_id = doc.c_id)
- WHERE
- doc.c_id = $course_id AND
- lp.iid = ".$item_id;
- $res_step = Database::query($sql);
- $row_step = Database::fetch_array($res_step, 'ASSOC');
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('edit', $item_id, $row_step);
- break;
- case TOOL_QUIZ:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('edit', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('edit', $item_id, $row);
- break;
- case TOOL_FORUM:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('edit', $item_id, $row);
- break;
- case TOOL_THREAD:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_thread_form('edit', $item_id, $row);
- break;
- }
- return $return;
- }
- /**
- * Function that displays a list with al the resources that
- * could be added to the learning path.
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return bool
- */
- public function display_resources()
- {
- $course_code = api_get_course_id();
- // Get all the docs.
- $documents = $this->get_documents(true);
- // Get all the exercises.
- $exercises = $this->get_exercises();
- // Get all the links.
- $links = $this->get_links();
- // Get all the student publications.
- $works = $this->get_student_publications();
- // Get all the forums.
- $forums = $this->get_forums(null, $course_code);
- // Get the final item form (see BT#11048) .
- $finish = $this->getFinalItemForm();
- $headers = [
- Display::return_icon('folder_document.png', get_lang('Documents'), [], ICON_SIZE_BIG),
- Display::return_icon('quiz.png', get_lang('Quiz'), [], ICON_SIZE_BIG),
- Display::return_icon('links.png', get_lang('Links'), [], ICON_SIZE_BIG),
- Display::return_icon('works.png', get_lang('Works'), [], ICON_SIZE_BIG),
- Display::return_icon('forum.png', get_lang('Forums'), [], ICON_SIZE_BIG),
- Display::return_icon('add_learnpath_section.png', get_lang('NewChapter'), [], ICON_SIZE_BIG),
- Display::return_icon('certificate.png', get_lang('Certificate'), [], ICON_SIZE_BIG),
- ];
- echo Display::return_message(get_lang('ClickOnTheLearnerViewToSeeYourLearningPath'), 'normal');
- $dir = $this->display_item_form('dir', get_lang('EnterDataNewChapter'), 'add_item');
- $selected = isset($_REQUEST['lp_build_selected']) ? (int) $_REQUEST['lp_build_selected'] : 0;
- echo Display::tabs(
- $headers,
- [
- $documents,
- $exercises,
- $links,
- $works,
- $forums,
- $dir,
- $finish,
- ],
- 'resource_tab',
- [],
- [],
- $selected
- );
- return true;
- }
- /**
- * Returns the extension of a document.
- *
- * @param string $filename
- *
- * @return string Extension (part after the last dot)
- */
- public function get_extension($filename)
- {
- $explode = explode('.', $filename);
- return $explode[count($explode) - 1];
- }
- /**
- * Displays a document by id.
- *
- * @param int $id
- * @param bool $show_title
- * @param bool $iframe
- * @param bool $edit_link
- *
- * @return string
- */
- public function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
- {
- $_course = api_get_course_info();
- $course_id = api_get_course_int_id();
- $id = (int) $id;
- $return = '';
- $table = Database::get_course_table(TABLE_DOCUMENT);
- $sql_doc = "SELECT * FROM $table
- WHERE c_id = $course_id AND iid = $id";
- $res_doc = Database::query($sql_doc);
- $row_doc = Database::fetch_array($res_doc);
- // TODO: Add a path filter.
- if ($iframe) {
- $return .= '<iframe id="learnpath_preview_frame" frameborder="0" height="400" width="100%" scrolling="auto" src="'.api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.str_replace('%2F', '/', urlencode($row_doc['path'])).'?'.api_get_cidreq().'"></iframe>';
- } else {
- $return .= file_get_contents(api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/'.$row_doc['path']);
- }
- return $return;
- }
- /**
- * Return HTML form to add/edit a quiz.
- *
- * @param string $action Action (add/edit)
- * @param int $id Item ID if already exists
- * @param mixed $extra_info Extra information (quiz ID if integer)
- *
- * @throws Exception
- *
- * @return string HTML form
- */
- public function display_quiz_form($action = 'add', $id = 0, $extra_info = '')
- {
- $course_id = api_get_course_int_id();
- $id = (int) $id;
- $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
- if ($id != 0 && is_array($extra_info)) {
- $item_title = $extra_info['title'];
- $item_description = $extra_info['description'];
- } elseif (is_numeric($extra_info)) {
- $sql = "SELECT title, description
- FROM $tbl_quiz
- WHERE c_id = $course_id AND iid = ".$extra_info;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- } else {
- $item_title = '';
- $item_description = '';
- }
- $item_title = Security::remove_XSS($item_title);
- $item_description = Security::remove_XSS($item_description);
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- $form = new FormValidator(
- 'quiz_form',
- 'POST',
- $this->getCurrentBuildingModeURL()
- );
- $defaults = [];
- if ($action === 'add') {
- $legend = get_lang('CreateTheExercise');
- } elseif ($action === 'move') {
- $legend = get_lang('MoveTheCurrentExercise');
- } else {
- $legend = get_lang('EditCurrentExecice');
- }
- if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
- $legend .= Display::return_message(get_lang('Warning').' ! '.get_lang('WarningEditingDocument'));
- }
- $form->addHeader($legend);
- if ($action != 'move') {
- $this->setItemTitle($form);
- $defaults['title'] = $item_title;
- }
- // Select for Parent item, root or chapter
- $selectParent = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- [],
- ['id' => 'idParent', 'onchange' => 'load_cbo(this.value);']
- );
- $selectParent->addOption($this->name, 0);
- $arrHide = [
- $id,
- ];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (
- ($arrLP[$i]['item_type'] == 'dir') &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- }
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $selectPrevious = $form->addSelect(
- 'previous',
- get_lang('Position'),
- [],
- ['id' => 'previous']
- );
- $selectPrevious->addOption(get_lang('FirstPosition'), 0);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent &&
- $arrLP[$i]['id'] != $id
- ) {
- $selectPrevious->addOption(
- get_lang('After').' "'.$arrLP[$i]['title'].'"',
- $arrLP[$i]['id']
- );
- if (is_array($extra_info)) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- }
- } elseif ($action == 'add') {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- }
- }
- }
- if ($action != 'move') {
- $arrHide = [];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- }
- if ($action === 'add') {
- $form->addButtonSave(get_lang('AddExercise'), 'submit_button');
- } else {
- $form->addButtonSave(get_lang('EditCurrentExecice'), 'submit_button');
- }
- if ($action === 'move') {
- $form->addHidden('title', $item_title);
- $form->addHidden('description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addHidden('path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addHidden('path', $extra_info['path']);
- }
- $form->addHidden('type', TOOL_QUIZ);
- $form->addHidden('post_time', time());
- $form->setDefaults($defaults);
- return '<div class="sectioncomment">'.$form->returnForm().'</div>';
- }
- /**
- * Addition of Hotpotatoes tests.
- *
- * @param string $action
- * @param int $id Internal ID of the item
- * @param string $extra_info
- *
- * @return string HTML structure to display the hotpotatoes addition formular
- */
- public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
- {
- $course_id = api_get_course_int_id();
- $uploadPath = DIR_HOTPOTATOES;
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- } elseif (is_numeric($extra_info)) {
- $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT * FROM $TBL_DOCUMENT
- WHERE
- c_id = $course_id AND
- path LIKE '".$uploadPath."/%/%htm%' AND
- iid = ".(int) $extra_info."
- ORDER BY iid ASC";
- $res_hot = Database::query($sql);
- $row = Database::fetch_array($res_hot);
- $item_title = $row['title'];
- $item_description = $row['description'];
- if (!empty($row['comment'])) {
- $item_title = $row['comment'];
- }
- } else {
- $item_title = '';
- $item_description = '';
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $legend = '<legend>';
- if ($action == 'add') {
- $legend .= get_lang('CreateTheExercise');
- } elseif ($action == 'move') {
- $legend .= get_lang('MoveTheCurrentExercise');
- } else {
- $legend .= get_lang('EditCurrentExecice');
- }
- if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
- $legend .= Display:: return_message(
- get_lang('Warning').' ! '.get_lang('WarningEditingDocument')
- );
- }
- $legend .= '</legend>';
- $return = '<form method="POST">';
- $return .= $legend;
- $return .= '<table cellpadding="0" cellspacing="0" class="lp_form">';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idParent">'.get_lang('Parent').' :</label></td>';
- $return .= '<td class="input">';
- $return .= '<select id="idParent" name="parent" onChange="javascript: load_cbo(this.value);" size="1">';
- $return .= '<option class="top" value="0">'.$this->name.'</option>';
- $arrHide = [$id];
- if (count($arrLP) > 0) {
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if ($arrLP[$i]['item_type'] == 'dir' &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $return .= '<option '.(($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '').'style="padding-left:'.($arrLP[$i]['depth'] * 10).'px;" value="'.$arrLP[$i]['id'].'">'.$arrLP[$i]['title'].'</option>';
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $return .= '<option '.(($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '').'style="padding-left:'.($arrLP[$i]['depth'] * 10).'px;" value="'.$arrLP[$i]['id'].'">'.$arrLP[$i]['title'].'</option>';
- }
- }
- }
- reset($arrLP);
- }
- $return .= '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- $return .= '<tr>';
- $return .= '<td class="label"><label for="previous">'.get_lang('Position').' :</label></td>';
- $return .= '<td class="input">';
- $return .= '<select id="previous" name="previous" size="1">';
- $return .= '<option class="top" value="0">'.get_lang('FirstPosition').'</option>';
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
- $selected = 'selected="selected" ';
- } elseif ($action == 'add') {
- $selected = 'selected="selected" ';
- } else {
- $selected = '';
- }
- $return .= '<option '.$selected.'value="'.$arrLP[$i]['id'].'">'.
- get_lang('After').' "'.$arrLP[$i]['title'].'"</option>';
- }
- }
- $return .= '</select>';
- $return .= '</td>';
- $return .= '</tr>';
- if ($action != 'move') {
- $return .= '<tr>';
- $return .= '<td class="label"><label for="idTitle">'.get_lang('Title').' :</label></td>';
- $return .= '<td class="input"><input id="idTitle" name="title" type="text" value="'.$item_title.'" /></td>';
- $return .= '</tr>';
- $id_prerequisite = 0;
- if (is_array($arrLP) && count($arrLP) > 0) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- $arrHide = [];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- }
- }
- $return .= '<tr>';
- $return .= '<td> </td><td><button class="save" name="submit_button" action="edit" type="submit">'.
- get_lang('SaveHotpotatoes').'</button></td>';
- $return .= '</tr>';
- $return .= '</table>';
- if ($action == 'move') {
- $return .= '<input name="title" type="hidden" value="'.$item_title.'" />';
- $return .= '<input name="description" type="hidden" value="'.$item_description.'" />';
- }
- if (is_numeric($extra_info)) {
- $return .= '<input name="path" type="hidden" value="'.$extra_info.'" />';
- } elseif (is_array($extra_info)) {
- $return .= '<input name="path" type="hidden" value="'.$extra_info['path'].'" />';
- }
- $return .= '<input name="type" type="hidden" value="'.TOOL_HOTPOTATOES.'" />';
- $return .= '<input name="post_time" type="hidden" value="'.time().'" />';
- $return .= '</form>';
- return $return;
- }
- /**
- * Return the form to display the forum edit/add option.
- *
- * @param string $action
- * @param int $id ID of the lp_item if already exists
- * @param string $extra_info
- *
- * @throws Exception
- *
- * @return string HTML form
- */
- public function display_forum_form($action = 'add', $id = 0, $extra_info = '')
- {
- $course_id = api_get_course_int_id();
- $tbl_forum = Database::get_course_table(TABLE_FORUM);
- $item_title = '';
- $item_description = '';
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- } elseif (is_numeric($extra_info)) {
- $sql = "SELECT forum_title as title, forum_comment as comment
- FROM $tbl_forum
- WHERE c_id = $course_id AND forum_id = ".$extra_info;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['comment'];
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- if ($action == 'add') {
- $legend = get_lang('CreateTheForum');
- } elseif ($action == 'move') {
- $legend = get_lang('MoveTheCurrentForum');
- } else {
- $legend = get_lang('EditCurrentForum');
- }
- $form = new FormValidator(
- 'forum_form',
- 'POST',
- $this->getCurrentBuildingModeURL()
- );
- $defaults = [];
- $form->addHeader($legend);
- if ($action != 'move') {
- $this->setItemTitle($form);
- $defaults['title'] = $item_title;
- }
- $selectParent = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- [],
- ['id' => 'idParent', 'onchange' => 'load_cbo(this.value);', 'class' => 'learnpath_item_form']
- );
- $selectParent->addOption($this->name, 0);
- $arrHide = [
- $id,
- ];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if ($arrLP[$i]['item_type'] == 'dir' &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- }
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $selectPrevious = $form->addSelect(
- 'previous',
- get_lang('Position'),
- [],
- ['id' => 'previous', 'class' => 'learnpath_item_form']
- );
- $selectPrevious->addOption(get_lang('FirstPosition'), 0);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent &&
- $arrLP[$i]['id'] != $id
- ) {
- $selectPrevious->addOption(
- get_lang('After').' "'.$arrLP[$i]['title'].'"',
- $arrLP[$i]['id']
- );
- if (isset($extra_info['previous_item_id']) &&
- $extra_info['previous_item_id'] == $arrLP[$i]['id']
- ) {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- } elseif ($action == 'add') {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- }
- }
- }
- if ($action != 'move') {
- $id_prerequisite = 0;
- if (is_array($arrLP)) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = [];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir') {
- if (isset($extra_info['previous_item_id']) &&
- $extra_info['previous_item_id'] == $arrLP[$i]['id']
- ) {
- $s_selected_position = $arrLP[$i]['id'];
- } elseif ($action == 'add') {
- $s_selected_position = 0;
- }
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- }
- if ($action == 'add') {
- $form->addButtonSave(get_lang('AddForumToCourse'), 'submit_button');
- } else {
- $form->addButtonSave(get_lang('EditCurrentForum'), 'submit_button');
- }
- if ($action == 'move') {
- $form->addHidden('title', $item_title);
- $form->addHidden('description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addHidden('path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addHidden('path', $extra_info['path']);
- }
- $form->addHidden('type', TOOL_FORUM);
- $form->addHidden('post_time', time());
- $form->setDefaults($defaults);
- return '<div class="sectioncomment">'.$form->returnForm().'</div>';
- }
- /**
- * Return HTML form to add/edit forum threads.
- *
- * @param string $action
- * @param int $id Item ID if already exists in learning path
- * @param string $extra_info
- *
- * @throws Exception
- *
- * @return string HTML form
- */
- public function display_thread_form($action = 'add', $id = 0, $extra_info = '')
- {
- $course_id = api_get_course_int_id();
- if (empty($course_id)) {
- return null;
- }
- $tbl_forum = Database::get_course_table(TABLE_FORUM_THREAD);
- $item_title = '';
- $item_description = '';
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- } elseif (is_numeric($extra_info)) {
- $sql = "SELECT thread_title as title FROM $tbl_forum
- WHERE c_id = $course_id AND thread_id = ".$extra_info;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $item_title = $row['title'];
- $item_description = '';
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- $form = new FormValidator(
- 'thread_form',
- 'POST',
- $this->getCurrentBuildingModeURL()
- );
- $defaults = [];
- if ($action == 'add') {
- $legend = get_lang('CreateTheForum');
- } elseif ($action == 'move') {
- $legend = get_lang('MoveTheCurrentForum');
- } else {
- $legend = get_lang('EditCurrentForum');
- }
- $form->addHeader($legend);
- $selectParent = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- [],
- ['id' => 'idParent', 'onchange' => 'load_cbo(this.value);']
- );
- $selectParent->addOption($this->name, 0);
- $arrHide = [
- $id,
- ];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (
- ($arrLP[$i]['item_type'] == 'dir') &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- }
- }
- }
- if ($arrLP != null) {
- reset($arrLP);
- }
- $selectPrevious = $form->addSelect(
- 'previous',
- get_lang('Position'),
- [],
- ['id' => 'previous']
- );
- $selectPrevious->addOption(get_lang('FirstPosition'), 0);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- $selectPrevious->addOption(
- get_lang('After').' "'.$arrLP[$i]['title'].'"',
- $arrLP[$i]['id']
- );
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- } elseif ($action == 'add') {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- }
- }
- }
- if ($action != 'move') {
- $this->setItemTitle($form);
- $defaults['title'] = $item_title;
- $id_prerequisite = 0;
- if ($arrLP != null) {
- foreach ($arrLP as $key => $value) {
- if ($value['id'] == $id) {
- $id_prerequisite = $value['prerequisite'];
- break;
- }
- }
- }
- $arrHide = [];
- $s_selected_position = 0;
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir') {
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
- $s_selected_position = $arrLP[$i]['id'];
- } elseif ($action == 'add') {
- $s_selected_position = 0;
- }
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- $selectPrerequisites = $form->addSelect(
- 'prerequisites',
- get_lang('LearnpathPrerequisites'),
- [],
- ['id' => 'prerequisites']
- );
- $selectPrerequisites->addOption(get_lang('NoPrerequisites'), 0);
- foreach ($arrHide as $key => $value) {
- $selectPrerequisites->addOption($value['value'], $key);
- if ($key == $s_selected_position && $action == 'add') {
- $selectPrerequisites->setSelected($key);
- } elseif ($key == $id_prerequisite && $action == 'edit') {
- $selectPrerequisites->setSelected($key);
- }
- }
- }
- $form->addButtonSave(get_lang('Ok'), 'submit_button');
- if ($action == 'move') {
- $form->addHidden('title', $item_title);
- $form->addHidden('description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addHidden('path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addHidden('path', $extra_info['path']);
- }
- $form->addHidden('type', TOOL_THREAD);
- $form->addHidden('post_time', time());
- $form->setDefaults($defaults);
- return $form->returnForm();
- }
- /**
- * Return the HTML form to display an item (generally a dir item).
- *
- * @param string $item_type
- * @param string $title
- * @param string $action
- * @param int $id
- * @param string $extra_info
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string HTML form
- */
- public function display_item_form(
- $item_type,
- $title = '',
- $action = 'add_item',
- $id = 0,
- $extra_info = 'new'
- ) {
- $_course = api_get_course_info();
- global $charset;
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $item_title = '';
- $item_description = '';
- $item_path_fck = '';
- if ($id != 0 && is_array($extra_info)) {
- $item_title = $extra_info['title'];
- $item_description = $extra_info['description'];
- $item_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
- $item_path_fck = '/scorm/'.$this->path.'/'.stripslashes($extra_info['path']);
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $id = (int) $id;
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE
- lp_id = ".$this->lp_id." AND
- iid != $id";
- if ($item_type == 'dir') {
- $sql .= " AND parent_item_id = 0";
- }
- $result = Database::query($sql);
- $arrLP = [];
- while ($row = Database::fetch_array($result)) {
- $arrLP[] = [
- 'id' => $row['iid'],
- 'item_type' => $row['item_type'],
- 'title' => $this->cleanItemTitle($row['title']),
- 'path' => $row['path'],
- 'description' => $row['description'],
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'display_order' => $row['display_order'],
- ];
- }
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- $url = api_get_self().'?'.api_get_cidreq().'&action='.$action.'&type='.$item_type.'&lp_id='.$this->lp_id;
- $form = new FormValidator('form_'.$item_type, 'POST', $url);
- $defaults['title'] = api_html_entity_decode(
- $item_title,
- ENT_QUOTES,
- $charset
- );
- $defaults['description'] = $item_description;
- $form->addHeader($title);
- $arrHide[0]['value'] = Security::remove_XSS($this->name);
- $arrHide[0]['padding'] = 20;
- $charset = api_get_system_encoding();
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if ($arrLP[$i]['item_type'] === 'dir' && !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- } else {
- if ($arrLP[$i]['item_type'] === 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
- if ($parent == $arrLP[$i]['id']) {
- $s_selected_parent = $arrHide[$arrLP[$i]['id']];
- }
- }
- }
- }
- if ($action != 'move') {
- $this->setItemTitle($form);
- } else {
- $form->addElement('hidden', 'title');
- }
- $parentSelect = $form->addElement(
- 'select',
- 'parent',
- get_lang('Parent'),
- '',
- [
- 'id' => 'idParent',
- 'onchange' => 'javascript: load_cbo(this.value);',
- ]
- );
- foreach ($arrHide as $key => $value) {
- $parentSelect->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$value['padding'].'px;"'
- );
- $lastPosition = $key;
- }
- if (!empty($s_selected_parent)) {
- $parentSelect->setSelected($s_selected_parent);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = [];
- // POSITION
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id &&
- $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) {
- //this is the same!
- if (isset($extra_info['previous_item_id']) &&
- $extra_info['previous_item_id'] == $arrLP[$i]['id']
- ) {
- $s_selected_position = $arrLP[$i]['id'];
- } elseif ($action == 'add') {
- $s_selected_position = $arrLP[$i]['id'];
- }
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After').' "'.$arrLP[$i]['title'].'"';
- }
- }
- $position = $form->addElement(
- 'select',
- 'previous',
- get_lang('Position'),
- '',
- ['id' => 'previous']
- );
- $padding = isset($value['padding']) ? $value['padding'] : 0;
- $position->addOption(get_lang('FirstPosition'), 0, 'style="padding-left:'.$padding.'px;"');
- $lastPosition = null;
- foreach ($arrHide as $key => $value) {
- $position->addOption($value['value'], $key, 'style="padding-left:'.$padding.'px;"');
- $lastPosition = $key;
- }
- if (!empty($s_selected_position)) {
- $position->setSelected($s_selected_position);
- }
- // When new chapter add at the end
- if ($action === 'add_item') {
- $position->setSelected($lastPosition);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $form->addButtonSave(get_lang('SaveSection'), 'submit_button');
- //fix in order to use the tab
- if ($item_type === 'dir') {
- $form->addElement('hidden', 'type', 'dir');
- }
- $extension = null;
- if (!empty($item_path)) {
- $extension = pathinfo($item_path, PATHINFO_EXTENSION);
- }
- //assets can't be modified
- //$item_type == 'asset' ||
- if (($item_type == 'sco') && ($extension == 'html' || $extension == 'htm')) {
- if ($item_type == 'sco') {
- $form->addElement(
- 'html',
- '<script>alert("'.get_lang('WarningWhenEditingScorm').'")</script>'
- );
- }
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate(
- '<br /> {label}<br />{element}',
- 'content_lp'
- );
- $relative_prefix = '';
- $editor_config = [
- 'ToolbarSet' => 'LearningPathDocuments',
- 'Width' => '100%',
- 'Height' => '500',
- 'FullPage' => true,
- 'CreateDocumentDir' => $relative_prefix,
- 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/scorm/',
- 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().$item_path_fck,
- ];
- $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
- $content_path = api_get_path(SYS_COURSE_PATH).api_get_course_path().$item_path_fck;
- $defaults['content_lp'] = file_get_contents($content_path);
- }
- if (!empty($id)) {
- $form->addHidden('id', $id);
- }
- $form->addElement('hidden', 'type', $item_type);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->returnForm();
- }
- /**
- * @return string
- */
- public function getCurrentBuildingModeURL()
- {
- $pathItem = isset($_GET['path_item']) ? (int) $_GET['path_item'] : '';
- $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : '';
- $id = isset($_GET['id']) ? (int) $_GET['id'] : '';
- $view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : '';
- $currentUrl = api_get_self().'?'.api_get_cidreq().
- '&action='.$action.'&lp_id='.$this->lp_id.'&path_item='.$pathItem.'&view='.$view.'&id='.$id;
- return $currentUrl;
- }
- /**
- * Returns the form to update or create a document.
- *
- * @param string $action (add/edit)
- * @param int $id ID of the lp_item (if already exists)
- * @param mixed $extra_info Integer if document ID, string if info ('new')
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string HTML form
- */
- public function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
- {
- $course_id = api_get_course_int_id();
- $_course = api_get_course_info();
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $no_display_edit_textarea = false;
- $item_description = '';
- //If action==edit document
- //We don't display the document form if it's not an editable document (html or txt file)
- if ($action === 'edit') {
- if (is_array($extra_info)) {
- $path_parts = pathinfo($extra_info['dir']);
- if ($path_parts['extension'] != 'txt' && $path_parts['extension'] != 'html') {
- $no_display_edit_textarea = true;
- }
- }
- }
- $no_display_add = false;
- // If action==add an existing document
- // We don't display the document form if it's not an editable document (html or txt file).
- if ($action === 'add') {
- if (is_numeric($extra_info)) {
- $extra_info = (int) $extra_info;
- $sql_doc = "SELECT path FROM $tbl_doc
- WHERE c_id = $course_id AND iid = ".$extra_info;
- $result = Database::query($sql_doc);
- $path_file = Database::result($result, 0, 0);
- $path_parts = pathinfo($path_file);
- if ($path_parts['extension'] != 'txt' && $path_parts['extension'] != 'html') {
- $no_display_add = true;
- }
- }
- }
- $item_title = '';
- $item_description = '';
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- if (empty($item_title)) {
- $path_parts = pathinfo($extra_info['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } elseif (is_numeric($extra_info)) {
- $sql = "SELECT path, title FROM $tbl_doc
- WHERE
- c_id = ".$course_id." AND
- iid = ".intval($extra_info);
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $item_title = $row['title'];
- $item_title = str_replace('_', ' ', $item_title);
- if (empty($item_title)) {
- $path_parts = pathinfo($row['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- }
- $return = '<legend>';
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- if ($action == 'add') {
- $return .= get_lang('CreateTheDocument');
- } elseif ($action == 'move') {
- $return .= get_lang('MoveTheCurrentDocument');
- } else {
- $return .= get_lang('EditTheCurrentDocument');
- }
- $return .= '</legend>';
- if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
- $return .= Display::return_message(
- '<strong>'.get_lang('Warning').' !</strong><br />'.get_lang('WarningEditingDocument'),
- false
- );
- }
- $form = new FormValidator(
- 'form',
- 'POST',
- $this->getCurrentBuildingModeURL(),
- '',
- ['enctype' => 'multipart/form-data']
- );
- $defaults['title'] = Security::remove_XSS($item_title);
- if (empty($item_title)) {
- $defaults['title'] = Security::remove_XSS($item_title);
- }
- $defaults['description'] = $item_description;
- $form->addElement('html', $return);
- if ($action != 'move') {
- $data = $this->generate_lp_folder($_course);
- if ($action != 'edit') {
- $folders = DocumentManager::get_all_document_folders(
- $_course,
- 0,
- true
- );
- DocumentManager::build_directory_selector(
- $folders,
- '',
- [],
- true,
- $form,
- 'directory_parent_id'
- );
- }
- if (isset($data['id'])) {
- $defaults['directory_parent_id'] = $data['id'];
- }
- $this->setItemTitle($form);
- }
- $arrHide[0]['value'] = $this->name;
- $arrHide[0]['padding'] = 20;
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if ($arrLP[$i]['item_type'] == 'dir' &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
- }
- }
- }
- $parentSelect = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- [],
- [
- 'id' => 'idParent',
- 'onchange' => 'javascript: load_cbo(this.value);',
- ]
- );
- $my_count = 0;
- foreach ($arrHide as $key => $value) {
- if ($my_count != 0) {
- // The LP name is also the first section and is not in the same charset like the other sections.
- $value['value'] = Security::remove_XSS($value['value']);
- $parentSelect->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$value['padding'].'px;"'
- );
- } else {
- $value['value'] = Security::remove_XSS($value['value']);
- $parentSelect->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$value['padding'].'px;"'
- );
- }
- $my_count++;
- }
- if (!empty($id)) {
- $parentSelect->setSelected($parent);
- } else {
- $parent_item_id = Session::read('parent_item_id', 0);
- $parentSelect->setSelected($parent_item_id);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = [];
- // POSITION
- for ($i = 0; $i < count($arrLP); $i++) {
- if (($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) ||
- $arrLP[$i]['item_type'] == TOOL_LP_FINAL_ITEM
- ) {
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After').' "'.$arrLP[$i]['title'].'"';
- }
- }
- $selectedPosition = isset($extra_info['previous_item_id']) ? $extra_info['previous_item_id'] : 0;
- $position = $form->addSelect(
- 'previous',
- get_lang('Position'),
- [],
- ['id' => 'previous']
- );
- $position->addOption(get_lang('FirstPosition'), 0);
- foreach ($arrHide as $key => $value) {
- $padding = isset($value['padding']) ? $value['padding'] : 20;
- $position->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$padding.'px;"'
- );
- }
- $position->setSelected($selectedPosition);
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- if ($action != 'move') {
- $arrHide = [];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir' &&
- $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM
- ) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- if (!$no_display_add) {
- $item_type = isset($extra_info['item_type']) ? $extra_info['item_type'] : null;
- $edit = isset($_GET['edit']) ? $_GET['edit'] : null;
- if ($extra_info == 'new' || $item_type == TOOL_DOCUMENT ||
- $item_type == TOOL_LP_FINAL_ITEM || $edit == 'true'
- ) {
- if (isset($_POST['content'])) {
- $content = stripslashes($_POST['content']);
- } elseif (is_array($extra_info)) {
- //If it's an html document or a text file
- if (!$no_display_edit_textarea) {
- $content = $this->display_document(
- $extra_info['path'],
- false,
- false
- );
- }
- } elseif (is_numeric($extra_info)) {
- $content = $this->display_document(
- $extra_info,
- false,
- false
- );
- } else {
- $content = '';
- }
- if (!$no_display_edit_textarea) {
- // We need to calculate here some specific settings for the online editor.
- // The calculated settings work for documents in the Documents tool
- // (on the root or in subfolders).
- // For documents in native scorm packages it is unclear whether the
- // online editor should be activated or not.
- // A new document, it is in the root of the repository.
- $relative_path = '';
- $relative_prefix = '';
- if (is_array($extra_info) && $extra_info != 'new') {
- // The document already exists. Whe have to determine its relative path towards the repository root.
- $relative_path = explode('/', $extra_info['dir']);
- $cnt = count($relative_path) - 2;
- if ($cnt < 0) {
- $cnt = 0;
- }
- $relative_prefix = str_repeat('../', $cnt);
- $relative_path = array_slice($relative_path, 1, $cnt);
- $relative_path = implode('/', $relative_path);
- if (strlen($relative_path) > 0) {
- $relative_path = $relative_path.'/';
- }
- } else {
- $result = $this->generate_lp_folder($_course);
- $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
- $relative_prefix = '../../';
- }
- $editor_config = [
- 'ToolbarSet' => 'LearningPathDocuments',
- 'Width' => '100%',
- 'Height' => '500',
- 'FullPage' => true,
- 'CreateDocumentDir' => $relative_prefix,
- 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
- 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/'.$relative_path,
- ];
- if ($_GET['action'] == 'add_item') {
- $class = 'add';
- $text = get_lang('LPCreateDocument');
- } else {
- if ($_GET['action'] == 'edit_item') {
- $class = 'save';
- $text = get_lang('SaveDocument');
- }
- }
- $form->addButtonSave($text, 'submit_button');
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate(' {label}{element}', 'content_lp');
- $form->addElement('html', '<div class="editor-lp">');
- $form->addHtmlEditor('content_lp', null, null, true, $editor_config, true);
- $form->addElement('html', '</div>');
- $defaults['content_lp'] = $content;
- }
- } elseif (is_numeric($extra_info)) {
- $form->addButtonSave(get_lang('SaveDocument'), 'submit_button');
- $return = $this->display_document($extra_info, true, true, true);
- $form->addElement('html', $return);
- }
- }
- }
- if (isset($extra_info['item_type']) &&
- $extra_info['item_type'] == TOOL_LP_FINAL_ITEM
- ) {
- $parentSelect->freeze();
- $position->freeze();
- }
- if ($action == 'move') {
- $form->addElement('hidden', 'title', $item_title);
- $form->addElement('hidden', 'description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addButtonSave(get_lang('SaveDocument'), 'submit_button');
- $form->addElement('hidden', 'path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addButtonSave(get_lang('SaveDocument'), 'submit_button');
- $form->addElement('hidden', 'path', $extra_info['path']);
- }
- $form->addElement('hidden', 'type', TOOL_DOCUMENT);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->returnForm();
- }
- /**
- * Returns the form to update or create a read-out text.
- *
- * @param string $action "add" or "edit"
- * @param int $id ID of the lp_item (if already exists)
- * @param mixed $extra_info Integer if document ID, string if info ('new')
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string HTML form
- */
- public function displayFrmReadOutText($action = 'add', $id = 0, $extra_info = 'new')
- {
- $course_id = api_get_course_int_id();
- $_course = api_get_course_info();
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $no_display_edit_textarea = false;
- $item_description = '';
- //If action==edit document
- //We don't display the document form if it's not an editable document (html or txt file)
- if ($action == 'edit') {
- if (is_array($extra_info)) {
- $path_parts = pathinfo($extra_info['dir']);
- if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
- $no_display_edit_textarea = true;
- }
- }
- }
- $no_display_add = false;
- $item_title = '';
- $item_description = '';
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_terms = stripslashes($extra_info['terms']);
- if (empty($item_title)) {
- $path_parts = pathinfo($extra_info['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- } elseif (is_numeric($extra_info)) {
- $sql = "SELECT path, title FROM $tbl_doc WHERE c_id = ".$course_id." AND iid = ".intval($extra_info);
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $item_title = $row['title'];
- $item_title = str_replace('_', ' ', $item_title);
- if (empty($item_title)) {
- $path_parts = pathinfo($row['path']);
- $item_title = stripslashes($path_parts['filename']);
- }
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- if ($action === 'add') {
- $formHeader = get_lang('CreateTheDocument');
- } else {
- $formHeader = get_lang('EditTheCurrentDocument');
- }
- if ('edit' === $action) {
- $urlAudioIcon = Display::url(
- Display::return_icon('audio.png', get_lang('CreateReadOutText'), [], ICON_SIZE_TINY),
- api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&lp_id='.$this->lp_id.'&'
- .http_build_query(['view' => 'build', 'id' => $id, 'action' => 'add_audio'])
- );
- } else {
- $urlAudioIcon = Display::return_icon('audio.png', get_lang('CreateReadOutText'), [], ICON_SIZE_TINY);
- }
- $form = new FormValidator(
- 'frm_add_reading',
- 'POST',
- $this->getCurrentBuildingModeURL(),
- '',
- ['enctype' => 'multipart/form-data']
- );
- $form->addHeader($formHeader);
- $form->addHtml(
- Display::return_message(
- sprintf(get_lang('FrmReadOutTextIntro'), $urlAudioIcon),
- 'normal',
- false
- )
- );
- $defaults['title'] = !empty($item_title) ? Security::remove_XSS($item_title) : '';
- $defaults['description'] = $item_description;
- $data = $this->generate_lp_folder($_course);
- if ($action != 'edit') {
- $folders = DocumentManager::get_all_document_folders($_course, 0, true);
- DocumentManager::build_directory_selector(
- $folders,
- '',
- [],
- true,
- $form,
- 'directory_parent_id'
- );
- }
- if (isset($data['id'])) {
- $defaults['directory_parent_id'] = $data['id'];
- }
- $this->setItemTitle($form);
- $arrHide[0]['value'] = $this->name;
- $arrHide[0]['padding'] = 20;
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if ($arrLP[$i]['item_type'] == 'dir' &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- $arrHide[$arrLP[$i]['id']]['padding'] = 20 + $arrLP[$i]['depth'] * 20;
- }
- }
- }
- $parent_select = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- [],
- ['onchange' => "javascript: load_cbo(this.value, 'frm_add_reading_previous');"]
- );
- $my_count = 0;
- foreach ($arrHide as $key => $value) {
- if ($my_count != 0) {
- // The LP name is also the first section and is not in the same charset like the other sections.
- $value['value'] = Security::remove_XSS($value['value']);
- $parent_select->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$value['padding'].'px;"'
- );
- } else {
- $value['value'] = Security::remove_XSS($value['value']);
- $parent_select->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$value['padding'].'px;"'
- );
- }
- $my_count++;
- }
- if (!empty($id)) {
- $parent_select->setSelected($parent);
- } else {
- $parent_item_id = Session::read('parent_item_id', 0);
- $parent_select->setSelected($parent_item_id);
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = [];
- $s_selected_position = null;
- // POSITION
- $lastPosition = null;
- for ($i = 0; $i < count($arrLP); $i++) {
- if (($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) &&
- $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM
- ) {
- if ((isset($extra_info['previous_item_id']) &&
- $extra_info['previous_item_id'] == $arrLP[$i]['id']) || $action == 'add'
- ) {
- $s_selected_position = $arrLP[$i]['id'];
- }
- $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After').' "'.$arrLP[$i]['title'].'"';
- }
- $lastPosition = $arrLP[$i]['id'];
- }
- if (empty($s_selected_position)) {
- $s_selected_position = $lastPosition;
- }
- $position = $form->addSelect(
- 'previous',
- get_lang('Position'),
- []
- );
- $position->addOption(get_lang('FirstPosition'), 0);
- foreach ($arrHide as $key => $value) {
- $padding = isset($value['padding']) ? $value['padding'] : 20;
- $position->addOption(
- $value['value'],
- $key,
- 'style="padding-left:'.$padding.'px;"'
- );
- }
- $position->setSelected($s_selected_position);
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $arrHide = [];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir' &&
- $arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM
- ) {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- if (!$no_display_add) {
- $item_type = isset($extra_info['item_type']) ? $extra_info['item_type'] : null;
- $edit = isset($_GET['edit']) ? $_GET['edit'] : null;
- if ($extra_info == 'new' || $item_type == TOOL_READOUT_TEXT || $edit == 'true') {
- if (!$no_display_edit_textarea) {
- $content = '';
- if (isset($_POST['content'])) {
- $content = stripslashes($_POST['content']);
- } elseif (is_array($extra_info)) {
- $content = $this->display_document($extra_info['path'], false, false);
- } elseif (is_numeric($extra_info)) {
- $content = $this->display_document($extra_info, false, false);
- }
- // A new document, it is in the root of the repository.
- if (is_array($extra_info) && $extra_info != 'new') {
- } else {
- $this->generate_lp_folder($_course);
- }
- if ($_GET['action'] == 'add_item') {
- $text = get_lang('LPCreateDocument');
- } else {
- $text = get_lang('SaveDocument');
- }
- $form->addTextarea('content_lp', get_lang('Content'), ['rows' => 20]);
- $form
- ->defaultRenderer()
- ->setElementTemplate($form->getDefaultElementTemplate(), 'content_lp');
- $form->addButtonSave($text, 'submit_button');
- $defaults['content_lp'] = $content;
- }
- } elseif (is_numeric($extra_info)) {
- $form->addButtonSave(get_lang('SaveDocument'), 'submit_button');
- $return = $this->display_document($extra_info, true, true, true);
- $form->addElement('html', $return);
- }
- }
- if (is_numeric($extra_info)) {
- $form->addElement('hidden', 'path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addElement('hidden', 'path', $extra_info['path']);
- }
- $form->addElement('hidden', 'type', TOOL_READOUT_TEXT);
- $form->addElement('hidden', 'post_time', time());
- $form->setDefaults($defaults);
- return $form->returnForm();
- }
- /**
- * @param array $courseInfo
- * @param string $content
- * @param string $title
- * @param int $parentId
- *
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- *
- * @return int
- */
- public function createReadOutText($courseInfo, $content = '', $title = '', $parentId = 0)
- {
- $creatorId = api_get_user_id();
- $sessionId = api_get_session_id();
- // Generates folder
- $result = $this->generate_lp_folder($courseInfo);
- $dir = $result['dir'];
- if (empty($parentId) || $parentId == '/') {
- $postDir = isset($_POST['dir']) ? $_POST['dir'] : $dir;
- $dir = isset($_GET['dir']) ? $_GET['dir'] : $postDir; // Please, do not modify this dirname formatting.
- if ($parentId === '/') {
- $dir = '/';
- }
- // Please, do not modify this dirname formatting.
- if (strstr($dir, '..')) {
- $dir = '/';
- }
- if (!empty($dir[0]) && $dir[0] == '.') {
- $dir = substr($dir, 1);
- }
- if (!empty($dir[0]) && $dir[0] != '/') {
- $dir = '/'.$dir;
- }
- if (isset($dir[strlen($dir) - 1]) && $dir[strlen($dir) - 1] != '/') {
- $dir .= '/';
- }
- } else {
- $parentInfo = DocumentManager::get_document_data_by_id(
- $parentId,
- $courseInfo['code']
- );
- if (!empty($parentInfo)) {
- $dir = $parentInfo['path'].'/';
- }
- }
- $filepath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$dir;
- if (!is_dir($filepath)) {
- $dir = '/';
- $filepath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$dir;
- }
- $originalTitle = !empty($title) ? $title : $_POST['title'];
- if (!empty($title)) {
- $title = api_replace_dangerous_char(stripslashes($title));
- } else {
- $title = api_replace_dangerous_char(stripslashes($_POST['title']));
- }
- $title = disable_dangerous_file($title);
- $filename = $title;
- $content = !empty($content) ? $content : $_POST['content_lp'];
- $tmpFileName = $filename;
- $i = 0;
- while (file_exists($filepath.$tmpFileName.'.html')) {
- $tmpFileName = $filename.'_'.++$i;
- }
- $filename = $tmpFileName.'.html';
- $content = stripslashes($content);
- if (file_exists($filepath.$filename)) {
- return 0;
- }
- $putContent = file_put_contents($filepath.$filename, $content);
- if ($putContent === false) {
- return 0;
- }
- $fileSize = filesize($filepath.$filename);
- $saveFilePath = $dir.$filename;
- $documentId = add_document(
- $courseInfo,
- $saveFilePath,
- 'file',
- $fileSize,
- $tmpFileName,
- '',
- 0, //readonly
- true,
- null,
- $sessionId,
- $creatorId
- );
- if (!$documentId) {
- return 0;
- }
- api_item_property_update(
- $courseInfo,
- TOOL_DOCUMENT,
- $documentId,
- 'DocumentAdded',
- $creatorId,
- null,
- null,
- null,
- null,
- $sessionId
- );
- $newComment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
- $newTitle = $originalTitle;
- if ($newComment || $newTitle) {
- $em = Database::getManager();
- /** @var CDocument $doc */
- $doc = $em->find('ChamiloCourseBundle:CDocument', $documentId);
- if ($newComment) {
- $doc->setComment($newComment);
- }
- if ($newTitle) {
- $doc->setTitle($newTitle);
- }
- $em->persist($doc);
- $em->flush();
- }
- return $documentId;
- }
- /**
- * Return HTML form to add/edit a link item.
- *
- * @param string $action (add/edit)
- * @param int $id Item ID if exists
- * @param mixed $extra_info
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string HTML form
- */
- public function display_link_form($action = 'add', $id = 0, $extra_info = '')
- {
- $course_id = api_get_course_int_id();
- $tbl_link = Database::get_course_table(TABLE_LINK);
- $item_title = '';
- $item_description = '';
- $item_url = '';
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- $item_url = stripslashes($extra_info['url']);
- } elseif (is_numeric($extra_info)) {
- $extra_info = (int) $extra_info;
- $sql = "SELECT title, description, url
- FROM $tbl_link
- WHERE c_id = $course_id AND iid = $extra_info";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $item_title = $row['title'];
- $item_description = $row['description'];
- $item_url = $row['url'];
- }
- $form = new FormValidator(
- 'edit_link',
- 'POST',
- $this->getCurrentBuildingModeURL()
- );
- $defaults = [];
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- if ($action == 'add') {
- $legend = get_lang('CreateTheLink');
- } elseif ($action == 'move') {
- $legend = get_lang('MoveCurrentLink');
- } else {
- $legend = get_lang('EditCurrentLink');
- }
- $form->addHeader($legend);
- if ($action != 'move') {
- $this->setItemTitle($form);
- $defaults['title'] = $item_title;
- }
- $selectParent = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- [],
- ['id' => 'idParent', 'onchange' => 'load_cbo(this.value);', 'class' => 'learnpath_item_form']
- );
- $selectParent->addOption($this->name, 0);
- $arrHide = [
- $id,
- ];
- $parent_item_id = Session::read('parent_item_id', 0);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (
- ($arrLP[$i]['item_type'] == 'dir') &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px;']
- );
- if ($parent == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $selectParent->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(20 + $arrLP[$i]['depth'] * 20).'px']
- );
- if ($parent_item_id == $arrLP[$i]['id']) {
- $selectParent->setSelected($arrLP[$i]['id']);
- }
- }
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $selectPrevious = $form->addSelect(
- 'previous',
- get_lang('Position'),
- [],
- ['id' => 'previous', 'class' => 'learnpath_item_form']
- );
- $selectPrevious->addOption(get_lang('FirstPosition'), 0);
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- $selectPrevious->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id']
- );
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- } elseif ($action == 'add') {
- $selectPrevious->setSelected($arrLP[$i]['id']);
- }
- }
- }
- if ($action != 'move') {
- $urlAttributes = ['class' => 'learnpath_item_form'];
- if (is_numeric($extra_info)) {
- $urlAttributes['disabled'] = 'disabled';
- }
- $form->addElement('url', 'url', get_lang('Url'), $urlAttributes);
- $defaults['url'] = $item_url;
- $arrHide = [];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dir') {
- $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
- }
- }
- }
- if ($action == 'add') {
- $form->addButtonSave(get_lang('AddLinkToCourse'), 'submit_button');
- } else {
- $form->addButtonSave(get_lang('EditCurrentLink'), 'submit_button');
- }
- if ($action == 'move') {
- $form->addHidden('title', $item_title);
- $form->addHidden('description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addHidden('path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addHidden('path', $extra_info['path']);
- }
- $form->addHidden('type', TOOL_LINK);
- $form->addHidden('post_time', time());
- $form->setDefaults($defaults);
- return '<div class="sectioncomment">'.$form->returnForm().'</div>';
- }
- /**
- * Return HTML form to add/edit a student publication (work).
- *
- * @param string $action
- * @param int $id Item ID if already exists
- * @param string $extra_info
- *
- * @throws Exception
- *
- * @return string HTML form
- */
- public function display_student_publication_form(
- $action = 'add',
- $id = 0,
- $extra_info = ''
- ) {
- $course_id = api_get_course_int_id();
- $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
- $item_title = get_lang('Student_publication');
- if ($id != 0 && is_array($extra_info)) {
- $item_title = stripslashes($extra_info['title']);
- $item_description = stripslashes($extra_info['description']);
- } elseif (is_numeric($extra_info)) {
- $extra_info = (int) $extra_info;
- $sql = "SELECT title, description
- FROM $tbl_publication
- WHERE c_id = $course_id AND id = ".$extra_info;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if ($row) {
- $item_title = $row['title'];
- }
- }
- $parent = 0;
- if ($id != 0 && is_array($extra_info)) {
- $parent = $extra_info['parent_item_id'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- $form = new FormValidator('frm_student_publication', 'post', '#');
- if ($action == 'add') {
- $form->addHeader(get_lang('Student_publication'));
- } elseif ($action == 'move') {
- $form->addHeader(get_lang('MoveCurrentStudentPublication'));
- } else {
- $form->addHeader(get_lang('EditCurrentStudentPublication'));
- }
- if ($action != 'move') {
- $this->setItemTitle($form);
- }
- $parentSelect = $form->addSelect(
- 'parent',
- get_lang('Parent'),
- ['0' => $this->name],
- [
- 'onchange' => 'javascript: load_cbo(this.value);',
- 'class' => 'learnpath_item_form',
- 'id' => 'idParent',
- ]
- );
- $arrHide = [$id];
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($action != 'add') {
- if (
- ($arrLP[$i]['item_type'] == 'dir') &&
- !in_array($arrLP[$i]['id'], $arrHide) &&
- !in_array($arrLP[$i]['parent_item_id'], $arrHide)
- ) {
- $parentSelect->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(($arrLP[$i]['depth'] * 10) + 20).'px;']
- );
- if ($parent == $arrLP[$i]['id']) {
- $parentSelect->setSelected($arrLP[$i]['id']);
- }
- } else {
- $arrHide[] = $arrLP[$i]['id'];
- }
- } else {
- if ($arrLP[$i]['item_type'] == 'dir') {
- $parentSelect->addOption(
- $arrLP[$i]['title'],
- $arrLP[$i]['id'],
- ['style' => 'padding-left: '.(($arrLP[$i]['depth'] * 10) + 20).'px;']
- );
- if ($parent == $arrLP[$i]['id']) {
- $parentSelect->setSelected($arrLP[$i]['id']);
- }
- }
- }
- }
- if (is_array($arrLP)) {
- reset($arrLP);
- }
- $previousSelect = $form->addSelect(
- 'previous',
- get_lang('Position'),
- ['0' => get_lang('FirstPosition')],
- ['id' => 'previous', 'class' => 'learnpath_item_form']
- );
- for ($i = 0; $i < count($arrLP); $i++) {
- if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
- $previousSelect->addOption(
- get_lang('After').' "'.$arrLP[$i]['title'].'"',
- $arrLP[$i]['id']
- );
- if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
- $previousSelect->setSelected($arrLP[$i]['id']);
- } elseif ($action == 'add') {
- $previousSelect->setSelected($arrLP[$i]['id']);
- }
- }
- }
- if ($action == 'add') {
- $form->addButtonCreate(get_lang('AddAssignmentToCourse'), 'submit_button');
- } else {
- $form->addButtonCreate(get_lang('EditCurrentStudentPublication'), 'submit_button');
- }
- if ($action == 'move') {
- $form->addHidden('title', $item_title);
- $form->addHidden('description', $item_description);
- }
- if (is_numeric($extra_info)) {
- $form->addHidden('path', $extra_info);
- } elseif (is_array($extra_info)) {
- $form->addHidden('path', $extra_info['path']);
- }
- $form->addHidden('type', TOOL_STUDENTPUBLICATION);
- $form->addHidden('post_time', time());
- $form->setDefaults(['title' => $item_title]);
- $return = '<div class="sectioncomment">';
- $return .= $form->returnForm();
- $return .= '</div>';
- return $return;
- }
- /**
- * Displays the menu for manipulating a step.
- *
- * @param id $item_id
- * @param string $item_type
- *
- * @return string
- */
- public function display_manipulate($item_id, $item_type = TOOL_DOCUMENT)
- {
- $_course = api_get_course_info();
- $course_code = api_get_course_id();
- $item_id = (int) $item_id;
- $return = '<div class="actions">';
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE iid = ".$item_id;
- $result = Database::query($sql);
- $row = Database::fetch_assoc($result);
- $audio_player = null;
- // We display an audio player if needed.
- if (!empty($row['audio'])) {
- $webAudioPath = '../..'.api_get_path(REL_COURSE_PATH).$_course['path'].'/document/audio/'.$row['audio'];
- $audio_player .= '<div class="lp_mediaplayer" id="container">'
- .'<audio src="'.$webAudioPath.'" controls>'
- .'</div><br>';
- }
- $url = api_get_self().'?'.api_get_cidreq().'&view=build&id='.$item_id.'&lp_id='.$this->lp_id;
- if ($item_type != TOOL_LP_FINAL_ITEM) {
- $return .= Display::url(
- Display::return_icon(
- 'edit.png',
- get_lang('Edit'),
- [],
- ICON_SIZE_SMALL
- ),
- $url.'&action=edit_item&path_item='.$row['path']
- );
- $return .= Display::url(
- Display::return_icon(
- 'move.png',
- get_lang('Move'),
- [],
- ICON_SIZE_SMALL
- ),
- $url.'&action=move_item'
- );
- }
- // Commented for now as prerequisites cannot be added to chapters.
- if ($item_type != 'dir') {
- $return .= Display::url(
- Display::return_icon(
- 'accept.png',
- get_lang('LearnpathPrerequisites'),
- [],
- ICON_SIZE_SMALL
- ),
- $url.'&action=edit_item_prereq'
- );
- }
- $return .= Display::url(
- Display::return_icon(
- 'delete.png',
- get_lang('Delete'),
- [],
- ICON_SIZE_SMALL
- ),
- $url.'&action=delete_item'
- );
- if (in_array($item_type, [TOOL_DOCUMENT, TOOL_LP_FINAL_ITEM, TOOL_HOTPOTATOES])) {
- $documentData = DocumentManager::get_document_data_by_id($row['path'], $course_code);
- if (empty($documentData)) {
- // Try with iid
- $table = Database::get_course_table(TABLE_DOCUMENT);
- $sql = "SELECT path FROM $table
- WHERE
- c_id = ".api_get_course_int_id()." AND
- iid = ".$row['path']." AND
- path NOT LIKE '%_DELETED_%'";
- $result = Database::query($sql);
- $documentData = Database::fetch_array($result);
- if ($documentData) {
- $documentData['absolute_path_from_document'] = '/document'.$documentData['path'];
- }
- }
- if (isset($documentData['absolute_path_from_document'])) {
- $return .= get_lang('File').': '.$documentData['absolute_path_from_document'];
- }
- }
- $return .= '</div>';
- if (!empty($audio_player)) {
- $return .= $audio_player;
- }
- return $return;
- }
- /**
- * Creates the javascript needed for filling up the checkboxes without page reload.
- *
- * @return string
- */
- public function get_js_dropdown_array()
- {
- $course_id = api_get_course_int_id();
- $return = 'var child_name = new Array();'."\n";
- $return .= 'var child_value = new Array();'."\n\n";
- $return .= 'child_name[0] = new Array();'."\n";
- $return .= 'child_value[0] = new Array();'."\n\n";
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM ".$tbl_lp_item."
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->lp_id." AND
- parent_item_id = 0
- ORDER BY display_order ASC";
- $res_zero = Database::query($sql);
- $i = 0;
- $list = $this->getItemsForForm(true);
- foreach ($list as $row_zero) {
- if ($row_zero['item_type'] !== TOOL_LP_FINAL_ITEM) {
- if ($row_zero['item_type'] == TOOL_QUIZ) {
- $row_zero['title'] = Exercise::get_formated_title_variable($row_zero['title']);
- }
- $js_var = json_encode(get_lang('After').' '.$row_zero['title']);
- $return .= 'child_name[0]['.$i.'] = '.$js_var.' ;'."\n";
- $return .= 'child_value[0]['.$i++.'] = "'.$row_zero['iid'].'";'."\n";
- }
- }
- $return .= "\n";
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
- $res = Database::query($sql);
- while ($row = Database::fetch_array($res)) {
- $sql_parent = "SELECT * FROM ".$tbl_lp_item."
- WHERE
- c_id = ".$course_id." AND
- parent_item_id = ".$row['iid']."
- ORDER BY display_order ASC";
- $res_parent = Database::query($sql_parent);
- $i = 0;
- $return .= 'child_name['.$row['iid'].'] = new Array();'."\n";
- $return .= 'child_value['.$row['iid'].'] = new Array();'."\n\n";
- while ($row_parent = Database::fetch_array($res_parent)) {
- $js_var = json_encode(get_lang('After').' '.$this->cleanItemTitle($row_parent['title']));
- $return .= 'child_name['.$row['iid'].']['.$i.'] = '.$js_var.' ;'."\n";
- $return .= 'child_value['.$row['iid'].']['.$i++.'] = "'.$row_parent['iid'].'";'."\n";
- }
- $return .= "\n";
- }
- $return .= "
- function load_cbo(id) {
- if (!id) {
- return false;
- }
-
- var cbo = document.getElementById('previous');
- for(var i = cbo.length - 1; i > 0; i--) {
- cbo.options[i] = null;
- }
-
- var k=0;
- for(var i = 1; i <= child_name[id].length; i++){
- var option = new Option(child_name[id][i - 1], child_value[id][i - 1]);
- option.style.paddingLeft = '40px';
- cbo.options[i] = option;
- k = i;
- }
-
- cbo.options[k].selected = true;
- $('#previous').selectpicker('refresh');
- }";
- return $return;
- }
- /**
- * Display the form to allow moving an item.
- *
- * @param int $item_id Item ID
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string HTML form
- */
- public function display_move_item($item_id)
- {
- $return = '';
- if (is_numeric($item_id)) {
- $item_id = (int) $item_id;
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE iid = $item_id";
- $res = Database::query($sql);
- $row = Database::fetch_array($res);
- switch ($row['item_type']) {
- case 'dir':
- case 'asset':
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_item_form(
- $row['item_type'],
- get_lang('MoveCurrentChapter'),
- 'move',
- $item_id,
- $row
- );
- break;
- case TOOL_DOCUMENT:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_document_form('move', $item_id, $row);
- break;
- case TOOL_LINK:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_HOTPOTATOES:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_link_form('move', $item_id, $row);
- break;
- case TOOL_QUIZ:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_quiz_form('move', $item_id, $row);
- break;
- case TOOL_STUDENTPUBLICATION:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_student_publication_form('move', $item_id, $row);
- break;
- case TOOL_FORUM:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- break;
- case TOOL_THREAD:
- $return .= $this->display_manipulate($item_id, $row['item_type']);
- $return .= $this->display_forum_form('move', $item_id, $row);
- break;
- }
- }
- return $return;
- }
- /**
- * Return HTML form to allow prerequisites selection.
- *
- * @todo use FormValidator
- *
- * @param int Item ID
- *
- * @return string HTML form
- */
- public function display_item_prerequisites_form($item_id = 0)
- {
- $course_id = api_get_course_int_id();
- $item_id = (int) $item_id;
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- /* Current prerequisite */
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE iid = $item_id";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $prerequisiteId = $row['prerequisite'];
- $return = '<legend>';
- $return .= get_lang('AddEditPrerequisites');
- $return .= '</legend>';
- $return .= '<form method="POST">';
- $return .= '<div class="table-responsive">';
- $return .= '<table class="table table-hover">';
- $return .= '<thead>';
- $return .= '<tr>';
- $return .= '<th>'.get_lang('LearnpathPrerequisites').'</th>';
- $return .= '<th width="140">'.get_lang('Minimum').'</th>';
- $return .= '<th width="140">'.get_lang('Maximum').'</th>';
- $return .= '</tr>';
- $return .= '</thead>';
- // Adding the none option to the prerequisites see http://www.chamilo.org/es/node/146
- $return .= '<tbody>';
- $return .= '<tr>';
- $return .= '<td colspan="3">';
- $return .= '<div class="radio learnpath"><label for="idNone">';
- $return .= '<input checked="checked" id="idNone" name="prerequisites" type="radio" />';
- $return .= get_lang('None').'</label>';
- $return .= '</div>';
- $return .= '</tr>';
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
- $result = Database::query($sql);
- $selectedMinScore = [];
- $selectedMaxScore = [];
- $masteryScore = [];
- while ($row = Database::fetch_array($result)) {
- if ($row['iid'] == $item_id) {
- $selectedMinScore[$row['prerequisite']] = $row['prerequisite_min_score'];
- $selectedMaxScore[$row['prerequisite']] = $row['prerequisite_max_score'];
- }
- $masteryScore[$row['iid']] = $row['mastery_score'];
- }
- $arrLP = $this->getItemsForForm();
- $this->tree_array($arrLP);
- $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
- unset($this->arrMenu);
- for ($i = 0; $i < count($arrLP); $i++) {
- $item = $arrLP[$i];
- if ($item['id'] == $item_id) {
- break;
- }
- $selectedMaxScoreValue = isset($selectedMaxScore[$item['id']]) ? $selectedMaxScore[$item['id']] : $item['max_score'];
- $selectedMinScoreValue = isset($selectedMinScore[$item['id']]) ? $selectedMinScore[$item['id']] : 0;
- $masteryScoreAsMinValue = isset($masteryScore[$item['id']]) ? $masteryScore[$item['id']] : 0;
- $return .= '<tr>';
- $return .= '<td '.(($item['item_type'] != TOOL_QUIZ && $item['item_type'] != TOOL_HOTPOTATOES) ? ' colspan="3"' : '').'>';
- $return .= '<div style="margin-left:'.($item['depth'] * 20).'px;" class="radio learnpath">';
- $return .= '<label for="id'.$item['id'].'">';
- $return .= '<input'.(in_array($prerequisiteId, [$item['id'], $item['ref']]) ? ' checked="checked" ' : '').($item['item_type'] == 'dir' ? ' disabled="disabled" ' : ' ').'id="id'.$item['id'].'" name="prerequisites" type="radio" value="'.$item['id'].'" />';
- $icon_name = str_replace(' ', '', $item['item_type']);
- if (file_exists('../img/lp_'.$icon_name.'.png')) {
- $return .= Display::return_icon('lp_'.$icon_name.'.png');
- } else {
- if (file_exists('../img/lp_'.$icon_name.'.png')) {
- $return .= Display::return_icon('lp_'.$icon_name.'.png');
- } else {
- $return .= Display::return_icon('folder_document.png');
- }
- }
- $return .= $item['title'].'</label>';
- $return .= '</div>';
- $return .= '</td>';
- if ($item['item_type'] == TOOL_QUIZ) {
- // lets update max_score Quiz information depending of the Quiz Advanced properties
- $lpItemObj = new LpItem($course_id, $item['id']);
- $exercise = new Exercise($course_id);
- $exercise->read($lpItemObj->path);
- $lpItemObj->max_score = $exercise->get_max_score();
- $lpItemObj->update();
- $item['max_score'] = $lpItemObj->max_score;
- if (empty($selectedMinScoreValue) && !empty($masteryScoreAsMinValue)) {
- // Backwards compatibility with 1.9.x use mastery_score as min value
- $selectedMinScoreValue = $masteryScoreAsMinValue;
- }
- $return .= '<td>';
- $return .= '<input
- class="form-control"
- size="4" maxlength="3"
- name="min_'.$item['id'].'"
- type="number"
- min="0"
- step="1"
- max="'.$item['max_score'].'"
- value="'.$selectedMinScoreValue.'"
- />';
- $return .= '</td>';
- $return .= '<td>';
- $return .= '<input
- class="form-control"
- size="4"
- maxlength="3"
- name="max_'.$item['id'].'"
- type="number"
- min="0"
- step="1"
- max="'.$item['max_score'].'"
- value="'.$selectedMaxScoreValue.'"
- />';
- $return .= '</td>';
- }
- if ($item['item_type'] == TOOL_HOTPOTATOES) {
- $return .= '<td>';
- $return .= '<input
- size="4"
- maxlength="3"
- name="min_'.$item['id'].'"
- type="number"
- min="0"
- step="1"
- max="'.$item['max_score'].'"
- value="'.$selectedMinScoreValue.'"
- />';
- $return .= '</td>';
- $return .= '<td>';
- $return .= '<input
- size="4"
- maxlength="3"
- name="max_'.$item['id'].'"
- type="number"
- min="0"
- step="1"
- max="'.$item['max_score'].'"
- value="'.$selectedMaxScoreValue.'"
- />';
- $return .= '</td>';
- }
- $return .= '</tr>';
- }
- $return .= '<tr>';
- $return .= '</tr>';
- $return .= '</tbody>';
- $return .= '</table>';
- $return .= '</div>';
- $return .= '<div class="form-group">';
- $return .= '<button class="btn btn-primary" name="submit_button" type="submit">'.
- get_lang('ModifyPrerequisites').'</button>';
- $return .= '</form>';
- return $return;
- }
- /**
- * Return HTML list to allow prerequisites selection for lp.
- *
- * @return string HTML form
- */
- public function display_lp_prerequisites_list()
- {
- $course_id = api_get_course_int_id();
- $lp_id = $this->lp_id;
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- // get current prerequisite
- $sql = "SELECT * FROM $tbl_lp WHERE iid = $lp_id ";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $prerequisiteId = $row['prerequisite'];
- $session_id = api_get_session_id();
- $session_condition = api_get_session_condition($session_id, true, true);
- $sql = "SELECT * FROM $tbl_lp
- WHERE c_id = $course_id $session_condition
- ORDER BY display_order ";
- $rs = Database::query($sql);
- $return = '';
- $return .= '<select name="prerequisites" class="form-control">';
- $return .= '<option value="0">'.get_lang('None').'</option>';
- if (Database::num_rows($rs) > 0) {
- while ($row = Database::fetch_array($rs)) {
- if ($row['id'] == $lp_id) {
- continue;
- }
- $return .= '<option value="'.$row['id'].'" '.(($row['id'] == $prerequisiteId) ? ' selected ' : '').'>'.$row['name'].'</option>';
- }
- }
- $return .= '</select>';
- return $return;
- }
- /**
- * Creates a list with all the documents in it.
- *
- * @param bool $showInvisibleFiles
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string
- */
- public function get_documents($showInvisibleFiles = false)
- {
- $course_info = api_get_course_info();
- $sessionId = api_get_session_id();
- $documentTree = DocumentManager::get_document_preview(
- $course_info,
- $this->lp_id,
- null,
- $sessionId,
- true,
- null,
- null,
- $showInvisibleFiles,
- true
- );
- $headers = [
- get_lang('Files'),
- get_lang('CreateTheDocument'),
- get_lang('CreateReadOutText'),
- get_lang('Upload'),
- ];
- $form = new FormValidator(
- 'form_upload',
- 'POST',
- $this->getCurrentBuildingModeURL(),
- '',
- ['enctype' => 'multipart/form-data']
- );
- $folders = DocumentManager::get_all_document_folders(
- api_get_course_info(),
- 0,
- true
- );
- $lpPathInfo = $this->generate_lp_folder(api_get_course_info());
- DocumentManager::build_directory_selector(
- $folders,
- $lpPathInfo['id'],
- [],
- true,
- $form,
- 'directory_parent_id'
- );
- $group = [
- $form->createElement(
- 'radio',
- 'if_exists',
- get_lang('UplWhatIfFileExists'),
- get_lang('UplDoNothing'),
- 'nothing'
- ),
- $form->createElement(
- 'radio',
- 'if_exists',
- null,
- get_lang('UplOverwriteLong'),
- 'overwrite'
- ),
- $form->createElement(
- 'radio',
- 'if_exists',
- null,
- get_lang('UplRenameLong'),
- 'rename'
- ),
- ];
- $form->addGroup($group, null, get_lang('UplWhatIfFileExists'));
- $fileExistsOption = api_get_setting('document_if_file_exists_option');
- $defaultFileExistsOption = 'rename';
- if (!empty($fileExistsOption)) {
- $defaultFileExistsOption = $fileExistsOption;
- }
- $form->setDefaults(['if_exists' => $defaultFileExistsOption]);
- // Check box options
- $form->addElement(
- 'checkbox',
- 'unzip',
- get_lang('Options'),
- get_lang('Uncompress')
- );
- $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?'.api_get_cidreq().'&a=upload_file&curdirpath=';
- $form->addMultipleUpload($url);
- $new = $this->display_document_form('add', 0);
- $frmReadOutText = $this->displayFrmReadOutText('add');
- $tabs = Display::tabs(
- $headers,
- [$documentTree, $new, $frmReadOutText, $form->returnForm()],
- 'subtab'
- );
- return $tabs;
- }
- /**
- * Creates a list with all the exercises (quiz) in it.
- *
- * @return string
- */
- public function get_exercises()
- {
- $course_id = api_get_course_int_id();
- $session_id = api_get_session_id();
- $userInfo = api_get_user_info();
- // New for hotpotatoes.
- $uploadPath = DIR_HOTPOTATOES; //defined in main_api
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $condition_session = api_get_session_condition($session_id, true, true);
- $setting = api_get_configuration_value('show_invisible_exercise_in_lp_list');
- $activeCondition = ' active <> -1 ';
- if ($setting) {
- $activeCondition = ' active = 1 ';
- }
- $categoryCondition = '';
- $categoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] : 0;
- if (api_get_configuration_value('allow_exercise_categories') && !empty($categoryId)) {
- $categoryCondition = " AND exercise_category_id = $categoryId ";
- }
- $keywordCondition = '';
- $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
- if (!empty($keyword)) {
- $keyword = Database::escape_string($keyword);
- $keywordCondition = " AND title LIKE '%$keyword%' ";
- }
- $sql_quiz = "SELECT * FROM $tbl_quiz
- WHERE
- c_id = $course_id AND
- $activeCondition
- $condition_session
- $categoryCondition
- $keywordCondition
- ORDER BY title ASC";
- $sql_hot = "SELECT * FROM $tbl_doc
- WHERE
- c_id = $course_id AND
- path LIKE '".$uploadPath."/%/%htm%'
- $condition_session
- ORDER BY id ASC";
- $res_quiz = Database::query($sql_quiz);
- $res_hot = Database::query($sql_hot);
- $currentUrl = api_get_self().'?'.api_get_cidreq().'&action=add_item&type=step&lp_id='.$this->lp_id.'#resource_tab-2';
- // Create a search-box
- $form = new FormValidator('search_simple', 'get', $currentUrl);
- $form->addHidden('action', 'add_item');
- $form->addHidden('type', 'step');
- $form->addHidden('lp_id', $this->lp_id);
- $form->addHidden('lp_build_selected', '2');
- $form->addCourseHiddenParams();
- $form->addText(
- 'keyword',
- get_lang('Search'),
- false,
- [
- 'aria-label' => get_lang('Search'),
- ]
- );
- if (api_get_configuration_value('allow_exercise_categories')) {
- $manager = new ExerciseCategoryManager();
- $options = $manager->getCategoriesForSelect(api_get_course_int_id());
- if (!empty($options)) {
- $form->addSelect(
- 'category_id',
- get_lang('Category'),
- $options,
- ['placeholder' => get_lang('SelectAnOption')]
- );
- }
- }
- $form->addButtonSearch(get_lang('Search'));
- $return = $form->returnForm();
- $return .= '<ul class="lp_resource">';
- $return .= '<li class="lp_resource_element">';
- $return .= Display::return_icon('new_exercice.png');
- $return .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise_admin.php?'.api_get_cidreq().'&lp_id='.$this->lp_id.'">'.
- get_lang('NewExercise').'</a>';
- $return .= '</li>';
- $previewIcon = Display::return_icon(
- 'preview_view.png',
- get_lang('Preview')
- );
- $quizIcon = Display::return_icon('quiz.png', '', [], ICON_SIZE_TINY);
- $moveIcon = Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
- $exerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/showinframes.php?'.api_get_cidreq();
- // Display hotpotatoes
- while ($row_hot = Database::fetch_array($res_hot)) {
- $link = Display::url(
- $previewIcon,
- $exerciseUrl.'&file='.$row_hot['path'],
- ['target' => '_blank']
- );
- $return .= '<li class="lp_resource_element" data_id="'.$row_hot['id'].'" data_type="hotpotatoes" title="'.$row_hot['title'].'" >';
- $return .= '<a class="moved" href="#">';
- $return .= Display::return_icon(
- 'move_everywhere.png',
- get_lang('Move'),
- [],
- ICON_SIZE_TINY
- );
- $return .= '</a> ';
- $return .= Display::return_icon('hotpotatoes_s.png');
- $return .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_HOTPOTATOES.'&file='.$row_hot['id'].'&lp_id='.$this->lp_id.'">'.
- ((!empty($row_hot['comment'])) ? $row_hot['comment'] : Security::remove_XSS($row_hot['title'])).$link.'</a>';
- $return .= '</li>';
- }
- $exerciseUrl = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.api_get_cidreq();
- while ($row_quiz = Database::fetch_array($res_quiz)) {
- $title = strip_tags(
- api_html_entity_decode($row_quiz['title'])
- );
- $visibility = api_get_item_visibility(
- ['real_id' => $course_id],
- TOOL_QUIZ,
- $row_quiz['iid'],
- $session_id
- );
- $link = Display::url(
- $previewIcon,
- $exerciseUrl.'&exerciseId='.$row_quiz['id'],
- ['target' => '_blank']
- );
- $return .= '<li class="lp_resource_element" data_id="'.$row_quiz['id'].'" data_type="quiz" title="'.$title.'" >';
- $return .= Display::url($moveIcon, '#', ['class' => 'moved']);
- $return .= $quizIcon;
- $sessionStar = api_get_session_image(
- $row_quiz['session_id'],
- $userInfo['status']
- );
- $return .= Display::url(
- Security::remove_XSS(cut($title, 80)).$link.$sessionStar,
- api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_QUIZ.'&file='.$row_quiz['id'].'&lp_id='.$this->lp_id,
- [
- 'class' => $visibility == 0 ? 'moved text-muted' : 'moved',
- ]
- );
- $return .= '</li>';
- }
- $return .= '</ul>';
- return $return;
- }
- /**
- * Creates a list with all the links in it.
- *
- * @return string
- */
- public function get_links()
- {
- $selfUrl = api_get_self();
- $courseIdReq = api_get_cidreq();
- $course = api_get_course_info();
- $userInfo = api_get_user_info();
- $course_id = $course['real_id'];
- $tbl_link = Database::get_course_table(TABLE_LINK);
- $linkCategoryTable = Database::get_course_table(TABLE_LINK_CATEGORY);
- $moveEverywhereIcon = Display::return_icon(
- 'move_everywhere.png',
- get_lang('Move'),
- [],
- ICON_SIZE_TINY
- );
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition(
- $session_id,
- true,
- true,
- 'link.session_id'
- );
- $sql = "SELECT
- link.id as link_id,
- link.title as link_title,
- link.session_id as link_session_id,
- link.category_id as category_id,
- link_category.category_title as category_title
- FROM $tbl_link as link
- LEFT JOIN $linkCategoryTable as link_category
- ON (link.category_id = link_category.id AND link.c_id = link_category.c_id)
- WHERE link.c_id = $course_id $condition_session
- ORDER BY link_category.category_title ASC, link.title ASC";
- $result = Database::query($sql);
- $categorizedLinks = [];
- $categories = [];
- while ($link = Database::fetch_array($result)) {
- if (!$link['category_id']) {
- $link['category_title'] = get_lang('Uncategorized');
- }
- $categories[$link['category_id']] = $link['category_title'];
- $categorizedLinks[$link['category_id']][$link['link_id']] = $link;
- }
- $linksHtmlCode =
- '<script>
- function toggle_tool(tool, id) {
- if(document.getElementById(tool+"_"+id+"_content").style.display == "none"){
- document.getElementById(tool+"_"+id+"_content").style.display = "block";
- document.getElementById(tool+"_"+id+"_opener").src = "'.Display::returnIconPath('remove.gif').'";
- } else {
- document.getElementById(tool+"_"+id+"_content").style.display = "none";
- document.getElementById(tool+"_"+id+"_opener").src = "'.Display::returnIconPath('add.gif').'";
- }
- }
- </script>
- <ul class="lp_resource">
- <li class="lp_resource_element">
- '.Display::return_icon('linksnew.gif').'
- <a href="'.api_get_path(WEB_CODE_PATH).'link/link.php?'.$courseIdReq.'&action=addlink&lp_id='.$this->lp_id.'" title="'.get_lang('LinkAdd').'">'.
- get_lang('LinkAdd').'
- </a>
- </li>';
- foreach ($categorizedLinks as $categoryId => $links) {
- $linkNodes = null;
- foreach ($links as $key => $linkInfo) {
- $title = $linkInfo['link_title'];
- $linkSessionId = $linkInfo['link_session_id'];
- $link = Display::url(
- Display::return_icon('preview_view.png', get_lang('Preview')),
- api_get_path(WEB_CODE_PATH).'link/link_goto.php?'.api_get_cidreq().'&link_id='.$key,
- ['target' => '_blank']
- );
- if (api_get_item_visibility($course, TOOL_LINK, $key, $session_id) != 2) {
- $sessionStar = api_get_session_image($linkSessionId, $userInfo['status']);
- $linkNodes .=
- '<li class="lp_resource_element" data_id="'.$key.'" data_type="'.TOOL_LINK.'" title="'.$title.'" >
- <a class="moved" href="#">'.
- $moveEverywhereIcon.
- '</a>
- '.Display::return_icon('links.png', '', [], ICON_SIZE_TINY).'
- <a class="moved" href="'.$selfUrl.'?'.$courseIdReq.'&action=add_item&type='.
- TOOL_LINK.'&file='.$key.'&lp_id='.$this->lp_id.'">'.
- Security::remove_XSS($title).$sessionStar.$link.
- '</a>
- </li>';
- }
- }
- $linksHtmlCode .=
- '<li>
- <a style="cursor:hand" onclick="javascript: toggle_tool(\''.TOOL_LINK.'\','.$categoryId.')" style="vertical-align:middle">
- <img src="'.Display::returnIconPath('add.gif').'" id="'.TOOL_LINK.'_'.$categoryId.'_opener"
- align="absbottom" />
- </a>
- <span style="vertical-align:middle">'.Security::remove_XSS($categories[$categoryId]).'</span>
- </li>
- <div style="display:none" id="'.TOOL_LINK.'_'.$categoryId.'_content">'.$linkNodes.'</div>';
- }
- $linksHtmlCode .= '</ul>';
- return $linksHtmlCode;
- }
- /**
- * Creates a list with all the student publications in it.
- *
- * @return string
- */
- public function get_student_publications()
- {
- $return = '<ul class="lp_resource">';
- $return .= '<li class="lp_resource_element">';
- $return .= Display::return_icon('works_new.gif');
- $return .= ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_STUDENTPUBLICATION.'&lp_id='.$this->lp_id.'">'.
- get_lang('AddAssignmentPage').'</a>';
- $return .= '</li>';
- require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
- $works = getWorkListTeacher(0, 100, null, null, null);
- if (!empty($works)) {
- foreach ($works as $work) {
- $link = Display::url(
- Display::return_icon('preview_view.png', get_lang('Preview')),
- api_get_path(WEB_CODE_PATH).'work/work_list_all.php?'.api_get_cidreq().'&id='.$work['iid'],
- ['target' => '_blank']
- );
- $return .= '<li class="lp_resource_element" data_id="'.$work['iid'].'" data_type="'.TOOL_STUDENTPUBLICATION.'" title="'.Security::remove_XSS(cut(strip_tags($work['title']), 80)).'">';
- $return .= '<a class="moved" href="#">';
- $return .= Display::return_icon(
- 'move_everywhere.png',
- get_lang('Move'),
- [],
- ICON_SIZE_TINY
- );
- $return .= '</a> ';
- $return .= Display::return_icon('works.png', '', [], ICON_SIZE_TINY);
- $return .= ' <a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_STUDENTPUBLICATION.'&file='.$work['iid'].'&lp_id='.$this->lp_id.'">'.
- Security::remove_XSS(cut(strip_tags($work['title']), 80)).' '.$link.'
- </a>';
- $return .= '</li>';
- }
- }
- $return .= '</ul>';
- return $return;
- }
- /**
- * Creates a list with all the forums in it.
- *
- * @return string
- */
- public function get_forums()
- {
- require_once '../forum/forumfunction.inc.php';
- $forumCategories = get_forum_categories();
- $forumsInNoCategory = get_forums_in_category(0);
- if (!empty($forumsInNoCategory)) {
- $forumCategories = array_merge(
- $forumCategories,
- [
- [
- 'cat_id' => 0,
- 'session_id' => 0,
- 'visibility' => 1,
- 'cat_comment' => null,
- ],
- ]
- );
- }
- $forumList = get_forums();
- $a_forums = [];
- foreach ($forumCategories as $forumCategory) {
- // The forums in this category.
- $forumsInCategory = get_forums_in_category($forumCategory['cat_id']);
- if (!empty($forumsInCategory)) {
- foreach ($forumList as $forum) {
- if (isset($forum['forum_category']) &&
- $forum['forum_category'] == $forumCategory['cat_id']
- ) {
- $a_forums[] = $forum;
- }
- }
- }
- }
- $return = '<ul class="lp_resource">';
- // First add link
- $return .= '<li class="lp_resource_element">';
- $return .= Display::return_icon('new_forum.png');
- $return .= Display::url(
- get_lang('CreateANewForum'),
- api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'add',
- 'content' => 'forum',
- 'lp_id' => $this->lp_id,
- ]),
- ['title' => get_lang('CreateANewForum')]
- );
- $return .= '</li>';
- $return .= '<script>
- function toggle_forum(forum_id) {
- if (document.getElementById("forum_"+forum_id+"_content").style.display == "none") {
- document.getElementById("forum_"+forum_id+"_content").style.display = "block";
- document.getElementById("forum_"+forum_id+"_opener").src = "'.Display::returnIconPath('remove.gif').'";
- } else {
- document.getElementById("forum_"+forum_id+"_content").style.display = "none";
- document.getElementById("forum_"+forum_id+"_opener").src = "'.Display::returnIconPath('add.gif').'";
- }
- }
- </script>';
- foreach ($a_forums as $forum) {
- if (!empty($forum['forum_id'])) {
- $link = Display::url(
- Display::return_icon('preview_view.png', get_lang('Preview')),
- api_get_path(WEB_CODE_PATH).'forum/viewforum.php?'.api_get_cidreq().'&forum='.$forum['forum_id'],
- ['target' => '_blank']
- );
- $return .= '<li class="lp_resource_element" data_id="'.$forum['forum_id'].'" data_type="'.TOOL_FORUM.'" title="'.$forum['forum_title'].'" >';
- $return .= '<a class="moved" href="#">';
- $return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
- $return .= ' </a>';
- $return .= Display::return_icon('forum.png', '', [], ICON_SIZE_TINY);
- $return .= '<a onclick="javascript:toggle_forum('.$forum['forum_id'].');" style="cursor:hand; vertical-align:middle">
- <img src="'.Display::returnIconPath('add.gif').'" id="forum_'.$forum['forum_id'].'_opener" align="absbottom" />
- </a>
- <a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_FORUM.'&forum_id='.$forum['forum_id'].'&lp_id='.$this->lp_id.'" style="vertical-align:middle">'.
- Security::remove_XSS($forum['forum_title']).' '.$link.'</a>';
- $return .= '</li>';
- $return .= '<div style="display:none" id="forum_'.$forum['forum_id'].'_content">';
- $a_threads = get_threads($forum['forum_id']);
- if (is_array($a_threads)) {
- foreach ($a_threads as $thread) {
- $link = Display::url(
- Display::return_icon('preview_view.png', get_lang('Preview')),
- api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum['forum_id'].'&thread='.$thread['thread_id'],
- ['target' => '_blank']
- );
- $return .= '<li class="lp_resource_element" data_id="'.$thread['thread_id'].'" data_type="'.TOOL_THREAD.'" title="'.$thread['thread_title'].'" >';
- $return .= ' <a class="moved" href="#">';
- $return .= Display::return_icon('move_everywhere.png', get_lang('Move'), [], ICON_SIZE_TINY);
- $return .= ' </a>';
- $return .= Display::return_icon('forumthread.png', get_lang('Thread'), [], ICON_SIZE_TINY);
- $return .= '<a class="moved" href="'.api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_THREAD.'&thread_id='.$thread['thread_id'].'&lp_id='.$this->lp_id.'">'.
- Security::remove_XSS($thread['thread_title']).' '.$link.'</a>';
- $return .= '</li>';
- }
- }
- $return .= '</div>';
- }
- }
- $return .= '</ul>';
- return $return;
- }
- /**
- * // TODO: The output encoding should be equal to the system encoding.
- *
- * Exports the learning path as a SCORM package. This is the main function that
- * gathers the content, transforms it, writes the imsmanifest.xml file, zips the
- * whole thing and returns the zip.
- *
- * This method needs to be called in PHP5, as it will fail with non-adequate
- * XML package (like the ones for PHP4), and it is *not* a static method, so
- * you need to call it on a learnpath object.
- *
- * @TODO The method might be redefined later on in the scorm class itself to avoid
- * creating a SCORM structure if there is one already. However, if the initial SCORM
- * path has been modified, it should use the generic method here below.
- *
- * @return string Returns the zip package string, or null if error
- */
- public function scormExport()
- {
- api_set_more_memory_and_time_limits();
- $_course = api_get_course_info();
- $course_id = $_course['real_id'];
- // Create the zip handler (this will remain available throughout the method).
- $archivePath = api_get_path(SYS_ARCHIVE_PATH);
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $temp_dir_short = uniqid('scorm_export', true);
- $temp_zip_dir = $archivePath.'/'.$temp_dir_short;
- $temp_zip_file = $temp_zip_dir.'/'.md5(time()).'.zip';
- $zip_folder = new PclZip($temp_zip_file);
- $current_course_path = api_get_path(SYS_COURSE_PATH).api_get_course_path();
- $root_path = $main_path = api_get_path(SYS_PATH);
- $files_cleanup = [];
- // Place to temporarily stash the zip file.
- // create the temp dir if it doesn't exist
- // or do a cleanup before creating the zip file.
- if (!is_dir($temp_zip_dir)) {
- mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
- } else {
- // Cleanup: Check the temp dir for old files and delete them.
- $handle = opendir($temp_zip_dir);
- while (false !== ($file = readdir($handle))) {
- if ($file != '.' && $file != '..') {
- unlink("$temp_zip_dir/$file");
- }
- }
- closedir($handle);
- }
- $zip_files = $zip_files_abs = $zip_files_dist = [];
- if (is_dir($current_course_path.'/scorm/'.$this->path) &&
- is_file($current_course_path.'/scorm/'.$this->path.'/imsmanifest.xml')
- ) {
- // Remove the possible . at the end of the path.
- $dest_path_to_lp = substr($this->path, -1) == '.' ? substr($this->path, 0, -1) : $this->path;
- $dest_path_to_scorm_folder = str_replace('//', '/', $temp_zip_dir.'/scorm/'.$dest_path_to_lp);
- mkdir(
- $dest_path_to_scorm_folder,
- api_get_permissions_for_new_directories(),
- true
- );
- copyr(
- $current_course_path.'/scorm/'.$this->path,
- $dest_path_to_scorm_folder,
- ['imsmanifest'],
- $zip_files
- );
- }
- // Build a dummy imsmanifest structure.
- // Do not add to the zip yet (we still need it).
- // This structure is developed following regulations for SCORM 1.2 packaging in the SCORM 1.2 Content
- // Aggregation Model official document, section "2.3 Content Packaging".
- // We are going to build a UTF-8 encoded manifest.
- // Later we will recode it to the desired (and supported) encoding.
- $xmldoc = new DOMDocument('1.0');
- $root = $xmldoc->createElement('manifest');
- $root->setAttribute('identifier', 'SingleCourseManifest');
- $root->setAttribute('version', '1.1');
- $root->setAttribute('xmlns', 'http://www.imsproject.org/xsd/imscp_rootv1p1p2');
- $root->setAttribute('xmlns:adlcp', 'http://www.adlnet.org/xsd/adlcp_rootv1p2');
- $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
- $root->setAttribute(
- 'xsi:schemaLocation',
- 'http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd'
- );
- // Build mandatory sub-root container elements.
- $metadata = $xmldoc->createElement('metadata');
- $md_schema = $xmldoc->createElement('schema', 'ADL SCORM');
- $metadata->appendChild($md_schema);
- $md_schemaversion = $xmldoc->createElement('schemaversion', '1.2');
- $metadata->appendChild($md_schemaversion);
- $root->appendChild($metadata);
- $organizations = $xmldoc->createElement('organizations');
- $resources = $xmldoc->createElement('resources');
- // Build the only organization we will use in building our learnpaths.
- $organizations->setAttribute('default', 'chamilo_scorm_export');
- $organization = $xmldoc->createElement('organization');
- $organization->setAttribute('identifier', 'chamilo_scorm_export');
- // To set the title of the SCORM entity (=organization), we take the name given
- // in Chamilo and convert it to HTML entities using the Chamilo charset (not the
- // learning path charset) as it is the encoding that defines how it is stored
- // in the database. Then we convert it to HTML entities again as the "&" character
- // alone is not authorized in XML (must be &).
- // The title is then decoded twice when extracting (see scorm::parse_manifest).
- $org_title = $xmldoc->createElement('title', api_utf8_encode($this->get_name()));
- $organization->appendChild($org_title);
- $folder_name = 'document';
- // Removes the learning_path/scorm_folder path when exporting see #4841
- $path_to_remove = '';
- $path_to_replace = '';
- $result = $this->generate_lp_folder($_course);
- if (isset($result['dir']) && strpos($result['dir'], 'learning_path')) {
- $path_to_remove = 'document'.$result['dir'];
- $path_to_replace = $folder_name.'/';
- }
- // Fixes chamilo scorm exports
- if ($this->ref === 'chamilo_scorm_export') {
- $path_to_remove = 'scorm/'.$this->path.'/document/';
- }
- // For each element, add it to the imsmanifest structure, then add it to the zip.
- $link_updates = [];
- $links_to_create = [];
- foreach ($this->ordered_items as $index => $itemId) {
- /** @var learnpathItem $item */
- $item = $this->items[$itemId];
- if (!in_array($item->type, [TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION])) {
- // Get included documents from this item.
- if ($item->type === 'sco') {
- $inc_docs = $item->get_resources_from_source(
- null,
- $current_course_path.'/scorm/'.$this->path.'/'.$item->get_path()
- );
- } else {
- $inc_docs = $item->get_resources_from_source();
- }
- // Give a child element <item> to the <organization> element.
- $my_item_id = $item->get_id();
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$my_item_id);
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$my_item_id);
- $my_item->setAttribute('isvisible', 'true');
- // Give a child element <title> to the <item> element.
- $my_title = $xmldoc->createElement(
- 'title',
- htmlspecialchars(
- api_utf8_encode($item->get_title()),
- ENT_QUOTES,
- 'UTF-8'
- )
- );
- $my_item->appendChild($my_title);
- // Give a child element <adlcp:prerequisites> to the <item> element.
- $my_prereqs = $xmldoc->createElement(
- 'adlcp:prerequisites',
- $this->get_scorm_prereq_string($my_item_id)
- );
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
- // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
- //$xmldoc->createElement('adlcp:maxtimeallowed','');
- // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
- //$xmldoc->createElement('adlcp:timelimitaction','');
- // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
- //$xmldoc->createElement('adlcp:datafromlms','');
- // Give a child element <adlcp:masteryscore> to the <item> element.
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
- // Attach this item to the organization element or hits parent if there is one.
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- $possible_parent = $this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
- if (is_object($possible_parent)) {
- $possible_parent->appendChild($my_item);
- } else {
- if ($this->debug > 0) {
- error_log('Parent ITEM_'.$item->parent.' of item ITEM_'.$my_item_id.' not found');
- }
- }
- } else {
- if ($this->debug > 0) {
- error_log('No parent');
- }
- $organization->appendChild($my_item);
- }
- // Get the path of the file(s) from the course directory root.
- $my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
- $my_xml_file_path = $my_file_path;
- if (!empty($path_to_remove)) {
- // From docs
- $my_xml_file_path = str_replace($path_to_remove, $path_to_replace, $my_file_path);
- // From quiz
- if ($this->ref === 'chamilo_scorm_export') {
- $path_to_remove = 'scorm/'.$this->path.'/';
- $my_xml_file_path = str_replace($path_to_remove, '', $my_file_path);
- }
- }
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
- $my_xml_sub_dir = $my_sub_dir;
- // Give a <resource> child to the <resources> element
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
- // adlcp:scormtype can be either 'sco' or 'asset'.
- if ($item->type === 'sco') {
- $my_resource->setAttribute('adlcp:scormtype', 'sco');
- } else {
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
- }
- // xml:base is the base directory to find the files declared in this resource.
- $my_resource->setAttribute('xml:base', '');
- // Give a <file> child to the <resource> element.
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
- // Dependency to other files - not yet supported.
- $i = 1;
- if ($inc_docs) {
- foreach ($inc_docs as $doc_info) {
- if (count($doc_info) < 1 || empty($doc_info[0])) {
- continue;
- }
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier', $res_id);
- $my_dep->setAttribute('type', 'webcontent');
- $my_dep->setAttribute('adlcp:scormtype', 'asset');
- $my_dep_file = $xmldoc->createElement('file');
- // Check type of URL.
- if ($doc_info[1] == 'remote') {
- // Remote file. Save url as is.
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- } elseif ($doc_info[1] === 'local') {
- switch ($doc_info[2]) {
- case 'url':
- // Local URL - save path as url for now, don't zip file.
- $abs_path = api_get_path(SYS_PATH).
- str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- $current_dir = dirname($abs_path);
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($abs_path);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
- // The calculated real path is really inside Chamilo's root path.
- // Reduce file path to what's under the DocumentRoot.
- $replace = $file_path;
- $file_path = substr($file_path, strlen($root_path) - 1);
- $destinationFile = $file_path;
- if (strstr($file_path, 'upload/users') !== false) {
- $pos = strpos($file_path, 'my_files/');
- if ($pos !== false) {
- $onlyDirectory = str_replace(
- 'upload/users/',
- '',
- substr($file_path, $pos, strlen($file_path))
- );
- }
- $replace = $onlyDirectory;
- $destinationFile = $replace;
- }
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $destinationFile,
- 'replace' => $replace,
- ];
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- } elseif (empty($file_path)) {
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- // We get the relative path.
- $file_path = substr($file_path, strlen($current_dir));
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $file_path,
- ];
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'abs':
- // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- // The next lines fix a bug when using the "subdir" mode of Chamilo, whereas
- // an image path would be constructed as /var/www/subdir/subdir/img/foo.bar
- $abs_img_path_without_subdir = $doc_info[0];
- $relp = api_get_path(REL_PATH); // The url-append config param.
- $pos = strpos($abs_img_path_without_subdir, $relp);
- if ($pos === 0) {
- $abs_img_path_without_subdir = trim('/'.substr($abs_img_path_without_subdir, strlen($relp)));
- }
- $file_path = realpath(api_get_path(SYS_APP_PATH).$abs_img_path_without_subdir);
- $file_path = str_replace(['\\', '//'], '/', $file_path);
- // Prepare the current directory path (until just under 'document') with a trailing slash.
- $cur_path = substr($current_course_path, -1) == '/' ? $current_course_path : $current_course_path.'/';
- // Check if the current document is in that path.
- if (strstr($file_path, $cur_path) !== false) {
- $destinationFile = substr($file_path, strlen($cur_path));
- $filePathNoCoursePart = substr($file_path, strlen($cur_path));
- $fileToTest = $cur_path.$my_file_path;
- if (!empty($path_to_remove)) {
- $fileToTest = str_replace(
- $path_to_remove.'/',
- $path_to_replace,
- $cur_path.$my_file_path
- );
- }
- $relative_path = api_get_relative_path($fileToTest, $file_path);
- // Put the current document in the zip (this array is the array
- // that will manage documents already in the course folder - relative).
- $zip_files[] = $filePathNoCoursePart;
- // Update the links to the current document in the
- // containing document (make them relative).
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $destinationFile,
- 'replace' => $relative_path,
- ];
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- } elseif (strstr($file_path, $main_path) !== false) {
- // The calculated real path is really inside Chamilo's root path.
- // Reduce file path to what's under the DocumentRoot.
- $file_path = substr($file_path, strlen($root_path));
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = ['orig' => $doc_info[0], 'dest' => $file_path];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- } elseif (empty($file_path)) {
- // Probably this is an image inside "/main" directory
- $file_path = api_get_path(SYS_PATH).$abs_img_path_without_subdir;
- $abs_path = api_get_path(SYS_PATH).str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- if (file_exists($file_path)) {
- if (strstr($file_path, 'main/default_course_document') !== false) {
- // We get the relative path.
- $pos = strpos($file_path, 'main/default_course_document/');
- if ($pos !== false) {
- $onlyDirectory = str_replace(
- 'main/default_course_document/',
- '',
- substr($file_path, $pos, strlen($file_path))
- );
- }
- $destinationFile = 'default_course_document/'.$onlyDirectory;
- $fileAbs = substr($file_path, strlen(api_get_path(SYS_PATH)));
- $zip_files_abs[] = $fileAbs;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $destinationFile,
- ];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- }
- break;
- case 'rel':
- // Path relative to the current document.
- // Save xml:base as current document's directory and save file in zip as subdir.file_path
- if (substr($doc_info[0], 0, 2) === '..') {
- // Relative path going up.
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($current_dir.$doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
- if (strstr($file_path, $main_path) !== false) {
- // The calculated real path is really inside Chamilo's root path.
- // Reduce file path to what's under the DocumentRoot.
- $file_path = substr($file_path, strlen($root_path));
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = ['orig' => $doc_info[0], 'dest' => $file_path];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- } else {
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref', $res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
- }
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
- } else {
- // If the item is a quiz or a link or whatever non-exportable, we include a step indicating it.
- switch ($item->type) {
- case TOOL_LINK:
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible', 'true');
- // Give a child element <title> to the <item> element.
- $my_title = $xmldoc->createElement(
- 'title',
- htmlspecialchars(
- api_utf8_encode($item->get_title()),
- ENT_QUOTES,
- 'UTF-8'
- )
- );
- $my_item->appendChild($my_title);
- // Give a child element <adlcp:prerequisites> to the <item> element.
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
- // Give a child element <adlcp:maxtimeallowed> to the <item> element - not yet supported.
- //$xmldoc->createElement('adlcp:maxtimeallowed', '');
- // Give a child element <adlcp:timelimitaction> to the <item> element - not yet supported.
- //$xmldoc->createElement('adlcp:timelimitaction', '');
- // Give a child element <adlcp:datafromlms> to the <item> element - not yet supported.
- //$xmldoc->createElement('adlcp:datafromlms', '');
- // Give a child element <adlcp:masteryscore> to the <item> element.
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
- // Attach this item to the organization element or its parent if there is one.
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- for ($i = 0; $i < $children->length; $i++) {
- $item_temp = $children->item($i);
- if ($item_temp->nodeName == 'item') {
- if ($item_temp->getAttribute('identifier') == 'ITEM_'.$item->parent) {
- $item_temp->appendChild($my_item);
- }
- }
- }
- } else {
- $organization->appendChild($my_item);
- }
- $my_file_path = 'link_'.$item->get_id().'.html';
- $sql = 'SELECT url, title FROM '.Database::get_course_table(TABLE_LINK).'
- WHERE c_id = '.$course_id.' AND id = '.$item->path;
- $rs = Database::query($sql);
- if ($link = Database::fetch_array($rs)) {
- $url = $link['url'];
- $title = stripslashes($link['title']);
- $links_to_create[$my_file_path] = ['title' => $title, 'url' => $url];
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
- $my_xml_sub_dir = $my_sub_dir;
- // Give a <resource> child to the <resources> element.
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
- // adlcp:scormtype can be either 'sco' or 'asset'.
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
- // xml:base is the base directory to find the files declared in this resource.
- $my_resource->setAttribute('xml:base', '');
- // give a <file> child to the <resource> element.
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- }
- break;
- case TOOL_QUIZ:
- $exe_id = $item->path;
- // Should be using ref when everything will be cleaned up in this regard.
- $exe = new Exercise();
- $exe->read($exe_id);
- $my_item = $xmldoc->createElement('item');
- $my_item->setAttribute('identifier', 'ITEM_'.$item->get_id());
- $my_item->setAttribute('identifierref', 'RESOURCE_'.$item->get_id());
- $my_item->setAttribute('isvisible', 'true');
- // Give a child element <title> to the <item> element.
- $my_title = $xmldoc->createElement(
- 'title',
- htmlspecialchars(
- api_utf8_encode($item->get_title()),
- ENT_QUOTES,
- 'UTF-8'
- )
- );
- $my_item->appendChild($my_title);
- $my_max_score = $xmldoc->createElement('max_score', $item->get_max());
- $my_item->appendChild($my_max_score);
- // Give a child element <adlcp:prerequisites> to the <item> element.
- $my_prereqs = $xmldoc->createElement('adlcp:prerequisites', $item->get_prereq_string());
- $my_prereqs->setAttribute('type', 'aicc_script');
- $my_item->appendChild($my_prereqs);
- // Give a child element <adlcp:masteryscore> to the <item> element.
- $my_masteryscore = $xmldoc->createElement('adlcp:masteryscore', $item->get_mastery_score());
- $my_item->appendChild($my_masteryscore);
- // Attach this item to the organization element or hits parent if there is one.
- if (!empty($item->parent) && $item->parent != 0) {
- $children = $organization->childNodes;
- $possible_parent = $this->get_scorm_xml_node($children, 'ITEM_'.$item->parent);
- if ($possible_parent) {
- if ($possible_parent->getAttribute('identifier') === 'ITEM_'.$item->parent) {
- $possible_parent->appendChild($my_item);
- }
- }
- } else {
- $organization->appendChild($my_item);
- }
- // Get the path of the file(s) from the course directory root
- //$my_file_path = $item->get_file_path('scorm/'.$this->path.'/');
- $my_file_path = 'quiz_'.$item->get_id().'.html';
- // Write the contents of the exported exercise into a (big) html file
- // to later pack it into the exported SCORM. The file will be removed afterwards.
- $scormExercise = new ScormExercise($exe, true);
- $contents = $scormExercise->export();
- $tmp_file_path = $archivePath.$temp_dir_short.'/'.$my_file_path;
- $res = file_put_contents($tmp_file_path, $contents);
- if ($res === false) {
- error_log('Could not write into file '.$tmp_file_path.' '.__FILE__.' '.__LINE__, 0);
- }
- $files_cleanup[] = $tmp_file_path;
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
- $my_xml_sub_dir = $my_sub_dir;
- // Give a <resource> child to the <resources> element.
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $my_xml_file_path);
- // adlcp:scormtype can be either 'sco' or 'asset'.
- $my_resource->setAttribute('adlcp:scormtype', 'sco');
- // xml:base is the base directory to find the files declared in this resource.
- $my_resource->setAttribute('xml:base', '');
- // Give a <file> child to the <resource> element.
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', $my_xml_file_path);
- $my_resource->appendChild($my_file);
- // Get included docs.
- $inc_docs = $item->get_resources_from_source(null, $tmp_file_path);
- // Dependency to other files - not yet supported.
- $i = 1;
- foreach ($inc_docs as $doc_info) {
- if (count($doc_info) < 1 || empty($doc_info[0])) {
- continue;
- }
- $my_dep = $xmldoc->createElement('resource');
- $res_id = 'RESOURCE_'.$item->get_id().'_'.$i;
- $my_dep->setAttribute('identifier', $res_id);
- $my_dep->setAttribute('type', 'webcontent');
- $my_dep->setAttribute('adlcp:scormtype', 'asset');
- $my_dep_file = $xmldoc->createElement('file');
- // Check type of URL.
- if ($doc_info[1] == 'remote') {
- // Remote file. Save url as is.
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', '');
- } elseif ($doc_info[1] == 'local') {
- switch ($doc_info[2]) {
- case 'url': // Local URL - save path as url for now, don't zip file.
- // Save file but as local file (retrieve from URL).
- $abs_path = api_get_path(SYS_PATH).
- str_replace(api_get_path(WEB_PATH), '', $doc_info[0]);
- $current_dir = dirname($abs_path);
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($abs_path);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
- // The calculated real path is really inside the chamilo root path.
- // Reduce file path to what's under the DocumentRoot.
- $file_path = substr($file_path, strlen($root_path));
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => 'document/'.$file_path,
- ];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- } elseif (empty($file_path)) {
- $file_path = $_SERVER['DOCUMENT_ROOT'].$abs_path;
- $file_path = str_replace('//', '/', $file_path);
- if (file_exists($file_path)) {
- $file_path = substr($file_path, strlen($current_dir));
- // We get the relative path.
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => 'document/'.$file_path,
- ];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'abs':
- // Absolute path from DocumentRoot. Save file and leave path as is in the zip.
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
- $my_dep_file->setAttribute('href', $file_path);
- $my_dep->setAttribute('xml:base', '');
- if (strstr($file_path, $main_path) !== false) {
- // The calculated real path is really inside the chamilo root path.
- // Reduce file path to what's under the DocumentRoot.
- $file_path = substr($file_path, strlen($root_path));
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $file_path,
- ];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- } elseif (empty($file_path)) {
- $docSysPartPath = str_replace(
- api_get_path(REL_COURSE_PATH),
- '',
- $doc_info[0]
- );
- $docSysPartPathNoCourseCode = str_replace(
- $_course['directory'].'/',
- '',
- $docSysPartPath
- );
- $docSysPath = api_get_path(SYS_COURSE_PATH).$docSysPartPath;
- if (file_exists($docSysPath)) {
- $file_path = $docSysPartPathNoCourseCode;
- $zip_files[] = $my_sub_dir.'/'.$file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $file_path,
- ];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- }
- break;
- case 'rel':
- // Path relative to the current document. Save xml:base as current document's
- // directory and save file in zip as subdir.file_path
- if (substr($doc_info[0], 0, 2) === '..') {
- // Relative path going up.
- $current_dir = dirname($current_course_path.'/'.$item->get_file_path()).'/';
- $current_dir = str_replace('\\', '/', $current_dir);
- $file_path = realpath($current_dir.$doc_info[0]);
- $file_path = str_replace('\\', '/', $file_path);
- if (strstr($file_path, $main_path) !== false) {
- // The calculated real path is really inside Chamilo's root path.
- // Reduce file path to what's under the DocumentRoot.
- $file_path = substr($file_path, strlen($root_path));
- $file_path_dest = $file_path;
- // File path is courses/CHAMILO/document/....
- $info_file_path = explode('/', $file_path);
- if ($info_file_path[0] == 'courses') {
- // Add character "/" in file path.
- $file_path_dest = 'document/'.$file_path;
- }
- $zip_files_abs[] = $file_path;
- $link_updates[$my_file_path][] = [
- 'orig' => $doc_info[0],
- 'dest' => $file_path_dest,
- ];
- $my_dep_file->setAttribute('href', 'document/'.$file_path);
- $my_dep->setAttribute('xml:base', '');
- }
- } else {
- $zip_files[] = $my_sub_dir.'/'.$doc_info[0];
- $my_dep_file->setAttribute('href', $doc_info[0]);
- $my_dep->setAttribute('xml:base', $my_xml_sub_dir);
- }
- break;
- default:
- $my_dep_file->setAttribute('href', $doc_info[0]); // ../../courses/
- $my_dep->setAttribute('xml:base', '');
- break;
- }
- }
- $my_dep->appendChild($my_dep_file);
- $resources->appendChild($my_dep);
- $dependency = $xmldoc->createElement('dependency');
- $dependency->setAttribute('identifierref', $res_id);
- $my_resource->appendChild($dependency);
- $i++;
- }
- $resources->appendChild($my_resource);
- $zip_files[] = $my_file_path;
- break;
- default:
- // Get the path of the file(s) from the course directory root
- $my_file_path = 'non_exportable.html';
- //$my_xml_file_path = api_htmlentities(api_utf8_encode($my_file_path), ENT_COMPAT, 'UTF-8');
- $my_xml_file_path = $my_file_path;
- $my_sub_dir = dirname($my_file_path);
- $my_sub_dir = str_replace('\\', '/', $my_sub_dir);
- //$my_xml_sub_dir = api_htmlentities(api_utf8_encode($my_sub_dir), ENT_COMPAT, 'UTF-8');
- $my_xml_sub_dir = $my_sub_dir;
- // Give a <resource> child to the <resources> element.
- $my_resource = $xmldoc->createElement('resource');
- $my_resource->setAttribute('identifier', 'RESOURCE_'.$item->get_id());
- $my_resource->setAttribute('type', 'webcontent');
- $my_resource->setAttribute('href', $folder_name.'/'.$my_xml_file_path);
- // adlcp:scormtype can be either 'sco' or 'asset'.
- $my_resource->setAttribute('adlcp:scormtype', 'asset');
- // xml:base is the base directory to find the files declared in this resource.
- $my_resource->setAttribute('xml:base', '');
- // Give a <file> child to the <resource> element.
- $my_file = $xmldoc->createElement('file');
- $my_file->setAttribute('href', 'document/'.$my_xml_file_path);
- $my_resource->appendChild($my_file);
- $resources->appendChild($my_resource);
- break;
- }
- }
- }
- $organizations->appendChild($organization);
- $root->appendChild($organizations);
- $root->appendChild($resources);
- $xmldoc->appendChild($root);
- $copyAll = api_get_configuration_value('add_all_files_in_lp_export');
- // then add the file to the zip, then destroy the file (this is done automatically).
- // http://www.reload.ac.uk/scormplayer.html - once done, don't forget to close FS#138
- foreach ($zip_files as $file_path) {
- if (empty($file_path)) {
- continue;
- }
- $filePath = $sys_course_path.$_course['path'].'/'.$file_path;
- $dest_file = $archivePath.$temp_dir_short.'/'.$file_path;
- if (!empty($path_to_remove) && !empty($path_to_replace)) {
- $dest_file = str_replace($path_to_remove, $path_to_replace, $dest_file);
- }
- $this->create_path($dest_file);
- @copy($filePath, $dest_file);
- // Check if the file needs a link update.
- if (in_array($file_path, array_keys($link_updates))) {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach ($link_updates[$file_path] as $old_new) {
- // This is an ugly hack that allows .flv files to be found by the flv player that
- // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
- // to find the flv to play in document/main/, so we replace main/ in the flv path by
- // ../../.. to return from inc/lib/flv_player to the document/main path.
- if (substr($old_new['dest'], -3) === 'flv' &&
- substr($old_new['dest'], 0, 5) === 'main/'
- ) {
- $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
- } elseif (substr($old_new['dest'], -3) === 'flv' &&
- substr($old_new['dest'], 0, 6) === 'video/'
- ) {
- $old_new['dest'] = str_replace('video/', '../../../../video/', $old_new['dest']);
- }
- // Fix to avoid problems with default_course_document
- if (strpos('main/default_course_document', $old_new['dest']) === false) {
- $newDestination = $old_new['dest'];
- if (isset($old_new['replace']) && !empty($old_new['replace'])) {
- $newDestination = $old_new['replace'];
- }
- } else {
- $newDestination = str_replace('document/', '', $old_new['dest']);
- }
- $string = str_replace($old_new['orig'], $newDestination, $string);
- // Add files inside the HTMLs
- $new_path = str_replace(api_get_path(REL_COURSE_PATH), '', $old_new['orig']);
- $destinationFile = $archivePath.$temp_dir_short.'/'.$old_new['dest'];
- if (file_exists($sys_course_path.$new_path) && is_file($sys_course_path.$new_path)) {
- copy(
- $sys_course_path.$new_path,
- $destinationFile
- );
- }
- }
- file_put_contents($dest_file, $string);
- }
- if (file_exists($filePath) && $copyAll) {
- $extension = $this->get_extension($filePath);
- if (in_array($extension, ['html', 'html'])) {
- $containerOrigin = dirname($filePath);
- $containerDestination = dirname($dest_file);
- $finder = new Finder();
- $finder->files()->in($containerOrigin)
- ->notName('*_DELETED_*')
- ->exclude('share_folder')
- ->exclude('chat_files')
- ->exclude('certificates')
- ;
- if (is_dir($containerOrigin) &&
- is_dir($containerDestination)
- ) {
- $fs = new Filesystem();
- $fs->mirror(
- $containerOrigin,
- $containerDestination,
- $finder
- );
- }
- }
- }
- }
- foreach ($zip_files_abs as $file_path) {
- if (empty($file_path)) {
- continue;
- }
- if (!is_file($main_path.$file_path) || !is_readable($main_path.$file_path)) {
- continue;
- }
- $dest_file = $archivePath.$temp_dir_short.'/document/'.$file_path;
- if (strstr($file_path, 'upload/users') !== false) {
- $pos = strpos($file_path, 'my_files/');
- if ($pos !== false) {
- $onlyDirectory = str_replace(
- 'upload/users/',
- '',
- substr($file_path, $pos, strlen($file_path))
- );
- $dest_file = $archivePath.$temp_dir_short.'/document/'.$onlyDirectory;
- }
- }
- if (strstr($file_path, 'default_course_document/') !== false) {
- $replace = str_replace('/main', '', $file_path);
- $dest_file = $archivePath.$temp_dir_short.'/document/'.$replace;
- }
- if (empty($dest_file)) {
- continue;
- }
- $this->create_path($dest_file);
- copy($main_path.$file_path, $dest_file);
- // Check if the file needs a link update.
- if (in_array($file_path, array_keys($link_updates))) {
- $string = file_get_contents($dest_file);
- unlink($dest_file);
- foreach ($link_updates[$file_path] as $old_new) {
- // This is an ugly hack that allows .flv files to be found by the flv player that
- // will be added in document/main/inc/lib/flv_player/flv_player.swf and that needs
- // to find the flv to play in document/main/, so we replace main/ in the flv path by
- // ../../.. to return from inc/lib/flv_player to the document/main path.
- if (substr($old_new['dest'], -3) == 'flv' &&
- substr($old_new['dest'], 0, 5) == 'main/'
- ) {
- $old_new['dest'] = str_replace('main/', '../../../', $old_new['dest']);
- }
- $string = str_replace($old_new['orig'], $old_new['dest'], $string);
- }
- file_put_contents($dest_file, $string);
- }
- }
- if (is_array($links_to_create)) {
- foreach ($links_to_create as $file => $link) {
- $content = '<!DOCTYPE html><head>
- <meta charset="'.api_get_language_isocode().'" />
- <title>'.$link['title'].'</title>
- </head>
- <body dir="'.api_get_text_direction().'">
- <div style="text-align:center">
- <a href="'.$link['url'].'">'.$link['title'].'</a></div>
- </body>
- </html>';
- file_put_contents($archivePath.$temp_dir_short.'/'.$file, $content);
- }
- }
- // Add non exportable message explanation.
- $lang_not_exportable = get_lang('ThisItemIsNotExportable');
- $file_content = '<!DOCTYPE html><head>
- <meta charset="'.api_get_language_isocode().'" />
- <title>'.$lang_not_exportable.'</title>
- <meta http-equiv="Content-Type" content="text/html; charset='.api_get_system_encoding().'" />
- </head>
- <body dir="'.api_get_text_direction().'">';
- $file_content .=
- <<<EOD
- <style>
- .error-message {
- font-family: arial, verdana, helvetica, sans-serif;
- border-width: 1px;
- border-style: solid;
- left: 50%;
- margin: 10px auto;
- min-height: 30px;
- padding: 5px;
- right: 50%;
- width: 500px;
- background-color: #FFD1D1;
- border-color: #FF0000;
- color: #000;
- }
- </style>
- <body>
- <div class="error-message">
- $lang_not_exportable
- </div>
- </body>
- </html>
- EOD;
- if (!is_dir($archivePath.$temp_dir_short.'/document')) {
- @mkdir($archivePath.$temp_dir_short.'/document', api_get_permissions_for_new_directories());
- }
- file_put_contents($archivePath.$temp_dir_short.'/document/non_exportable.html', $file_content);
- // Add the extra files that go along with a SCORM package.
- $main_code_path = api_get_path(SYS_CODE_PATH).'lp/packaging/';
- $fs = new Filesystem();
- $fs->mirror($main_code_path, $archivePath.$temp_dir_short);
- // Finalize the imsmanifest structure, add to the zip, then return the zip.
- $manifest = @$xmldoc->saveXML();
- $manifest = api_utf8_decode_xml($manifest); // The manifest gets the system encoding now.
- file_put_contents($archivePath.'/'.$temp_dir_short.'/imsmanifest.xml', $manifest);
- $zip_folder->add(
- $archivePath.'/'.$temp_dir_short,
- PCLZIP_OPT_REMOVE_PATH,
- $archivePath.'/'.$temp_dir_short.'/'
- );
- // Clean possible temporary files.
- foreach ($files_cleanup as $file) {
- $res = unlink($file);
- if ($res === false) {
- error_log(
- 'Could not delete temp file '.$file.' '.__FILE__.' '.__LINE__,
- 0
- );
- }
- }
- $name = api_replace_dangerous_char($this->get_name()).'.zip';
- DocumentManager::file_send_for_download($temp_zip_file, true, $name);
- }
- /**
- * @param int $lp_id
- *
- * @return bool
- */
- public function scorm_export_to_pdf($lp_id)
- {
- $lp_id = (int) $lp_id;
- $files_to_export = [];
- $sessionId = api_get_session_id();
- $course_data = api_get_course_info($this->cc);
- if (!empty($course_data)) {
- $scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
- $list = self::get_flat_ordered_items_list($lp_id);
- if (!empty($list)) {
- foreach ($list as $item_id) {
- $item = $this->items[$item_id];
- switch ($item->type) {
- case 'document':
- // Getting documents from a LP with chamilo documents
- $file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
- // Try loading document from the base course.
- if (empty($file_data) && !empty($sessionId)) {
- $file_data = DocumentManager::get_document_data_by_id(
- $item->path,
- $this->cc,
- false,
- 0
- );
- }
- $file_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$file_data['path'];
- if (file_exists($file_path)) {
- $files_to_export[] = [
- 'title' => $item->get_title(),
- 'path' => $file_path,
- ];
- }
- break;
- case 'asset': //commes from a scorm package generated by chamilo
- case 'sco':
- $file_path = $scorm_path.'/'.$item->path;
- if (file_exists($file_path)) {
- $files_to_export[] = [
- 'title' => $item->get_title(),
- 'path' => $file_path,
- ];
- }
- break;
- case 'dir':
- $files_to_export[] = [
- 'title' => $item->get_title(),
- 'path' => null,
- ];
- break;
- }
- }
- }
- $pdf = new PDF();
- $result = $pdf->html_to_pdf(
- $files_to_export,
- $this->name,
- $this->cc,
- true,
- true,
- true,
- $this->get_name()
- );
- return $result;
- }
- return false;
- }
- /**
- * Temp function to be moved in main_api or the best place around for this.
- * Creates a file path if it doesn't exist.
- *
- * @param string $path
- */
- public function create_path($path)
- {
- $path_bits = explode('/', dirname($path));
- // IS_WINDOWS_OS has been defined in main_api.lib.php
- $path_built = IS_WINDOWS_OS ? '' : '/';
- foreach ($path_bits as $bit) {
- if (!empty($bit)) {
- $new_path = $path_built.$bit;
- if (is_dir($new_path)) {
- $path_built = $new_path.'/';
- } else {
- mkdir($new_path, api_get_permissions_for_new_directories());
- $path_built = $new_path.'/';
- }
- }
- }
- }
- /**
- * Delete the image relative to this learning path. No parameter. Only works on instanciated object.
- *
- * @return bool The results of the unlink function, or false if there was no image to start with
- */
- public function delete_lp_image()
- {
- $img = $this->get_preview_image();
- if ($img != '') {
- $del_file = $this->get_preview_image_path(null, 'sys');
- if (isset($del_file) && file_exists($del_file)) {
- $del_file_2 = $this->get_preview_image_path(64, 'sys');
- if (file_exists($del_file_2)) {
- unlink($del_file_2);
- }
- $this->set_preview_image('');
- return @unlink($del_file);
- }
- }
- return false;
- }
- /**
- * Uploads an author image to the upload/learning_path/images directory.
- *
- * @param array The image array, coming from the $_FILES superglobal
- *
- * @return bool True on success, false on error
- */
- public function upload_image($image_array)
- {
- if (!empty($image_array['name'])) {
- $upload_ok = process_uploaded_file($image_array);
- $has_attachment = true;
- }
- if ($upload_ok && $has_attachment) {
- $courseDir = api_get_course_path().'/upload/learning_path/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
- // Try to add an extension to the file if it hasn't one.
- $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
- if (filter_extension($new_file_name)) {
- $file_extension = explode('.', $image_array['name']);
- $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
- $filename = uniqid('');
- $new_file_name = $filename.'.'.$file_extension;
- $new_path = $updir.'/'.$new_file_name;
- // Resize the image.
- $temp = new Image($image_array['tmp_name']);
- $temp->resize(104);
- $result = $temp->send_image($new_path);
- // Storing the image filename.
- if ($result) {
- $this->set_preview_image($new_file_name);
- //Resize to 64px to use on course homepage
- $temp->resize(64);
- $temp->send_image($updir.'/'.$filename.'.64.'.$file_extension);
- return true;
- }
- }
- }
- return false;
- }
- /**
- * @param int $lp_id
- * @param string $status
- */
- public function set_autolaunch($lp_id, $status)
- {
- $course_id = api_get_course_int_id();
- $lp_id = (int) $lp_id;
- $status = (int) $status;
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- // Setting everything to autolaunch = 0
- $attributes['autolaunch'] = 0;
- $where = [
- 'session_id = ? AND c_id = ? ' => [
- api_get_session_id(),
- $course_id,
- ],
- ];
- Database::update($lp_table, $attributes, $where);
- if ($status == 1) {
- //Setting my lp_id to autolaunch = 1
- $attributes['autolaunch'] = 1;
- $where = [
- 'iid = ? AND session_id = ? AND c_id = ?' => [
- $lp_id,
- api_get_session_id(),
- $course_id,
- ],
- ];
- Database::update($lp_table, $attributes, $where);
- }
- }
- /**
- * Gets previous_item_id for the next element of the lp_item table.
- *
- * @author Isaac flores paz
- *
- * @return int Previous item ID
- */
- public function select_previous_item_id()
- {
- $course_id = api_get_course_int_id();
- $table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- // Get the max order of the items
- $sql = "SELECT max(display_order) AS display_order FROM $table_lp_item
- WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
- $rs_max_order = Database::query($sql);
- $row_max_order = Database::fetch_object($rs_max_order);
- $max_order = $row_max_order->display_order;
- // Get the previous item ID
- $sql = "SELECT iid as previous FROM $table_lp_item
- WHERE
- c_id = $course_id AND
- lp_id = ".$this->lp_id." AND
- display_order = '$max_order' ";
- $rs_max = Database::query($sql);
- $row_max = Database::fetch_object($rs_max);
- // Return the previous item ID
- return $row_max->previous;
- }
- /**
- * Copies an LP.
- */
- public function copy()
- {
- // Course builder
- $cb = new CourseBuilder();
- //Setting tools that will be copied
- $cb->set_tools_to_build(['learnpaths']);
- //Setting elements that will be copied
- $cb->set_tools_specific_id_list(
- ['learnpaths' => [$this->lp_id]]
- );
- $course = $cb->build();
- //Course restorer
- $course_restorer = new CourseRestorer($course);
- $course_restorer->set_add_text_in_items(true);
- $course_restorer->set_tool_copy_settings(
- ['learnpaths' => ['reset_dates' => true]]
- );
- $course_restorer->restore(
- api_get_course_id(),
- api_get_session_id(),
- false,
- false
- );
- }
- /**
- * Verify document size.
- *
- * @param string $s
- *
- * @return bool
- */
- public static function verify_document_size($s)
- {
- $post_max = ini_get('post_max_size');
- if (substr($post_max, -1, 1) == 'M') {
- $post_max = intval(substr($post_max, 0, -1)) * 1024 * 1024;
- } elseif (substr($post_max, -1, 1) == 'G') {
- $post_max = intval(substr($post_max, 0, -1)) * 1024 * 1024 * 1024;
- }
- $upl_max = ini_get('upload_max_filesize');
- if (substr($upl_max, -1, 1) == 'M') {
- $upl_max = intval(substr($upl_max, 0, -1)) * 1024 * 1024;
- } elseif (substr($upl_max, -1, 1) == 'G') {
- $upl_max = intval(substr($upl_max, 0, -1)) * 1024 * 1024 * 1024;
- }
- $documents_total_space = DocumentManager::documents_total_space();
- $course_max_space = DocumentManager::get_course_quota();
- $total_size = filesize($s) + $documents_total_space;
- if (filesize($s) > $post_max || filesize($s) > $upl_max || $total_size > $course_max_space) {
- return true;
- }
- return false;
- }
- /**
- * Clear LP prerequisites.
- */
- public function clear_prerequisites()
- {
- $course_id = $this->get_course_int_id();
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $lp_id = $this->get_id();
- // Cleaning prerequisites
- $sql = "UPDATE $tbl_lp_item SET prerequisite = ''
- WHERE c_id = $course_id AND lp_id = $lp_id";
- Database::query($sql);
- // Cleaning mastery score for exercises
- $sql = "UPDATE $tbl_lp_item SET mastery_score = ''
- WHERE c_id = $course_id AND lp_id = $lp_id AND item_type = 'quiz'";
- Database::query($sql);
- }
- public function set_previous_step_as_prerequisite_for_all_items()
- {
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $course_id = $this->get_course_int_id();
- $lp_id = $this->get_id();
- if (!empty($this->items)) {
- $previous_item_id = null;
- $previous_item_max = 0;
- $previous_item_type = null;
- $last_item_not_dir = null;
- $last_item_not_dir_type = null;
- $last_item_not_dir_max = null;
- foreach ($this->ordered_items as $itemId) {
- $item = $this->getItem($itemId);
- // if there was a previous item... (otherwise jump to set it)
- if (!empty($previous_item_id)) {
- $current_item_id = $item->get_id(); //save current id
- if ($item->get_type() != 'dir') {
- // Current item is not a folder, so it qualifies to get a prerequisites
- if ($last_item_not_dir_type == 'quiz') {
- // if previous is quiz, mark its max score as default score to be achieved
- $sql = "UPDATE $tbl_lp_item SET mastery_score = '$last_item_not_dir_max'
- WHERE c_id = $course_id AND lp_id = $lp_id AND iid = $last_item_not_dir";
- Database::query($sql);
- }
- // now simply update the prerequisite to set it to the last non-chapter item
- $sql = "UPDATE $tbl_lp_item SET prerequisite = '$last_item_not_dir'
- WHERE c_id = $course_id AND lp_id = $lp_id AND iid = $current_item_id";
- Database::query($sql);
- // record item as 'non-chapter' reference
- $last_item_not_dir = $item->get_id();
- $last_item_not_dir_type = $item->get_type();
- $last_item_not_dir_max = $item->get_max();
- }
- } else {
- if ($item->get_type() != 'dir') {
- // Current item is not a folder (but it is the first item) so record as last "non-chapter" item
- $last_item_not_dir = $item->get_id();
- $last_item_not_dir_type = $item->get_type();
- $last_item_not_dir_max = $item->get_max();
- }
- }
- // Saving the item as "previous item" for the next loop
- $previous_item_id = $item->get_id();
- $previous_item_max = $item->get_max();
- $previous_item_type = $item->get_type();
- }
- }
- }
- /**
- * @param array $params
- *
- * @throws \Doctrine\ORM\OptimisticLockException
- *
- * @return int
- */
- public static function createCategory($params)
- {
- $em = Database::getManager();
- $item = new CLpCategory();
- $item->setName($params['name']);
- $item->setCId($params['c_id']);
- $em->persist($item);
- $em->flush();
- api_item_property_update(
- api_get_course_info(),
- TOOL_LEARNPATH_CATEGORY,
- $item->getId(),
- 'visible',
- api_get_user_id()
- );
- return $item->getId();
- }
- /**
- * @param array $params
- *
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- */
- public static function updateCategory($params)
- {
- $em = Database::getManager();
- /** @var CLpCategory $item */
- $item = $em->find('ChamiloCourseBundle:CLpCategory', $params['id']);
- if ($item) {
- $item->setName($params['name']);
- $em->merge($item);
- $em->flush();
- }
- }
- /**
- * @param int $id
- *
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- */
- public static function moveUpCategory($id)
- {
- $id = (int) $id;
- $em = Database::getManager();
- /** @var CLpCategory $item */
- $item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
- if ($item) {
- $position = $item->getPosition() - 1;
- $item->setPosition($position);
- $em->persist($item);
- $em->flush();
- }
- }
- /**
- * @param int $id
- *
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- */
- public static function moveDownCategory($id)
- {
- $id = (int) $id;
- $em = Database::getManager();
- /** @var CLpCategory $item */
- $item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
- if ($item) {
- $position = $item->getPosition() + 1;
- $item->setPosition($position);
- $em->persist($item);
- $em->flush();
- }
- }
- /**
- * @param int $courseId
- *
- * @throws \Doctrine\ORM\Query\QueryException
- *
- * @return int|mixed
- */
- public static function getCountCategories($courseId)
- {
- if (empty($courseId)) {
- return 0;
- }
- $em = Database::getManager();
- $query = $em->createQuery('SELECT COUNT(u.id) FROM ChamiloCourseBundle:CLpCategory u WHERE u.cId = :id');
- $query->setParameter('id', $courseId);
- return $query->getSingleScalarResult();
- }
- /**
- * @param int $courseId
- *
- * @return mixed
- */
- public static function getCategories($courseId)
- {
- $em = Database::getManager();
- // Using doctrine extensions
- /** @var SortableRepository $repo */
- $repo = $em->getRepository('ChamiloCourseBundle:CLpCategory');
- $items = $repo
- ->getBySortableGroupsQuery(['cId' => $courseId])
- ->getResult();
- return $items;
- }
- /**
- * @param int $id
- *
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- *
- * @return CLpCategory
- */
- public static function getCategory($id)
- {
- $id = (int) $id;
- $em = Database::getManager();
- $item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
- return $item;
- }
- /**
- * @param int $courseId
- *
- * @return array
- */
- public static function getCategoryByCourse($courseId)
- {
- $em = Database::getManager();
- $items = $em->getRepository('ChamiloCourseBundle:CLpCategory')->findBy(
- ['cId' => $courseId]
- );
- return $items;
- }
- /**
- * @param int $id
- *
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
- * @throws \Doctrine\ORM\TransactionRequiredException
- *
- * @return mixed
- */
- public static function deleteCategory($id)
- {
- $em = Database::getManager();
- $item = $em->find('ChamiloCourseBundle:CLpCategory', $id);
- if ($item) {
- $courseId = $item->getCId();
- $query = $em->createQuery('SELECT u FROM ChamiloCourseBundle:CLp u WHERE u.cId = :id AND u.categoryId = :catId');
- $query->setParameter('id', $courseId);
- $query->setParameter('catId', $item->getId());
- $lps = $query->getResult();
- // Setting category = 0.
- if ($lps) {
- foreach ($lps as $lpItem) {
- $lpItem->setCategoryId(0);
- }
- }
- // Removing category.
- $em->remove($item);
- $em->flush();
- $courseInfo = api_get_course_info_by_id($courseId);
- $sessionId = api_get_session_id();
- // Delete link tool
- $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
- $link = 'lp/lp_controller.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId.'&gidReq=0&gradebook=0&origin=&action=view_category&id='.$id;
- // Delete tools
- $sql = "DELETE FROM $tbl_tool
- WHERE c_id = ".$courseId." AND (link LIKE '$link%' AND image='lp_category.gif')";
- Database::query($sql);
- return true;
- }
- return false;
- }
- /**
- * @param int $courseId
- * @param bool $addSelectOption
- *
- * @return mixed
- */
- public static function getCategoryFromCourseIntoSelect($courseId, $addSelectOption = false)
- {
- $items = self::getCategoryByCourse($courseId);
- $cats = [];
- if ($addSelectOption) {
- $cats = [get_lang('SelectACategory')];
- }
- if (!empty($items)) {
- foreach ($items as $cat) {
- $cats[$cat->getId()] = $cat->getName();
- }
- }
- return $cats;
- }
- /**
- * @param string $courseCode
- * @param int $lpId
- * @param int $user_id
- *
- * @return learnpath
- */
- public static function getLpFromSession($courseCode, $lpId, $user_id)
- {
- $debug = 0;
- $learnPath = null;
- $lpObject = Session::read('lpobject');
- if ($lpObject !== null) {
- $learnPath = UnserializeApi::unserialize('lp', $lpObject);
- if ($debug) {
- error_log('getLpFromSession: unserialize');
- error_log('------getLpFromSession------');
- error_log('------unserialize------');
- error_log("lp_view_session_id: ".$learnPath->lp_view_session_id);
- error_log("api_get_sessionid: ".api_get_session_id());
- }
- }
- if (!is_object($learnPath)) {
- $learnPath = new learnpath($courseCode, $lpId, $user_id);
- if ($debug) {
- error_log('------getLpFromSession------');
- error_log('getLpFromSession: create new learnpath');
- error_log("create new LP with $courseCode - $lpId - $user_id");
- error_log("lp_view_session_id: ".$learnPath->lp_view_session_id);
- error_log("api_get_sessionid: ".api_get_session_id());
- }
- }
- return $learnPath;
- }
- /**
- * @param int $itemId
- *
- * @return learnpathItem|false
- */
- public function getItem($itemId)
- {
- if (isset($this->items[$itemId]) && is_object($this->items[$itemId])) {
- return $this->items[$itemId];
- }
- return false;
- }
- /**
- * @return int
- */
- public function getCurrentAttempt()
- {
- $attempt = $this->getItem($this->get_current_item_id());
- if ($attempt) {
- $attemptId = $attempt->get_attempt_id();
- return $attemptId;
- }
- return 0;
- }
- /**
- * @return int
- */
- public function getCategoryId()
- {
- return (int) $this->categoryId;
- }
- /**
- * @param int $categoryId
- *
- * @return bool
- */
- public function setCategoryId($categoryId)
- {
- $this->categoryId = (int) $categoryId;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET category_id = ".$this->categoryId."
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Get whether this is a learning path with the possibility to subscribe
- * users or not.
- *
- * @return int
- */
- public function getSubscribeUsers()
- {
- return $this->subscribeUsers;
- }
- /**
- * Set whether this is a learning path with the possibility to subscribe
- * users or not.
- *
- * @param int $value (0 = false, 1 = true)
- *
- * @return bool
- */
- public function setSubscribeUsers($value)
- {
- $this->subscribeUsers = (int) $value;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET subscribe_users = ".$this->subscribeUsers."
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Calculate the count of stars for a user in this LP
- * This calculation is based on the following rules:
- * - the student gets one star when he gets to 50% of the learning path
- * - the student gets a second star when the average score of all tests inside the learning path >= 50%
- * - the student gets a third star when the average score of all tests inside the learning path >= 80%
- * - the student gets the final star when the score for the *last* test is >= 80%.
- *
- * @param int $sessionId Optional. The session ID
- *
- * @return int The count of stars
- */
- public function getCalculateStars($sessionId = 0)
- {
- $stars = 0;
- $progress = self::getProgress(
- $this->lp_id,
- $this->user_id,
- $this->course_int_id,
- $sessionId
- );
- if ($progress >= 50) {
- $stars++;
- }
- // Calculate stars chapters evaluation
- $exercisesItems = $this->getExercisesItems();
- if (!empty($exercisesItems)) {
- $totalResult = 0;
- foreach ($exercisesItems as $exerciseItem) {
- $exerciseResultInfo = Event::getExerciseResultsByUser(
- $this->user_id,
- $exerciseItem->path,
- $this->course_int_id,
- $sessionId,
- $this->lp_id,
- $exerciseItem->db_id
- );
- $exerciseResultInfo = end($exerciseResultInfo);
- if (!$exerciseResultInfo) {
- continue;
- }
- if (!empty($exerciseResultInfo['exe_weighting'])) {
- $exerciseResult = $exerciseResultInfo['exe_result'] * 100 / $exerciseResultInfo['exe_weighting'];
- } else {
- $exerciseResult = 0;
- }
- $totalResult += $exerciseResult;
- }
- $totalExerciseAverage = $totalResult / (count($exercisesItems) > 0 ? count($exercisesItems) : 1);
- if ($totalExerciseAverage >= 50) {
- $stars++;
- }
- if ($totalExerciseAverage >= 80) {
- $stars++;
- }
- }
- // Calculate star for final evaluation
- $finalEvaluationItem = $this->getFinalEvaluationItem();
- if (!empty($finalEvaluationItem)) {
- $evaluationResultInfo = Event::getExerciseResultsByUser(
- $this->user_id,
- $finalEvaluationItem->path,
- $this->course_int_id,
- $sessionId,
- $this->lp_id,
- $finalEvaluationItem->db_id
- );
- $evaluationResultInfo = end($evaluationResultInfo);
- if ($evaluationResultInfo) {
- $evaluationResult = $evaluationResultInfo['exe_result'] * 100 / $evaluationResultInfo['exe_weighting'];
- if ($evaluationResult >= 80) {
- $stars++;
- }
- }
- }
- return $stars;
- }
- /**
- * Get the items of exercise type.
- *
- * @return array The items. Otherwise return false
- */
- public function getExercisesItems()
- {
- $exercises = [];
- foreach ($this->items as $item) {
- if ($item->type != 'quiz') {
- continue;
- }
- $exercises[] = $item;
- }
- array_pop($exercises);
- return $exercises;
- }
- /**
- * Get the item of exercise type (evaluation type).
- *
- * @return array The final evaluation. Otherwise return false
- */
- public function getFinalEvaluationItem()
- {
- $exercises = [];
- foreach ($this->items as $item) {
- if ($item->type != 'quiz') {
- continue;
- }
- $exercises[] = $item;
- }
- return array_pop($exercises);
- }
- /**
- * Calculate the total points achieved for the current user in this learning path.
- *
- * @param int $sessionId Optional. The session Id
- *
- * @return int
- */
- public function getCalculateScore($sessionId = 0)
- {
- // Calculate stars chapters evaluation
- $exercisesItems = $this->getExercisesItems();
- $finalEvaluationItem = $this->getFinalEvaluationItem();
- $totalExercisesResult = 0;
- $totalEvaluationResult = 0;
- if ($exercisesItems !== false) {
- foreach ($exercisesItems as $exerciseItem) {
- $exerciseResultInfo = Event::getExerciseResultsByUser(
- $this->user_id,
- $exerciseItem->path,
- $this->course_int_id,
- $sessionId,
- $this->lp_id,
- $exerciseItem->db_id
- );
- $exerciseResultInfo = end($exerciseResultInfo);
- if (!$exerciseResultInfo) {
- continue;
- }
- $totalExercisesResult += $exerciseResultInfo['exe_result'];
- }
- }
- if (!empty($finalEvaluationItem)) {
- $evaluationResultInfo = Event::getExerciseResultsByUser(
- $this->user_id,
- $finalEvaluationItem->path,
- $this->course_int_id,
- $sessionId,
- $this->lp_id,
- $finalEvaluationItem->db_id
- );
- $evaluationResultInfo = end($evaluationResultInfo);
- if ($evaluationResultInfo) {
- $totalEvaluationResult += $evaluationResultInfo['exe_result'];
- }
- }
- return $totalExercisesResult + $totalEvaluationResult;
- }
- /**
- * Check if URL is not allowed to be show in a iframe.
- *
- * @param string $src
- *
- * @return string
- */
- public function fixBlockedLinks($src)
- {
- $urlInfo = parse_url($src);
- $platformProtocol = 'https';
- if (strpos(api_get_path(WEB_CODE_PATH), 'https') === false) {
- $platformProtocol = 'http';
- }
- $protocolFixApplied = false;
- //Scheme validation to avoid "Notices" when the lesson doesn't contain a valid scheme
- $scheme = isset($urlInfo['scheme']) ? $urlInfo['scheme'] : null;
- $host = isset($urlInfo['host']) ? $urlInfo['host'] : null;
- if ($platformProtocol != $scheme) {
- Session::write('x_frame_source', $src);
- $src = 'blank.php?error=x_frames_options';
- $protocolFixApplied = true;
- }
- if ($protocolFixApplied == false) {
- if (strpos(api_get_path(WEB_PATH), $host) === false) {
- // Check X-Frame-Options
- $ch = curl_init();
- $options = [
- CURLOPT_URL => $src,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HEADER => true,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_ENCODING => "",
- CURLOPT_AUTOREFERER => true,
- CURLOPT_CONNECTTIMEOUT => 120,
- CURLOPT_TIMEOUT => 120,
- CURLOPT_MAXREDIRS => 10,
- ];
- $proxySettings = api_get_configuration_value('proxy_settings');
- if (!empty($proxySettings) &&
- isset($proxySettings['curl_setopt_array'])
- ) {
- $options[CURLOPT_PROXY] = $proxySettings['curl_setopt_array']['CURLOPT_PROXY'];
- $options[CURLOPT_PROXYPORT] = $proxySettings['curl_setopt_array']['CURLOPT_PROXYPORT'];
- }
- curl_setopt_array($ch, $options);
- $response = curl_exec($ch);
- $httpCode = curl_getinfo($ch);
- $headers = substr($response, 0, $httpCode['header_size']);
- $error = false;
- if (stripos($headers, 'X-Frame-Options: DENY') > -1
- //|| stripos($headers, 'X-Frame-Options: SAMEORIGIN') > -1
- ) {
- $error = true;
- }
- if ($error) {
- Session::write('x_frame_source', $src);
- $src = 'blank.php?error=x_frames_options';
- }
- }
- }
- return $src;
- }
- /**
- * Check if this LP has a created forum in the basis course.
- *
- * @return bool
- */
- public function lpHasForum()
- {
- $forumTable = Database::get_course_table(TABLE_FORUM);
- $itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $fakeFrom = "
- $forumTable f
- INNER JOIN $itemProperty ip
- ON (f.forum_id = ip.ref AND f.c_id = ip.c_id)
- ";
- $resultData = Database::select(
- 'COUNT(f.iid) AS qty',
- $fakeFrom,
- [
- 'where' => [
- 'ip.visibility != ? AND ' => 2,
- 'ip.tool = ? AND ' => TOOL_FORUM,
- 'f.c_id = ? AND ' => intval($this->course_int_id),
- 'f.lp_id = ?' => intval($this->lp_id),
- ],
- ],
- 'first'
- );
- return $resultData['qty'] > 0;
- }
- /**
- * Get the forum for this learning path.
- *
- * @param int $sessionId
- *
- * @return bool
- */
- public function getForum($sessionId = 0)
- {
- $forumTable = Database::get_course_table(TABLE_FORUM);
- $itemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $fakeFrom = "$forumTable f
- INNER JOIN $itemProperty ip ";
- if ($this->lp_session_id == 0) {
- $fakeFrom .= "
- ON (
- f.forum_id = ip.ref AND f.c_id = ip.c_id AND (
- f.session_id = ip.session_id OR ip.session_id IS NULL
- )
- )
- ";
- } else {
- $fakeFrom .= "
- ON (
- f.forum_id = ip.ref AND f.c_id = ip.c_id AND f.session_id = ip.session_id
- )
- ";
- }
- $resultData = Database::select(
- 'f.*',
- $fakeFrom,
- [
- 'where' => [
- 'ip.visibility != ? AND ' => 2,
- 'ip.tool = ? AND ' => TOOL_FORUM,
- 'f.session_id = ? AND ' => $sessionId,
- 'f.c_id = ? AND ' => intval($this->course_int_id),
- 'f.lp_id = ?' => intval($this->lp_id),
- ],
- ],
- 'first'
- );
- if (empty($resultData)) {
- return false;
- }
- return $resultData;
- }
- /**
- * Create a forum for this learning path.
- *
- * @param int $forumCategoryId
- *
- * @return int The forum ID if was created. Otherwise return false
- */
- public function createForum($forumCategoryId)
- {
- require_once api_get_path(SYS_CODE_PATH).'/forum/forumfunction.inc.php';
- $forumId = store_forum(
- [
- 'lp_id' => $this->lp_id,
- 'forum_title' => $this->name,
- 'forum_comment' => null,
- 'forum_category' => (int) $forumCategoryId,
- 'students_can_edit_group' => ['students_can_edit' => 0],
- 'allow_new_threads_group' => ['allow_new_threads' => 0],
- 'default_view_type_group' => ['default_view_type' => 'flat'],
- 'group_forum' => 0,
- 'public_private_group_forum_group' => ['public_private_group_forum' => 'public'],
- ],
- [],
- true
- );
- return $forumId;
- }
- /**
- * Get the LP Final Item form.
- *
- * @throws Exception
- * @throws HTML_QuickForm_Error
- *
- * @return string
- */
- public function getFinalItemForm()
- {
- $finalItem = $this->getFinalItem();
- $title = '';
- if ($finalItem) {
- $title = $finalItem->get_title();
- $buttonText = get_lang('Save');
- $content = $this->getSavedFinalItem();
- } else {
- $buttonText = get_lang('LPCreateDocument');
- $content = $this->getFinalItemTemplate();
- }
- $courseInfo = api_get_course_info();
- $result = $this->generate_lp_folder($courseInfo);
- $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
- $relative_prefix = '../../';
- $editorConfig = [
- 'ToolbarSet' => 'LearningPathDocuments',
- 'Width' => '100%',
- 'Height' => '500',
- 'FullPage' => true,
- 'CreateDocumentDir' => $relative_prefix,
- 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
- 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/'.$relative_path,
- ];
- $url = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
- 'type' => 'document',
- 'lp_id' => $this->lp_id,
- ]);
- $form = new FormValidator('final_item', 'POST', $url);
- $form->addText('title', get_lang('Title'));
- $form->addButtonSave($buttonText);
- $form->addHtml(
- Display::return_message(
- 'Variables :</br></br> <b>((certificate))</b> </br> <b>((skill))</b>',
- 'normal',
- false
- )
- );
- $renderer = $form->defaultRenderer();
- $renderer->setElementTemplate(' {label}{element}', 'content_lp_certificate');
- $form->addHtmlEditor(
- 'content_lp_certificate',
- null,
- true,
- false,
- $editorConfig,
- true
- );
- $form->addHidden('action', 'add_final_item');
- $form->addHidden('path', Session::read('pathItem'));
- $form->addHidden('previous', $this->get_last());
- $form->setDefaults(
- ['title' => $title, 'content_lp_certificate' => $content]
- );
- if ($form->validate()) {
- $values = $form->exportValues();
- $lastItemId = $this->getLastInFirstLevel();
- if (!$finalItem) {
- $documentId = $this->create_document(
- $this->course_info,
- $values['content_lp_certificate'],
- $values['title']
- );
- $this->add_item(
- 0,
- $lastItemId,
- 'final_item',
- $documentId,
- $values['title'],
- ''
- );
- Display::addFlash(
- Display::return_message(get_lang('Added'))
- );
- } else {
- $this->edit_document($this->course_info);
- }
- }
- return $form->returnForm();
- }
- /**
- * Check if the current lp item is first, both, last or none from lp list.
- *
- * @param int $currentItemId
- *
- * @return string
- */
- public function isFirstOrLastItem($currentItemId)
- {
- $lpItemId = [];
- $typeListNotToVerify = self::getChapterTypes();
- // Using get_toc() function instead $this->items because returns the correct order of the items
- foreach ($this->get_toc() as $item) {
- if (!in_array($item['type'], $typeListNotToVerify)) {
- $lpItemId[] = $item['id'];
- }
- }
- $lastLpItemIndex = count($lpItemId) - 1;
- $position = array_search($currentItemId, $lpItemId);
- switch ($position) {
- case 0:
- if (!$lastLpItemIndex) {
- $answer = 'both';
- break;
- }
- $answer = 'first';
- break;
- case $lastLpItemIndex:
- $answer = 'last';
- break;
- default:
- $answer = 'none';
- }
- return $answer;
- }
- /**
- * Get whether this is a learning path with the accumulated SCORM time or not.
- *
- * @return int
- */
- public function getAccumulateScormTime()
- {
- return $this->accumulateScormTime;
- }
- /**
- * Set whether this is a learning path with the accumulated SCORM time or not.
- *
- * @param int $value (0 = false, 1 = true)
- *
- * @return bool Always returns true
- */
- public function setAccumulateScormTime($value)
- {
- $this->accumulateScormTime = (int) $value;
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $lp_table
- SET accumulate_scorm_time = ".$this->accumulateScormTime."
- WHERE iid = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * Returns an HTML-formatted link to a resource, to incorporate directly into
- * the new learning path tool.
- *
- * The function is a big switch on tool type.
- * In each case, we query the corresponding table for information and build the link
- * with that information.
- *
- * @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on
- * previous work (display_addedresource_link_in_learnpath())
- *
- * @param int $course_id Course code
- * @param int $learningPathId The learning path ID (in lp table)
- * @param int $id_in_path the unique index in the items table
- * @param int $lpViewId
- *
- * @return string
- */
- public static function rl_get_resource_link_for_learnpath(
- $course_id,
- $learningPathId,
- $id_in_path,
- $lpViewId
- ) {
- $session_id = api_get_session_id();
- $course_info = api_get_course_info_by_id($course_id);
- $learningPathId = (int) $learningPathId;
- $id_in_path = (int) $id_in_path;
- $lpViewId = (int) $lpViewId;
- $em = Database::getManager();
- $lpItemRepo = $em->getRepository('ChamiloCourseBundle:CLpItem');
- /** @var CLpItem $rowItem */
- $rowItem = $lpItemRepo->findOneBy([
- 'cId' => $course_id,
- 'lpId' => $learningPathId,
- 'iid' => $id_in_path,
- ]);
- if (!$rowItem) {
- // Try one more time with "id"
- /** @var CLpItem $rowItem */
- $rowItem = $lpItemRepo->findOneBy([
- 'cId' => $course_id,
- 'lpId' => $learningPathId,
- 'id' => $id_in_path,
- ]);
- if (!$rowItem) {
- return -1;
- }
- }
- $course_code = $course_info['code'];
- $type = $rowItem->getItemType();
- $id = empty($rowItem->getPath()) ? '0' : $rowItem->getPath();
- $main_dir_path = api_get_path(WEB_CODE_PATH);
- $main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
- $link = '';
- $extraParams = api_get_cidreq(true, true, 'learnpath').'&session_id='.$session_id;
- switch ($type) {
- case 'dir':
- return $main_dir_path.'lp/blank.php';
- case TOOL_CALENDAR_EVENT:
- return $main_dir_path.'calendar/agenda.php?agenda_id='.$id.'&'.$extraParams;
- case TOOL_ANNOUNCEMENT:
- return $main_dir_path.'announcements/announcements.php?ann_id='.$id.'&'.$extraParams;
- case TOOL_LINK:
- $linkInfo = Link::getLinkInfo($id);
- if (isset($linkInfo['url'])) {
- return $linkInfo['url'];
- }
- return '';
- case TOOL_QUIZ:
- if (empty($id)) {
- return '';
- }
- // Get the lp_item_view with the highest view_count.
- $learnpathItemViewResult = $em
- ->getRepository('ChamiloCourseBundle:CLpItemView')
- ->findBy(
- ['cId' => $course_id, 'lpItemId' => $rowItem->getId(), 'lpViewId' => $lpViewId],
- ['viewCount' => 'DESC'],
- 1
- );
- /** @var CLpItemView $learnpathItemViewData */
- $learnpathItemViewData = current($learnpathItemViewResult);
- $learnpathItemViewId = $learnpathItemViewData ? $learnpathItemViewData->getId() : 0;
- return $main_dir_path.'exercise/overview.php?'.$extraParams.'&'
- .http_build_query([
- 'lp_init' => 1,
- 'learnpath_item_view_id' => $learnpathItemViewId,
- 'learnpath_id' => $learningPathId,
- 'learnpath_item_id' => $id_in_path,
- 'exerciseId' => $id,
- ]);
- case TOOL_HOTPOTATOES: //lowercase because of strtolower above
- $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
- $result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND iid=$id");
- $myrow = Database::fetch_array($result);
- $path = $myrow['path'];
- return $main_dir_path.'exercise/showinframes.php?file='.$path.'&cid='.$course_code.'&uid='
- .api_get_user_id().'&learnpath_id='.$learningPathId.'&learnpath_item_id='.$id_in_path
- .'&lp_view_id='.$lpViewId.'&'.$extraParams;
- case TOOL_FORUM:
- return $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&'.$extraParams;
- case TOOL_THREAD:
- // forum post
- $tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD);
- if (empty($id)) {
- return '';
- }
- $sql = "SELECT * FROM $tbl_topics WHERE c_id = $course_id AND thread_id=$id";
- $result = Database::query($sql);
- $myrow = Database::fetch_array($result);
- return $main_dir_path.'forum/viewthread.php?thread='.$id.'&forum='.$myrow['forum_id'].'&lp=true&'
- .$extraParams;
- case TOOL_POST:
- $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
- $result = Database::query("SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=$id");
- $myrow = Database::fetch_array($result);
- return $main_dir_path.'forum/viewthread.php?post='.$id.'&thread='.$myrow['thread_id'].'&forum='
- .$myrow['forum_id'].'&lp=true&'.$extraParams;
- case TOOL_READOUT_TEXT:
- return api_get_path(WEB_CODE_PATH).
- 'lp/readout_text.php?&id='.$id.'&lp_id='.$learningPathId.'&'.$extraParams;
- case TOOL_DOCUMENT:
- $repo = $em->getRepository('ChamiloCourseBundle:CDocument');
- $document = $repo->findOneBy(['cId' => $course_id, 'iid' => $id]);
- if (empty($document)) {
- // Try with normal id
- $document = $repo->findOneBy(['cId' => $course_id, 'id' => $id]);
- if (empty($document)) {
- return '';
- }
- }
- $documentPathInfo = pathinfo($document->getPath());
- $mediaSupportedFiles = ['mp3', 'mp4', 'ogv', 'flv', 'm4v'];
- $extension = isset($documentPathInfo['extension']) ? $documentPathInfo['extension'] : '';
- $showDirectUrl = !in_array($extension, $mediaSupportedFiles);
- $openmethod = 2;
- $officedoc = false;
- Session::write('openmethod', $openmethod);
- Session::write('officedoc', $officedoc);
- if ($showDirectUrl) {
- $file = $main_course_path.'document'.$document->getPath().'?'.$extraParams;
- if (api_get_configuration_value('allow_pdf_viewerjs_in_lp')) {
- if (Link::isPdfLink($file)) {
- $pdfUrl = api_get_path(WEB_LIBRARY_PATH).'javascript/ViewerJS/index.html#'.$file;
- return $pdfUrl;
- }
- }
- return $file;
- }
- return api_get_path(WEB_CODE_PATH).'document/showinframes.php?id='.$id.'&'.$extraParams;
- case TOOL_LP_FINAL_ITEM:
- return api_get_path(WEB_CODE_PATH).'lp/lp_final_item.php?&id='.$id.'&lp_id='.$learningPathId.'&'
- .$extraParams;
- case 'assignments':
- return $main_dir_path.'work/work.php?'.$extraParams;
- case TOOL_DROPBOX:
- return $main_dir_path.'dropbox/index.php?'.$extraParams;
- case 'introduction_text': //DEPRECATED
- return '';
- case TOOL_COURSE_DESCRIPTION:
- return $main_dir_path.'course_description?'.$extraParams;
- case TOOL_GROUP:
- return $main_dir_path.'group/group.php?'.$extraParams;
- case TOOL_USER:
- return $main_dir_path.'user/user.php?'.$extraParams;
- case TOOL_STUDENTPUBLICATION:
- if (!empty($rowItem->getPath())) {
- return $main_dir_path.'work/work_list.php?id='.$rowItem->getPath().'&'.$extraParams;
- }
- return $main_dir_path.'work/work.php?'.api_get_cidreq().'&id='.$rowItem->getPath().'&'.$extraParams;
- }
- return $link;
- }
- /**
- * Gets the name of a resource (generally used in learnpath when no name is provided).
- *
- * @author Yannick Warnier <ywarnier@beeznest.org>
- *
- * @param string $course_code Course code
- * @param int $learningPathId
- * @param int $id_in_path The resource ID
- *
- * @return string
- */
- public static function rl_get_resource_name($course_code, $learningPathId, $id_in_path)
- {
- $_course = api_get_course_info($course_code);
- if (empty($_course)) {
- return '';
- }
- $course_id = $_course['real_id'];
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $learningPathId = (int) $learningPathId;
- $id_in_path = (int) $id_in_path;
- $sql = "SELECT item_type, title, ref
- FROM $tbl_lp_item
- WHERE c_id = $course_id AND lp_id = $learningPathId AND iid = $id_in_path";
- $res_item = Database::query($sql);
- if (Database::num_rows($res_item) < 1) {
- return '';
- }
- $row_item = Database::fetch_array($res_item);
- $type = strtolower($row_item['item_type']);
- $id = $row_item['ref'];
- $output = '';
- switch ($type) {
- case TOOL_CALENDAR_EVENT:
- $TABLEAGENDA = Database::get_course_table(TABLE_AGENDA);
- $result = Database::query("SELECT * FROM $TABLEAGENDA WHERE c_id = $course_id AND id=$id");
- $myrow = Database::fetch_array($result);
- $output = $myrow['title'];
- break;
- case TOOL_ANNOUNCEMENT:
- $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
- $result = Database::query("SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id=$id");
- $myrow = Database::fetch_array($result);
- $output = $myrow['title'];
- break;
- case TOOL_LINK:
- // Doesn't take $target into account.
- $TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
- $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$id");
- $myrow = Database::fetch_array($result);
- $output = $myrow['title'];
- break;
- case TOOL_QUIZ:
- $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
- $result = Database::query("SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id = $id");
- $myrow = Database::fetch_array($result);
- $output = $myrow['title'];
- break;
- case TOOL_FORUM:
- $TBL_FORUMS = Database::get_course_table(TABLE_FORUM);
- $result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id = $id");
- $myrow = Database::fetch_array($result);
- $output = $myrow['forum_name'];
- break;
- case TOOL_THREAD:
- $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
- // Grabbing the title of the post.
- $sql_title = "SELECT * FROM $tbl_post WHERE c_id = $course_id AND post_id=".$id;
- $result_title = Database::query($sql_title);
- $myrow_title = Database::fetch_array($result_title);
- $output = $myrow_title['post_title'];
- break;
- case TOOL_POST:
- $tbl_post = Database::get_course_table(TABLE_FORUM_POST);
- $sql = "SELECT * FROM $tbl_post p WHERE c_id = $course_id AND p.post_id = $id";
- $result = Database::query($sql);
- $post = Database::fetch_array($result);
- $output = $post['post_title'];
- break;
- case 'dir':
- case TOOL_DOCUMENT:
- $title = $row_item['title'];
- $output = '-';
- if (!empty($title)) {
- $output = $title;
- }
- break;
- case 'hotpotatoes':
- $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
- $result = Database::query("SELECT * FROM $tbl_doc WHERE c_id = $course_id AND iid = $id");
- $myrow = Database::fetch_array($result);
- $pathname = explode('/', $myrow['path']); // Making a correct name for the link.
- $last = count($pathname) - 1; // Making a correct name for the link.
- $filename = $pathname[$last]; // Making a correct name for the link.
- $myrow['path'] = rawurlencode($myrow['path']);
- $output = $filename;
- break;
- }
- return stripslashes($output);
- }
- /**
- * Get the parent names for the current item.
- *
- * @param int $newItemId Optional. The item ID
- *
- * @return array
- */
- public function getCurrentItemParentNames($newItemId = 0)
- {
- $newItemId = $newItemId ?: $this->get_current_item_id();
- $return = [];
- $item = $this->getItem($newItemId);
- $parent = $this->getItem($item->get_parent());
- while ($parent) {
- $return[] = $parent->get_title();
- $parent = $this->getItem($parent->get_parent());
- }
- return array_reverse($return);
- }
- /**
- * Reads and process "lp_subscription_settings" setting.
- *
- * @return array
- */
- public static function getSubscriptionSettings()
- {
- $subscriptionSettings = api_get_configuration_value('lp_subscription_settings');
- if (empty($subscriptionSettings)) {
- // By default allow both settings
- $subscriptionSettings = [
- 'allow_add_users_to_lp' => true,
- 'allow_add_users_to_lp_category' => true,
- ];
- } else {
- $subscriptionSettings = $subscriptionSettings['options'];
- }
- return $subscriptionSettings;
- }
- /**
- * Exports a LP to a courseBuilder zip file. It adds the documents related to the LP.
- */
- public function exportToCourseBuildFormat()
- {
- if (!api_is_allowed_to_edit()) {
- return false;
- }
- $courseBuilder = new CourseBuilder();
- $itemList = [];
- /** @var learnpathItem $item */
- foreach ($this->items as $item) {
- $itemList[$item->get_type()][] = $item->get_path();
- }
- if (empty($itemList)) {
- return false;
- }
- if (isset($itemList['document'])) {
- // Get parents
- foreach ($itemList['document'] as $documentId) {
- $documentInfo = DocumentManager::get_document_data_by_id($documentId, api_get_course_id(), true);
- if (!empty($documentInfo['parents'])) {
- foreach ($documentInfo['parents'] as $parentInfo) {
- if (in_array($parentInfo['iid'], $itemList['document'])) {
- continue;
- }
- $itemList['document'][] = $parentInfo['iid'];
- }
- }
- }
- $courseInfo = api_get_course_info();
- foreach ($itemList['document'] as $documentId) {
- $documentInfo = DocumentManager::get_document_data_by_id($documentId, api_get_course_id());
- $items = DocumentManager::get_resources_from_source_html(
- $documentInfo['absolute_path'],
- true,
- TOOL_DOCUMENT
- );
- if (!empty($items)) {
- foreach ($items as $item) {
- // Get information about source url
- $url = $item[0]; // url
- $scope = $item[1]; // scope (local, remote)
- $type = $item[2]; // type (rel, abs, url)
- $origParseUrl = parse_url($url);
- $realOrigPath = isset($origParseUrl['path']) ? $origParseUrl['path'] : null;
- if ($scope == 'local') {
- if ($type == 'abs' || $type == 'rel') {
- $documentFile = strstr($realOrigPath, 'document');
- if (strpos($realOrigPath, $documentFile) !== false) {
- $documentFile = str_replace('document', '', $documentFile);
- $itemDocumentId = DocumentManager::get_document_id($courseInfo, $documentFile);
- // Document found! Add it to the list
- if ($itemDocumentId) {
- $itemList['document'][] = $itemDocumentId;
- }
- }
- }
- }
- }
- }
- }
- $courseBuilder->build_documents(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- $itemList['document']
- );
- }
- if (isset($itemList['quiz'])) {
- $courseBuilder->build_quizzes(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- $itemList['quiz']
- );
- }
- require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
- /*if (!empty($itemList['thread'])) {
- $postList = [];
- foreach ($itemList['thread'] as $postId) {
- $post = get_post_information($postId);
- if ($post) {
- if (!isset($itemList['forum'])) {
- $itemList['forum'] = [];
- }
- $itemList['forum'][] = $post['forum_id'];
- $postList[] = $postId;
- }
- }
- if (!empty($postList)) {
- $courseBuilder->build_forum_posts(
- $this->get_course_int_id(),
- null,
- null,
- $postList
- );
- }
- }*/
- if (!empty($itemList['thread'])) {
- $threadList = [];
- $em = Database::getManager();
- $repo = $em->getRepository('ChamiloCourseBundle:CForumThread');
- foreach ($itemList['thread'] as $threadId) {
- /** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */
- $thread = $repo->find($threadId);
- if ($thread) {
- $itemList['forum'][] = $thread->getForumId();
- $threadList[] = $thread->getIid();
- }
- }
- if (!empty($threadList)) {
- $courseBuilder->build_forum_topics(
- api_get_session_id(),
- $this->get_course_int_id(),
- null,
- $threadList
- );
- }
- }
- $forumCategoryList = [];
- if (isset($itemList['forum'])) {
- foreach ($itemList['forum'] as $forumId) {
- $forumInfo = get_forums($forumId);
- $forumCategoryList[] = $forumInfo['forum_category'];
- }
- }
- if (!empty($forumCategoryList)) {
- $courseBuilder->build_forum_category(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- $forumCategoryList
- );
- }
- if (!empty($itemList['forum'])) {
- $courseBuilder->build_forums(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- $itemList['forum']
- );
- }
- if (isset($itemList['link'])) {
- $courseBuilder->build_links(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- $itemList['link']
- );
- }
- if (!empty($itemList['student_publication'])) {
- $courseBuilder->build_works(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- $itemList['student_publication']
- );
- }
- $courseBuilder->build_learnpaths(
- api_get_session_id(),
- $this->get_course_int_id(),
- true,
- [$this->get_id()],
- false
- );
- $courseBuilder->restoreDocumentsFromList();
- $zipFile = CourseArchiver::createBackup($courseBuilder->course);
- $zipPath = CourseArchiver::getBackupDir().$zipFile;
- $result = DocumentManager::file_send_for_download(
- $zipPath,
- true,
- $this->get_name().'.zip'
- );
- if ($result) {
- api_not_allowed();
- }
- return true;
- }
- /**
- * Get whether this is a learning path with the accumulated work time or not.
- *
- * @return int
- */
- public function getAccumulateWorkTime()
- {
- return (int) $this->accumulateWorkTime;
- }
- /**
- * Get whether this is a learning path with the accumulated work time or not.
- *
- * @return int
- */
- public function getAccumulateWorkTimeTotalCourse()
- {
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT SUM(accumulate_work_time) AS total
- FROM $table
- WHERE c_id = ".$this->course_int_id;
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return (int) $row['total'];
- }
- /**
- * Set whether this is a learning path with the accumulated work time or not.
- *
- * @param int $value (0 = false, 1 = true)
- *
- * @return bool
- */
- public function setAccumulateWorkTime($value)
- {
- if (!api_get_configuration_value('lp_minimum_time')) {
- return false;
- }
- $this->accumulateWorkTime = (int) $value;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $lp_id = $this->get_id();
- $sql = "UPDATE $table SET accumulate_work_time = ".$this->accumulateWorkTime."
- WHERE c_id = ".$this->course_int_id." AND id = $lp_id";
- Database::query($sql);
- return true;
- }
- /**
- * @param int $lpId
- * @param int $courseId
- *
- * @return mixed
- */
- public static function getAccumulateWorkTimePrerequisite($lpId, $courseId)
- {
- $lpId = (int) $lpId;
- $courseId = (int) $courseId;
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "SELECT accumulate_work_time
- FROM $table
- WHERE c_id = $courseId AND id = $lpId";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row['accumulate_work_time'];
- }
- /**
- * @param int $courseId
- *
- * @return int
- */
- public static function getAccumulateWorkTimeTotal($courseId)
- {
- $table = Database::get_course_table(TABLE_LP_MAIN);
- $courseId = (int) $courseId;
- $sql = "SELECT SUM(accumulate_work_time) AS total
- FROM $table
- WHERE c_id = $courseId";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return (int) $row['total'];
- }
- /**
- * In order to use the lp icon option you need to create the "lp_icon" LP extra field
- * and put the images in.
- *
- * @return array
- */
- public static function getIconSelect()
- {
- $theme = api_get_visual_theme();
- $path = api_get_path(SYS_PUBLIC_PATH).'css/themes/'.$theme.'/lp_icons/';
- $icons = ['' => get_lang('SelectAnOption')];
- if (is_dir($path)) {
- $finder = new Finder();
- $finder->files()->in($path);
- $allowedExtensions = ['jpeg', 'jpg', 'png'];
- /** @var SplFileInfo $file */
- foreach ($finder as $file) {
- if (in_array(strtolower($file->getExtension()), $allowedExtensions)) {
- $icons[$file->getFilename()] = $file->getFilename();
- }
- }
- }
- return $icons;
- }
- /**
- * @param int $lpId
- *
- * @return string
- */
- public static function getSelectedIcon($lpId)
- {
- $extraFieldValue = new ExtraFieldValue('lp');
- $lpIcon = $extraFieldValue->get_values_by_handler_and_field_variable($lpId, 'lp_icon');
- $icon = '';
- if (!empty($lpIcon) && isset($lpIcon['value'])) {
- $icon = $lpIcon['value'];
- }
- return $icon;
- }
- /**
- * @param int $lpId
- *
- * @return string
- */
- public static function getSelectedIconHtml($lpId)
- {
- $icon = self::getSelectedIcon($lpId);
- if (empty($icon)) {
- return '';
- }
- $theme = api_get_visual_theme();
- $path = api_get_path(WEB_PUBLIC_PATH).'css/themes/'.$theme.'/lp_icons/'.$icon;
- return Display::img($path);
- }
- /**
- * @param string $value
- *
- * @return string
- */
- public function cleanItemTitle($value)
- {
- $value = Security::remove_XSS(strip_tags($value));
- return $value;
- }
- /**
- * @param FormValidator $form
- */
- public function setItemTitle(FormValidator $form)
- {
- if (api_get_configuration_value('save_titles_as_html')) {
- $form->addHtmlEditor(
- 'title',
- get_lang('Title'),
- true,
- false,
- ['ToolbarSet' => 'TitleAsHtml']
- );
- } else {
- $form->addText('title', get_lang('Title'), true, ['id' => 'idTitle', 'class' => 'learnpath_item_form']);
- $form->applyFilter('title', 'trim');
- $form->applyFilter('title', 'html_filter');
- }
- }
- /**
- * @return array
- */
- public function getItemsForForm($addParentCondition = false)
- {
- $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $tbl_lp_item
- WHERE c_id = $course_id AND lp_id = ".$this->lp_id;
- if ($addParentCondition) {
- $sql .= ' AND parent_item_id = 0 ';
- }
- $sql .= ' ORDER BY display_order ASC';
- $result = Database::query($sql);
- $arrLP = [];
- while ($row = Database::fetch_array($result)) {
- $arrLP[] = [
- 'iid' => $row['iid'],
- 'id' => $row['iid'],
- 'item_type' => $row['item_type'],
- 'title' => $this->cleanItemTitle($row['title']),
- 'path' => $row['path'],
- 'description' => Security::remove_XSS($row['description']),
- 'parent_item_id' => $row['parent_item_id'],
- 'previous_item_id' => $row['previous_item_id'],
- 'next_item_id' => $row['next_item_id'],
- 'display_order' => $row['display_order'],
- 'max_score' => $row['max_score'],
- 'min_score' => $row['min_score'],
- 'mastery_score' => $row['mastery_score'],
- 'prerequisite' => $row['prerequisite'],
- 'max_time_allowed' => $row['max_time_allowed'],
- 'prerequisite_min_score' => $row['prerequisite_min_score'],
- 'prerequisite_max_score' => $row['prerequisite_max_score'],
- ];
- }
- return $arrLP;
- }
- /**
- * Get the depth level of LP item.
- *
- * @param array $items
- * @param int $currentItemId
- *
- * @return int
- */
- private static function get_level_for_item($items, $currentItemId)
- {
- $parentItemId = 0;
- if (isset($items[$currentItemId])) {
- $parentItemId = $items[$currentItemId]->parent;
- }
- if ($parentItemId == 0) {
- return 0;
- } else {
- return self::get_level_for_item($items, $parentItemId) + 1;
- }
- }
- /**
- * Generate the link for a learnpath category as course tool.
- *
- * @param int $categoryId
- *
- * @return string
- */
- private static function getCategoryLinkForTool($categoryId)
- {
- $categoryId = (int) $categoryId;
- $link = 'lp/lp_controller.php?'.api_get_cidreq().'&'
- .http_build_query(
- [
- 'action' => 'view_category',
- 'id' => $categoryId,
- ]
- );
- return $link;
- }
- /**
- * Return the scorm item type object with spaces replaced with _
- * The return result is use to build a css classname like scorm_type_$return.
- *
- * @param $in_type
- *
- * @return mixed
- */
- private static function format_scorm_type_item($in_type)
- {
- return str_replace(' ', '_', $in_type);
- }
- /**
- * Check and obtain the lp final item if exist.
- *
- * @return learnpathItem
- */
- private function getFinalItem()
- {
- if (empty($this->items)) {
- return null;
- }
- foreach ($this->items as $item) {
- if ($item->type !== 'final_item') {
- continue;
- }
- return $item;
- }
- }
- /**
- * Get the LP Final Item Template.
- *
- * @return string
- */
- private function getFinalItemTemplate()
- {
- return file_get_contents(api_get_path(SYS_CODE_PATH).'lp/final_item_template/template.html');
- }
- /**
- * Get the LP Final Item Url.
- *
- * @return string
- */
- private function getSavedFinalItem()
- {
- $finalItem = $this->getFinalItem();
- $doc = DocumentManager::get_document_data_by_id(
- $finalItem->path,
- $this->cc
- );
- if ($doc && file_exists($doc['absolute_path'])) {
- return file_get_contents($doc['absolute_path']);
- }
- return '';
- }
- }
|