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


PHP Item::find_by_subject方法代码示例

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


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

示例1: sync

 public static function sync($params)
 {
     $item = Item::find_by_subject($params["type"], $params["id"]);
     if (empty($item)) {
         // create
         Item::create($params);
     } else {
         // sync
         $item->update($params);
     }
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:11,代码来源:Item.php

示例2: render

 function render()
 {
     // view-specific stuff
     switch ($this->view) {
         case 'item':
             $this->subject_type = $this->params['subject_type'];
             $this->subject_id = $this->params['subject_id'];
             $this->item = Item::find_by_subject($this->subject_type, $this->subject_id);
             if (empty($this->item)) {
                 return "Item {$this->subject_type}:{$this->subject_id} not found.  Is the frontend server sending it correctly?";
             }
             // actually get the fans here
             list($this->fans, $this->n_fans, $this->n_pages, $this->page, $this->per_page) = Fan::get_recent_by_subject($this->subject_type, $this->subject_id, $this->per_page, $this->page);
             // see if current user isFan
             $this->isFan = FALSE;
             foreach ($this->fans as $i => $fan) {
                 if ($fan->user_id == PA::$login_user->user_id) {
                     $this->isFan = TRUE;
                     break;
                 }
             }
             break;
         case 'recent_by_user':
             if (empty($this->uid)) {
                 return "user_id is required";
             }
             list($this->fanof, $this->n_items, $this->n_pages, $this->page, $this->per_page) = Fan::get_recent_by_user($this->uid, $this->per_page, $this->page);
             break;
         case 'top':
             // $this->items = Item::get_most_fans($this->subject_type, 5);
             break;
         default:
             return "Unknown FansWidgetModule view {$this->view}";
             break;
     }
     $tpl =& new Template(dirname(__FILE__) . "/" . $this->skin . "_" . $this->view . ".tpl", $this);
     $this->inner_HTML = $tpl->fetch();
     return parent::render();
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:39,代码来源:FansWidgetModule.php

示例3: render

 function render()
 {
     $this->title = __('Reviews');
     $this->subject_type = @$this->params['subject_type'];
     $this->subject_id = @$this->params['subject_id'];
     $this->page = (int) @$this->params['page'] ? (int) $this->params['page'] : 1;
     switch ($this->view) {
         case 'item':
             // reviews on an item
             if (empty($this->subject_type) || empty($this->subject_id)) {
                 return "subject_type and subject_id are required";
             }
             $this->item = Item::find_by_subject($this->subject_type, $this->subject_id);
             if (empty($this->item)) {
                 return "Item {$this->subject_type}:{$this->subject_id} not found.  Is the frontend server sending it correctly?";
             }
             list($this->reviews, $this->n_reviews, $this->n_pages, $this->page, $this->per_page) = Review::get_recent_by_subject($this->subject_type, $this->subject_id, 5, $this->page);
             // get tags
             $this->tags = ItemTags::get_tags_for_item($this->subject_type, $this->subject_id);
             break;
         case 'recent_single':
             // most recent review of an item (a chosen new release)
             if (empty($this->subject_type) || empty($this->subject_id)) {
                 return "subject_type and subject_id are required";
             }
             $this->item = Item::find_by_subject($this->subject_type, $this->subject_id);
             if (empty($this->item)) {
                 return "Item {$this->subject_type}:{$this->subject_id} not found.  Is the frontend server sending it correctly?";
             }
             list($this->reviews, , , , ) = Review::get_recent_by_subject($this->subject_type, $this->subject_id, 1, 1);
             break;
         case 'recent':
             // recent reviews
             if (empty($this->subject_type)) {
                 return "subject_type is required";
             }
             $this->reviews = Review::get_recent_by_subject_type($this->subject_type, 3);
             foreach ($this->reviews as &$review) {
                 $review->item = Item::find_by_subject($review->subject_type, $review->subject_id);
                 if (empty($review->item)) {
                     return "Item {$this->subject_type}:{$this->subject_id} not found.  Is the frontend server sending it correctly?";
                 }
             }
             break;
         case 'top':
             // top reviewers
             $this->reviewers = User::get_top_reviewers(8);
             foreach ($this->reviewers as &$u) {
                 foreach ($u->get_profile_fields("videoplay", array("display_login_name", "url", "thumbnail_url")) as $k => $v) {
                     $u->{$k} = $v;
                 }
             }
             break;
         case 'recent_by_user':
             if (empty($this->uid)) {
                 return "user_id parameter is required";
             }
             // recent reviews from a user
             list($this->reviews, $this->n_reviews, $this->n_pages, $this->page, $this->per_page) = Review::get_recent_by_user($this->uid, 5, $this->page);
             break;
         default:
             return "Unknown ReviewModule view: {$this->view}";
     }
     // find unique author user_id values
     $user_ids = array();
     foreach ($this->reviews as $rev) {
         $user_ids[$rev->author_id] = 1;
     }
     if (!empty($user_ids)) {
         // load all users
         $us = new User();
         $users = $us->load_users(array_keys($user_ids));
         // add in videoplay-specific profile data
         foreach ($users as &$u) {
             $us->user_id = $u['user_id'];
             foreach ($us->get_profile_fields("videoplay", array("display_login_name", "url", "thumbnail_url")) as $k => $v) {
                 $u[$k] = $v;
             }
         }
         unset($u);
         // map ids to user info
         $user_map = array();
         foreach ($users as $u) {
             $user_map[$u['user_id']] = $u;
         }
         // and finally put them all in the review objects
         foreach ($this->reviews as $rev) {
             $rev->author = $user_map[$rev->author_id];
         }
     }
     $tpl =& new Template(dirname(__FILE__) . "/" . $this->skin . "_" . $this->view . ".tpl", $this);
     $this->inner_HTML = $tpl->fetch();
     if (preg_match($this->skin, "/_inner\$/")) {
         $content = parent::render();
     } else {
         $content = $this->inner_HTML;
     }
     return $content;
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:99,代码来源:ReviewModule.php

示例4: rate

 /**
  * Function to rate an entity. If their is no existing record for the entity rating a new record will be inserted,
  * otherwise the existing entry will be updated  
  */
 public function rate()
 {
     Logger::log("Enter: Rating::rate()");
     try {
         $sql = 'SELECT index_id FROM {rating} WHERE rating_type = ? AND type_id = ? AND attribute_id = ? AND user_id = ?';
         $data = array($this->rating_type, $this->type_id, $this->attribute_id, $this->user_id);
         $res = Dal::query($sql, $data);
         if ($res->numRows()) {
             //update the existing rating
             $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
             $this->index_id = $row->index_id;
             $sql = 'UPDATE {rating} SET rating = ?, max_rating = ? WHERE index_id = ?';
             $data = array($this->rating, $this->max_rating, $this->index_id);
             Dal::query($sql, $data);
         } else {
             //creating a new rating
             $sql = 'INSERT INTO {rating} (rating_type, type_id, attribute_id, rating, max_rating, user_id) values (?, ?, ?, ?, ?, ?)';
             $data = array($this->rating_type, $this->type_id, $this->attribute_id, $this->rating, $this->max_rating, $this->user_id);
             Dal::query($sql, $data);
         }
         //TODO: update denormalization
     } catch (PAException $e) {
         throw $e;
     }
     // update the avg rating for item if we have items
     try {
         $overall = $this->get_rating();
         // get the overall rating
         $avg_rating = $overall[0]->total_rating / $overall[0]->total_max_rating * $this->max_rating;
         $ratings = $overall[0]->ratings;
         require_once PA::$path . '/api/Item/Item.php';
         $item = Item::find_by_subject($this->rating_type, $this->type_id);
         $item->update(array("average_rating" => $avg_rating, "rating_count" => $ratings));
     } catch (PAException $e) {
         Logger::log("NOTE: Rating::rate(), there seems to be a problem with items " . $e->getMessage());
         throw $e;
     }
     Logger::log("Exit: Rating::rate()");
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:43,代码来源:Rating.php

示例5: render

 function render()
 {
     $login_uid = @PA::$login_user->user_id;
     $this->gid = @$this->params['blog_id'];
     $this->blog_name = @$this->params['blog_name'];
     $this->note = '';
     if ($this->blog_name) {
         $this->find_or_create_blog();
     }
     if ($this->gid) {
         $this->type == 'group';
         $group = new Group();
         $group->collection_id = $this->gid;
         $group->load($this->gid);
         $this->group_member = Group::member_exists($group->collection_id, $login_uid) ? TRUE : FALSE;
         switch ($this->view) {
             case "recent_post":
                 // load content
                 $this->contents = $group->get_contents_for_collection($type = 'all', $cnt = FALSE, 1, 1, 'created', 'DESC');
                 $this->inner_template = 'recent_post.tpl';
                 break;
             case 'user':
                 // load content
                 if (@$this->params['cid']) {
                     // permalink, load only this one
                     $bp = new BlogPost();
                     try {
                         $bp->load((int) $this->params['cid']);
                         $this->count = 1;
                         $content = array();
                         foreach ($bp as $k => $v) {
                             $content[$k] = $v;
                         }
                         $this->contents[] = $content;
                     } catch (PAException $e) {
                         $this->err = __("Couldn't load BlogPost. ") . $e->getMessage();
                     }
                 } else {
                     $this->count = $group->get_contents_for_collection($type = 'all', $cnt = TRUE, 'all', 0, $sort_by = 'created', $direction = 'DESC');
                     $this->contents = $group->get_contents_for_collection($type = 'all', $cnt = FALSE, $this->show, $this->page, 'created', 'DESC');
                 }
                 break;
             case "admin":
                 $this->title = "Managing authors for " . $this->blog_name;
                 $this->inner_template = 'manageauthors.tpl';
                 // find members
                 $this->members = $group->get_members();
                 $this->member_count = count($this->members);
                 break;
         }
         // load Items for all BlogPosts -> for Comments to work
         foreach ($this->contents as $i => $post) {
             $item_params = array("type" => 'blogpost', "id" => $post['content_id'], "name" => $post['content_id'], "thumbnail" => "", "thumbnail_w" => "0", "thumbnail_h" => "0", "genres" => "blog", "url" => $this->blog_url . "?b_cid=" . $post['content_id']);
             Item::sync($item_params);
             // create or update row in 'items' database table
             $item = Item::find_by_subject('blogpost', $post['content_id']);
             $this->contents[$i]['comment_count'] = $item->comment_count;
         }
     } else {
         $this->err = __("No Blog found.");
     }
     $tmp_file = dirname(__FILE__) . "/" . $this->skin . "_" . $this->inner_template;
     $inner_html_gen =& new Template($tmp_file, $this);
     $this->inner_HTML = $inner_html_gen->fetch();
     $content = parent::render();
     return $content;
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:67,代码来源:BlogWidgetModule.php

示例6: peopleaggregator_getItems

function peopleaggregator_getItems($args)
{
    global $_PA;
    require_once PA::$path . "/api/Item/Item.php";
    $remote_user = @$args['remoteUser'];
    if ($remote_user) {
        if (!$_PA->enable_widgetization_server) {
            throw new PAException(OPERATION_NOT_PERMITTED, "Widgetization disabled; you cannot use remote user functions");
        }
        require_once PA::$path . "/api/User/ShadowUser.php";
        require_once PA::$path . "/api/Rating/Rating.php";
        require_once PA::$path . "/ext/PA_Rating/PA_Rating.php";
        $remote_id = explode(":", $remote_user);
        if (count($remote_id) == 1) {
            throw new PAException(INVALID_ID, "Remote user IDs must be of the form 'namespace:id'");
        }
        $u = new ShadowUser($remote_id[0]);
        $u->load($remote_id[1]);
        if (!$u->user_id) {
            throw new PAException(USER_NOT_FOUND, "Failed to locate user '" . $remote_id[1] . "' in namespace '" . $remote_id[0] . "'");
        }
    } else {
        $u = NULL;
    }
    $items_out = array();
    foreach (explode(",", $args['ids']) as $packed_id) {
        $item_id = explode(":", $packed_id);
        if (count($item_id) == 1) {
            throw new PAException(INVALID_ID, "Individual item IDs must be of the form 'type:id'");
        }
        $item = Item::find_by_subject($item_id[0], $item_id[1]);
        if ($item == NULL) {
            continue;
        }
        // ignore IDs that don't exist
        $item_out = item_to_array($item);
        if ($u) {
            $params = array('rating_type' => $item_id[0], 'user_id' => $u->user_id, 'type_id' => $item_id[1]);
            $user_rating_details = PA_Rating::get($params);
            if (count($user_rating_details)) {
                $item_out['userRating'] = (int) $user_rating_details[0]->rating;
            }
        }
        $items_out[] = $item_out;
    }
    return array("success" => TRUE, "msg" => "Retrieved " . count($items_out) . " item(s)", "items" => $items_out);
}
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:47,代码来源:api_impl.php

示例7: render

 function render()
 {
     // if (empty(PA::$login_user)) return __("Login required");
     $this->title = __('Comments');
     $this->subject_type = @$this->params['subject_type'];
     $this->page = (int) @$this->params['page'] ? (int) $this->params['page'] : 1;
     switch ($this->view) {
         case 'item':
             $this->subject_id = $this->params['subject_id'];
             $this->item = Item::find_by_subject($this->subject_type, $this->subject_id);
             if (empty($this->item)) {
                 return "Item {$this->subject_type}:{$this->subject_id} not found.  Is the frontend server sending it correctly?";
             }
             if (empty($this->subject_type) || empty($this->subject_id)) {
                 return "subject_type and subject_id are required";
             }
             list($this->comments, $this->n_comments, $this->n_pages, $this->page, $this->per_page) = Comment2::get_recent_by_subject($this->subject_type, $this->subject_id, 5, $this->page);
             break;
         case 'most_commented':
             if (empty($this->subject_type)) {
                 return "subject_type is required";
             }
             $this->items = Item::get_most_commented_by_subject_type($this->subject_type, 3);
             break;
         case 'recent_by_user':
             if (empty($this->uid)) {
                 return "user_id is required";
             }
             //TODO
             list($this->comments, $this->n_comments, $this->n_pages, $this->page, $this->per_page) = Comment2::get_recent_by_user($this->uid, 5, $this->page);
             break;
         default:
             return "Unknown CommentModule view: {$this->view}";
     }
     // find unique author user_id values
     $user_ids = array();
     foreach ($this->comments as $c) {
         $user_ids[$c->author_id] = 1;
     }
     if (!empty($user_ids)) {
         // load all users
         $us = new User();
         $users = $us->load_users(array_keys($user_ids));
         // add in videoplay-specific profile data
         foreach ($users as &$u) {
             $us->user_id = $u['user_id'];
             foreach ($us->get_profile_fields("videoplay", array("display_login_name", "url", "thumbnail_url")) as $k => $v) {
                 $u[$k] = $v;
             }
         }
         unset($u);
         // free the reference so we don't break stuff down below by assigning $u
         // map ids to user info
         $user_map = array();
         foreach ($users as $u) {
             $user_map[$u['user_id']] = $u;
         }
         // and finally put them all in the comment objects
         foreach ($this->comments as $rev) {
             $rev->author = $user_map[$rev->author_id];
         }
     }
     $this->inner_HTML = $this->generate_inner_html();
     if (preg_match($this->skin, "/_inner\$/")) {
         $content = parent::render();
     } else {
         $content = $this->inner_HTML;
     }
     return $content;
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:70,代码来源:CommentModule.php

示例8: get_recent_by_user

 function get_recent_by_user($uid, $cnt)
 {
     $scale = 5;
     $user_ratings = PA_Rating::get_recent_by_user($uid, $cnt);
     foreach ($user_ratings as $i => $r) {
         $r->html = $this->stars($r->rating);
         $r->item = Item::find_by_subject($r->rating_type, $r->type_id);
     }
     return $user_ratings;
 }
开发者ID:CivicCommons,项目名称:oldBellCaPA,代码行数:10,代码来源:RatingModule.php


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