예제 #1
0
 public function load($cid)
 {
     static $instances = array();
     if (empty($cid)) {
         return NULL;
     }
     if (!isset($instances[$cid])) {
         // Check if this record exist or not
         $sql = Komento::getSql();
         $sql->select('#__js_res_record')->column('id', 'id', 'count')->where('id', $cid);
         $result = $sql->loadResult();
         if ($result < 1) {
             return $this->onLoadArticleError($cid);
         }
         $item = ItemsStore::getRecord($cid);
         $item->url = $this->prepareLink(Url::record($item));
         $instances[$cid] = $item;
     }
     $this->_item = $instances[$cid];
     return $this;
 }
예제 #2
0
 function reindex($params)
 {
     $types = $params->get('types', false);
     set_time_limit(0);
     ini_set('max_execution_time', 0);
     if (!$types) {
         return;
     }
     if (!is_array($types)) {
         settype($types, 'array');
     }
     $db = JFactory::getDbo();
     $db->setQuery('SELECT id, title, type_id, section_id, user_id FROM `#__js_res_record` WHERE type_id IN (' . implode(',', $types) . ')');
     $ids = $db->loadObjectList();
     $count = 0;
     if (!empty($ids)) {
         require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_cobalt' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'fields.php';
         $fields_model = new CobaltModelFields();
         foreach ($ids as $item) {
             $out_fieldsdata = array();
             $fields_list = $fields_model->getFormFields($item->type_id, $item->id, FALSE);
             $type = ItemsStore::getType($item->type_id);
             $section = ItemsStore::getSection($item->section_id);
             if (!is_object($section->params)) {
                 $section->params = new JRegistry($section->params);
             }
             foreach ($fields_list as $field) {
                 if ($field->params->get('core.searchable')) {
                     $data = $field->onPrepareFullTextSearch($field->value, $item, $type, $section);
                     if (is_array($data)) {
                         $data = implode(', ', $data);
                     }
                     $out_fieldsdata[$field->id] = $data;
                 }
             }
             $user = JFactory::getUser($item->user_id);
             if ($section->params->get('more.search_title')) {
                 $out_fieldsdata[] = $item->title;
             }
             if ($section->params->get('more.search_name')) {
                 $out_fieldsdata[] = $user->get('name');
                 $out_fieldsdata[] = $user->get('username');
             }
             if ($section->params->get('more.search_email')) {
                 $out_fieldsdata[] = $user->get('email');
             }
             $db2 = JFactory::getDbo();
             $db2->setQuery("UPDATE `#__js_res_record` SET fieldsdata = '" . $db2->escape(strip_tags(implode(', ', $out_fieldsdata))) . "' WHERE id = {$item->id}");
             $db2->query();
             unset($db2, $out_fieldsdata, $user, $type, $section);
             if ($count == 10000) {
                 //exit;
             }
             $count++;
         }
     }
     $app = JFactory::getApplication();
     $app->enqueueMessage(JText::sprintf('%d record(s) have been reindexed.', $count));
 }
예제 #3
0
 public static function getSectionRecords($params)
 {
     $db = JFactory::getDbo();
     $items = null;
     $sql = $db->getQuery(true);
     $sql->select('id');
     $sql->from('#__js_res_record');
     $sql->where('published = 1');
     $sql->where('hidden = 0');
     $sql->where('section_id = ' . $params->get('section_id'));
     $sql->where("ctime < " . $db->quote(JFactory::getDate()->toSql()));
     $sql->where("(extime = '0000-00-00 00:00:00' OR extime > '" . JFactory::getDate()->toSql() . "')");
     $sql->where("id NOT IN (SELECT record_id FROM #__js_res_record_category WHERE section_id = '" . $params->get('section_id') . "')");
     $db->setQuery($sql, 0, $params->get('records_limit') ? $params->get('records_limit') + 1 : 0);
     if ($recs = $db->loadColumn()) {
         $items = array();
         foreach ($recs as $rid) {
             $record = ItemsStore::getRecord($rid);
             $record->url = Url::record($record);
             $items[] = $record;
         }
     }
     return $items;
 }