Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the array utility class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage Util
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Dominik Ziegler
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * The
 20:  * article collector returns you a list of articles, which destination you can
 21:  * choose.
 22:  * You have the ability to limit, sort and filter the article list.
 23:  *
 24:  * You can configure the article collector with an options array, which can include the
 25:  * following configuration.
 26:  *
 27:  * - idcat - category ID
 28:  * - categories - array with multiple category IDs
 29:  * - lang - language ID, active language if ommited
 30:  * - client - client ID, active client if ommited
 31:  * - artspecs - array of article specifications, which should be considered
 32:  * - offline - include offline article in the collection, defaults to false
 33:  * - offlineonly - only list offline articles, defaults to false
 34:  * - start - include start article in the collection, defaults to false
 35:  * - startonly - only list start articles, defaults to false
 36:  * - order - articles will be ordered by this property, defaults to created
 37:  * - direction - order direction, ASC or DESC for ascending/descending, defaults to DESC
 38:  * - limit - limit numbers of articles in collection, default to 0 (unlimited)
 39:  *
 40:  * TODO: Use generic DB instead of SQL queries
 41:  *
 42:  * @package Core
 43:  * @subpackage Util
 44:  */
 45: class cArticleCollector implements SeekableIterator, Countable {
 46: 
 47:     /**
 48:      * Options for the collector.
 49:      *
 50:      * @var array
 51:      */
 52:     protected $_options = array();
 53: 
 54:     /**
 55:      * Loaded articles.
 56:      *
 57:      * @var array
 58:      */
 59:     protected $_articles = array();
 60: 
 61:     /**
 62:      * Total paging data.
 63:      *
 64:      * @var array
 65:      */
 66:     protected $_pages = array();
 67: 
 68:     /**
 69:      * Start articles of the requested categories.
 70:      *
 71:      * @var array
 72:      */
 73:     protected $_startArticles = array();
 74: 
 75:     /**
 76:      * Current position for the iterator.
 77:      *
 78:      * @var int
 79:      */
 80:     protected $_currentPosition = 0;
 81: 
 82:     /**
 83:      * Constructor. If options are defined, the loading process is automatically
 84:      * initiated.
 85:      *
 86:      * @param array $options array with options for the collector (optional,
 87:      *            default: empty array)
 88:      */
 89:     public function __construct($options = array()) {
 90:         $this->setOptions($options);
 91:         $this->loadArticles();
 92:     }
 93: 
 94:     /**
 95:      * Setter for the collector options. Validates incoming options and sets the
 96:      * default of the missing options.
 97:      *
 98:      * @param array $options array with option
 99:      */
100:     public function setOptions($options) {
101:         if (isset($options['idcat']) && !isset($options['categories'])) {
102:             $options['categories'] = array(
103:                     $options['idcat']
104:             );
105:         }
106: 
107:         if (isset($options['categories']) === false) {
108:             $options['categories'] = array();
109:         }
110: 
111:         if (isset($options['lang']) === false) {
112:             $options['lang'] = cRegistry::getLanguageId();
113:         }
114: 
115:         if (isset($options['client']) === false) {
116:             $options['client'] = cRegistry::getClientId();
117:         }
118: 
119:         if (isset($options['start']) === false) {
120:             $options['start'] = false;
121:         }
122: 
123:         if (isset($options['startonly']) === false) {
124:             $options['startonly'] = false;
125:         }
126: 
127:         if (isset($options['offline']) === false) {
128:             $options['offline'] = false;
129:         }
130: 
131:         if (isset($options['offlineonly']) === false) {
132:             $options['offlineonly'] = false;
133:         }
134: 
135:         switch ($options['order']) {
136:             case 'sortsequence':
137:                 $options['order'] = 'artsort';
138:                 break;
139: 
140:             case 'title':
141:                 $options['order'] = 'title';
142:                 break;
143: 
144:             case 'modificationdate':
145:                 $options['order'] = 'lastmodified';
146:                 break;
147: 
148:             case 'publisheddate':
149:                 $options['order'] = 'published';
150:                 break;
151: 
152:             case 'creationdate':
153:             default:
154:                 $options['order'] = 'created';
155:                 break;
156:         }
157: 
158:         if (isset($options['artspecs']) === false) {
159:             $options['artspecs'] = array();
160:         }
161: 
162:         if (isset($options['direction']) === false) {
163:             $options['direction'] = 'DESC';
164:         }
165: 
166:         if (isset($options['limit']) === false) {
167:             $options['limit'] = 0;
168:         }
169: 
170:         $this->_options = $options;
171:     }
172: 
173:     /**
174:      * Executes the article search with the given options.
175:      *
176:      * @throws cUnexpectedValueException
177:      */
178:     public function loadArticles() {
179:         $this->_articles = array();
180: 
181:         $cfg = cRegistry::getConfig();
182: 
183:         $sqlCat = (count($this->_options['categories']) > 0) ? " idcat IN ('" . implode("','", $this->_options['categories']) . "') AND " : '';
184: 
185:         $db = cRegistry::getDb();
186:         $sql = "SELECT startidartlang, idcat FROM " . $cfg['tab']['cat_lang'] . " WHERE " . $sqlCat . " idlang=" . $this->_options['lang'];
187:         $db->query($sql);
188: 
189:         while ($db->nextRecord()) {
190:             $startId = $db->f('startidartlang');
191:             if ($startId > 0) {
192:                 $this->_startArticles[$db->f('idcat')] = $startId;
193:             }
194:         }
195: 
196:         $sqlCat = (count($this->_options['categories']) > 0) ? " c.idcat IN ('" . implode("','", $this->_options['categories']) . "') AND b.idart = c.idart AND " : '';
197:         $sqlArtSpecs = (count($this->_options['artspecs']) > 0) ? " a.artspec IN ('" . implode("','", $this->_options['artspecs']) . "') AND " : '';
198: 
199:         if (count($this->_startArticles) > 0) {
200:             if ($this->_options['start'] == false) {
201:                 $sqlStartArticles = "a.idartlang NOT IN ('" . implode("','", $this->_startArticles) . "') AND ";
202:             } 
203:             
204:             if ($this->_options['startonly'] == true) {
205:                 $sqlStartArticles = "a.idartlang IN ('" . implode("','", $this->_startArticles) . "') AND ";
206:             }
207:         }
208:         
209:         if ($this->_options['startonly'] == true && count($this->_startArticles) == 0) {
210:             return;
211:         }
212: 
213:         $sql = "SELECT DISTINCT a.idartlang FROM " . $cfg['tab']['art_lang'] . " AS a, ";
214:         $sql .= $cfg['tab']['art'] . " AS b, " . $cfg['tab']['cat_art'] . " AS c " . " WHERE ";
215:         $sql .= $sqlCat . $sqlStartArticles . $sqlArtSpecs . "b.idclient = '" . $this->_options['client'] . "' AND ";
216:         $sql .= "a.idlang = '" . $this->_options['lang'] . "' AND " . "a.idart = b.idart";
217: 
218:         if ($this->_options['offlineonly'] == true) {
219:             $sql .= " AND a.online = 0";
220:         } elseif ($this->_options['offline'] == false) {
221:             $sql .= " AND a.online = 1";
222:         }
223: 
224:         $sql .= " ORDER BY a." . $this->_options['order'] . " " . $this->_options['direction'];
225: 
226:         if ((int) $this->_options['limit'] > 0) {
227:             $sql .= " LIMIT " . $this->_options['limit'];
228:         }
229: 
230:         $db->query($sql);
231: 
232:         while ($db->nextRecord()) {
233:             $artLangId = $db->f('idartlang');
234:             $this->_articles[] = new cApiArticleLanguage($artLangId);
235:         }
236: 
237:         // Execute cec hook
238:         cApiCecHook::execute('Contenido.ArticleCollector.Articles', array(
239:             'idart' => cRegistry::getArticleId(),
240:             'articles' => $this->_articles
241:         ));
242:     }
243: 
244:     /**
245:      * Compatibility method for old ArticleCollection class. Returns the start
246:      * article of a category. Does work only if one category was requested.
247:      *
248:      * @return cApiArticleLanguage
249:      * @throws cBadMethodCallException
250:      */
251:     public function startArticle() {
252:         if (count($this->_startArticles) != 1) {
253:             throw new cBadMethodCallException("Can not load start article due to multiple loaded start articles.");
254:         }
255: 
256:         return new cApiArticleLanguage(current($this->_startArticles));
257:     }
258: 
259:     /**
260:      * Compatibility method for old ArticleCollection class. Returns the next
261:      * article.
262:      *
263:      * @return bool cApiArticleLanguage
264:      */
265:     public function nextArticle() {
266:         $next = $this->current();
267:         $this->next();
268: 
269:         if ($next instanceof cApiArticleLanguage) {
270:             return $next;
271:         }
272: 
273:         return false;
274:     }
275: 
276:     /**
277:      * Compatibility method for old ArticleCollection. Split the article results
278:      * into pages of a given size.
279:      * Example: Article Collection with 5 articles
280:      * [0] => 250 [1] => 251 [2] => 253 [3] => 254 [4] => 255
281:      * $collection->setResultPerPage(2)
282:      * Would split the results into 3 pages
283:      * [0] => [0] => 250 [1] => 251 [1] => [0] => 253 [1] => 254 [2] => [0] =>
284:      * 255
285:      * A page can be selected with $collection->setPage(int page)
286:      *
287:      * @param int $resPerPage
288:      */
289:     public function setResultPerPage($resPerPage) {
290:         if ($resPerPage > 0) {
291:             if (is_array($this->_articles)) {
292:                 $this->_pages = array_chunk($this->_articles, $resPerPage);
293:             } else {
294:                 $this->_pages = array();
295:             }
296:         }
297:     }
298: 
299:     /**
300:      * Compatibility method for old ArticleCollection. Select a page if the
301:      * results was divided before.
302:      * $collection->setResultPerPage(2); $collection->setPage(1);
303:      * // Iterate through all articles of page two while ($art =
304:      * $collection->nextArticle()) { ... }
305:      *
306:      * @param int $page The page of the article collection
307:      */
308:     public function setPage($page) {
309:         if (is_array($this->_pages[$page])) {
310:             $this->_articles = $this->_pages[$page];
311:         }
312:     }
313: 
314:     /**
315:      * Seeks a specific position in the loaded articles.
316:      *
317:      * @param int $position position to load
318:      * @throws cOutOfBoundsException
319:      */
320:     public function seek($position) {
321:         $this->_currentPosition = $position;
322: 
323:         if ($this->valid() === false) {
324:             throw new cOutOfBoundsException("Invalid seek position: " . $position);
325:         }
326:     }
327: 
328:     /**
329:      * Method "rewind" of the implemented iterator.
330:      */
331:     public function rewind() {
332:         $this->_currentPosition = 0;
333:     }
334: 
335:     /**
336:      * Method "current" of the implemented iterator.
337:      *
338:      * @return mixed
339:      */
340:     public function current() {
341:         return $this->_articles[$this->_currentPosition];
342:     }
343: 
344:     /**
345:      * Method "key" of the implemented iterator.
346:      *
347:      * @return int mixed
348:      */
349:     public function key() {
350:         return $this->_currentPosition;
351:     }
352: 
353:     /**
354:      * Method "next" of the implemented iterator.
355:      */
356:     public function next() {
357:         ++$this->_currentPosition;
358:     }
359: 
360:     /**
361:      * Method "valid" of the implemented iterator.
362:      *
363:      * @return bool
364:      */
365:     public function valid() {
366:         return isset($this->_articles[$this->_currentPosition]);
367:     }
368: 
369:     /**
370:      * Method "count" of the implemented Countable interface. Returns the amount
371:      * of all loaded articles.
372:      *
373:      * @return int
374:      */
375:     public function count() {
376:         return count($this->_articles);
377:     }
378: 
379: }
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen