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


PHP ORM::loaded方法代码示例

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


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

示例1: update

 /**
  * Function for easy update a ORM object
  *
  * @param ORM $object ORM object to update
  * @param array $messages Array of custom messages
  */
 public function update(ORM $object, array $messages = array())
 {
     // Check if is a valid object
     if (!$object->loaded()) {
         Messages::warning(isset($messages['warning']) ? $messages['warning'] : 'El elemento que intentas modificar no existe o fue eliminado.');
         $this->go();
     }
     // Only if Request is POST
     if ($this->request->method() == Request::POST) {
         // Catch ORM_Validation
         try {
             // Set object values and update
             $object->values($this->request->post())->update();
             // If object is saved....
             if ($object->saved()) {
                 // Success message & redirect
                 Messages::success(isset($messages['success']) ? $messages['success'] : 'El elemento fue modificado correctamente.');
                 $this->go();
             }
         } catch (ORM_Validation_Exception $e) {
             // Error message
             if (isset($messages['error'])) {
                 Messages::error($messages['error']);
             }
             // Validation messages
             Messages::validation($e);
         }
     }
 }
开发者ID:NegoCore,项目名称:core,代码行数:35,代码来源:CRUD.php

示例2: row_exist

function row_exist(ORM $orm, $field_name, $field_value, array $where = array())
{
    $search_orm = clone $orm;
    $search_orm->clear();
    foreach ($where as $_conf) {
        if ($_conf[0] === 'and') {
            $search_orm->where($_conf[1], $_conf[2], $_conf[3]);
        } elseif ($_conf[0] === 'or') {
            $search_orm->or_where($_conf[1], $_conf[2], $_conf[3]);
        }
    }
    if ($orm->loaded()) {
        $orm = $search_orm->where($field_name, '=', $field_value)->and_where('id', '!=', $orm->id)->find();
    } else {
        $orm = $search_orm->where($field_name, '=', $field_value)->find();
    }
    return $orm->loaded();
}
开发者ID:greor,项目名称:satin-spb,代码行数:18,代码来源:init.php

