/** * @param $array * * @return array */ function arrayClean(array $array) { if (is_array($array) && count($array) === 1) { $array = array_shift($array); if (is_array($array)) { $array = arrayClean($array); } } return $array; }
function createFinalArray($reqids, $conn) { $out = array(); $q = "SELECT * FROM approved WHERE reqid=:reqid"; $cleanReqIds = arrayClean($reqids); foreach ($cleanReqIds as $project => $req) { // Loop through the projects. $sum = 0; for ($i = 0; $i < count($req); $i++) { // Loop through the request ids. $sql = $conn->prepare($q); $sql->BindParam(":reqid", $req[$i]); if ($sql->execute()) { $results = $sql->fetch(PDO::FETCH_ASSOC); $sum += intval($results["hours"]); } } // Set the variable for it $out[$project]["timeSpent"] = $sum; } return $out; }
/** * Creates a new NLM citation description and adds the data * of an array of property/value pairs as statements. * @param $metadataArray array * @return MetadataDescription */ function &getNlm30CitationDescriptionFromMetadataArray(&$metadataArray) { // Create a new citation description $citationDescription = new MetadataDescription('lib.pkp.plugins.metadata.nlm30.schema.Nlm30CitationSchema', ASSOC_TYPE_CITATION); // Add the meta-data to the description $metadataArray = arrayClean($metadataArray); if (!$citationDescription->setStatements($metadataArray)) { $translationParams = array('filterName' => $this->getDisplayName()); $this->addError(__('submission.citations.filter.invalidMetadata', $translationParams)); $nullVar = null; return $nullVar; } // Set display name in the meta-data description // to the corresponding value from the filter. This is important // so that we later know which result came from which filter. $citationDescription->setDisplayName($this->getDisplayName()); return $citationDescription; }
/** * Adds the data of an array of property/value pairs * as statements to an NLM citation description. * If no citation description is given, a new one will * be instantiated. * @param $metadataArray array * @param $citationDescription MetadataDescription * @return MetadataDescription */ function &addMetadataArrayToNlmCitationDescription(&$metadataArray, $citationDescription = null) { // Create a new citation description if no one was given if (is_null($citationDescription)) { $metadataSchema = new NlmCitationSchema(); $citationDescription = new MetadataDescription($metadataSchema, ASSOC_TYPE_CITATION); } // Add the meta-data to the description $metadataArray = arrayClean($metadataArray); if (!$citationDescription->setStatements($metadataArray)) { $nullVar = null; return $nullVar; } return $citationDescription; }