/** * Append a field to a source's fieldlayout programmatically. * * @param BaseModel $source The element's source (e.g. a EntryTypeModel or CategoryGroupModel) * @param FieldModel $field The field's model * @param int $index The index of the field on the tab (optional - defaults to 0) * @param string $tabName The fieldlayout's tab (optional) */ public static function addToFieldLayout(BaseModel $source, FieldModel $field, $index = 0, $tabName = '') { // Assemble layout array $layout = array($tabName => array()); // Get fieldlayout $fieldlayout = $source->getFieldLayout(); // Get element type $elementType = $source->elementType; // Get field layout tabs $fieldlayouttabs = $fieldlayout->getTabs(); // Loop through tabs foreach ($fieldlayouttabs as $tab) { // Gather tab fields for assembly $layout[$tab->name] = array(); // Get tab fields $tabfields = $tab->getFields(); // Loop through tab fields foreach ($tabfields as $tabfield) { // Gather field id's $layout[$tab->name][] = $tabfield->getField()->id; } } // Add the new fields to the tab array_splice($layout[$tabName], $index, 0, $field->id); // Asemble the layout // @TODO - Set required fields $assembledLayout = craft()->fields->assembleLayout($layout, array()); $assembledLayout->type = $elementType; // Set the assembled layout on the company $source->setFieldLayout($assembledLayout); }
/** * Append a field to a source's fieldlayout programmatically. * * @param string $elementType The fieldlayout's Element Type * @param BaseModel $source The element's source (e.g. a EntryTypeModel or CategoryGroupModel) * @param FieldModel $field The field's model * @param string $tabName The fieldlayout's tab * * @return BaseModel */ public static function addToFieldLayout($elementType, BaseModel $source, FieldModel $field, $tabName) { // Assemble layout array $layout = array(); // Get fieldlayout $fieldlayout = $source->getFieldLayout(); // Get field layout tabs $fieldlayouttabs = $fieldlayout->getTabs(); // Loop through tabs foreach ($fieldlayouttabs as $tab) { // Gather tab fields for assembly $layout[$tab->name] = array(); // Get tab fields $tabfields = $tab->getFields(); // Loop through tab fields foreach ($tabfields as $tabfield) { // Gather field id's $layout[$tab->name][] = $tabfield->getField()->id; } } // Add the new fields to the tab $layout[$tabName][] = $field->id; // Asemble the layout $assembledLayout = craft()->fields->assembleLayout($layout, array()); $assembledLayout->type = $elementType; // Set the assembled layout on the company $source->setFieldLayout($assembledLayout); // Return source return $source; }
/** * Delete a model. * * @param BaseModel $model */ public function delete($model, $flush = true) { $this->getDispatcher()->dispatch('model_before_delete', new ModelEvent($model, $this->getContainer())); $this->getDispatcher()->dispatch($model->getEventPrefix() . '_before_delete', new ModelEvent($model, $this->getContainer())); $this->_delete($model, $flush); $this->getDispatcher()->dispatch('model_after_delete', new ModelEvent($model, $this->getContainer())); $this->getDispatcher()->dispatch($model->getEventPrefix() . '_after_delete', new ModelEvent($model, $this->getContainer())); }
static function sql($sql) { if (!$sql) { return false; } $model = new BaseModel(); $result = $model->sql($sql); return $result; }
/** * Returns the translated definition for the word hatred * * {Injects a static method dependency for Craft::t} * * @param string $translator The name of the static class that defines t() * * @return string */ public function getTranslatedDefinition(BaseModel $model) { if ($model->validate()) { // Static method dependencies are just not elegant to work with // We can use $model->property but using $model->getAttribute('property') make this method more testable return call_user_func_array($this->translator . '::t', array($model->getAttribute('definition'))); } return false; }
/** * @param BaseModel $model * @param array|mixed $obj */ public function renderObjectContentSafely(&$model, $obj) { $content = $model->getContent(); foreach ($content as $attribute => $value) { if (is_string($value) && stripos($value, '{') !== false) { $model->getContent()->{$attribute} = $this->renderObjectTemplateSafely($value, $obj); } } }
/** * Perform actions after new user has been stored * @param BaseModel $user User that has just been stored */ public function onStore($user) { // Make the first user SuperAdmin if (count(User::all()) == 1 && !$user->hasRole('Super Admin')) { $user->roles()->attach(Role::where('name', '=', 'Super Admin')->firstOrFail()); Log::debug(e($user->username) . ': Assigning "Super Admin" role as first user to log in', [$user->api_key]); } // Generate an API key if the user does not have one if (empty($user->api_key)) { $user->api_key = md5(str_random(32)); $user->save(); Log::debug(e($user->username) . ': Generating API key', [$user->api_key]); } }
/** * The "booting" method of the model. * * @return void */ public static function boot() { parent::boot(); static::saving(function ($item) { $item->key = hash('sha512', microtime() . rand()); }); }
/** * 获取分表中的表名,获取数据库抽象类对象,获取Memcached抽象对象 * @param $pid */ function __construct($pid = '', $persister = false) { parent::__construct($pid); $this->dbConfig = BaseModel::getConfigVar('database'); //v($this->dbConfig); $this->setTable(); $dbName = "default"; $child_classname = get_class($this); if (isset($this->dbConfig['config_map_class'])) { foreach ($this->dbConfig['config_map_class'] as $key => $row) { if (in_array($child_classname, $row)) { $dbName = $key; break; } } } $this->dbName = $dbName; //Slave数据库预连接 if (empty($this->slaveDB)) { $this->slaveDB = $this->dbConnect($dbName, $persister); } //var_dump($this->slaveDB); if (empty($this->masterDB)) { $this->masterDB = $this->dbMasterConnect($dbName, $persister); //Master数据库预连接 } }
function export_to_db() { $array = parent::export_to_db(); $array["includes_tshirt"] = self::bool_to_db($this->includes_tshirt); $array["available_at_door"] = self::bool_to_db($this->available_at_door); return $array; }
public function __construct($pixie) { parent::__construct($pixie); $this->created_at = date('Y-m-d H:i:s'); $this->status = self::STATUS_NEW; $this->amount = 0; }
public function __construct($id = -1) { parent::__construct(); $q = "SELECT * FROM RiskMitigationPlan WHERE id = {$id}"; $db = new Dbase(); $res = $db->executeQuery($q); if ($res && $res->num_rows > 0) { if ($row = $res->fetch_assoc()) { $this->id = $row['id']; $this->prelaunch_checklist = $row['prelaunch_checklist']; $this->UAT_required = $row['UAT_required']; $this->UAT_conducted_by = $row['UAT_conducted_by']; $this->UAT_date = $row['UAT_date']; $this->vetted_by_stakeholders = $row['vetted_by_stakeholders']; $this->feedback_taken_from = $row['feedback_taken_from']; $this->feedback = $row['feedback']; $this->feedback_incorporated = $row['feedback_incorporated']; $this->feedback_incorporation_date = $row['feedback_incorporation_date']; $this->final_UAT = $row['final_UAT']; $this->final_UAT_conducted_by = $row['final_UAT_conducted_by']; $this->final_sign_off = $row['final_sign_off']; $this->GTM_sign_off = $row['GTM_sign_off']; $this->SVP_sign_off = $row['SVP_sign_off']; } } $res->free(); }
/** * Returns this model's normalized attribute configs. * * @return array */ public function getAttributeConfigs() { if (!isset($this->_attributeConfigs)) { $this->_attributeConfigs = parent::getAttributeConfigs(); } return $this->_attributeConfigs; }
public function setAttribute($name, $value) { parent::setAttribute($name, $value); if (in_array($name, $this->attributeNames())) { $attributes = $this->getAttributeConfigs(); $config = $attributes[$name]; // Handle special case attribute types switch ($config['type']) { case AttributeType::Bool: if ($value) { $value = (bool) $value; } break; case AttributeType::Number: if ($value) { $value = floatval(number_format($value, $config['decimals'])); } break; } $this->{$name} = $value; return true; } else { return false; } }
function canEdit($user) { if (parent::canEdit($user)) { return true; } if ($user) { // User created comment $this->user->get(); if ($this->user) { if ($this->user->id == $user->id) { return true; } } // User owns comment's entry $this->entry->get(); if ($this->entry) { $this->entry->user->get(); if ($this->entry->user) { if ($user->id == $this->entry->user->id) { return true; } } } } return false; }
public function Index() { parent::GetAccountInfo(); //get all commands $sql = "SELECT * FROM commands"; if ($stmt = $this->database->prepare($sql)) { $stmt->execute(); $row = $stmt->fetchAll(PDO::FETCH_ASSOC); $this->view->commands = $row; $stmt->closeCursor(); } //get current state command id $command_id = null; $sql = "SELECT command_id FROM state LIMIT 1"; if ($stmt = $this->database->prepare($sql)) { $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $command_id = $row['command_id']; $stmt->closeCursor(); } //get current command $sql = "SELECT * FROM commands WHERE id=:command_id"; if ($stmt = $this->database->prepare($sql)) { $stmt->bindParam(':command_id', $command_id, PDO::PARAM_STR); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->view->current_command = $row; $stmt->closeCursor(); } }
public function initialize() { parent::initialize(); $database = new Elements(); $database = $database->getDatabase(); $this->setConnectionService($database); }
public function __construct($params = null) { parent::__construct(); if (isset($params['config'])) { $this->config = $params['config']; } $this->scriptsDir = sprintf('%s/upgrade', $this->config->paths->configs); $this->systems = array('readme', 'base', 'db', 'fs'); $defaults = $this->config->defaults; $this->currentCodeVersion = $defaults->currentCodeVersion; $currentParts = explode('.', $this->currentCodeVersion); $this->currentCodeMajorVersion = $currentParts[0]; $this->currentCodeMinorVersion = $currentParts[1]; $this->currentCodeTrivialVersion = $currentParts[2]; $siteConfig = $this->config->site; if (isset($siteConfig->lastCodeVersion) && !empty($siteConfig->lastCodeVersion)) { $this->lastCodeVersion = $siteConfig->lastCodeVersion; } else { $this->lastCodeVersion = $defaults->lastCodeVersion; } $lastParts = explode('.', $this->lastCodeVersion); $this->lastCodeMajorVersion = $lastParts[0]; $this->lastCodeMinorVersion = $lastParts[1]; $this->lastCodeTrivialVersion = $lastParts[2]; }
/** * @param $id * @return bool * @author Erik Aybar */ public static function destroy($id) { $upload = static::getOne($id); $real_path = static::getRealPathFromStoredName($upload['stored_filename']); $destroyed = file_exists($real_path) && unlink($real_path) && parent::destroy($id); return $destroyed; }
public function save() { $parameters = array('name' => $this->name, 'password' => $this->password, 'admin' => $this->admin); $query = 'INSERT INTO Forum_User (name, password, admin) VALUES (:name, :password, :admin) RETURNING id'; $row = parent::queryWithParametersLimit1($query, $parameters); $this->id = $row['id']; }
function __construct() { parent::__construct(); // @deprecated: to be removed osc_run_hook('init_admin'); osc_run_hook('init_admin_insecure'); }
public function __construct($attributes = null) { if (is_array($attributes)) { parent::__construct($attributes); } $this->validators = array('validate_username', 'validate_password'); }
public function __construct($id = -1) { parent::__construct(); $q = "SELECT * FROM BRDRequirements WHERE id = {$id}"; $db = new Dbase(); $res = $db->executeQuery($q); if ($res && $res->num_rows > 0) { if ($row = $res->fetch_assoc()) { $this->id = $row['id']; $this->BRD_ref_number = $row['BRD_ref_number']; $this->BRD_date = $row['BRD_date']; $this->approved = $row['approved']; $this->approved_by = $row['approved_by']; $this->approval_date = $row['approval_date']; $this->stakeholders = $row['stakeholders']; $this->stakeholder_BU = $row['stakeholder_BU']; $this->expected_impact_BU = $row['expected_impact_BU']; $this->stakeholder_approved = $row['stakeholder_approved']; $this->stk_app_date = $row['stk_app_date']; $this->responsible = $row['responsible']; $this->accountable = $row['accountable']; $this->consulted = $row['consulted']; $this->informed = $row['informed']; } } $res->free(); }
/** * Sets a new start time and creates an instance * of both the Profile and Message collection * * @return Null */ public function __construct() { parent::__construct(); $this->startTime = microtime(true); $this->profiles = new Collection('GroundSix\\Component\\Model\\Profile'); $this->messages = new Collection('GroundSix\\Component\\Model\\Message'); }
public function update($project_id, $data) { $project_id = intval($project_id); if (!$project_id) { return NULL; } M("ProjectManageRecords")->where("project_id = {$project_id}")->delete(); $last_id = 0; for ($i = 0; $i < 20; $i++) { $v['project_id'] = $project_id; $v['change_time'] = $data['change_time_' . $i]; $v['from_manager_id'] = intval($data['from_manager_id_' . $i]); $v['from_manager_name'] = M('Users')->getFieldById($v['from_manager_id'], 'realname'); $v['manager_id'] = intval($data['manager_id_' . $i]); $v['manager_name'] = M('Users')->getFieldById($v['manager_id'], 'realname'); $v['status_note'] = $data['status_note_' . $i]; $v['note'] = $data['note_' . $i]; if (!$v['project_id'] || !$v['change_time'] || !$v['manager_id']) { continue; } $v['create_time'] = date('Y-m-d H:i:s'); $v['create_user_id'] = parent::getLoginUserId(); $last_id = $v['manager_id']; D('ProjectManageRecords')->add($v); } return $last_id; }
function __construct($con, $config, $routes) { $this->con = $con; $this->config = $config; $this->routes = $routes; BaseModel::$con = $con; }
/** * @return mixed */ public function getKey() { if (!$this->getKeyName()) { throw new \InvalidArgumentException("Virtual model doesn't have a primary key"); } return parent::getKey(); }
/** * @inheritDoc BaseModel::setAttribute() * * @param string $name * @param mixed $value * * @return bool|null */ public function setAttribute($name, $value) { if ($name == 'releases') { $value = PluginNewReleaseModel::populateModels($value); } parent::setAttribute($name, $value); }
/** * @inheritDoc BaseModel::setAttribute() * * @param string $name * @param mixed $value * * @return bool|null */ public function setAttribute($name, $value) { if ($name == 'plugins') { $value = PluginUpdateModel::populateModels($value); } parent::setAttribute($name, $value); }
/** * {@inheritdoc} */ public function __construct($configuration) { parent::__construct($configuration); $this->person = PersonReferenceModel::create($configuration['person']); $this->list = ListReferenceModel::create($configuration['list']); $this->alreadyMember = $configuration['already_member']; }