/** * Creates and returns an instance of Ini * * @param array|mixed $file * * @return static */ public static function makeFromFile($file) { $_ini = new static(); $_ini->setFile($file); $_ini->load(); return $_ini; }
/** * Get the current user's wishlist * * @return \Shop\Models\Wishlists */ public static function fetchForUser() { $wishlist = new static(); $identity = \Dsc\System::instance()->get('auth')->getIdentity(); $session_id = \Dsc\System::instance()->get('session')->id(); if (!empty($identity->id)) { $wishlist->load(array('user_id' => new \MongoId((string) $identity->id))); $wishlist->user_id = $identity->id; $session_wishlist = static::fetchForSession(); // if there was no user wishlist but there IS a session wishlist, just add the user_id to the session wishlist and save it if (empty($wishlist->id) && !empty($session_wishlist->id)) { $wishlist = $session_wishlist; $wishlist->user_id = $identity->id; $wishlist->save(); } // if there was a user wishlist and there is a session wishlist, merge them and delete the session wishlist // if we already did the merge, skip this $session_wishlist_merged = \Dsc\System::instance()->get('session')->get('shop.session_wishlist_merged'); if (!empty($session_wishlist->id) && $session_wishlist->id != $wishlist->id && empty($session_wishlist_merged)) { $wishlist->session_id = $session_id; $wishlist->merge($session_wishlist->cast()); $session_wishlist->remove(); \Dsc\System::instance()->get('session')->set('shop.session_wishlist_merged', true); } if (empty($wishlist->id)) { $wishlist->save(); } } return $wishlist; }
/** * Create a thumbnail */ static function create($source, $options = array()) { // Create thumb $thumb = new static(); // Load $thumb->load($source); // Set properties $properties = array('type', 'quality', 'alignX', 'alignY', 'background'); // Loop foreach ($properties as $property) { // If set if (isset($options[$property])) { // Set it $thumb->{$property} = $options[$property]; } } // If there's width if (isset($options['width']) && ($width = $options['width'])) { // Set width $thumb->width = $width; } // If there's height if (isset($options['height']) && ($height = $options['height'])) { // Set height $thumb->height = $height; } // Resize $thumb->resize(); // Render and return return $thumb->render(); }
public static function Factory($id = null) { $obj = new static(); if ($id) { $obj->load($id); } return $obj; }
public static function getByID($avID) { $uav = new static(); $uav->load($avID); if ($uav->getAttributeValueID() == $avID) { return $uav; } }
public static function getByID($akID) { $ak = new static(); $ak->load($akID); if ($ak->getAttributeKeyID() > 0) { return $ak; } }
/** * โหลด template * ครั้งแรกจะตรวจสอบไฟล์จาก module ถ้าไม่พบ จะใช้ไฟล์จาก owner * * @param string $owner ชื่อโมดูลที่ติดตั้ง * @param string $module ชื่อโมดูล * @param string $name ชื่อ template ไม่ต้องระบุนามสกุลของไฟล์ * @return \static * * @assert ('', '', 'FileNotFound')->isEmpty() [==] true */ public static function create($owner, $module, $name) { $obj = new static(); $obj->skin = $obj->load($owner, $module, $name); $obj->items = array(); $obj->num = -1; return $obj; }
/** * Save link preview model and return id * @param $post * @return integer|null */ public static function saveAndGetId($post) { $model = new static(); if ($model->load($post) && $model->save()) { return $model->id; } return null; }
/** * โหลด template * ครั้งแรกจะตรวจสอบไฟล์จาก module ถ้าไม่พบ จะใช้ไฟล์จาก owner * * @param string $owner ชื่อโมดูลที่ติดตั้ง * @param string $module ชื่อโมดูล * @param string $name ชื่อ template ไม่ต้องระบุนามสกุลของไฟล์ * @param int $cols 0 (default) แสดงผลแบบปกติ มากกว่า 0 แสดงผลด้วยกริด * @return \static */ public static function create($owner, $module, $name, $cols = 0) { $obj = new static(); $obj->skin = $obj->load($owner, $module, $name); $obj->items = array(); $obj->cols = (int) $cols; $obj->num = $obj->cols; return $obj; }
/** * Check if a user is in a group * @param int $group_id * @param int $user_id * @return bool */ public static function userIsInGroup($group_id, $user_id = null) { $f3 = \Base::instance(); if ($user_id === null) { $user_id = $f3->get("user.id"); } $group = new static(); $group->load(array('user_id = ? AND group_id = ?', $user_id, $group_id)); return $group->id ? true : false; }
/** * Cancel the invoice * @return static * @throws UnsavedException */ public function cancel() { if (!$this->saved()) { throw new UnsavedException(); } $path = $this->router->path([$this->_id, 'cancel']); $response = $this->client->get($path); $cancelInvoice = new static($this->client, true); $cancelInvoice->load($response['id']); return $cancelInvoice; }
/** * Set a configuration value * @param string $key * @param mixed $value * @return Config */ public static function setVal($key, $value) { $f3 = \Base::instance(); $f3->set($key, $value); $item = new static(); $item->load(array('attribute = ?', $key)); $item->attribute = $key; $item->value = $value; $item->save(); return $item; }
/** * @param string $xml * @return static */ public static function createByXml($xml) { $model = new static(); $attributes = ToolsHelper::xmlToArray($xml); foreach ($attributes as $name => $value) { if ($value instanceof SimpleXMLElement) { unset($attributes[$name]); } } $model->load($attributes, ''); return $model; }
static function getList($sql = NULL) { $db = Registry::getInstance()->get(static::DB); $recordset = $db->getRecordset($sql ? $sql : 'SELECT * FROM `' . static::TABLE . '` ORDER BY `name`'); $list = []; while ($record = $recordset->fetch()) { $entity = new static(); $entity->load($record); $list[$entity->id] = $entity; } return $list; }
/** * Load a DAO by its ID(s) * * @param ...$id * * @return static * @throws DaoNotFoundException */ public static function loadById(...$id) { $dao = new static(); /** * @var $dao AbstractDao */ $dao->hydrateDao(array_combine($dao->getDaoIDProperties(), $id)); /** * @var $dao LsdTrait */ $dao->load(); return $dao; }
/** * Create a new service locator for the AWS SDK * * You can configure the service locator is four different ways: * * 1. Use the default configuration file shipped with the SDK that wires * class names with service short names and specify global parameters to * add to every definition (e.g. key, secret, credentials, etc) * * 2. Use a custom configuration file that extends the default config and * supplies credentials for each service. * * 3. Use a custom config file that wires services to custom short names for * services. * * 4. If you are on Amazon EC2, you can use the default configuration file * and not provide any credentials so that you are using InstanceProfile * credentials. * * @param array|string|\SimpleXMLElement $config An instantiated SimpleXMLElement containing configuration * data, the full path to an .xml or .js|.json file, or when * using the default configuration file, an associative * array of data to use as global parameters to pass to each * service as it is instantiated. * @param array $globalParameters Array of global parameters to pass to every service as it * is instantiated. * * @return ServiceBuilder */ public static function factory($config = null, array $globalParameters = array()) { if (!$config) { // If nothing is passed in, then use the default configuration file // with Instance profile credentials $config = self::getDefaultServiceDefinition(); } elseif (is_array($config)) { // If an array was passed, then use the default configuration file // with global parameter overrides in the first argument $globalParameters = $config; $config = self::getDefaultServiceDefinition(); } $loader = new static(); return $loader->load($config, $globalParameters); }
/** * Получение массива с данными локализации для группы сущностей * @param int[] $idList Массив идентификаторов родителей * @return array */ static function getListByIds($idList) { $result = []; if (is_array($idList) && count($idList)) { $ids = array_map('intval', $idList); foreach ($l = self::loadByParentIds($ids) as $parentId => $l10nData) { $l10n = new static(); $l10n->parentId = $parentId; foreach ($l10nData as $localeId => $l10nItem) { $l10n->load($localeId, $l10nItem); } $result[$parentId] = $l10n; } } return $result; }
/** * Load from yaml file * * @param string $file * @return boolean * @throws \RuntimeException */ public static function loadFromYamlFile($file = null) { if ($file === null) { $yaml = Config::get('schema'); } else { if (!file_exists($file)) { throw new \RuntimeException("file `{$file}` is not found"); } $yaml = Yaml::parse(file_get_contents($file)); } if (!empty($yaml)) { $self = new static(); return $self->load($yaml); } return false; }
public static function findOne($name, $as_array = false) { $auth = Yii::$app->authManager; $role = $auth->getRole($name); $model = new static(); $model->load(ArrayHelper::toArray($role), ''); $children = $auth->getChildren($role->name); foreach ($children as $item) { if ($item->type == Item::TYPE_ROLE) { $model->roles[] = $item->name; } elseif ($item->type == Item::TYPE_PERMISSION) { $model->permissions[] = $item->name; } } return $model; }
public static function getByHandle($akHandle) { $ak = CacheLocal::getEntry('collection_attribute_key_by_handle', $akHandle); if (is_object($ak)) { return $ak; } elseif ($ak == -1) { return false; } $ak = new static(); $ak->load($akHandle, 'akHandle'); if ($ak->getAttributeKeyID() < 1) { $ak = -1; } CacheLocal::set('collection_attribute_key_by_handle', $akHandle, $ak); if ($ak === -1) { return false; } return $ak; }
/** * @param array $where * @param array $order * @return static[] */ public static function getAll($where = array(), $order = array('id' => true)) { $mappedWhere = array(); $mapping = static::getMapping(); foreach ($where as $property => $value) { if (isset($mapping[$property])) { $mappedWhere[$mapping[$property]] = $value; } else { $mappedWhere[$property] = $value; } } $rows = Database::get()->select(static::TABLE_NAME, $mappedWhere, $order); $objects = array(); foreach ($rows as $row) { $object = new static(); $objects[] = $object->load($row); } return $objects; }
/** * Factory method * * @param string $iniFile File path for the ini file to parse. * @param array $additionalConstants Additional constants that will be translated * when parsing paths. * @deprecated Use ConfigFinder::loadAll() instead. */ public static function buildFromIniFile($iniFile = null, $constants = array()) { if (empty($iniFile)) { $iniFile = CONFIG . 'asset_compress.ini'; } $config = new static([], $constants); return $config->load($iniFile); }
/** * Returns a list of all themes. * @return array Returns an array of the Theme objects. */ public static function all() { $path = base_path() . Config::get('cms.themesDir'); $it = new DirectoryIterator($path); $it->rewind(); $result = []; foreach ($it as $fileinfo) { if (!$fileinfo->isDir() || $fileinfo->isDot()) { continue; } $theme = new static(); $theme->load($fileinfo->getFilename()); $result[] = $theme; } return $result; }
/** * @return static */ public static function createDefault() { $model = new static(); $model->load([$model->formName() => ['limit' => static::LIMIT_MAX, 'sortType' => static::SORT_UPDATED, 'sortDirection' => SORT_DESC]]); return $model; }
public static function fetchForEmail($email) { $actor = new static(); $user = \Users\Models\Users::emailExists($email); if (!empty($user->id)) { $actor->load(array('user_id' => $user->id)); $actor->user_id = $user->id; $actor->name = $user->email; } else { $actor->load(array('name' => $email)); $actor->name = $email; } if (empty($actor->id)) { $actor->is_excluded = false; $actor->is_excluded_last_checked = date('Y-m-d', strtotime('today')); $actor->is_bot = false; $actor->is_bot_last_checked = date('Y-m-d', strtotime('today')); $actor->save(); } if ($actor->is_bot_last_checked < date('Y-m-d', strtotime('today')) || $actor->is_excluded_last_checked < date('Y-m-d', strtotime('today'))) { $actor->is_excluded_last_checked = date('Y-m-d', strtotime('today')); $actor->is_bot_last_checked = date('Y-m-d', strtotime('today')); $actor->store(); } return $actor; }
/** * Check a field value exists in database or not, to keep a field unique. * * @param string $field The field name to check. * * @return boolean */ public function valueExists($field) { $record = new static($this->table, $this->keys, $this->db); $record->load(array($field => $this->{$field})); if ($record->{$field} != $this->{$field}) { return false; } // check record keys same as self $same = array(); foreach ($this->keys as $key) { $same[] = $record->{$key} == $this->{$key}; } // Key not same, means same value exists in other record. if (in_array(false, $same, true)) { return true; } return false; }
/** * @param $params * @return static */ public static function create($params) { $object = new static(); $object->load($params); return $object; }
/** * Gets the root of the specified tree, if possible * * @param unknown $tree * @return \Dsc\Mongo\Collections\Nested|boolean */ public static function getRoot($tree) { $root = new static(); $root->load(array('tree' => new \MongoId((string) $tree), 'is_root' => true)); if (!empty($root->id)) { return $root; } return false; }
protected function loadMany($items, $find = false) { $models = array(); foreach ($items as $item) { $model = new static($this->params); $model->load($item, $find); $models[] = $model; } return $models; }
public static function getById($id) { $c = new static(); return $c->load(array(static::FIELD_ID . '=?', $id)); }