/** * is utilized for reading data from inaccessible members. * * @param $name string * @return mixed * @link http://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members */ function readAll() { //supponiamo di leggere qualcosa dal db, come fa un manager (ex model) $b = new Bean(); $b->setProva("ciao"); $b->setProva2("ciao"); $b2 = new Bean(); $b2->setProva("ciao2"); $b2->setProva2("ciao2"); return array($b, $b2); }
function log($priority, $message, $file = null, $line = null, $e = null) { $schema = "DEFAULT"; $table = "logs"; $trace = ""; if (!empty($e)) { $trace = $e->getTraceAsString(); } if (is_object($message)) { $message = JSON::encode($message); } $now = new Date(); $log = array(); $log["priority"] = $priority; $log["message"] = $message; $log["trace"] = $trace; $log["file"] = $file; $log["line"] = $line; $log["createdBy"] = "SYS"; $log["createdTime"] = $now; $log["updatedBy"] = "SYS"; $log["updatedTime"] = $now; $driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER; $insert = new Insert($table, $log, $schema); $link = DB::connect(); $success = mysql_query($insert->sql(), $link); if (!$success) { $result = Bean::invoke(String::camelize('_'.$driver.'_driver'), "error", array($schema)); throw new Exception("Cannot persist object. ".$result); } }
public function result($xmlData, $intLevel = 0) { if (!$this->hasAttribute('src')) { return; } return Bean::create(file_get_contents($this->attribute('src')))->run($xmlData); }
function validate(&$action) { Apu::dispatch($action->validation); if (!empty($GLOBALS["VALIDATION"])) { reset($GLOBALS["VALIDATION"]); while (list($method, $methodValidations) = each($GLOBALS["VALIDATION"])) { if ($method == "-" || $method == $action->method) { reset($methodValidations); while (list($field, $fieldValidations) = each($methodValidations)) { $fieldValue = $action->get($field); while (list($i, $val) = each($fieldValidations)) { $function = $val["validate"]; $not = false; if (substr($val["validate"], 0, 1) == "!") { $function = trim($function, "!"); $not = true; } $validate = Bean::invoke("Validation", $function, array(&$action, $val, $field, $not)); if ($not) { $validate = !$validate; } if (!$validate) { $defaultMessage = $GLOBALS["CFG_VALIDATION"]->MSG[$val["validate"]]; $action->addMsgMessage($defaultMessage, $field); } } } } } } }
function remove($name, $property = null) { Session::start(); if (empty($property)) { unset($_SESSION[$name]); } else { Bean::set($_SESSION[$name], $property, null); } }
function valueString() { reset($this->meta); $values = array(); while(list(,$meta) = each($this->meta)) { $value = Bean::get($this->value, String::camelize($meta["name"])); $values[] = $this->escape($value, $meta["name"]); } return implode(', ', $values); }
function populate() { $scope = $GLOBALS["CFG_ACTION"]->SCOPE; $scopeVars = Bean::get('$'.$scope); while (list($key, $var) = each($scopeVars)) { if ($scope == "_REQUEST" || $scope == "_POST" || $scope == "_GET") { $key = str_replace("_", ".", $key); } Bean::set($this, $key, $var); } }
function doInvoke() { try { $result = Bean::invoke($this->md, $this->mt, $this->ps); $this->json = $result; } catch (Exception $e) { $error = new stdClass(); $error->error = $e->getMessage(); $this->json = $error; } }
function delete($table, $obj, $schema = "DEFAULT") { $driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER; $objId = Bean::get($obj, "__ID__"); if (empty($objId)) { throw new Exception("Cannot delete unpersisted object"); } $delete = new Delete($table, $obj, $schema); $success = DB::query($delete, $schema); if (!$success) { $result = Bean::invoke(String::camelize('_'.$driver.'_driver'), "error", array($schema)); throw new Exception("Cannot delete object. ".$result); } }
/** * Internal: Add Leads that match the specified email address to the result array * * @param Array $output_list -- List of matching detail records * @param String $email_address -- Email address * @param Bean $seed_lead -- Seed Lead Bean * @param int $msi_id -- output array offset. */ function add_leads_matching_email_address(&$output_list, $email_address, &$seed_lead, &$msi_id) { $safe_email_address = addslashes($email_address); if (!$seed_lead->ACLAccess('ListView')) { return; } $where = "leads.email1 like '{$safe_email_address}' OR leads.email2 like '{$safe_email_address}'"; $response = $seed_lead->get_list("last_name, first_name", $where, 0); $leadList = $response['list']; // create a return array of names and email addresses. foreach ($leadList as $lead) { $output_list[] = array("name1" => $lead->first_name, "name2" => $lead->last_name, "association" => $lead->account_name, "type" => 'Lead', "id" => $lead->id, "msi_id" => $msi_id, "email_address" => $lead->email1); $msi_id = $msi_id + 1; } }
/** * Internal: Add Leads that match the specified email address to the result array * * @param Array $output_list -- List of matching detail records * @param String $email_address -- Email address * @param Bean $seed_lead -- Seed Lead Bean * @param int $msi_id -- output array offset. */ function add_leads_matching_email_address(&$output_list, $email_address, &$seed_lead, &$msi_id) { $safe_email_address = $GLOBALS['db']->quote($email_address); if (!$seed_lead->ACLAccess('ListView')) { return; } $leadList = $seed_lead->emailAddress->getBeansByEmailAddress($safe_email_address); // create a return array of names and email addresses. foreach ($leadList as $lead) { if (!is_a($lead, 'Lead')) { continue; } $output_list[] = array("name1" => $lead->first_name, "name2" => $lead->last_name, "association" => $lead->account_name, "type" => 'Lead', "id" => $lead->id, "msi_id" => $msi_id, "email_address" => $lead->email1); $msi_id = $msi_id + 1; } }
/** * Fetches an external dataset. * * @param string $strURL The URL or directory of the file * @param string $strType Declares the type of data (plain*, xml, bean, json) * @param string $strMethod Loading method for the external resource: open*, get, post * @return object|string */ private function xdrRetriveExternal($strURL, $strType = 'plain', $strMethod = 'open') { // TESTING: $this->probe('xdrRetriveExternal', 'Trying to load the external resource now: '.$strURL.'; Method: '.$strMethod.'; Type: '.$strType, 4); $strData = null; $strMethod = strtolower($strMethod); switch ($strMethod) { case 'get': if (class_exists('\\REST\\Client')) { $req = new \REST\Client($strURL); $strData = $req->post(); } else { // If the REST library is not present, simply use file_get_contents $strData = file_get_contents($strURL); } break; case 'post': if (!class_exists('\\REST\\Client')) { throw new Exception('Class REST\\Client not found. Please include the library from https://github.com/zeyon/rest'); } $req = new \REST\Client($strURL); $strData = $req->post(); break; default: $strData = is_readable(self::$basepath . $strURL) ? file_get_contents(self::$basepath . $strURL) : false; break; } if (!$strData) { return; } if ($strType == 'xml') { return Xml::create($strData); } elseif ($strType == 'bean') { return Bean::create($strData); } elseif ($strType == 'json') { return json_decode($strData, 1); } else { return $strData; } }
function escape($value, $name) { $schema = $this->schema; $driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER; $value = Bean::invoke(String::camelize('_'.$driver.'_driver'), "escape", array($value, $name, $this->meta)); return $value; }
/** * @test */ public function aliasingBean() { $bean = new Bean(['value' => ['alias' => 'someAlias']]); self::assertSame($bean->getAlias(), 'someAlias'); }
/** * Get Records All. * * @return array */ public function get() { $this->data = Bean::all($this->module, $this->options); return ['data' => suite_params_array_response_multiple($this->data['entry_list']), 'paginate' => ['count' => (int) $this->data['result_count'], 'total' => (int) $this->data['total_count'], 'first' => 1, 'last' => $this->paginationLast(), 'prev' => $this->paginationPrev(), 'next' => $this->paginationNext(), 'limit' => (int) $this->options['max_results']]]; }
} $elem .= '</select>'; } elseif ($this->attribute('type') == 'multi') { $elem .= '<textarea class="form-control" name="' . $id . '" name="' . $name . '" rows="' . ($this->hasAttribute('rows') ? $this->attribute('rows') : 3) . '"></textarea>'; } else { $elem .= '<input type="' . ($this->hasAttribute('type') ? $this->attribute('type') : 'text') . '"' . ($this->hasAttribute('placeholder') ? ' placeholder="' . $this->attribute('placeholder') . '"' : '') . ' class="form-control" name="' . $id . '" name="' . $name . '" />'; } return $elem . '</div></div>'; } } $xlyDoc = Bean::create('<?xml version="1.0" encoding="UTF-8"?> <html> <form:frame width="2"> <form:field name="Firstname" label="First name" required="true" /> <form:field name="Lastname" label="Last name" required="true" /> <form:field name="Email" label="E-mail" type="email" /> <form:field name="region" label="Region?" placeholder="- Please Select -"> <option>North America</option> <option>Central America</option> <option>South America</option> <option>European Union</option> <option>Eastern Europe</option> <option>Africa</option> <option>Middle East</option> <option>Asia</option> <option>Oceania</option> <option>The Caribbean</option> </form:field> </form:frame> </html>'); echo $xlyDoc->run();
function doEditOk() { $lookup = LookupDao::byId($this->id); Bean::copy($this->lookup, $lookup, array("type", "code", "name", "description", "priority")); $this->lookup = $lookup; $this->save("lookup"); if (!empty($this->messages)) { Msg::save($this->messages); Apu::redirect("lookup/edit"); } if (empty($this->lookup["priority"])) { $this->lookup["priority"] = 0; } $this->lookup["updatedBy"] = LookupDao::loginUserName(); $this->lookup["updatedTime"] = new Raw("now()"); try { DB::persist("lookups", $this->lookup); $this->remove("lookup"); Apu::redirect("lookup"); } catch (Exception $e) { $this->addMsgString($e->getMessage()); Msg::save($this->messages); Apu::redirect("lookup/edit"); } }
/** * Fetches an external dataset. * * @param string $strURL The URL or directory of the file * @param string strType Declares the type of data (plain*, xml, bean, json) * @param string $strMethod Loading method for the external resource: open*, get, post * @return object|string */ private function xdr_external($strURL, $strType = 'plain', $strMethod = 'open') { // TESTING: $this->probe('xdr_external', 'Trying to load the external resource now: '.$strURL.'; Method: '.$strMethod.'; Type: '.$strType, 4); $strData = null; $strMethod = strtolower($strMethod); switch ($strMethod) { case 'get': case 'post': if (class_exists('\\REST\\Client')) { $req = new \REST\Client($strURL); $strData = $strMethod == 'get' ? $req->get() : $req->post(); } break; default: $strData = is_readable(self::$basepath . $strURL) ? file_get_contents(self::$basepath . $strURL) : false; break; } if (!$strData) { return; } if ($strType == 'xml') { return Xml::create($strData); } elseif ($strType == 'bean') { return Bean::create($strData); } elseif ($strType == 'json') { return json_decode($strData, 1); } else { return $strData; } }
function copy($source, &$destination, $includes) { while(list(,$include) = each($includes)) { $value = Bean::get($source, $include); Bean::set($destination, $include, $value); } }
function listen() { $this->pre(); $methodName = String::camelize("do_".$this->method); Bean::invoke($this, $methodName); $this->post(); }
/** * Initialize the parser by loading a file or an XML string * * @param string $strXML Name of the XML file or XML string * @param Xml|Bean $xmlMom Parent node * @param bool $bolLoadFile Load from file or parse locally * @return Xml|Bean */ public static function returnNode($strXML, $xmlMom, $bolLoadFile) { try { if ($bolLoadFile) { $strXML = file_get_contents($strXML); } } catch (Exception $e) { throw new Exception("Could not read file: " . $strXML); } if ($xmlResult = $xmlMom->parse($strXML)) { return $xmlResult; } throw new Exception('Could not create XML node due to an parsing error.'); }