public static function getInstance($pid) { $post = new self($pid); $post->setPost(\WP_Post::get_instance($pid)); $post->fetch(); return $post; }
public static function get($bin = null) { $_bl = new self(); if (!is_numeric($bin)) { $_bl->setError('no bin provided or not numeric'); return $_bl; } return $_bl->fetch($bin); }
public static function display($templateFile = "") { $view = new self(); $view->templateFile = !empty($templateFile) ? $templateFile : $view->templateFile; $myfile_content = file_get_contents($view->viewFile); $myfile_content = $view->tag_replace($myfile_content); $view->create_template($view->templateFile_c, $myfile_content); $content = $view->fetch($view->templateFile_c . ".php"); $view->create_template($view->templateFile, $content); // 输出模板内容 $view->render($content); }
static function cleanup($profile_list) { $subs = new self(); $subs->profile_tag_id = $profile_list->id; $subs->find(); while ($subs->fetch()) { $profile = Profile::getKV('id', $subs->profile_id); Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile)); // Delete anyway $subs->delete(); Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile)); } }
/** * Based on vacancy ID and/or given permission return list of permission * that the logged in user have or return TRUE/FALSE if the loggedin user * has permission in the given permission list $checkPermissions respectively * * @param int $vacancyID vacancy ID to retrieve its permission for loggedin user * @param array $checkPermissions list of permission to check if loggedin user has any of the permission for given vacancy * whose id = $vacancyID * * @return boolean|array * @access public * @static */ public static function checkVacancyPermission($vacancyID, $checkPermissions = array(), $defaultPermissions = array()) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); $vacancyPermissions = array(); $dao = new self(); $dao->vacancy_id = $vacancyID; $dao->contact_id = $userID; $dao->find(); if (CRM_Core_Permission::check('administer CiviCRM')) { if (count($checkPermissions) && in_array('administer CiviCRM', $checkPermissions)) { return TRUE; } else { $vacancyPermissions[] = 'administer CiviCRM'; } } if (empty($defaultPermissions)) { $defaultPermissions[] = $checkPermissions; } if (count($defaultPermissions) && CRM_Core_Permission::check($defaultPermissions)) { return TRUE; } while ($dao->fetch()) { if (count($checkPermissions)) { if (in_array($dao->permission, $checkPermissions)) { return TRUE; } } else { $vacancyPermissions[] = $dao->permission; } } if (count($checkPermissions)) { return FALSE; } return $vacancyPermissions; }
/** * Create an instance of the specified tour. * * @param int $id The ID of the tour to load. * @return tour */ public static function instance($id) { $tour = new self(); return $tour->fetch($id); }
/** * renders a template that displays relationships that have granted a specific permission */ function myrel_permission_grants($params, $type = 'select') { if (!$params['permission']) { return '<strong><code>Permission must be specified in order to use myrel_' . $type . '</code></strong>'; } //end if // instantiate a new smarty object because we don't want to inherit // or override any variables $tpl = new self(); if ($params['user'] instanceof \PSUPerson) { $myuser = $params['user']; } elseif ($params['user']) { $myuser = \PSUPerson::get($params['user']); } elseif ($_SESSION['wp_id']) { $myuser = \PSUPerson::get($_SESSION['wp_id']); } else { $myuser = \PSUPerson::get($_SESSION['pidm']); } //end else if ($params['selected'] instanceof \PSUPerson) { $selected_user = $params['selected']; } elseif ($params['selected']) { $selected_user = \PSUPerson::get($params['selected']); } //end else $myuser->pidm; if ($params['hide_self']) { if (!isset($myuser->pidm)) { $tpl->assign('family_member', true); } else { $tpl->assign('family_member', false); } } $tpl->assign('myuser', $myuser); $tpl->assign('selected', $selected_user); $tpl->assign('type', $type); $tpl->assign('permission', $params['permission']); $tpl->assign('identifier', $params['identifier'] ? $params['identifier'] : 'id'); if ($params['url']) { if (strpos($params['url'], '?') === false) { $tpl->assign('no_url_params', true); } $tpl->assign('url', $params['url']); } //end if //check if we want a question mark added to our identifier if ($params['no_qm']) { $tpl->assign('no_qm', true); } //end question mark check return $tpl->fetch(PSU_BASE_DIR . '/app/core/templates/myrelationships.permission_grants.tpl'); }
/** * Update a record into database * * @param int $id Id of product * @param User $user Object user making update * @param int $notrigger Disable triggers * @param string $action Current action for hookmanager ('add' or 'update') * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user, $notrigger = false, $action = 'update') { global $langs, $conf, $hookmanager; $error = 0; // Check parameters if (!$this->label) { $this->label = 'MISSING LABEL'; } // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->label = trim($this->label); $this->description = trim($this->description); $this->note = isset($this->note) ? trim($this->note) : null; $this->weight = price2num($this->weight); $this->weight_units = trim($this->weight_units); $this->length = price2num($this->length); $this->length_units = trim($this->length_units); $this->surface = price2num($this->surface); $this->surface_units = trim($this->surface_units); $this->volume = price2num($this->volume); $this->volume_units = trim($this->volume_units); if (empty($this->tva_tx)) { $this->tva_tx = 0; } if (empty($this->tva_npr)) { $this->tva_npr = 0; } if (empty($this->localtax1_tx)) { $this->localtax1_tx = 0; } if (empty($this->localtax2_tx)) { $this->localtax2_tx = 0; } if (empty($this->status)) { $this->status = 0; } if (empty($this->status_buy)) { $this->status_buy = 0; } if (empty($this->country_id)) { $this->country_id = 0; } // Barcode value $this->barcode = trim($this->barcode); $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell = trim($this->accountancy_code_sell); $this->db->begin(); // Check name is required and codes are ok or unique. // If error, this->errors[] is filled if ($action != 'add') { $result = $this->verify(); // We don't check when update called during a create because verify was already done } if ($result >= 0) { if (empty($this->oldcopy)) { $org = new self($this->db); $org->fetch($this->id); $this->oldcopy = $org; } // test if batch management is activated on existing product if ($this->hasbatch() && !$this->oldcopy->hasbatch()) { $this->load_stock(); foreach ($this->stock_warehouse as $idW => $ObjW) { $qty_batch = 0; foreach ($ObjW->detail_batch as $detail) { $qty_batch += $detail->qty; } // Quantities in batch details are not same same as stock quantity // So we add a default batch record if ($ObjW->real != $qty_batch) { $ObjBatch = new Productbatch($this->db); $ObjBatch->batch = $langs->trans('BatchDefaultNumber'); $ObjBatch->qty = $ObjW->real - $qty_batch; $ObjBatch->fk_product_stock = $ObjW->id; if ($ObjBatch->create($user, 1) < 0) { $error++; $this->errors = $ObjBatch->errors; } } } } // For automatic creation if ($this->barcode == -1) { $this->barcode = $this->get_barcode($this, $this->barcode_type_code); } $sql = "UPDATE " . MAIN_DB_PREFIX . "product"; $sql .= " SET label = '" . $this->db->escape($this->label) . "'"; $sql .= ", ref = '" . $this->db->escape($this->ref) . "'"; $sql .= ", ref_ext = " . (!empty($this->ref_ext) ? "'" . $this->db->escape($this->ref_ext) . "'" : "null"); $sql .= ", tva_tx = " . $this->tva_tx; $sql .= ", recuperableonly = " . $this->tva_npr; $sql .= ", localtax1_tx = " . $this->localtax1_tx; $sql .= ", localtax2_tx = " . $this->localtax2_tx; $sql .= ", barcode = " . (empty($this->barcode) ? "null" : "'" . $this->db->escape($this->barcode) . "'"); $sql .= ", fk_barcode_type = " . (empty($this->barcode_type) ? "null" : $this->db->escape($this->barcode_type)); $sql .= ", tosell = " . $this->status; $sql .= ", tobuy = " . $this->status_buy; $sql .= ", tobatch = " . (empty($this->status_batch) || $this->status_batch < 0 ? '0' : $this->status_batch); $sql .= ", finished = " . (!isset($this->finished) || $this->finished < 0 ? "null" : (int) $this->finished); $sql .= ", weight = " . ($this->weight != '' ? "'" . $this->weight . "'" : 'null'); $sql .= ", weight_units = " . ($this->weight_units != '' ? "'" . $this->weight_units . "'" : 'null'); $sql .= ", length = " . ($this->length != '' ? "'" . $this->length . "'" : 'null'); $sql .= ", length_units = " . ($this->length_units != '' ? "'" . $this->length_units . "'" : 'null'); $sql .= ", surface = " . ($this->surface != '' ? "'" . $this->surface . "'" : 'null'); $sql .= ", surface_units = " . ($this->surface_units != '' ? "'" . $this->surface_units . "'" : 'null'); $sql .= ", volume = " . ($this->volume != '' ? "'" . $this->volume . "'" : 'null'); $sql .= ", volume_units = " . ($this->volume_units != '' ? "'" . $this->volume_units . "'" : 'null'); $sql .= ", seuil_stock_alerte = " . (isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '' ? "'" . $this->seuil_stock_alerte . "'" : "null"); $sql .= ", description = '" . $this->db->escape($this->description) . "'"; $sql .= ", url = " . ($this->url ? "'" . $this->db->escape($this->url) . "'" : 'null'); $sql .= ", customcode = '" . $this->db->escape($this->customcode) . "'"; $sql .= ", fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); $sql .= ", note = " . (isset($this->note) ? "'" . $this->db->escape($this->note) . "'" : 'null'); $sql .= ", duration = '" . $this->db->escape($this->duration_value . $this->duration_unit) . "'"; $sql .= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) . "'"; $sql .= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) . "'"; $sql .= ", desiredstock = " . (isset($this->desiredstock) && $this->desiredstock != '' ? $this->desiredstock : "null"); $sql .= ", fk_unit= " . (!$this->fk_unit ? 'NULL' : $this->fk_unit); $sql .= " WHERE rowid = " . $id; dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->id = $id; // Multilangs if (!empty($conf->global->MAIN_MULTILANGS)) { if ($this->setMultiLangs() < 0) { $this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; return -2; } } $action = 'update'; // Actions on extra fields (by external module or standard code) $hookmanager->initHooks(array('productdao')); $parameters = array('id' => $this->id); $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } } else { if ($reshook < 0) { $error++; } } if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('PRODUCT_MODIFY', $user); if ($result < 0) { $error++; } // End call triggers } if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->product->dir_output) { $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $res = dol_move($olddir, $newdir); if (!$res) { $this->error = 'ErrorFailToMoveDir'; $error++; } } } } if (!$error) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -$error; } } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { if (empty($conf->barcode->enabled)) { $this->error = $langs->trans("Error") . " : " . $langs->trans("ErrorProductAlreadyExists", $this->ref); } else { $this->error = $langs->trans("Error") . " : " . $langs->trans("ErrorProductBarCodeAlreadyExists", $this->barcode); } $this->db->rollback(); return -1; } else { $this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; $this->db->rollback(); return -2; } } } else { $this->db->rollback(); dol_syslog(get_class($this) . "::Update fails verify " . join(',', $this->errors), LOG_WARNING); return -3; } }
/** * @param int $id * * @return bool|conf_caja */ public static function get($id = 0) { $conf_caja = new self(); return $conf_caja->fetch($id); }
/** * @param int $id * * @return bool|pago_por_caja */ public static function get($id = 0) { $pago_por_caja = new self(); return $pago_por_caja->fetch($id); }