当前位置: 首页>>代码示例>>PHP>>正文


PHP Model_Location::get_parents_ids方法代码示例

本文整理汇总了PHP中Model_Location::get_parents_ids方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_Location::get_parents_ids方法的具体用法?PHP Model_Location::get_parents_ids怎么用?PHP Model_Location::get_parents_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Model_Location的用法示例。


在下文中一共展示了Model_Location::get_parents_ids方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_location_count

 /**
  * counts how many ads have each location
  * @return array
  */
 public static function get_location_count()
 {
     //name used in the cache for storage
     $cache_name = 'get_location_count';
     if (($locs_count = Core::cache($cache_name)) === NULL) {
         $expr_date = is_numeric(core::config('advertisement.expire_date')) ? core::config('advertisement.expire_date') : 0;
         $db_prefix = Database::instance('default')->table_prefix();
         //get the locations that have ads id_location->num ads
         $count_ads = DB::select('l.id_location', array(DB::expr('COUNT("a.id_ad")'), 'count'))->from(array('locations', 'l'))->join(array('ads', 'a'))->using('id_location')->where(DB::expr('IF(' . $expr_date . ' <> 0, DATE_ADD( published, INTERVAL ' . $expr_date . ' DAY), DATE_ADD( NOW(), INTERVAL 1 DAY))'), '>', Date::unix2mysql())->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->group_by('l.id_location')->order_by('l.order', 'asc')->cached()->execute();
         $count_ads = $count_ads->as_array('id_location');
         //getting the count of ads into the parents
         $parents_count = array();
         foreach ($count_ads as $count_ad) {
             $id_location = $count_ad['id_location'];
             $count = $count_ad['count'];
             //adding himself if doesnt exists
             if (!isset($parents_count[$id_location])) {
                 $parents_count[$id_location] = $count_ad;
                 $parents_count[$id_location]['has_siblings'] = FALSE;
             }
             $location = new Model_Location($id_location);
             //for each parent of this location add the count
             $parents_ids = $location->get_parents_ids();
             if (count($parents_ids) > 0) {
                 foreach ($parents_ids as $id) {
                     if (isset($parents_count[$id])) {
                         $parents_count[$id]['count'] += $count_ads[$location->id_location]['count'];
                     } else {
                         $parents_count[$id]['count'] = $count_ads[$location->id_location]['count'];
                     }
                     $parents_count[$id]['has_siblings'] = TRUE;
                 }
             }
         }
         //get all the locations with level 0 and 1
         $locations = new self();
         $locations = $locations->where('id_location', '!=', 1)->where('parent_deep', 'IN', array(0, 1))->order_by('order', 'asc')->cached()->find_all();
         //generating the array
         $locs_count = array();
         foreach ($locations as $location) {
             $has_siblings = isset($parents_count[$location->id_location]) ? $parents_count[$location->id_location]['has_siblings'] : FALSE;
             //they may not have counted the siblings since the count was 0 but he actually has siblings...
             if ($has_siblings === FALSE and $location->has_siblings()) {
                 $has_siblings = TRUE;
             }
             $locs_count[$location->id_location] = array('id_location' => $location->id_location, 'seoname' => $location->seoname, 'name' => $location->name, 'id_location_parent' => $location->id_location_parent, 'parent_deep' => $location->parent_deep, 'order' => $location->order, 'has_siblings' => $has_siblings, 'count' => isset($parents_count[$location->id_location]) ? $parents_count[$location->id_location]['count'] : 0);
             //counting the ads the parent have
         }
         //cache the result is expensive!
         Core::cache($cache_name, $locs_count);
     }
     return $locs_count;
 }
开发者ID:kotsios5,项目名称:openclassifieds2,代码行数:57,代码来源:location.php


注:本文中的Model_Location::get_parents_ids方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。