PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/api/2.0/models/Forkan.php

https://bitbucket.org/rakmana/forkan
PHP | 310 lines | 127 code | 68 blank | 115 comment | 5 complexity | fb36979c37b287897bcda41cf9c3b063 MD5 | raw file
  1. <?php
  2. //--- function to make param via array system without error
  3. function rg($name,$args){
  4. if (isset($args[$name])){
  5. return $args[$name];
  6. }
  7. else{
  8. return false;
  9. }
  10. };
  11. class ForkanData
  12. {
  13. /********************************[ Ayas functions ]************************************/
  14. /**
  15. * Get aya info as array
  16. *
  17. * @param mixed $ayaID
  18. * @param string $riwayaID
  19. * @return array [index,sura,aya,text,riwaya]
  20. */
  21. public static function getAyas($args){
  22. //index sura aya text riwaya view
  23. return R::getAll('SELECT * FROM quran WHERE `riwaya` = :rw AND `index` >= :id AND `index` < (:id+:nbr) ',array(':rw'=>1,':id'=>rg('id',$args),':nbr'=> rg('nbr',$args)));
  24. }
  25. /**
  26. * Get Ayas per Page
  27. *
  28. * @param mixed $args = [pageID, riwayaID]
  29. * @return array [index,sura,aya,text,riwaya]
  30. */
  31. public static function getAyasPerPage($args){
  32. //index sura aya text riwaya view
  33. $p1 = metaQuran::getAllAttr('page',rg('id',$args),'sura');
  34. $p2 = metaQuran::getAllAttr('page',rg('id',$args)+1);
  35. $start = (ForkanData::getAyaIndex($p1['sura'],$p1['aya'],1));
  36. $end = (ForkanData::getAyaIndex($p2['sura'],$p2['aya'],1))-$start;
  37. //var_dump($start);
  38. //exit;
  39. return R::getAll('SELECT * FROM quran WHERE `riwaya` = :rw AND `index` >= :id AND `index` < (:id+:end) ',array(':rw'=>1,':id'=>$start,':end'=>$end));
  40. }
  41. /********************************[ Other functions ]************************************/
  42. public static function getSuras(){
  43. // [start, ayas, order, rukus, name, tname, ename, type]
  44. //[],
  45. //[0, 7, 5, 1, 'الفاتحة', "Al-Faatiha", 'The Opening', 'Meccan'],
  46. //index="1" ayas="7" start="0" name="الْفَاتِحَة" tname="Al-Faatiha" ename="The Opening" type="Meccan"
  47. $els = $GLOBALS['WQX']->xml['data']->xpath("//sura");
  48. $ht = array();//'[],';
  49. $i = 1;
  50. foreach ($els as $e ){
  51. $atts = $e->attributes();
  52. //--- add 1 to start aya
  53. $atts['start'] += 1;
  54. //--- add index
  55. $atts['index'] = $i;
  56. $ht[] = $atts;
  57. $i++;
  58. }
  59. //$ht .= '[6236, 1]' ;
  60. return $ht;
  61. }
  62. public static function getPages(){
  63. // [index, sura, aya]
  64. // <page index="1" sura="1" aya="1"/>
  65. $els = $GLOBALS['WQX']->xml['data']->xpath("//page");
  66. $ht = array();//'[],';
  67. foreach ($els as $e ){
  68. $atts = $e->attributes();
  69. //--- add 1 to start aya
  70. $atts['start'] += 1;
  71. $ht[] = $atts;
  72. //$ht .= '['.$atts['start'].','.$atts['ayas'].','.$atts['order'].','./*$atts['rukus'].*/',';
  73. //$ht .= "'".$atts['name']."',\"".$atts['tname']."\",'".$atts['ename']."','".$atts['type']."'],";
  74. }
  75. //$ht .= '[6236, 1]' ;
  76. return $ht;
  77. }
  78. /**
  79. * Get translated Aya info as array
  80. *
  81. * @param mixed $ayaID
  82. * @param string $riwayaID
  83. * @return array [index,sura,aya,text,riwaya]
  84. */
  85. public static function getTrans($ayaID,$transID = '1'){
  86. //index sura aya text TransID view
  87. $y = dbase::jfetch("SELECT q.* FROM translations q WHERE index=$ayaID and q.transID = $transID");
  88. return $y;
  89. }
  90. /**
  91. * Get Aya index from SuraID+AyaPos
  92. *
  93. * @param mixed $sura
  94. * @param mixed $aya
  95. * @return void
  96. */
  97. public static function getAyaIndex($sura,$aya,$riwayaID = '1'){
  98. $y = R::getRow("SELECT q.index FROM quran q WHERE q.sura = :sura AND q.aya = :aya and q.riwaya = :riwayaID",array('sura'=>$sura,'aya'=>$aya,'riwayaID'=>$riwayaID));
  99. //var_dump($y);
  100. return $y['index'];
  101. }
  102. /**
  103. * Get SuraID+AyaPos from Aya index
  104. *
  105. * @param mixed $sura
  106. * @param mixed $aya
  107. * @return void
  108. */
  109. public static function getAyaFromIndex($index,$riwayaID = '1'){
  110. $y = dbase::jfetch("SELECT q.sura,q.aya FROM quran q WHERE q.index = $index and q.riwaya = $riwayaID");
  111. return $y;
  112. }
  113. }
  114. class metaQuran
  115. {
  116. public $xml = array();
  117. public static function init()
  118. {
  119. // create the KONFIG object
  120. metaQuran::load(KROT .'models'.DS.'quran-data.xml');
  121. // Lets make sure we save serialized data
  122. }
  123. public static function load($xmlfile)
  124. {
  125. $GLOBALS['WQX'] = kore::getInstance('metaQuran');
  126. $GLOBALS['WQX']->xml['data'] = xmldoc::import($xmlfile);
  127. $GLOBALS['WQX']->xml['data2'] = xmldoc::import(KROT .'models'.DS.'quran-data.xml');
  128. //btrack('KFG File loaded: '.$section);
  129. }
  130. /**
  131. * Get key Attribute from xml
  132. *
  133. * @param mixed $name
  134. * @param mixed $index
  135. * @param mixed $attr
  136. * @return mixed Attribute OR False
  137. */
  138. public static function getAttr($name,$index,$attr)
  139. {
  140. $element = @$GLOBALS['WQX']->xml['data']->xpath("//".$name."[@index='$index']");
  141. if (!isset($element[0])){
  142. return false;
  143. }
  144. $atts = $element[0]->attributes();
  145. if (!isset($atts[$attr])){
  146. return false;
  147. }
  148. $ret = $atts[$attr];
  149. //tools::dump($ret);
  150. return $ret;
  151. }
  152. //--- will b removed
  153. public static function rep(){
  154. $els = $GLOBALS['WQX']->xml['data']->xpath("//sura");
  155. foreach ($els as $e ){
  156. $atts = $e->attributes();
  157. $ndx = $atts['index'];
  158. $e2 = $GLOBALS['WQX']->xml['data2']->xpath("//sura[@index='$ndx']");
  159. $atts2 = $e2[0]->attributes();
  160. $name2 = $atts2['name'];
  161. if (!empty($name2)){
  162. $atts['name'] = $name2;
  163. }
  164. }
  165. $GLOBALS['WQX']->xml['data']->asXML(PAPP .'forkan'.DS. 'quran-data.xml');
  166. return true;
  167. }
  168. /**
  169. * Get All attributes of the given key
  170. *
  171. * @param mixed $name
  172. * @param mixed $index
  173. * @return
  174. */
  175. public static function getAllAttr($name,$index){
  176. $element = $GLOBALS['WQX']->xml['data']->xpath("//".$name."[@index='$index']");
  177. if (!isset($element[0])){
  178. return false;
  179. }
  180. $ret = $element[0]->attributes();
  181. return $ret;
  182. }
  183. /**
  184. * Get sura metadata
  185. * [index,ayas,start,name,tname,ename,type(Medinan,Meccan),order,rukus]
  186. *
  187. * @param mixed $index
  188. * @param mixed $meta
  189. * @return mixed Meta OR False
  190. */
  191. public static function getSuraMeta($index,$meta){
  192. return self::getAttr('sura',$index,$meta);
  193. }
  194. /**
  195. * Get Juz metadata
  196. * [index,sura,aya]
  197. *
  198. * @param mixed $index
  199. * @param mixed $meta
  200. * @return mixed Meta OR False
  201. */
  202. public static function getJuzMeta($index,$meta){
  203. return self::getAttr('juz',$index,$meta);
  204. }
  205. /**
  206. * Get Quarter metadata
  207. * [index,sura,aya]
  208. *
  209. * @param mixed $index
  210. * @param mixed $meta
  211. * @return mixed Meta OR False
  212. */
  213. public static function getQuarterMeta($index,$meta){
  214. return self::getAttr('quarter',$index,$meta);
  215. }
  216. /**
  217. * Get Page metadata
  218. * [index,sura,aya]
  219. *
  220. * @param mixed $index
  221. * @param mixed $meta
  222. * @return mixed Meta OR False
  223. */
  224. public static function getPageMeta($index,$meta){
  225. return self::getAttr('page',$index,$meta);
  226. }
  227. function xit()
  228. {
  229. $GLOBALS['WQX']->xml['data']->asXML(KROT .'models'.DS.'quran-data.xml');
  230. }
  231. /**
  232. * konfig::save()
  233. *
  234. * @param mixed $section
  235. * @param mixed $xmlfile
  236. * @return
  237. */
  238. function save($section, $xmlfile)
  239. {
  240. $GLOBALS['WQX']->xml['data']->asXML($xmlfile);
  241. }
  242. }