示例3: comment

 /**
  * Make sure the user has permission to do the action on this object
  *
  * Similar to [Comment::access] but this return TRUE/FALSE instead of exception
  *
  * @param   string     $action   The action `view|edit|delete` default `view`
  * @param   ORM        $comment  The comment object
  * @param   Model_User $user     The user object to check permission, defaults to loaded in user
  * @param   string     $misc     The misc element usually `id|slug` for logging purpose
  *
  * @return  boolean
  *
  * @throws  HTTP_Exception_404
  *
  * @uses    User::active_user
  * @uses    Module::event
  */
 public static function comment($action = 'view', ORM $comment, Model_User $user = NULL, $misc = NULL)
 {
     if (!in_array($action, array('view', 'edit', 'delete', 'add', 'list'), TRUE)) {
         // If the $action was not one of the supported ones, we return access denied.
         Log::notice('Unauthorized attempt to access non-existent action :act.', array(':act' => $action));
         return FALSE;
     }
     if (!$comment->loaded()) {
         // If the $action was not one of the supported ones, we return access denied.
         throw HTTP_Exception::factory(404, 'Attempt to access non-existent comment.');
     }
     // If no user object is supplied, the access check is for the current user.
     if (is_null($user)) {
         $user = User::active_user();
     }
     if (self::check('bypass comment access', $user)) {
         return TRUE;
     }
     // Allow other modules to interact with access
     Module::event('comment_access', $action, $comment);
     if ($action === 'view') {
         if ($comment->status === 'publish' and self::check('access comment', $user)) {
             return TRUE;
         } elseif ($comment->status != 'publish' and $comment->author == (int) $user->id and $user->id != 1) {
             return TRUE;
         } elseif (self::check('administer comment', $user)) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     if ($action === 'edit') {
         if (self::check('edit own comment') and $comment->author == (int) $user->id and $user->id != 1) {
             return TRUE;
         } elseif (self::check('administer comment', $user)) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     if ($action === 'delete') {
         if ((self::check('delete own comment') or self::check('delete any comment')) and $comment->author == (int) $user->id and $user->id != 1) {
             return TRUE;
         } elseif (self::check('administer comment', $user)) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     return TRUE;
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:68,代码来源:acl.php

示例4: sso_signup

 /**
  * Sign-up using data from OAuth provider.
  *
  * Override this method to add your own sign up process.
  *
  * @param   ORM     $user
  * @param   array   $data
  * @param   string  $provider
  * @return  ORM
  */
 public function sso_signup(ORM $user, array $data, $provider_field)
 {
     if (!$user->loaded()) {
         // Add user
         $user->{$provider_field} = $data['id'];
         $user->user_type = 0;
         $user->username = $provider_field . $data['id'];
         $user->user_password = md5($user->username . microtime(TRUE));
         if ($provider_field == 'vkontakte_id' or $provider_field == 'facebook_id') {
             $user->email = $user->username . '@bt-lady.com.ua';
             $user->firstname = $data['first_name'];
             $user->lastname = $data['last_name'];
             if (array_key_exists('birthday', $data) or array_key_exists('bdate', $data)) {
                 $date_key = isset($data['bdate']) ? 'bdate' : 'birthday';
                 $date = NULL;
                 try {
                     $_date = new DateTime($data[$date_key]);
                     $date = $_date->format('d-m-Y');
                 } catch (Exception $e) {
                 }
                 $user->birthday = $date;
             }
             if (array_key_exists('email', $data)) {
                 $user->email = $data['email'];
             }
             if (array_key_exists('photo_big', $data)) {
                 $user->avatar = $data['photo_big'];
             }
             if (array_key_exists('location', $data) or array_key_exists('hometown', $data)) {
                 $key = isset($data['location']) ? 'location' : 'hometown';
                 if (is_array($data[$key]) and array_key_exists('name', $data[$key])) {
                     $user->user_from = $data[$key]['name'];
                 }
             }
             if (array_key_exists('city', $data) and array_key_exists('country', $data)) {
                 $user->city_id = ORM::factory('city', array('vkontakte_cid' => $data['city']));
             }
         } elseif ($provider_field == 'twitter_id') {
             $user->email = $data['screen_name'] . '@twitter.com';
         }
         // Save user
         $user->save();
         $user->add('roles', ORM::factory('role', array('name' => $provider_field)));
         $user->add('roles', ORM::factory('role', array('name' => 'social')));
         $user->update();
     } elseif ($user->loaded() and empty($user->{$provider_field})) {
         // If user is found, but provider id is missing add it to details.
         // We can do this merge, because this means user is found by email address,
         // that is already confirmed by this OAuth provider, so it's considered trusted.
         $user->{$provider_field} = $data['id'];
         // Save user
         $user->save();
     }
     // Return user
     return $user;
 }
开发者ID:nergal,项目名称:2mio,代码行数:66,代码来源:user.php

示例5: _build_final_filter_query

 /**
  * Internal helper function for generating the final filtering query
  *
  * @param ORM                   $orm_instance
  * @param Database_Query_Select $sub_query
  * @param array                 $filters
  * @param string                $filter_type
  *
  * @return Database_Query_Select
  */
 private static function _build_final_filter_query($orm_instance, $sub_query, $filters, $filter_type)
 {
     $final_query = DB::select(array('droplets.id', 'droplet_id'));
     if ($sub_query) {
         $final_query->union($sub_query, TRUE);
     }
     $final_query->from('droplets');
     // Check the filter type
     if ($filter_type === 'tags') {
         $final_query->join('droplets_tags', 'INNER')->on('droplets_tags.droplet_id', '=', 'droplets.id')->join('tags', 'INNER')->on('droplets_tags.tag_id', '=', 'tags.id');
     } elseif ($filter_type === 'places') {
         $final_query->join('droplets_places', 'INNER')->on('droplets_places.droplet_id', '=', 'droplets.id')->join('places', 'INNER')->on('droplets_places.place_id', '=', 'places.id');
     }
     // Check the ORM instance class
     if ($orm_instance instanceof Model_River and $orm_instance->loaded()) {
         $final_query->join('rivers_droplets', 'INNER')->on('rivers_droplets.droplet_id', '=', 'droplets.id')->where('rivers_droplets.river_id', '=', $orm_instance->id);
     } elseif ($orm_instance instanceof Model_Bucket and $orm_instance->loaded()) {
         $final_query->join('buckets_droplets', 'INNER')->on('buckets_droplets.droplet_id', '=', 'droplets.id')->where('buckets_droplets.bucket_id', '=', $orm_instance->id);
     }
     if ($filter_type === 'tags') {
         $final_query->where('tags.tag_canonical', 'IN', $filters['tags']);
     } elseif ($filter_type === 'places') {
         $final_query->where('places.place_name_canonical', 'IN', $filters['places']);
     }
     return $final_query;
 }
开发者ID:rukku,项目名称:SwiftRiver,代码行数:36,代码来源:droplet.php

示例6: photo

 public function photo(ORM $object, $size = NULL, $type = 'cropr')
 {
     if ($object->loaded()) {
         if ($object instanceof Model_Photo or $object instanceof Model_Abstract_Page and $object->get_alias() == 'photo') {
             $url = array('/' . ($size === NULL ? 'uploads' : 'thumbnails'));
             if (preg_match('#^([a-f0-9]{32,})\\.(gif|jpe?g|png)$#ui', $object->photo)) {
                 $url[] = substr($object->photo, 0, 2);
                 $url[] = substr($object->photo, 2, 4);
                 $filename = $object->photo;
             } else {
                 $url = array('/' . ($size === NULL ? 'images' : 'thumbnails') . '/articles');
                 $photo = explode('/', $object->photo);
                 $photo = array_filter($photo);
                 $filename = array_splice($photo, -1, 1);
                 $filename = end($filename);
                 $url = array_merge($url, $photo);
             }
             if ($size !== NULL) {
                 $url[] = "{$type}_{$size}";
             }
             $url[] = $filename;
             $url = array_filter($url);
             return implode('/', $url);
         } elseif ($object instanceof Model_Media) {
             $url = array('/' . ($size === NULL ? 'images' : 'thumbnails') . '/articles');
             $photo = explode('/', basename($object->name));
             $photo = array_filter($photo);
             $filename = array_splice($photo, -1, 1);
             $filename = end($filename);
             $url = array_merge($url, $photo);
             if ($size !== NULL) {
                 $url[] = "{$type}_{$size}";
             }
             $url[] = $filename;
             $url = array_filter($url);
             return implode('/', $url);
         } elseif ($object->photo) {
             $url = array('/' . ($size === NULL ? 'images' : 'thumbnails') . '/articles');
             $photo = explode('/', $object->photo);
             $photo = array_filter($photo);
             $filename = array_splice($photo, -1, 1);
             $url = array_merge($url, $photo);
             if ($size !== NULL) {
                 $url[] = $type . '_' . $size;
             }
             $url[] = end($filename);
             return implode('/', $url);
         }
     }
     return '/i/placeholder.gif';
 }
开发者ID:nergal,项目名称:2mio,代码行数:51,代码来源:view.php


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