📄 company.class.php
字号:
*/ function canAddClient(User $user) { if (!$user->isMemberOf($this)) { return false; } return $user->isAccountOwner() || $user->isAdministrator($this); } // canAddClient /** * Check if this user can add new account to this company * * @access public * @param User $user * @return boolean */ function canAddUser(User $user) { return User::canAdd($user, $this); } // canAddUser /** * Check if user can update permissions of this company * * @param User $user * @return boolean */ function canUpdatePermissions(User $user) { if ($this->isOwner()) { return false; // owner company! } // if return $user->isAdministrator(); } // canUpdatePermissions // --------------------------------------------------- // URLs // --------------------------------------------------- /** * Show company card page * * @access public * @param void * @return null */ function getCardUrl() { return get_url('company', 'card', $this->getId()); } // getCardUrl /** * Return view company URL * * @access public * @param void * @return string */ function getViewUrl() { if ($this->getId() == owner_company()->getId()) { return get_url('administration', 'company'); } else { return get_url('company', 'view_client', $this->getId()); } // if } // getViewUrl /** * Edit owner company * * @access public * @param void * @return null */ function getEditUrl() { return $this->isOwner() ? get_url('company', 'edit') : get_url('company', 'edit_client', $this->getId()); } // getEditUrl /** * Return delete company URL * * @access public * @param void * @return string */ function getDeleteClientUrl() { return get_url('company', 'delete_client', $this->getId()); } // getDeleteClientUrl /** * Return update permissions URL * * @param void * @return string */ function getUpdatePermissionsUrl() { return get_url('company', 'update_permissions', $this->getId()); } // getUpdatePermissionsUrl /** * Return add user URL * * @access public * @param void * @return string */ function getAddUserUrl() { return get_url('user', 'add', array('company_id' => $this->getId())); } // getAddUserUrl /** * Return update avatar URL * * @access public * @param void * @return string */ function getEditLogoUrl() { return get_url('company', 'edit_logo', $this->getId()); } // getEditLogoUrl /** * Return delete logo URL * * @access public * @param void * @return string */ function getDeleteLogoUrl() { return get_url('company', 'delete_logo', $this->getId()); } // getDeleteLogoUrl // --------------------------------------------------- // Logo // --------------------------------------------------- /** * Set logo value * * @param string $source Source file * @param integer $max_width * @param integer $max_height * @param boolean $save Save object when done * @return null */ function setLogo($source, $max_width = 50, $max_height = 50, $save = true) { if (!is_readable($source)) { return false; } do { $temp_file = ROOT . '/cache/' . sha1(uniqid(rand(), true)); } while (is_file($temp_file)); try { Env::useLibrary('simplegd'); $image = new SimpleGdImage($source); $thumb = $image->scale($max_width, $max_height, SimpleGdImage::BOUNDARY_DECREASE_ONLY, false); $thumb->saveAs($temp_file, IMAGETYPE_PNG); $public_filename = PublicFiles::addFile($temp_file, 'png'); if ($public_filename) { $this->setLogoFile($public_filename); if ($save) { $this->save(); } // if } // if $result = true; } catch(Exception $e) { $result = false; } // try // Cleanup if (!$result && $public_filename) { PublicFiles::deleteFile($public_filename); } // if @unlink($temp_file); return $result; } // setLogo /** * Delete logo * * @param void * @return null */ function deleteLogo() { if ($this->hasLogo()) { PublicFiles::deleteFile($this->getLogoFile()); $this->setLogoFile(''); } // if } // deleteLogo /** * Returns path of company logo. This function will not check if file really exists * * @access public * @param void * @return string */ function getLogoPath() { return PublicFiles::getFilePath($this->getLogoFile()); } // getLogoPath /** * description * * @access public * @param void * @return string */ function getLogoUrl() { return $this->hasLogo() ? PublicFiles::getFileUrl($this->getLogoFile()) : get_image_url('logo.gif'); } // getLogoUrl /** * Returns true if this company have logo file value and logo file exists * * @access public * @param void * @return boolean */ function hasLogo() { return trim($this->getLogoFile()) && is_file($this->getLogoPath()); } // hasLogo // --------------------------------------------------- // System functions // --------------------------------------------------- /** * Validate this object before save * * @param array $errors * @return boolean */ function validate(&$errors) { if (!$this->validatePresenceOf('name')) { $errors[] = lang('company name required'); } // if if ($this->validatePresenceOf('email')) { if (!is_valid_email($this->getEmail())) { $errors[] = lang('invalid email address'); } // if } // if if ($this->validatePresenceOf('homepage')) { if (!is_valid_url($this->getHomepage())) { $errors[] = lang('company homepage invalid'); } // if } // if } // validate /** * Delete this company and all related data * * @access public * @param void * @return boolean * @throws Error */ function delete() { if ($this->isOwner()) { throw new Error(lang('error delete owner company')); } // if $users = $this->getUsers(); if (is_array($users) && count($users)) { foreach ($users as $user) { $user->delete(); } } // if ProjectCompanies::clearByCompany($this); $this->deleteLogo(); return parent::delete(); } // delete // --------------------------------------------------- // ApplicationDataObject implementation // --------------------------------------------------- /** * Return object URl * * @access public * @param void * @return string */ function getObjectUrl() { return logged_user()->isAdministrator() ? $this->getViewUrl() : $this->getCardUrl(); } // getObjectUrl /** * Return object type name * * @param void * @return string */ function getObjectTypeName() { return lang('company'); } // getObjectTypeName } // Company ?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -