本文整理汇总了PHP中Companies::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Companies::findOne方法的具体用法?PHP Companies::findOne怎么用?PHP Companies::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Companies
的用法示例。
在下文中一共展示了Companies::findOne方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getOwnerCompany
/**
* Return owner company
*
* @access public
* @param void
* @return Company
*/
static function getOwnerCompany()
{
return Companies::findOne(array('conditions' => array('`client_of_id` = ?', 0)));
// findOne
}
示例2: import_from_vcard
function import_from_vcard()
{
if (logged_user()->isGuest()) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
@set_time_limit(0);
ini_set('auto_detect_line_endings', '1');
if (isset($_GET['from_menu']) && $_GET['from_menu'] == 1) {
unset($_SESSION['go_back']);
}
if (isset($_SESSION['go_back'])) {
unset($_SESSION['go_back']);
ajx_current("start");
}
tpl_assign('import_type', 'contact');
if (!Contact::canAdd(logged_user(), active_or_personal_project())) {
flash_error(lang('no access permissions'));
ajx_current("empty");
return;
}
// if
$this->setTemplate('vcard_import');
$filedata = array_var($_FILES, 'vcard_file');
if (is_array($filedata) && !array_var($_GET, 'step2')) {
$filename = ROOT . '/tmp/' . logged_user()->getId() . 'temp.vcf';
copy($filedata['tmp_name'], $filename);
//ajx_current("empty");
} else {
if (array_var($_GET, 'step2')) {
$filename = ROOT . '/tmp/' . logged_user()->getId() . 'temp.vcf';
$result = $this->read_vcard_file($filename);
unlink($filename);
$import_result = array('import_ok' => array(), 'import_fail' => array());
foreach ($result as $contact_data) {
try {
DB::beginWork();
if (isset($contact_data['photo_tmp_filename'])) {
$file_id = FileRepository::addFile($contact_data['photo_tmp_filename'], array('public' => true));
$contact_data['picture_file'] = $file_id;
unlink($contact_data['photo_tmp_filename']);
unset($contact_data['photo_tmp_filename']);
}
if (isset($contact_data['company_name'])) {
$company = Companies::findOne(array("conditions" => "`name` = '" . mysql_real_escape_string($contact_data['company_name']) . "'"));
if ($company == null) {
$company = new Company();
$company->setName($contact_data['company_name']);
$company->setClientOfId(logged_user()->getCompanyId());
$company->save();
ApplicationLogs::createLog($company, null, ApplicationLogs::ACTION_ADD);
}
$contact_data['company_id'] = $company->getId();
unset($contact_data['company_name']);
}
$contact_data['import_status'] = '(' . lang('updated') . ')';
$fname = mysql_real_escape_string(array_var($contact_data, "firstname"));
$lname = mysql_real_escape_string(array_var($contact_data, "lastname"));
$contact = Contacts::findOne(array("conditions" => "firstname = '" . $fname . "' AND lastname = '" . $lname . "' OR email <> '' AND email = '" . array_var($contact_data, "email") . "'"));
$log_action = ApplicationLogs::ACTION_EDIT;
if (!$contact) {
$contact = new Contact();
$contact_data['import_status'] = '(' . lang('new') . ')';
$log_action = ApplicationLogs::ACTION_ADD;
$can_import = active_project() != null ? $contact->canAdd(logged_user(), active_project()) : can_manage_contacts(logged_user());
} else {
$can_import = $contact->canEdit(logged_user());
}
if ($can_import) {
$contact->setFromAttributes($contact_data);
$contact->save();
ApplicationLogs::createLog($contact, null, $log_action);
$contact->setTagsFromCSV(array_var($_GET, 'tags'));
if (active_project() instanceof Project) {
$pc = ProjectContacts::findOne(array("conditions" => "contact_id = " . $contact->getId() . " AND project_id = " . active_project()->getId()));
if (!$pc) {
$pc = new ProjectContact();
$pc->setContactId($contact->getId());
$pc->setProjectId(active_project()->getId());
$pc->setRole(array_var($contact_data, 'role'));
$pc->save();
}
$contact->addToWorkspace(active_project());
}
$import_result['import_ok'][] = array('firstname' => $fname, 'lastname' => $lname, 'email' => $contact_data['email'], 'import_status' => $contact_data['import_status']);
} else {
throw new Exception(lang('no access permissions'));
}
DB::commit();
} catch (Exception $e) {
DB::rollback();
$fail_msg = substr_utf($e->getMessage(), strpos_utf($e->getMessage(), "\r\n"));
$import_result['import_fail'][] = array('firstname' => $fname, 'lastname' => $lname, 'email' => $contact_data['email'], 'import_status' => $contact_data['import_status'], 'fail_message' => $fail_msg);
}
}
$_SESSION['go_back'] = true;
tpl_assign('import_result', $import_result);
}
}
//.........这里部分代码省略.........
示例3: check_company_name
function check_company_name()
{
ajx_current("empty");
$name = array_var($_GET, 'name');
$company = Companies::findOne(array('conditions' => 'UPPER(name) = ' . strtoupper($name)));
if ($company) {
ajx_extra_data(array("id" => $company->getId(), "name" => $company->getName()));
} else {
ajx_extra_data(array("id" => 0, "name" => $name));
}
}
示例4: getOwnerCompany
/**
* Return owner company
*
* @access public
* @param void
* @return Company
*/
static function getOwnerCompany()
{
$owner_company = null;
if (GlobalCache::isAvailable()) {
$owner_company = GlobalCache::get('owner_company', $success);
if ($success && $owner_company instanceof Company) {
return $owner_company;
}
}
$owner_company = Companies::findOne(array('conditions' => array('`client_of_id` = ?', 0), 'include_trashed' => true));
// findOne
if (GlobalCache::isAvailable()) {
GlobalCache::update('owner_company', $owner_company);
}
return $owner_company;
}