Example #1
0
 /**
  * Render
  *
  * @return	void
  * @access	public
  */
 function render($outputMode = NULL, $skipChilds = false)
 {
     $from = '';
     $until = '';
     $set = '';
     $limitStart = 0;
     if (__Request::exists('resumptionToken')) {
         if (!__Request::exists('from') && !__Request::exists('until') && !__Request::exists('set') && !__Request::exists('metadataPrefix')) {
             // TODO controllare la data di scadenza del token
             $tokenId = __Request::get('resumptionToken');
             $fileName = __Paths::get('CACHE') . $tokenId;
             if (file_exists($fileName)) {
                 $info = unserialize(file_get_contents($fileName));
                 $limitStart = $info['limitEnd'];
                 $filters = $info['filters'];
                 $metadataPrefix = $info['metadataPrefix'];
             } else {
                 $this->_application->setError('badResumptionToken', '', $tokenId);
                 return;
             }
         } else {
             $this->_application->setError('exclusiveArgument');
             return;
         }
     } else {
         // controlla i parametri ricevuti
         if (__Request::exists('from')) {
             $from = __Request::get('from');
             if (!org_glizy_oaipmh_OaiPmh::checkDateFormat($from)) {
                 $this->_application->setError('badGranularity', 'from', $from);
                 return;
             }
         }
         if (__Request::exists('until')) {
             $until = __Request::get('until');
             if (!org_glizy_oaipmh_OaiPmh::checkDateFormat($until)) {
                 $this->_application->setError('badGranularity', 'until', $until);
                 return;
             }
         }
         if (__Request::exists('set')) {
             $set = __Request::get('set');
         }
         if (__Request::exists('metadataPrefix')) {
             $metadataPrefix = __Request::get('metadataPrefix');
         } else {
             $this->_application->setError('missingArgument', 'metadataPrefix');
             return;
         }
         $filters = array();
         if ($from) {
             $filters[] = 'picoqueue_date >= ' . org_glizy_dataAccess_DataAccess::qstr($from);
         }
         if ($until) {
             $filters[] = 'picoqueue_date <= ' . org_glizy_dataAccess_DataAccess::qstr($until);
         }
         if ($set) {
             $filters[] = 'picoqueue_recordModule = ' . org_glizy_dataAccess_DataAccess::qstr($set);
         }
     }
     $metadata = $this->_application->getMetadataFormat();
     if (isset($metadata[$metadataPrefix])) {
         // TODO
         //$inc_record = $metadata[$metadataPrefix]['myhandler'];
     } else {
         $this->_application->setError('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix);
         return;
     }
     $limitLength = __Config::get('oaipmh.maxRecords');
     $it = org_glizy_ObjectFactory::createModelIterator('org.glizy.oaipmh.models.PicoQueue', 'all', array('filters' => $filters, 'limit' => array($limitStart, $limitLength), 'numRows' => true));
     $num_rows = $it->count();
     if ($num_rows > 0) {
         $oaiPrefix = __Config::get('oaipmh.oaiPrefix');
         $countrec = 0;
         $output = '<ListRecords>';
         $output .= org_glizy_oaipmh_OaiPmh::createResumptionToken('ListRecords', array('numRows' => $num_rows, 'limitStart' => $limitStart, 'limitEnd' => $limitStart + $limitLength, 'filters' => $filters, 'metadataPrefix' => $metadataPrefix));
         while ($it->hasMore()) {
             $countrec++;
             $arC = $it->current();
             $it->next();
             $setClass = org_glizy_ObjectFactory::createObject($arC->picoqueue_recordModule, $this->_application);
             if (is_null($setClass)) {
                 continue;
             }
             $setClass->loadRecord($arC->picoqueue_recordId);
             $identifier = $oaiPrefix . $arC->picoqueue_identifier;
             $datestamp = org_glizy_oaipmh_OaiPmh::formatDatestamp($arC->picoqueue_date);
             $status_deleted = $arC->picoqueue_action == 'delete' ? true : false;
             $output .= '<record>';
             $output .= '<header';
             if ($status_deleted) {
                 $output .= ' status="deleted"';
             }
             $output .= '>';
             // use xmlrecord since we use stuff from database
             $output .= '<identifier>' . org_glizy_oaipmh_OaiPmh::encode($identifier) . '</identifier>';
             $output .= '<datestamp>' . org_glizy_oaipmh_OaiPmh::encode($datestamp) . '</datestamp>';
             if (!$status_deleted) {
                 $output .= '<setSpec>' . org_glizy_oaipmh_OaiPmh::encode($arC->picoqueue_recordModule) . '</setSpec>';
             }
             $output .= '</header>';
             $output .= '<metadata>';
             $output .= $setClass->getRecord($identifier);
             $output .= '</metadata>';
             $output .= '</record>';
         }
         $output .= '</ListRecords>';
         $this->addOutputCode($output);
     } else {
         $this->_application->setError('noRecordsMatch');
     }
 }
Example #2
0
 function &loadQuery($queryName, $options = array())
 {
     org_glizy_dataAccess_DataAccess::selectDB($this->_connNumber);
     if ($this->_conn->debug) {
         echo '<b>' . $queryName . '</b><br>';
     }
     if ($this->enableLog) {
         $eventInfo = array('type' => GLZ_LOG_EVENT, 'data' => array('level' => GLZ_LOG_DEBUG, 'group' => '', 'message' => 'loadQuery: ' . $queryName));
         $evt = org_glizy_ObjectFactory::createObject('org.glizy.events.Event', $this, $eventInfo);
         org_glizy_events_EventDispatcher::dispatchEvent($evt);
     }
     if (!isset($options['sql'])) {
         $sql = $this->_getQuerySqlString($queryName);
         $sql = rtrim($sql, ';');
         $params = isset($options['params']) ? $options['params'] : array();
         $checkIntegrity = isset($options['checkIntegrity']) ? $options['checkIntegrity'] : true;
         if (!isset($options['filters'])) {
             $options['filters'] = array();
         }
         if (!is_array($options['filters'])) {
             $options['filters'] = array($options['filters']);
         }
         if (strpos($sql, 'WHERE') === false) {
             foreach ($this->_fieldsList as $k => $v) {
                 if (isset($v['defaultSelectValue']) && !isset($options['filters'][$k])) {
                     if ($v['languageField'] === true || $v['versionField'] == true || $options['default'] !== false) {
                         $options['filters'][$k] = $v['defaultSelectValue'];
                     }
                 }
             }
         }
         // se � definito un sito forza la condizione
         if (!is_null(__Config::get('SITE_ID')) && !is_null($this->_siteIdField) && !isset($options['filters'][$this->_siteIdField])) {
             $options['filters'][$this->_siteIdField] = __Config::get('SITE_ID');
         }
         $sqlWhere = '(';
         foreach ($options['filters'] as $filterName => $filterValue) {
             if (!is_string($filterName)) {
                 $sqlWhere .= $filterValue . ' AND ';
                 continue;
             } else {
                 if (!isset($this->_fieldsList[$filterName]) && $checkIntegrity) {
                     continue;
                 }
             }
             if ($this->_fieldsList[$filterName]['type'] == AR_TYPE_DATE || $this->_fieldsList[$filterName]['type'] == AR_TYPE_DATETIME) {
                 if (is_array($filterValue) && $filterValue[0] == "=") {
                     $filterValue = $filterValue[1];
                 }
             }
             if (!is_array($filterValue)) {
                 switch ($this->_fieldsList[$filterName]['type']) {
                     case AR_TYPE_DATE:
                     case AR_TYPE_DATETIME:
                         $sqlWhere .= $filterName . ' LIKE ' . org_glizy_dataAccess_DataAccess::qstr('%' . $filterValue . '%') . ' AND ';
                         break;
                     case AR_TYPE_INTEGER:
                     case AR_TYPE_SITEID:
                     case AR_TYPE_ENUM:
                         if ($filterValue != '') {
                             $sqlWhere .= $filterName . '= ' . org_glizy_dataAccess_DataAccess::qstr($filterValue) . ' AND ';
                         }
                         break;
                     default:
                         if ($this->_fieldsList[$filterName]['canEncode'] === false) {
                             $filterValue = glz_encodeOutput($filterValue);
                         }
                         if (!empty($filterValue)) {
                             $sqlWhere .= $filterName . ' LIKE ' . org_glizy_dataAccess_DataAccess::qstr('%' . $filterValue . '%') . ' AND ';
                         }
                         break;
                 }
             } else {
                 $sqlWhere .= $filterName . ' ' . $filterValue[0] . (isset($filterValue[1]) ? ' ' . org_glizy_dataAccess_DataAccess::qstr($filterValue[1]) : '') . ' AND ';
             }
         }
         $sqlWhere .= '1=1) ';
         // se � definita l'acl
         $sqlWhere .= $this->_addAclClause();
         if (isset($options['categories'])) {
             $sqlWhere .= $this->_addAclCategoriesClause($options['categories']);
         }
         if (strripos($sql, 'WHERE') === false) {
             if (strripos($sql, 'ORDER') === false && strripos($sql, 'GROUP BY') === false) {
                 $sql .= ' WHERE ' . $sqlWhere;
             } else {
                 if (strripos($sql, 'GROUP BY') === false) {
                     $sql = str_replace('ORDER', ' WHERE ' . $sqlWhere . ' ORDER ', $sql);
                 } else {
                     $sql = str_replace('GROUP BY', ' WHERE ' . $sqlWhere . ' GROUP BY', $sql);
                 }
             }
         } else {
             $sql = str_replace('WHERE', 'WHERE ' . $sqlWhere . ' AND ', $sql);
         }
         $sql = str_replace('##W##', 'WHERE', $sql);
         if (isset($options['group'])) {
             if (strripos($sql, 'GROUP BY') !== false) {
                 $sql .= ' GROUP BY ' . $options['group'];
             }
         }
         if (isset($options['order'])) {
             // TODO
             // controllare che i valori passati in orderBy siano delle colonne valide
             $order = is_array($options['order']) ? implode(',', $options['order']) : $options['order'];
             if (strripos($sql, 'ORDER') === false) {
                 $order = ' ORDER BY ' . $order;
             } else {
                 $order = ', ' . $order;
             }
             // if ( strripos( $sql, 'GROUP BY') !== false )
             // {
             // 				list( $p1, $p2 ) = explode( 'GROUP BY', $sql );
             // 				$sql  = $p1.$order.' GROUP BY '.$p2;
             // }
             // else
             // {
             $sql .= $order;
             // }
         }
     } else {
         $sql = $options['sql'];
     }
     if (isset($options['numRows']) && $options['numRows'] == true) {
         if (stripos($sql, 'SELECT SQL_CALC_FOUND_ROWS') === false) {
             $pos = stripos($sql, 'SELECT');
             $sql = 'SELECT SQL_CALC_FOUND_ROWS ' . substr($sql, $pos + 7);
         }
     }
     // esegue la paginazione
     if (isset($options['limit']) && !empty($options['limit'])) {
         if (is_string($options['limit'])) {
             list($limitStart, $limitLength) = explode(',', $options['limit']);
         } else {
             if (!isset($options['limit']['start'])) {
                 $limitStart = $options['limit'][0];
                 $limitLength = $options['limit'][1];
             } else {
                 $limitStart = $options['limit']['start'];
                 $limitLength = $options['limit']['pageLength'];
             }
         }
         if (stripos($sql, 'limit')) {
             $sql = preg_replace('/limit\\s*\\d*,\\s*?\\d$/i', '', $sql);
         }
         $rs =& $this->_execute($sql, $params, $limitLength, $limitStart);
     } else {
         $rs =& $this->_execute($sql, $params);
     }
     if ($this->_conn->ErrorNo()) {
         $this->triggerError($this->getClassName() . ': ' . $this->_conn->ErrorMsg() . " " . $sql);
     }
     $recordIterator = new org_glizy_dataAccess_RecordIterator($rs, get_class($this));
     if (stripos($sql, 'SELECT SQL_CALC_FOUND_ROWS') !== false) {
         $rs2 = $this->execSql('SELECT FOUND_ROWS() as tot;');
         $recordIterator->setCount($rs2->fields['tot']);
     }
     return $recordIterator;
 }