Ejemplo n.º 1
0
 public function executeIndex()
 {
     $name = $this->getRequestParameter('tag', '');
     $c = new Criteria();
     if ($name) {
         $c->add(TagPeer::NAME, $name);
         $tag = TagPeer::doSelectOne($c);
         $this->forward404Unless($tag);
         $c->clear();
         $c->addJoin(PostTagPeer::POST_ID, PostPeer::ID, Criteria::LEFT_JOIN);
         $c->add(PostTagPeer::TAG_ID, $tag->getId());
     }
     $c->addDescendingOrderByColumn(PostPeer::CREATED_AT);
     $c->setLimit(sfConfig::get('app_posts_in_feed', 10));
     $c->add(PostPeer::DELETED, false);
     $posts = PostPeer::doSelect($c);
     $this->feed = $this->createFeed($posts, $name);
     ReaderPeer::increment();
 }
Ejemplo n.º 2
0
 public function executeStats()
 {
     $stats = array();
     $c = new Criteria();
     // readers_cnt
     $date = date('Y-m-d', strtotime('-1 day'));
     $c->clear();
     $c->add(ReaderPeer::DATE, $date);
     $readers = ReaderPeer::doSelectOne($c);
     $cnt = $readers ? $readers->getCnt() : 0;
     $tcnt = $cnt % 100;
     $str = '';
     if ($tcnt == 1) {
         $str = 'osoba';
     } else {
         if ($tcnt >= 12 && $tcnt <= 14) {
             $str = 'osób';
         } else {
             if ($tcnt % 10 > 1 && $tcnt % 10 < 5) {
                 $str = 'osoby';
             } else {
                 $str = 'osób';
             }
         }
     }
     $stats['reader_cnt'] = $cnt == 0 ? 'brak danych' : sprintf('%d %s', $cnt, $str);
     // blog_cnt
     $c->clear();
     $c->add(BlogPeer::APPROVED, true);
     $stats['blog_cnt'] = BlogPeer::doCount($c);
     // post_cnt
     $c->clear();
     $c->add(PostPeer::DELETED, false);
     $stats['post_cnt'] = PostPeer::doCount($c);
     // month_avg
     $c->clear();
     $c->addAscendingOrderByColumn(PostPeer::CREATED_AT);
     $post = PostPeer::doSelectOne($c);
     $ots = $post ? $post->getCreatedAt(null) : time();
     $years = date('Y') - date('Y', $ots);
     $months = $years * 12 + (date('n') - date('n', $ots));
     $stats['month_avg'] = $months > 0 ? round($stats['post_cnt'] / $months) : 0;
     // assign
     $this->stats = $stats;
 }
Ejemplo n.º 3
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      Connection $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(ReaderPeer::DATE, $pks, Criteria::IN);
         $objs = ReaderPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 4
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME,
  * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = ReaderPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setDate($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setCnt($arr[$keys[1]]);
     }
 }